From 59499d8dbc8e1bc39293431e59437d994ef73dda Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 19 Sep 2023 16:15:20 -0400 Subject: [PATCH] asahi: Fix agx_pack unrolling The loop is supposed to execute exactly once, but the previous logic inadvertently executes 0 or 1 times depending on whether dst is NULL (it never is). Reexpress the loop to execute exactly once, eliminating the unnecessary branch in this hot path. Noticed when reading the NIR of generated pack code. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/gen_pack.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/asahi/lib/gen_pack.py b/src/asahi/lib/gen_pack.py index c98b0b09637..9358ec48c89 100644 --- a/src/asahi/lib/gen_pack.py +++ b/src/asahi/lib/gen_pack.py @@ -99,10 +99,10 @@ __gen_from_groups(uint32_t value, uint32_t group_size, uint32_t length) #define agx_pack(dst, T, name) \\ for (struct AGX_ ## T name = { AGX_ ## T ## _header }, \\ - *_loop_terminate = (void *) (dst); \\ - __builtin_expect(_loop_terminate != NULL, 1); \\ + *_loop_count = (void *) ((uintptr_t) 0); \\ + (uintptr_t)_loop_count < 1; \\ ({ AGX_ ## T ## _pack((uint32_t *) (dst), &name); \\ - _loop_terminate = NULL; })) + _loop_count = (void*)(((uintptr_t)_loop_count) + 1); })) #define agx_unpack(fp, src, T, name) \\ struct AGX_ ## T name; \\