diff --git a/docs/design.md b/docs/design.md index 289c4cd596..362995cef7 100644 --- a/docs/design.md +++ b/docs/design.md @@ -438,7 +438,7 @@ How the generated SPIR-V expects the runtime to work: | Image atomics, size and LOD queries | `image_atomic_add/sub/and/or/xor/smin/smax/umin/umax` are `OpAtomicIAdd/ISub/And/Or/Xor/SMin/SMax/UMin/UMax` on the texel (`OpImageTexelPointer`) of an r32ui storage image, binding 4 for 2D and 7 for 3D, at the T#'s index (the view `StorageViews::r32ui` of `runtime/src/vulkan_bindless.h`). The data VGPR is the operand; with `glc` it receives the texel's previous value, without it it is not written (RDNA2 ISA, MIMG: the previous value is returned if glc is 1). `image_atomic_cmpswap` takes two data VGPRs, the new value and then the comparand (`OpAtomicCompareExchange`). A lane that EXEC turns off skips the access entirely (`OpAccessChain`, `OpImageTexelPointer`, `OpAtomic*`, and any `glc` write-back sit inside `if (active)`), leaving memory and `vdata` untouched. Two-VGPR `dmask:0x3` forms of the nine standard ops currently still operate on the low 32-bit dword as before; true 64-bit image atomics remain separate follow-up work. `image_get_resinfo` (2D, no sampler) gives, for the mip level in its address VGPR, width, height, depth (0 for 2D; a 2D array's layers minified from BASE_LEVEL, T# word 3 [15:12]) and the level count in VGPRs 0..3, with width, height and depth 0 past the last level (the size isn't queried there) (ISA: {num_mip_levels, depth, height, width} in VGPRs 3..0; `OpImageQuerySizeLod`, `OpImageQueryLevels`). `image_get_lod` (pixel shaders; 2D and 2D array, the slice ignored) gives the clamped LOD and the calculated LOD in VGPRs 0..1 (ISA: {rawLOD, clampedLOD} in VGPRs 1..0; `OpImageQueryLod`). In both, dmask keeps components and packs them into consecutive VGPRs. GPU-checked (TEST-184) on an RX 7900 XTX and a Ryzen 9 7950X3D integrated GPU (RADV, Mesa 26.3.1) and on Mesa llvmpipe, with the expected words derived by hand in each `.asm` header: `cs_imgatomic.asm` (every op on a 2D image: 0xfffffff0 tells the signed min/max from the unsigned ones, each with a case that goes the other way; cmpswap hit and miss; an op without `glc`; 63 lanes off; 64 threads adding to one texel) and `cs_imgatomic3d.asm` (six cases on a 4x4x4 volume, the three coordinates all different), through `vk_store_test words`; `cs_resinfo.asm` (a 16x4 image with five levels: levels 0, 1 and 3 in full, then dmask 0x3, 0xa and 0x8); `ps_get_lod.asm` and `ps_get_lod_array.asm` through `vk_texture_test` (calculated LOD 1 and 3 on the two-mip texture, the clamped LOD held at the last level, and at 0 by a sampler MAX_LOD of 0.25; 2 and -3 on the one-level array). Measured natively on RDNA2 (gfx1036, SHADER-388: `tools/image_query_probe.py`, 614 results in wave32 and wave64, all as follows). resinfo's depth word is 0 for a 2D image whatever T# WORD4 DEPTH holds; for a 2D array it is the layer count minified like a 3D depth, max(1, layers >> (BASE_LEVEL + level)). Past the last level, width, height and depth are 0. The level count is LAST_LEVEL - BASE_LEVEL + 1 and sizes count from BASE_LEVEL. The translator follows all three (`Gen.resinfo_words`; `cs_resinfo.asm` checks the 2D depth word and level 5 of five on RTX 5080 and Radeon Graphics, `tests/test_translate.py` the array rule). `image_get_lod`'s raw LOD includes the S#'s LOD_BIAS. Its clamped LOD is min(max(min(raw, MAX_LOD), MIN_LOD), levels - 1) under a linear mip filter (MIN_LOD wins when it is above MAX_LOD), that value rounded half up (the level read) under a point mip filter, and 0 with MIP_FILTER none: `OpImageQueryLod`'s definition. u is scaled by the width and v by the height (a 64x4 image). Unverified: the clamped LOD under a linear mip filter (the test's sampler is point-filtered, where 0.25 selects level 0), and the order of u and v in the LOD query (the test textures are square, where it makes no difference). `image_get_resinfo` on other dimensions is `Unsupported`. A host quirk the LOD test steps around: Mesa llvmpipe 26.3.1 does not apply a sampler's LOD range to `OpImageQueryLod` when its minimum and maximum are equal (0..0 gave level 1), so the second draw uses 0..0.25. | | `image_atomic_{swap,inc,dec,fmin,fmax,fcmpswap}` | The six remaining 32-bit MIMG image atomics on 2D (binding 4) and 3D (binding 7) `r32ui` storage images (including `a16` packed coordinates and optional `glc` return), guarded by `active_b` so inactive lanes skip memory access and preserve `vdata`. `image_atomic_swap` emits `OpAtomicExchange`; `inc`/`dec`/`fmin`/`fmax`/`fcmpswap` emit `OpAtomicLoad` (valid on `OpImageTexelPointer` `Image` pointers) followed by a Device-scope `OpAtomicCompareExchange` CAS loop (`inc`: `(M >= D) ? 0 : M + 1`; `dec`: `(M == 0 \|\| M > D) ? D : M - 1`; `fmin`/`fmax`: GLSL.std.450 `NMin`/`NMax`, no float-atomic extension required; `fcmpswap`: integer IEEE-754 binary32 ordered equality on raw 32-bit words — equal iff neither is NaN and `(cur == cmp) \|\| (both ±0.0)`, preserving subnormals even on Vulkan drivers reporting `shaderDenormPreserveFloat32 = false`, exiting without writing on mismatch or NaN; native RDNA2 subnormal behavior under denormal flush is unmeasured). Source: AMD RDNA2 ISA MIMG `IMAGE_ATOMIC_*`. CPU-checked structurally (including `spirv_mini_interp.check_structure` CFG validation) by `tests/semantic/test_image_atomics_32.py` (all 6 ops on 2D and 3D images, `a16`, `glc` and non-`glc`, no `AtomicFloat` capability, rejected widths/coords/dims). GPU-checked by `runtime/test/shaders/cs_imgatomic_ext.asm` through `vk_store_test words` (GPU-IMG-ATOMIC-EXT): all six ops on the 2D image and the volume, inc/dec on both sides of their wrap and with a D that is negative as a signed number, fmin/fmax with a NaN in the data register, fcmpswap with an equal and an unequal comparand, +0 against -0 and a NaN, `glc` and non-`glc` returns, inactive lanes held on a trap texel, and inc/dec/fmin/fmax from all 64 threads on one texel (the CAS loops under contention); every word exact on a Radeon 610M (`gfx1036`, RDNA2, RADV Mesa 26.2.6) and an RTX 4070 Ti (NVIDIA 620.70.06), natively and under `LEONIDA_W64_EMULATE=1`. Each of five planted translator faults (a signed inc/dec compare, fmin and fmax exchanged, fcmpswap without the +0/-0 rule, no inactive-lane guard, no `glc` return from swap) fails it on both. Not covered: NaN or denormal texels for fmin/fmax and fcmpswap, and +0 against -0 for fmin/fmax, where `NMin`/`NMax` and native RDNA2 may differ (native behaviour unmeasured). | | Hand-written short assembler forms | `llvm-mc` accepts `v_add_co_ci_u32 vD, src0, src1` (also `v_sub_co_ci_u32`, `v_subrev_co_ci_u32`) with the carry out and in left to VCC, and a modifier list shorter than the operands (`op_sel_hi:[0,0]`, `neg_lo:[1,0]` on a three-source op), whose missing entries are 0; it prints them as `v_add_co_ci_u32_e32 vD, vcc_lo, src0, src1, vcc_lo` and `[0,0,0]`. The GPU runner assembles through `llvm-mc -show-encoding`, so it sees the printed form; `tests/semantic/regen_fixtures.py` copies the `.asm` text as written, so the translator takes the source spelling too (it used to raise `IndexError` for these: the carry forms, `v_pk_fma_f16`, `v_fma_mix_*`). A probe of 42,000 operand and modifier variations of 302 ALU mnemonics, in the source spelling and as `llvm-mc` prints them, found no other `IndexError`, `KeyError` or `TypeError`. CPU-checked by `tests/semantic/test_short_asm_forms.py`. | -| SDWA | `_sdwa` forms: each source is narrowed to `src0_sel`/`src1_sel` (BYTE_n/WORD_n, zero-extended, or sign-extended under `sext()`) **before** neg/abs and the op. A VGPR result goes to `dst_sel`, with `dst_unused` setting the other bits: PAD = 0, SEXT = sign copies above the field, PRESERVE = old bits kept. A byte or word destination with PRESERVE reads its incoming VGPR on first use. The synthetic `sdwa_bary_input.asm` checks this with two raw fragment weights, following the [LLVM SDWA destination rules](https://llvm.org/docs/AMDGPUModifierSyntax.html#dst-unused). VOPC has no `dst_sel`, and GFX10 `v_cmpx` has no written destination. **Until 2026-11-20 the selects were silently ignored.** That affected 3,826 of the 13,926 translated shaders: they passed `spirv-val` but computed wrong values. GPU-checked with `runtime/test/shaders/ps_sdwa.asm` and `ps_ops.asm` (also `v_pk_fma_f16`, `v_min3_u32`, `v_max3_i32`, `v_bfe_i32`): byte/word source selects, `sext()`, `UNUSED_PRESERVE` into WORD_1 and `UNUSED_SEXT` at BYTE_2 all match on every pixel. **Measured natively on RDNA2** (gfx1036 iGPU, `tools/hw_oracle`, the game's MODE): all 172 distinct SDWA forms of the 26,503 listings (79,307 instructions: opcode, operand kinds, sels, `sext`, neg/abs, `dst_unused`, omod), 12 operand words per source, 21,204 cases. 18,885 give the translator's word. The rest are: a 16-bit result with `dst_sel:DWORD`, where the hardware zeroes the high half and the translator keeps it (1,888, #2187); a NaN result, where the hardware keeps the input's sign and payload (826, of which 556 also fall in the first group, so the groups add up to 21,204; as in the f16 transcendentals row); `div:2` on -0, which gives +0 (1, as in the output-modifier rows); and 160 cases whose translation is undefined in SPIR-V (`FClamp`/`FDiv`/`Sqrt` on NaN, zero or negative operands). `tests/semantic/test_alu_sdwa_hw.py` replays 624 of the matching words, up to four per form. | +| SDWA | `_sdwa` forms: each source is narrowed to `src0_sel`/`src1_sel` (BYTE_n/WORD_n, zero-extended, or sign-extended under `sext()`) **before** neg/abs and the op. A VGPR result goes to `dst_sel`, with `dst_unused` setting the other bits: PAD = 0, SEXT = sign copies above the field, PRESERVE = old bits kept. A byte or word destination with PRESERVE reads its incoming VGPR on first use. The synthetic `sdwa_bary_input.asm` checks this with two raw fragment weights, following the [LLVM SDWA destination rules](https://llvm.org/docs/AMDGPUModifierSyntax.html#dst-unused). VOPC has no `dst_sel`, and GFX10 `v_cmpx` has no written destination. In the long form of `v_add_co_ci_u32`, `v_sub_co_ci_u32` and `v_subrev_co_ci_u32` (vD, carry out, src0, src1, carry in) the selects start at src0, after the carry out; until SHADER-SDWA-CO-CI-SELECT `src0_sel` landed on the carry out and `src1_sel` on src0, and src1 was read whole (the short form vD, src0, src1 was right). CPU-checked by `tests/semantic/test_sdwa_carry_select.py` (both forms, carry in 0 and 1, byte/word/dword selects, seeded cases) against a plain-Python reference; not GPU-checked, and the hardware measurement below found no mismatch for these ops, so the corpus likely has no long-form carry op with a narrowing select. **Until 2026-11-20 the selects were silently ignored.** That affected 3,826 of the 13,926 translated shaders: they passed `spirv-val` but computed wrong values. GPU-checked with `runtime/test/shaders/ps_sdwa.asm` and `ps_ops.asm` (also `v_pk_fma_f16`, `v_min3_u32`, `v_max3_i32`, `v_bfe_i32`): byte/word source selects, `sext()`, `UNUSED_PRESERVE` into WORD_1 and `UNUSED_SEXT` at BYTE_2 all match on every pixel. **Measured natively on RDNA2** (gfx1036 iGPU, `tools/hw_oracle`, the game's MODE): all 172 distinct SDWA forms of the 26,503 listings (79,307 instructions: opcode, operand kinds, sels, `sext`, neg/abs, `dst_unused`, omod), 12 operand words per source, 21,204 cases. 18,885 give the translator's word. The rest are: a 16-bit result with `dst_sel:DWORD`, where the hardware zeroes the high half and the translator keeps it (1,888, #2187); a NaN result, where the hardware keeps the input's sign and payload (826, of which 556 also fall in the first group, so the groups add up to 21,204; as in the f16 transcendentals row); `div:2` on -0, which gives +0 (1, as in the output-modifier rows); and 160 cases whose translation is undefined in SPIR-V (`FClamp`/`FDiv`/`Sqrt` on NaN, zero or negative operands). `tests/semantic/test_alu_sdwa_hw.py` replays 624 of the matching words, up to four per form. | | VOP3 output and source modifiers in the game's forms, on RDNA2 | Every distinct float VALU form in the 26,503 listings that carries `clamp`, an omod (`mul:2`/`mul:4`/`div:2`), `op_sel`/`op_sel_hi` or neg/abs: 572 forms, 1,270,932 instructions (`v_mul_legacy_f32 … clamp` alone is 147,499; `v_fma_mix_f32` has 222 forms), up to 120 random operand triples each, run natively on gfx1036 (`tools/hw_oracle`, the game's MODE) and through the translator: 542 forms, 64,802 cases (the GFX10.1-only `v_mad_f32`/`v_mad_legacy_f32`/`v_mac_f32` and `v_permlanex16` are left out). 51,761 give the translator's word. The rest are differences already on record: NaN sign and payload (5,074); f32 denormal operands or results, and a denormal intermediate that the hardware flushes before the omod or clamp (1,178; SHADER-377); an omod turning a -0 result into +0 (121; the Output modifiers rows, #1281); 1 ulp or the known sin/cos precision in `v_rcp/v_rcp_iflag/v_log/v_sin/v_cos` with an omod (56); and 6,430 whose translation is undefined in SPIR-V, mostly `FClamp` of a NaN, where the hardware gives +0 under DX10_CLAMP (#2437; the f32/f16 clamp of a NaN gives +0 since 2026-11-24, see "Float min/max/med3 with NaN"). 182 cases were my harness's (three distinct SGPRs, over GFX10's two-read limit). No other modifier difference. `tests/semantic/test_alu_vop3_mods_hw.py` replays 1,616 matching words, up to three per form; it fails without `clamp` (326 rows) or without the omod (237). | | Byte permute | `v_perm_b32`: result byte i = BYTE_PERMUTE({src0, src1}, selector byte i), src1 = bytes 0–3 (AMD "RDNA 2" ISA reference, VOP3 opcode 836 V_PERM_B32, `byte_permute` pseudocode, page 189 of the PDF). Selector 0–7 picks that byte; **8, 9, 10, 11 give 0xff if bit 7 of byte 1, 3, 5, 7 is set, else 0x00**; 12 gives 0x00; 13 and above give 0xff. **Until 2026-11-21 selectors 8–11 gave 0x00 regardless of the sign bit**. In the 26,503-shader disassembled corpus (measured via `tools/feature_scan.py`), 0 of 10,500 shaders (11,930 `v_perm_b32` instructions) use selectors 8–11 or >= 13: all 11,258 immediate and 672 constant-register selectors (0 unresolved) use only bytes 0–7 (36,234) and 12 (11,486). GPU-checked with `runtime/test/shaders/ps_ops7.asm` (also `v_alignbit_b32` with a shift of 36, `v_med3_i32` vs `v_med3_u32`) and `ps_ops8.asm` (`v_mul_hi_u32/i32`, `v_bcnt_u32_b32`, `v_ffbl_b32`, `v_ffbh_u32` of 0, `v_xad_u32`, `v_add3_u32`), 4096/4096 pixels on an AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2, AMD driver 25.10.36) and an NVIDIA GeForce RTX 5070 (driver 621.24); before the fix `ps_ops7` gave 0x00000000 for the sign-selector word on both. Also executed by `tests/semantic/test_value_semantics.py`. When S2 is a literal or a currently known SGPR constant, the translator emits fixed byte extracts/inserts (including sign replication), folds the zero and 0xff bytes, and uses the selected source directly for a whole-word identity. `tests/semantic/test_perm_known_selector.py` checks the resulting words and that selector dispatch only remains for a clobbered SGPR. | | Sum of absolute differences (`v_sad_u8`, `v_sad_hi_u8`, `v_sad_u16`, `v_sad_u32`, `v_msad_u8`) | Unsigned, wrapping at 32 bits, with ABSDIFF(x, y) = `UMax − UMin`: `v_sad_u8` = S2 + the sum over the four bytes; `v_sad_hi_u8` = (that byte sum << 16) + S2; `v_sad_u16` = S2 + the sum over the two halves; `v_sad_u32` = \ \| S0 − S1\ \| + S2; `v_msad_u8` skips a byte where S1's byte is 0. `clamp` raises `Unsupported`: the ISA pseudocode doesn't say what it does to these ops. Source: RDNA2 ISA VOP3 opcodes 346–349 and 369 (pseudocode re-read for this row). CPU-checked by `tests/semantic/test_alu_sad.py` (#544): a 9×9 grid of edge words per op, 40 seeded cases, masked bytes, an SGPR source, `clamp` rejected; the PR also reports a 300-case differential run per op with 0 mismatches. None of them is in the translated corpus, and none is GPU-checked. **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137). Measured on native gfx1036 (AMD Radeon Graphics, RDNA2) through tools/hw_oracle across edge byte/half patterns, zero masks, and wrap cases: all match the ISA reference with 0 mismatches. | diff --git a/tests/semantic/test_sdwa_carry_select.py b/tests/semantic/test_sdwa_carry_select.py new file mode 100644 index 0000000000..cd3f486a72 --- /dev/null +++ b/tests/semantic/test_sdwa_carry_select.py @@ -0,0 +1,103 @@ +"""SDWA source selects on the VOP2 carry ops land on their sources (SHADER-SDWA-CO-CI-SELECT). + +v_add_co_ci_u32, v_sub_co_ci_u32 and v_subrev_co_ci_u32 are printed in a long form, +vD, carry out, src0, src1, carry in, with the carry out between the destination and the +sources. Gen.insn() used to attach src0_sel/src1_sel from the second operand on, as for +every other VOP2 op, so for the long form src0_sel landed on the carry out, src1_sel +narrowed src0 and src1 was read whole: a silent wrong result. The short form +vD, src0, src1 was already right and is kept as a control. + +Semantics (RDNA2 ISA VOP2 0x28/0x29/0x2a with the SDWA source rule): each source is +narrowed to its select, zero-extended, then + add: D = S0 + S1 + C, carry out = the bit past 32 + sub: D = S0 - S1 - C, borrow out = (S1 + C > S0) + subrev: D = S1 - S0 - C, borrow out = (S0 + C > S1) +Hand-written listings are translated by tools/rdna2spirv.py and run by spirv_mini_interp.py; +expected words come from the plain-Python reference below. +""" + +import random +import unittest + +from support import mrt0_words, translate_lines # noqa: F401 + +SEL = {"BYTE_0": (0, 8), "BYTE_1": (8, 8), "BYTE_2": (16, 8), "BYTE_3": (24, 8), + "WORD_0": (0, 16), "WORD_1": (16, 16), "DWORD": (0, 32)} +OPS = ("v_add_co_ci_u32", "v_sub_co_ci_u32", "v_subrev_co_ci_u32") + + +def narrow(v, sel): + off, width = SEL[sel] + return (v >> off) & ((1 << width) - 1) + + +def ref(op, x, y, sel0, sel1, cin): + s0, s1 = narrow(x, sel0), narrow(y, sel1) + if op == "v_add_co_ci_u32": + total = s0 + s1 + cin + return total & 0xFFFFFFFF, int(total > 0xFFFFFFFF) + if op == "v_subrev_co_ci_u32": + s0, s1 = s1, s0 + return (s0 - s1 - cin) & 0xFFFFFFFF, int(s1 + cin > s0) + + +def run(op, x, y, sel0, sel1, cin, long_form=True): + vcc = "-1" if cin else "0" + if long_form: + insn = f"{op}_sdwa v2, vcc, v1, v4, vcc" + else: + insn = f"{op}_sdwa v2, v1, v4" + lines = [ + f"v_mov_b32 v1, 0x{x:08x}", + f"v_mov_b32 v4, 0x{y:08x}", + f"s_mov_b32 vcc_lo, {vcc}", + f"s_mov_b32 vcc_hi, {vcc}", + f"{insn} dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:{sel0} src1_sel:{sel1}", + "v_cndmask_b32 v3, 0, 1, vcc", + "exp mrt0 v2, v3, v2, v3 done vm", + "s_endpgm", + ] + words = mrt0_words(translate_lines("ps_sdwa_carry", lines)) + return words[0], words[1] + + +class SdwaCarrySelect(unittest.TestCase): + def check(self, op, x, y, sel0, sel1, cin, long_form=True): + got = run(op, x, y, sel0, sel1, cin, long_form) + want = ref(op, x, y, sel0, sel1, cin) + self.assertEqual(got, want, f"{op} {'long' if long_form else 'short'} x={x:#010x} y={y:#010x} " + f"{sel0}/{sel1} cin={cin}: got {got[0]:#010x}/{got[1]}, " + f"want {want[0]:#010x}/{want[1]}") + + def test_reported_case(self): + # The words from the claim: v1 = v4 = 0x00050003, src0 = WORD_1 (5), src1 = WORD_0 (3), no carry in. + self.assertEqual(run("v_sub_co_ci_u32", 0x00050003, 0x00050003, "WORD_1", "WORD_0", 0), (2, 0)) + self.assertEqual(run("v_add_co_ci_u32", 0x00050003, 0x00050003, "WORD_1", "WORD_0", 0), (8, 0)) + self.assertEqual(run("v_subrev_co_ci_u32", 0x00050003, 0x00050003, "WORD_1", "WORD_0", 0), + (0xFFFFFFFE, 1)) + + def test_long_form_selects_each_source(self): + x, y = 0x80FF017F, 0x0102FE03 + for op in OPS: + for sel0, sel1 in (("WORD_1", "WORD_0"), ("WORD_0", "WORD_1"), ("BYTE_3", "BYTE_0"), + ("BYTE_1", "BYTE_2"), ("DWORD", "WORD_1"), ("BYTE_2", "DWORD")): + for cin in (0, 1): + self.check(op, x, y, sel0, sel1, cin) + + def test_short_form_unchanged(self): + for op in OPS: + for cin in (0, 1): + self.check(op, 0x00050003, 0x00050003, "WORD_1", "WORD_0", cin, long_form=False) + self.check(op, 0x80FF017F, 0x0102FE03, "BYTE_3", "BYTE_1", cin, long_form=False) + + def test_seeded(self): + rng = random.Random(20261124) + sels = sorted(SEL) + for _ in range(24): + op = rng.choice(OPS) + self.check(op, rng.getrandbits(32), rng.getrandbits(32), rng.choice(sels), rng.choice(sels), + rng.randrange(2)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 8d91dac70e..6a4ab5a366 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py @@ -220,6 +220,10 @@ def mesh_compute_layout(maxv, maxp, clip_count, cull_count, params): S2 = {"s_and_b32": "OpBitwiseAnd", "s_or_b32": "OpBitwiseOr", "s_lshl_b32": "OpShiftLeftLogical", "s_lshr_b32": "OpShiftRightLogical", "s_mul_i32": "OpIMul"} +# VOP2 carry ops whose long form (vD, carry out, src0, src1, carry in) puts the carry out between the destination +# and the sources; Gen.insn() starts their SDWA source selects at the first source (SHADER-SDWA-CO-CI-SELECT). +SDWA_CARRY_OPS = frozenset({"v_add_co_ci_u32", "v_sub_co_ci_u32", "v_subrev_co_ci_u32"}) + # RDNA2 ISA SOPC scalar compare (14 ops) and bit-test (4 ops) exact mnemonic sets (tools/rdna2_isa_tables.py SOPC). SOPC_CMP32_OPS = frozenset({ "s_cmp_eq_i32", "s_cmp_lg_i32", "s_cmp_gt_i32", "s_cmp_ge_i32", "s_cmp_lt_i32", "s_cmp_le_i32", @@ -7140,6 +7144,9 @@ def insn(self, ins): kv = dict(m.split(":", 1) for m in mods if m.split(":", 1)[0] in ("src0_sel", "src1_sel", "dst_sel", "dst_unused")) args = [dict(x) for x in ins["args"]] first = 0 if op.startswith("v_cmpx") else 1 + if op in SDWA_CARRY_OPS and len(args) == 5: + # the long form vD, carry out, src0, src1, carry in: the sources start after the carry out + first = 2 for i, key in enumerate(("src0_sel", "src1_sel")): j = first + i if j < len(args) and (kv.get(key, "DWORD") != "DWORD" or args[j].get("sext")):