diff --git a/src/broadcom/cle/gen_pack_header.py b/src/broadcom/cle/gen_pack_header.py index 0090b616d50..029856a3a9b 100644 --- a/src/broadcom/cle/gen_pack_header.py +++ b/src/broadcom/cle/gen_pack_header.py @@ -296,39 +296,39 @@ class Group(object): value = "%s - 1" % value if field.type == "mbo": - s = "__gen_mbo(%d, %d)" % \ + s = "util_bitpack_ones(%d, %d)" % \ (start, end) elif field.type == "address": extra_shift = (31 - (end - start)) // 8 * 8 s = "__gen_address_offset(&values->%s)" % byte.address.name elif field.type == "uint": - s = "__gen_uint(%s, %d, %d)" % \ + s = "util_bitpack_uint(%s, %d, %d)" % \ (value, start, end) elif field.type in self.parser.enums: - s = "__gen_uint(%s, %d, %d)" % \ + s = "util_bitpack_uint(%s, %d, %d)" % \ (value, start, end) elif field.type == "int": - s = "__gen_sint(%s, %d, %d)" % \ + s = "util_bitpack_sint(%s, %d, %d)" % \ (value, start, end) elif field.type == "bool": - s = "__gen_uint(%s, %d, %d)" % \ + s = "util_bitpack_uint(%s, %d, %d)" % \ (value, start, end) elif field.type == "float": s = "#error %s float value mixed in with other fields" % name elif field.type == "f187": - s = "__gen_uint(fui(%s) >> 16, %d, %d)" % \ + s = "util_bitpack_uint(fui(%s) >> 16, %d, %d)" % \ (value, start, end) elif field.type == "offset": s = "__gen_offset(%s, %d, %d)" % \ (value, start, end) elif field.type == 'ufixed': - s = "__gen_ufixed(%s, %d, %d, %d)" % \ + s = "util_bitpack_ufixed(%s, %d, %d, %d)" % \ (value, start, end, field.fractional_size) elif field.type == 'sfixed': - s = "__gen_sfixed(%s, %d, %d, %d)" % \ + s = "util_bitpack_sfixed(%s, %d, %d, %d)" % \ (value, start, end, field.fractional_size) elif field.type in self.parser.structs: - s = "__gen_uint(v%d_%d, %d, %d)" % \ + s = "util_bitpack_uint(v%d_%d, %d, %d)" % \ (index, field_index, start, end) field_index = field_index + 1 else: diff --git a/src/broadcom/cle/v3d_packet_helpers.h b/src/broadcom/cle/v3d_packet_helpers.h index 2b5e32ff215..41054618e3a 100644 --- a/src/broadcom/cle/v3d_packet_helpers.h +++ b/src/broadcom/cle/v3d_packet_helpers.h @@ -24,87 +24,20 @@ #ifndef MESA_V3D_PACKET_HELPERS_H #define MESA_V3D_PACKET_HELPERS_H -#include -#include -#include -#include -#include -#include "util/u_math.h" +#include "util/bitpack_helpers.h" #ifdef HAVE_VALGRIND #include #include #define VG(x) x -#ifndef NDEBUG -#define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x)) -#endif #else #define VG(x) ((void)0) #endif -#ifndef __gen_validate_value -#define __gen_validate_value(x) -#endif -/* -#ifndef __gen_address_type -#error #define __gen_address_type before including this file -#endif - -#ifndef __gen_user_data -#error #define __gen_combine_address before including this file -#endif -*/ -union __gen_value { - float f; - uint32_t dw; -}; - -static inline uint64_t -__gen_mbo(uint32_t start, uint32_t end) -{ - return (~0ull >> (64 - (end - start + 1))) << start; -} - -static inline uint64_t -__gen_uint(uint64_t v, uint32_t start, uint32_t end) -{ - __gen_validate_value(v); - -#ifndef NDEBUG - const int width = end - start + 1; - if (width < 64) { - const uint64_t max = (1ull << width) - 1; - assert(v <= max); - } -#endif - - return v << start; -} - -static inline uint64_t -__gen_sint(int64_t v, uint32_t start, uint32_t end) -{ - const int width = end - start + 1; - - __gen_validate_value(v); - -#ifndef NDEBUG - if (width < 64) { - const int64_t max = (1ll << (width - 1)) - 1; - const int64_t min = -(1ll << (width - 1)); - assert(min <= v && v <= max); - } -#endif - - const uint64_t mask = ~0ull >> (64 - width); - - return (v & mask) << start; -} - static inline uint64_t __gen_offset(uint64_t v, uint32_t start, uint32_t end) { - __gen_validate_value(v); + util_bitpack_validate_value(v); #ifndef NDEBUG uint64_t mask = (~0ull >> (64 - (end - start + 1))) << start; @@ -114,50 +47,6 @@ __gen_offset(uint64_t v, uint32_t start, uint32_t end) return v; } -static inline uint32_t -__gen_float(float v) -{ - __gen_validate_value(v); - return ((union __gen_value) { .f = (v) }).dw; -} - -static inline uint64_t -__gen_sfixed(float v, uint32_t start, uint32_t end, uint32_t fract_bits) -{ - __gen_validate_value(v); - - const float factor = (1 << fract_bits); - -#ifndef NDEBUG - const float max = ((1 << (end - start)) - 1) / factor; - const float min = -(1 << (end - start)) / factor; - assert(min <= v && v <= max); -#endif - - const int64_t int_val = llroundf(v * factor); - const uint64_t mask = ~0ull >> (64 - (end - start + 1)); - - return (int_val & mask) << start; -} - -static inline uint64_t -__gen_ufixed(float v, uint32_t start, uint32_t end, uint32_t fract_bits) -{ - __gen_validate_value(v); - - const float factor = (1 << fract_bits); - -#ifndef NDEBUG - const float max = ((1 << (end - start + 1)) - 1) / factor; - const float min = 0.0f; - assert(min <= v && v <= max); -#endif - - const uint64_t uint_val = llroundf(v * factor); - - return uint_val << start; -} - static inline uint64_t __gen_unpack_uint(const uint8_t *restrict cl, uint32_t start, uint32_t end) {