asahi: Use util/bitpack_helpers.h

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18062>
This commit is contained in:
Jason Ekstrand 2022-08-15 09:17:37 -05:00 committed by Marge Bot
parent 4615153d71
commit 4fab5ae8ba
3 changed files with 15 additions and 46 deletions

View file

@ -42,45 +42,12 @@ pack_header = """
#define AGX_PACK_H
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <math.h>
#include <inttypes.h>
#include "util/macros.h"
#include "util/u_math.h"
#include "util/bitpack_helpers.h"
#define __gen_unpack_float(x, y, z) uif(__gen_unpack_uint(x, y, z))
static inline uint64_t
__gen_uint(uint64_t v, uint32_t start, uint32_t end)
{
#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 uint32_t
__gen_sint(int32_t v, uint32_t start, uint32_t end)
{
#ifndef NDEBUG
const int width = end - start + 1;
if (width < 64) {
const int64_t max = (1ll << (width - 1)) - 1;
const int64_t min = -(1ll << (width - 1));
assert(min <= v && v <= max);
}
#endif
return (((uint32_t) v) << start) & ((2ll << end) - 1);
}
static inline uint64_t
__gen_unpack_uint(const uint8_t *restrict cl, uint32_t start, uint32_t end)
{
@ -100,9 +67,10 @@ __gen_unpack_uint(const uint8_t *restrict cl, uint32_t start, uint32_t end)
* avoid undefined behaviour for out-of-bounds inputs like +/- infinity.
*/
static inline uint32_t
__float_to_lod(float f)
__gen_pack_lod(float f, uint32_t start, uint32_t end)
{
return (uint32_t) CLAMP(f * (1 << 6), 0 /* 0.0 */, 0x380 /* 14.0 */);
uint32_t fixed = CLAMP(f * (1 << 6), 0 /* 0.0 */, 0x380 /* 14.0 */);
return util_bitpack_uint(fixed, start, end);
}
static inline float
@ -435,23 +403,23 @@ class Group(object):
value = "util_logbase2({})".format(value)
if field.type in ["uint", "hex", "Pixel Format", "address"]:
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":
assert(start == 0 and end == 31)
s = "__gen_uint(fui({}), 0, 32)".format(value)
s = "util_bitpack_float({})".format(value)
elif field.type == "lod":
assert(end - start + 1 == 10)
s = "__gen_uint(__float_to_lod(%s), %d, %d)" % (value, start, end)
s = "__gen_pack_lod(%s, %d, %d)" % (value, start, end)
else:
s = "#error unhandled field {}, type {}".format(contributor.path, field.type)

View file

@ -42,6 +42,7 @@ agx_pack = custom_target(
idep_agx_pack = declare_dependency(
sources : [agx_pack],
dependencies : dep_valgrind,
include_directories : include_directories('.'),
)
@ -51,7 +52,7 @@ libasahi_lib = static_library(
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_asahi],
c_args : [no_override_init_args],
gnu_symbol_visibility : 'hidden',
dependencies: [dep_libdrm, idep_nir, dep_iokit],
dependencies: [dep_libdrm, dep_valgrind, idep_nir, dep_iokit],
build_by_default : false,
)
@ -59,7 +60,7 @@ libasahi_decode = static_library(
'asahi_decode',
[libasahi_decode_files, agx_pack],
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_asahi],
dependencies : idep_mesautil,
dependencies : [dep_valgrind, idep_mesautil],
c_args : [no_override_init_args],
gnu_symbol_visibility : 'hidden',
build_by_default : false,

View file

@ -51,7 +51,7 @@ class LODClamp : public testing::Test {
TEST_F(LODClamp, Encode)
{
for (unsigned i = 0; i < ARRAY_SIZE(lod_cases); ++i)
ASSERT_EQ(__float_to_lod(lod_cases[i].f), lod_cases[i].encoded);
ASSERT_EQ(__gen_pack_lod(lod_cases[i].f, 0, 9), lod_cases[i].encoded);
}
TEST_F(LODClamp, Decode)