Skip to content

Commit c52d5ac

Browse files
gfxstrandMarge Bot
authored and
Marge Bot
committed
util,intel: Pull the bit packing helpers from genxml to a common header
Reviewed-by: Eric Engestrom <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18062>
1 parent 7fc1ab4 commit c52d5ac

File tree

5 files changed

+186
-148
lines changed

5 files changed

+186
-148
lines changed

src/gallium/drivers/crocus/crocus_state.c

-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@
7777
#include <memcheck.h>
7878
#include <valgrind.h>
7979
#define VG(x) x
80-
#ifdef DEBUG
81-
#define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
82-
#endif
8380
#else
8481
#define VG(x)
8582
#endif

src/gallium/drivers/iris/iris_state.c

-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@
7777
#include <valgrind.h>
7878
#include <memcheck.h>
7979
#define VG(x) x
80-
#ifdef DEBUG
81-
#define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
82-
#endif
8380
#else
8481
#define VG(x)
8582
#endif

src/intel/genxml/gen_pack_header.py

+11-139
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@
4444
#define %(guard)s
4545
4646
#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"
5149
5250
#ifndef __gen_validate_value
5351
#define __gen_validate_value(x)
@@ -62,67 +60,6 @@
6260
#define NDEBUG_UNUSED
6361
#endif
6462
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-
12663
static inline __attribute__((always_inline)) uint64_t
12764
__gen_offset(uint64_t v, NDEBUG_UNUSED uint32_t start, NDEBUG_UNUSED uint32_t end)
12865
{
@@ -159,71 +96,6 @@
15996
}
16097
}
16198
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-
22799
#ifndef __gen_address_type
228100
#error #define __gen_address_type before including this file
229101
#endif
@@ -486,37 +358,37 @@ def emit_pack_function(self, dwords, length):
486358
nz = "_nonzero" if field.nonzero else ""
487359

488360
if field.type == "mbo":
489-
non_address_fields.append("__gen_mbo(%d, %d)" % \
361+
non_address_fields.append("util_bitpack_ones(%d, %d)" % \
490362
(field.start - dword_start, field.end - dword_start))
491363
elif field.type == "mbz":
492364
assert not field.nonzero
493365
elif field.type == "address":
494366
pass
495367
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)" % \
497369
(nz, name, field.start - dword_start, field.end - dword_start))
498370
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)" % \
500372
(nz, name, field.start - dword_start, field.end - dword_start))
501373
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)" % \
503375
(nz, name, field.start - dword_start, field.end - dword_start))
504376
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)" % \
506378
(nz, name, field.start - dword_start, field.end - dword_start))
507379
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))
509381
elif field.type == "offset":
510382
non_address_fields.append("__gen_offset%s(values->%s, %d, %d)" % \
511383
(nz, name, field.start - dword_start, field.end - dword_start))
512384
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)" % \
514386
(nz, name, field.start - dword_start, field.end - dword_start, field.fractional_size))
515387
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)" % \
517389
(nz, name, field.start - dword_start, field.end - dword_start, field.fractional_size))
518390
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)" % \
520392
(index, field_index, field.start - dword_start, field.end - dword_start))
521393
field_index = field_index + 1
522394
else:

src/intel/vulkan/anv_private.h

-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
#include <valgrind.h>
3838
#include <memcheck.h>
3939
#define VG(x) x
40-
#ifndef NDEBUG
41-
#define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
42-
#endif
4340
#else
4441
#define VG(x) ((void)0)
4542
#endif

0 commit comments

Comments
 (0)