|
44 | 44 | #define %(guard)s
|
45 | 45 |
|
46 | 46 | #include <stdio.h>
|
47 |
| -#include <stdint.h> |
48 |
| -#include <stdbool.h> |
49 |
| -#include <assert.h> |
50 |
| -#include <math.h> |
| 47 | +
|
| 48 | +#include "util/bitpack_helpers.h" |
51 | 49 |
|
52 | 50 | #ifndef __gen_validate_value
|
53 | 51 | #define __gen_validate_value(x)
|
|
62 | 60 | #define NDEBUG_UNUSED
|
63 | 61 | #endif
|
64 | 62 |
|
65 |
| -union __intel_value { |
66 |
| - float f; |
67 |
| - uint32_t dw; |
68 |
| -}; |
69 |
| -
|
70 |
| -static inline __attribute__((always_inline)) uint64_t |
71 |
| -__gen_mbo(uint32_t start, uint32_t end) |
72 |
| -{ |
73 |
| - return (~0ull >> (64 - (end - start + 1))) << start; |
74 |
| -} |
75 |
| -
|
76 |
| -static inline __attribute__((always_inline)) uint64_t |
77 |
| -__gen_uint(uint64_t v, uint32_t start, NDEBUG_UNUSED uint32_t end) |
78 |
| -{ |
79 |
| - __gen_validate_value(v); |
80 |
| -
|
81 |
| -#ifndef NDEBUG |
82 |
| - const int width = end - start + 1; |
83 |
| - if (width < 64) { |
84 |
| - const uint64_t max = (1ull << width) - 1; |
85 |
| - assert(v <= max); |
86 |
| - } |
87 |
| -#endif |
88 |
| -
|
89 |
| - return v << start; |
90 |
| -} |
91 |
| -
|
92 |
| -static inline __attribute__((always_inline)) uint64_t |
93 |
| -__gen_uint_nonzero(uint64_t v, uint32_t start, uint32_t end) |
94 |
| -{ |
95 |
| - assert(v != 0ull); |
96 |
| - return __gen_uint(v, start, end); |
97 |
| -} |
98 |
| -
|
99 |
| -static inline __attribute__((always_inline)) uint64_t |
100 |
| -__gen_sint(int64_t v, uint32_t start, uint32_t end) |
101 |
| -{ |
102 |
| - const int width = end - start + 1; |
103 |
| -
|
104 |
| - __gen_validate_value(v); |
105 |
| -
|
106 |
| -#ifndef NDEBUG |
107 |
| - if (width < 64) { |
108 |
| - const int64_t max = (1ll << (width - 1)) - 1; |
109 |
| - const int64_t min = -(1ll << (width - 1)); |
110 |
| - assert(min <= v && v <= max); |
111 |
| - } |
112 |
| -#endif |
113 |
| -
|
114 |
| - const uint64_t mask = ~0ull >> (64 - width); |
115 |
| -
|
116 |
| - return (v & mask) << start; |
117 |
| -} |
118 |
| -
|
119 |
| -static inline __attribute__((always_inline)) uint64_t |
120 |
| -__gen_sint_nonzero(int64_t v, uint32_t start, uint32_t end) |
121 |
| -{ |
122 |
| - assert(v != 0ll); |
123 |
| - return __gen_sint(v, start, end); |
124 |
| -} |
125 |
| -
|
126 | 63 | static inline __attribute__((always_inline)) uint64_t
|
127 | 64 | __gen_offset(uint64_t v, NDEBUG_UNUSED uint32_t start, NDEBUG_UNUSED uint32_t end)
|
128 | 65 | {
|
|
159 | 96 | }
|
160 | 97 | }
|
161 | 98 |
|
162 |
| -static inline __attribute__((always_inline)) uint32_t |
163 |
| -__gen_float(float v) |
164 |
| -{ |
165 |
| - __gen_validate_value(v); |
166 |
| - return ((union __intel_value) { .f = (v) }).dw; |
167 |
| -} |
168 |
| -
|
169 |
| -static inline __attribute__((always_inline)) uint32_t |
170 |
| -__gen_float_nonzero(float v) |
171 |
| -{ |
172 |
| - assert(v != 0.0f); |
173 |
| - return __gen_float(v); |
174 |
| -} |
175 |
| -
|
176 |
| -static inline __attribute__((always_inline)) uint64_t |
177 |
| -__gen_sfixed(float v, uint32_t start, uint32_t end, uint32_t fract_bits) |
178 |
| -{ |
179 |
| - __gen_validate_value(v); |
180 |
| -
|
181 |
| - const float factor = (1 << fract_bits); |
182 |
| -
|
183 |
| -#ifndef NDEBUG |
184 |
| - const float max = ((1 << (end - start)) - 1) / factor; |
185 |
| - const float min = -(1 << (end - start)) / factor; |
186 |
| - assert(min <= v && v <= max); |
187 |
| -#endif |
188 |
| -
|
189 |
| - const int64_t int_val = llroundf(v * factor); |
190 |
| - const uint64_t mask = ~0ull >> (64 - (end - start + 1)); |
191 |
| -
|
192 |
| - return (int_val & mask) << start; |
193 |
| -} |
194 |
| -
|
195 |
| -static inline __attribute__((always_inline)) uint64_t |
196 |
| -__gen_sfixed_nonzero(float v, uint32_t start, uint32_t end, uint32_t fract_bits) |
197 |
| -{ |
198 |
| - assert(v != 0.0f); |
199 |
| - return __gen_sfixed(v, start, end, fract_bits); |
200 |
| -} |
201 |
| -
|
202 |
| -static inline __attribute__((always_inline)) uint64_t |
203 |
| -__gen_ufixed(float v, uint32_t start, NDEBUG_UNUSED uint32_t end, uint32_t fract_bits) |
204 |
| -{ |
205 |
| - __gen_validate_value(v); |
206 |
| -
|
207 |
| - const float factor = (1 << fract_bits); |
208 |
| -
|
209 |
| -#ifndef NDEBUG |
210 |
| - const float max = ((1 << (end - start + 1)) - 1) / factor; |
211 |
| - const float min = 0.0f; |
212 |
| - assert(min <= v && v <= max); |
213 |
| -#endif |
214 |
| -
|
215 |
| - const uint64_t uint_val = llroundf(v * factor); |
216 |
| -
|
217 |
| - return uint_val << start; |
218 |
| -} |
219 |
| -
|
220 |
| -static inline __attribute__((always_inline)) uint64_t |
221 |
| -__gen_ufixed_nonzero(float v, uint32_t start, uint32_t end, uint32_t fract_bits) |
222 |
| -{ |
223 |
| - assert(v != 0.0f); |
224 |
| - return __gen_ufixed(v, start, end, fract_bits); |
225 |
| -} |
226 |
| -
|
227 | 99 | #ifndef __gen_address_type
|
228 | 100 | #error #define __gen_address_type before including this file
|
229 | 101 | #endif
|
@@ -486,37 +358,37 @@ def emit_pack_function(self, dwords, length):
|
486 | 358 | nz = "_nonzero" if field.nonzero else ""
|
487 | 359 |
|
488 | 360 | if field.type == "mbo":
|
489 |
| - non_address_fields.append("__gen_mbo(%d, %d)" % \ |
| 361 | + non_address_fields.append("util_bitpack_ones(%d, %d)" % \ |
490 | 362 | (field.start - dword_start, field.end - dword_start))
|
491 | 363 | elif field.type == "mbz":
|
492 | 364 | assert not field.nonzero
|
493 | 365 | elif field.type == "address":
|
494 | 366 | pass
|
495 | 367 | elif field.type == "uint":
|
496 |
| - non_address_fields.append("__gen_uint%s(values->%s, %d, %d)" % \ |
| 368 | + non_address_fields.append("util_bitpack_uint%s(values->%s, %d, %d)" % \ |
497 | 369 | (nz, name, field.start - dword_start, field.end - dword_start))
|
498 | 370 | elif field.is_enum_type():
|
499 |
| - non_address_fields.append("__gen_uint%s(values->%s, %d, %d)" % \ |
| 371 | + non_address_fields.append("util_bitpack_uint%s(values->%s, %d, %d)" % \ |
500 | 372 | (nz, name, field.start - dword_start, field.end - dword_start))
|
501 | 373 | elif field.type == "int":
|
502 |
| - non_address_fields.append("__gen_sint%s(values->%s, %d, %d)" % \ |
| 374 | + non_address_fields.append("util_bitpack_sint%s(values->%s, %d, %d)" % \ |
503 | 375 | (nz, name, field.start - dword_start, field.end - dword_start))
|
504 | 376 | elif field.type == "bool":
|
505 |
| - non_address_fields.append("__gen_uint%s(values->%s, %d, %d)" % \ |
| 377 | + non_address_fields.append("util_bitpack_uint%s(values->%s, %d, %d)" % \ |
506 | 378 | (nz, name, field.start - dword_start, field.end - dword_start))
|
507 | 379 | elif field.type == "float":
|
508 |
| - non_address_fields.append("__gen_float%s(values->%s)" % (nz, name)) |
| 380 | + non_address_fields.append("util_bitpack_float%s(values->%s)" % (nz, name)) |
509 | 381 | elif field.type == "offset":
|
510 | 382 | non_address_fields.append("__gen_offset%s(values->%s, %d, %d)" % \
|
511 | 383 | (nz, name, field.start - dword_start, field.end - dword_start))
|
512 | 384 | elif field.type == 'ufixed':
|
513 |
| - non_address_fields.append("__gen_ufixed%s(values->%s, %d, %d, %d)" % \ |
| 385 | + non_address_fields.append("util_bitpack_ufixed%s(values->%s, %d, %d, %d)" % \ |
514 | 386 | (nz, name, field.start - dword_start, field.end - dword_start, field.fractional_size))
|
515 | 387 | elif field.type == 'sfixed':
|
516 |
| - non_address_fields.append("__gen_sfixed%s(values->%s, %d, %d, %d)" % \ |
| 388 | + non_address_fields.append("util_bitpack_sfixed%s(values->%s, %d, %d, %d)" % \ |
517 | 389 | (nz, name, field.start - dword_start, field.end - dword_start, field.fractional_size))
|
518 | 390 | elif field.is_struct_type():
|
519 |
| - non_address_fields.append("__gen_uint(v%d_%d, %d, %d)" % \ |
| 391 | + non_address_fields.append("util_bitpack_uint(v%d_%d, %d, %d)" % \ |
520 | 392 | (index, field_index, field.start - dword_start, field.end - dword_start))
|
521 | 393 | field_index = field_index + 1
|
522 | 394 | else:
|
|
0 commit comments