diff --git a/src/asahi/compiler/agx3_funop_core.c b/src/asahi/compiler/agx3_funop_core.c index 4643e5af4c24..a564f87db0c3 100644 --- a/src/asahi/compiler/agx3_funop_core.c +++ b/src/asahi/compiler/agx3_funop_core.c @@ -158,8 +158,32 @@ 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 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. + * + * 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);