From ed79255b51ed251fd3ca04644dfc0c1764524a5f Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sat, 21 Nov 2026 15:54:47 -0500 Subject: [PATCH 1/2] agx: admit the full half-index namespace in the G17-class unary encoder On G18G, floor/ceil/trunc and log2/exp2 are encoded through the funop encoder's runtime entry point (agx3_funop_encode_g17g() -> agx3_funop_encode_runtime()), which refused a destination or source above h127. A G18G shader whose allocation put one of these operands there failed to compile. In production, agx3_emit_funop() routes only G18G AGX3_FUNOP_FLOOR, AGX3_FUNOP_CEIL, AGX3_FUNOP_TRUNC, AGX3_FUNOP_LOG2, AGX3_FUNOP_EXP2, AGX3_FUNOP_RSQRT and AGX3_FUNOP_SQRT_STEP through the runtime entry point (agx3_pack_binary.c handles SRSQRT and unsaturated RSQRT earlier via separate ALU helpers that already take high registers, and agx3_emit_funop() keeps AGX3_FUNOP_RINT off this route so roundeven falls through to agx3_alu_unary_m5()). The runtime encoder helper itself supports all five G17-class scalar register unary forms -- f32rint (including AGX3_FUNOP_RINT), f32log2, f32exp2, f32rsqrt and f32sqrtstep -- each of which deposits every bit of its destination and source index fields identically in the AGX3C and AGX3D (G18G) tables. The runtime entry point now admits the full eight-bit half-index namespace (h0-h255) that the AGX3C packers already use. The pair rule for 32-bit operands stays: h254 encodes as h254:h255 and h255 is refused. Encodable is not allocatable: RA still caps AGX3C and AGX3D at 252 halves, so h252-h255 only appear in the encoder tests. The legacy entry point keeps its 128-half limit. It serves the fixed AGX3B/AGX3C replay forms and the remaining qualified production forms, whose SSA webs RA constrains to the low bank. The unit test encodes every register for each of these instructions, decodes the word with the G18G table and checks the registers it names, and checks that h256 and a 32-bit h255 are refused. Signed-off-by: Erik Bourget --- src/asahi/compiler/agx3_funop_core.c | 29 ++++++++++- .../compiler/test/test-agx3-funop-core.c | 52 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/asahi/compiler/agx3_funop_core.c b/src/asahi/compiler/agx3_funop_core.c index 4643e5af4c24..7e1295394a58 100644 --- a/src/asahi/compiler/agx3_funop_core.c +++ b/src/asahi/compiler/agx3_funop_core.c @@ -158,8 +158,33 @@ agx3_funop_encode_impl(enum agx_isa_encoding enc, enum agx3_funop op, uint16_t d (op == AGX3_FUNOP_SQRT_STEP && (dest_16 || src_neg || saturate)))) return false; - /* Native scalar half registers may be odd; float registers are pairs. */ - if (dest >= 128 || src >= 128 || (!dest_16 && (dest & 1)) || + /* Native scalar half registers may be odd; float registers are pairs, + * so a 32-bit h254 operand encodes as h254:h255 and a 32-bit h255 is + * refused. + * + * The runtime entry point (agx3_funop_encode_runtime() / + * agx3_funop_encode_g17g()) admits the full eight-bit half-index + * namespace (h0-h255) that the AGX3C packers, including + * agx3_alu_unary_m5(), already use. The encoder helper itself supports + * all five G17-class scalar register unary forms -- f32rint (including + * AGX3_FUNOP_RINT), f32log2, f32exp2, f32rsqrt and f32sqrtstep -- each + * of which deposits all of the destination and source index bits + * identically in the AGX3C and AGX3D (G18G) tables. In production, + * agx3_emit_funop() routes only G18G floor/ceil/trunc (keeping + * AGX3_FUNOP_RINT off this route so roundeven falls through to + * agx3_alu_unary_m5()), f32log2, f32exp2, f32rsqrt and f32sqrtstep here + * (with SRSQRT and unsaturated RSQRT caught earlier in + * agx3_pack_binary.c by separate ALU helpers). Encodable is not + * allocatable: RA caps AGX3C and AGX3D at 252 halves (AGX3C_NUM_REGS, + * AGX3D_NUM_REGS), so h252-h255 only occur in encoder tests. + * + * The legacy entry point, agx3_funop_encode_source_lifetime(), keeps its + * 128-half limit. It serves the fixed AGX3B/AGX3C replay forms and the + * remaining qualified production forms, and RA constrains the SSA webs of + * those forms to the low bank (texture_gpr in agx_register_allocate.c), so + * 128 is the contract those forms are allocated against. */ + const unsigned nr_regs = runtime ? 256 : 128; + if (dest >= nr_regs || src >= nr_regs || (!dest_16 && (dest & 1)) || (!src_16 && (src & 1))) return false; diff --git a/src/asahi/compiler/test/test-agx3-funop-core.c b/src/asahi/compiler/test/test-agx3-funop-core.c index 91148497a81a..9cfff2b1f36c 100644 --- a/src/asahi/compiler/test/test-agx3-funop-core.c +++ b/src/asahi/compiler/test/test-agx3-funop-core.c @@ -14,6 +14,7 @@ */ #include "agx3_funop_core.h" +#include "agx3_compose/agx3_decode.h" #include #include @@ -314,6 +315,57 @@ main(void) agx3_funop_encode(AGX_ISA_ENCODING_AGX3B, AGX3_FUNOP_FLOOR, 128, 0, false, false, false, 0, b, &len)); + /* The runtime path (G17G, G18G) takes every half register. Decode each + * word with the G18G table and check the registers it names, so a field + * bit the AGX3D encoding places differently from AGX3C fails here. */ + static const struct { + enum agx3_funop op; + enum agx3_mnemonic mnemonic; + bool half; + } high_ops[] = { + {AGX3_FUNOP_FLOOR, AGX3_MN_f32rint, false}, + {AGX3_FUNOP_CEIL, AGX3_MN_f32rint, false}, + {AGX3_FUNOP_TRUNC, AGX3_MN_f32rint, false}, + {AGX3_FUNOP_LOG2, AGX3_MN_f32log2, false}, + {AGX3_FUNOP_EXP2, AGX3_MN_f32exp2, false}, + {AGX3_FUNOP_LOG2, AGX3_MN_f32log2, true}, + {AGX3_FUNOP_EXP2, AGX3_MN_f32exp2, true}, + {AGX3_FUNOP_RSQRT, AGX3_MN_f32rsqrt, false}, + {AGX3_FUNOP_RSQRT, AGX3_MN_f32rsqrt, true}, + {AGX3_FUNOP_SQRT_STEP, AGX3_MN_f32sqrtstep, false}, + }; + for (unsigned i = 0; i < sizeof(high_ops) / sizeof(high_ops[0]); ++i) { + const unsigned step = high_ops[i].half ? 1 : 2; + for (unsigned reg = 0; reg < 256; reg += step) { + const uint16_t dest = reg, src = (reg + 130 * step) % 256; + const struct agx3_funop_runtime runtime = { + .src_cache = reg & 4, + .dest_16 = high_ops[i].half, + .src_16 = high_ops[i].half, + }; + checks++; + uint64_t fields[AGX3_MAX_FIELDS]; + if (!agx3_funop_encode_g17g(high_ops[i].op, dest, src, false, false, + false, reg & 1 ? 0x80 : 0, &runtime, b, + &len) || + agx3_decode(&agx3d_table, b, len, high_ops[i].mnemonic, + fields) < 0 || + fields[2] != dest || fields[18] != src) { + fprintf(stderr, "%s dest %u src %u: not encoded for G18G\n", + agx3_mnemonic_name(high_ops[i].mnemonic), dest, src); + failures++; + } + } + } + expect_refused("runtime register out of range", + agx3_funop_encode_g17g(AGX3_FUNOP_FLOOR, 256, 0, false, + false, false, 0, &(struct agx3_funop_runtime){0}, b, + &len)); + expect_refused("runtime 32-bit register pair past h255", + agx3_funop_encode_g17g(AGX3_FUNOP_FLOOR, 255, 0, false, + false, false, 0, &(struct agx3_funop_runtime){0}, b, + &len)); + if (failures) { fprintf(stderr, "agx3_funop_core: %u/%u checks failed\n", failures, checks); From ccad404e0b0979d8cd446efcea1d3d6a5f750839 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 25 Nov 2026 16:43:21 -0500 Subject: [PATCH 2/2] agx: update G18G funop comment for rounding op routing PR #1021 moved G18G floor/ceil/trunc onto agx3_alu_unary_m5() alongside roundeven, leaving only f32log2, f32exp2, f32rsqrt and f32sqrtstep on the agx3_funop_encode_g17g() production route in agx3_emit_funop(). Update the comment in agx3_funop_encode_impl() to match aurora-wip. Signed-off-by: Erik Bourget --- src/asahi/compiler/agx3_funop_core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/asahi/compiler/agx3_funop_core.c b/src/asahi/compiler/agx3_funop_core.c index 7e1295394a58..a564f87db0c3 100644 --- a/src/asahi/compiler/agx3_funop_core.c +++ b/src/asahi/compiler/agx3_funop_core.c @@ -170,11 +170,10 @@ agx3_funop_encode_impl(enum agx_isa_encoding enc, enum agx3_funop op, uint16_t d * AGX3_FUNOP_RINT), f32log2, f32exp2, f32rsqrt and f32sqrtstep -- each * of which deposits all of the destination and source index bits * identically in the AGX3C and AGX3D (G18G) tables. In production, - * agx3_emit_funop() routes only G18G floor/ceil/trunc (keeping - * AGX3_FUNOP_RINT off this route so roundeven falls through to - * agx3_alu_unary_m5()), f32log2, f32exp2, f32rsqrt and f32sqrtstep here - * (with SRSQRT and unsaturated RSQRT caught earlier in - * agx3_pack_binary.c by separate ALU helpers). Encodable is not + * agx3_emit_funop() routes only G18G f32log2, f32exp2, f32rsqrt and + * f32sqrtstep here (all four rounding ops fall through to + * agx3_alu_unary_m5(), and SRSQRT and unsaturated RSQRT are caught + * earlier in agx3_pack_binary.c by separate ALU helpers). Encodable is not * allocatable: RA caps AGX3C and AGX3D at 252 halves (AGX3C_NUM_REGS, * AGX3D_NUM_REGS), so h252-h255 only occur in encoder tests. *