diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2023-01-28 08:15:04 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2023-01-28 08:15:04 +0000 |
commit | 1c5c7896c1d54abd25c0f33ca996165b359eecb3 (patch) | |
tree | bc5a10bbe89ecd4008a5bed7a029babc992f66b5 /lib/mesa/src/util/u_math.h | |
parent | c55dff45ea3a2c70e45601240b248017acc48198 (diff) |
Import Mesa 22.3.4
Diffstat (limited to 'lib/mesa/src/util/u_math.h')
-rw-r--r-- | lib/mesa/src/util/u_math.h | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/lib/mesa/src/util/u_math.h b/lib/mesa/src/util/u_math.h index d3a062f9e..78790f30b 100644 --- a/lib/mesa/src/util/u_math.h +++ b/lib/mesa/src/util/u_math.h @@ -39,10 +39,11 @@ #define U_MATH_H -#include "c99_math.h" +#include "c99_compat.h" #include <assert.h> #include <float.h> #include <stdarg.h> +#include <math.h> #include "bitscan.h" #include "u_endian.h" /* for UTIL_ARCH_BIG_ENDIAN */ @@ -579,17 +580,31 @@ util_bswap16(uint16_t n) } /** - * Extend sign. + * Mask and sign-extend a number + * + * The bit at position `width - 1` is replicated to all the higher bits. + * This makes no assumptions about the high bits of the value and will + * overwrite them with the sign bit. + */ +static inline int64_t +util_mask_sign_extend(uint64_t val, unsigned width) +{ + assert(width > 0 && width <= 64); + unsigned shift = 64 - width; + return (int64_t)(val << shift) >> shift; +} + +/** + * Sign-extend a number + * + * The bit at position `width - 1` is replicated to all the higher bits. + * This assumes and asserts that the value fits into `width` bits. */ static inline int64_t util_sign_extend(uint64_t val, unsigned width) { - assert(width > 0); - if (val & (UINT64_C(1) << (width - 1))) { - return -(int64_t)((UINT64_C(1) << width) - val); - } else { - return val; - } + assert(width == 64 || val < (UINT64_C(1) << width)); + return util_mask_sign_extend(val, width); } static inline void* @@ -770,9 +785,9 @@ static inline bool util_is_vbo_upload_ratio_too_large(unsigned draw_vertex_count, unsigned upload_vertex_count) { - if (draw_vertex_count > 1024) + if (upload_vertex_count > 256) return upload_vertex_count > draw_vertex_count * 4; - else if (draw_vertex_count > 32) + else if (upload_vertex_count > 64) return upload_vertex_count > draw_vertex_count * 8; else return upload_vertex_count > draw_vertex_count * 16; |