shader: lower the 64-bit VOP3 shifts (v_lshlrev_b64, v_lshrrev_b64, v_ashrrev_i64) in pixel_aot #921

Closed
opened 2026-11-23 17:34:50 +00:00 by MasterDomino · 4 comments
MasterDomino commented 2026-11-23 17:34:50 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T17:34:50Z.


Problem

tools/pixel_aot.py rejects the three 64-bit VOP3 shifts: v_lshlrev_b64, v_lshrrev_b64 and v_ashrrev_i64. A pixel program that contains any of them fails with Unsupported instruction. All three are listed under VOP3 in docs/coverage/gfx1013.tsv, and no fixture covers them.

I checked the open pull requests and issues. No diff or thread mentions these three mnemonics. The nearby open integer work (#526, #531, #532) covers other VOP3 forms.

Proposal

I'd like to take these as one small PR, with the same structure as the 64-bit comparisons:

  • Semantics. The AMD "RDNA 2" ISA reference guide, section 12.12 "VOP3A & VOP3B Instructions" (p. 177 of 283), defines them as:

    • opcode 767 V_LSHLREV_B64: D.u64 = S1.u64 << S0.u[5:0]
    • opcode 768 V_LSHRREV_B64: D.u64 = S1.u64 >> S0.u[5:0]
    • opcode 769 V_ASHRREV_I64: D.u64 = signext(S1.u64) >> S0.u[5:0]

    Each entry also says "Only one scalar broadcast constant is allowed." This is the RDNA 2 guide, not a gfx1013-specific document. The opcode numbers match the gfx1013 encodings that LLVM 15.0.7 llvm-mc -mcpu=gfx1013 produces (VOP3 opcodes 0x2ff, 0x300 and 0x301). LLVM 15 also enforces the one-scalar limit for gfx1013: v_lshlrev_b64 v[12:13], s44, s[46:47] and v_lshlrev_b64 v[12:13], s44, 0x41 both fail with violates constant bus restrictions, and v_lshlrev_b64 v[12:13], 0x41, v[12:13] assembles.

  • Lowering. Read the 64-bit src1 through the existing int64_operand path as two 32-bit words, and emit the shift as two-word uint arithmetic. Then no 64-bit HLSL type or Int64 shader capability is needed. The 64-bit comparisons in lower() already work this way. The amount src0 uses the existing 32-bit operand rules: VGPR, SGPR, inline constant or literal. At most one of src0 and src1 may be an SGPR or literal, matching the ISA note.

  • Destination. The destination is a VGPR pair. Both words become defined 32-bit values that the existing readers accept.

  • Refusals. Keep VOP3 modifiers (clamp, op_sel, abs, neg) refused, and refuse a destination pair that overlaps a pending sample.

A second, independent check of the 6-bit amount, from the LLVM 15 compiler model rather than hardware. With LLVM 15.0.7 llc -march=amdgcn -mcpu=gfx1013 -O2, an IR shift by and i32 %s, 63 compiles to the bare v_lshlrev_b64 / v_lshrrev_b64 / v_ashrrev_i64, with the and removed. The same shift by and i32 %s, 31 keeps the v_and_b32_e32 v2, 31, v2. So LLVM treats the instructions as reading exactly bits [5:0] of the amount, which agrees with the ISA text. I haven't checked this on gfx1013 hardware.

Alternatives

  • Lower through uint64_t. That is simpler HLSL, but it needs the Int64 capability and doesn't match how the translator already handles 64-bit values.
  • Leave the three forms rejected. This is safe, but programs that use them can't be translated at all.

Verification

  • Binary. The fixture program assembles and disassembles with LLVM 15 (pixel_aot_check.py binary path), including all three mnemonics.
  • Draw. A new draw-shift64 mode, registered with a FORM_COVERAGE_RECORD like the other draw tests, exports through the bit-exact R32G32B32A32_UINT target. It compares both result words with a Python reference on WARP.
    • Shift amounts: 0, 1, 31, 32, 33, 63, plus amounts with bits above bit 5 set (64, 65, 0xffffffc1) to prove the 6-bit masking.
    • Source values include a set high bit, so v_ashrrev_i64 sign-fills and v_lshrrev_b64 zero-fills.
    • The amount comes from SGPR, VGPR and inline-constant sources.
  • Negative controls, each of which must fail the comparison:
    • The amount masked to 5 bits instead of 6.
    • The amount not masked at all.
    • v_ashrrev_i64 lowered as a logical shift.
    • The two result words swapped.
  • Rejection controls: each refused modifier, the invalid destinations above, and two scalar or literal sources.

I'll write and check the lowering on Linux with LLVM 15 (binary round-trip and HLSL output). The WARP draws will come from the Windows CI run on the PR. I can't run D3D12 locally, so I won't report hardware results.

  • I checked for an existing issue or pull request for this change.
  • I did not include game files, dumps, distribution links or credentials.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6565114093 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/928). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T17:34:50Z. --- ### Problem `tools/pixel_aot.py` rejects the three 64-bit VOP3 shifts: `v_lshlrev_b64`, `v_lshrrev_b64` and `v_ashrrev_i64`. A pixel program that contains any of them fails with `Unsupported instruction`. All three are listed under VOP3 in `docs/coverage/gfx1013.tsv`, and no fixture covers them. I checked the open pull requests and issues. No diff or thread mentions these three mnemonics. The nearby open integer work (#526, #531, #532) covers other VOP3 forms. ### Proposal I'd like to take these as one small PR, with the same structure as the 64-bit comparisons: - **Semantics.** The [AMD "RDNA 2" ISA reference guide](https://gpuopen.com/download/rdna2-shader-instruction-set-architecture.pdf), section 12.12 "VOP3A & VOP3B Instructions" (p. 177 of 283), defines them as: - opcode 767 `V_LSHLREV_B64`: `D.u64 = S1.u64 << S0.u[5:0]` - opcode 768 `V_LSHRREV_B64`: `D.u64 = S1.u64 >> S0.u[5:0]` - opcode 769 `V_ASHRREV_I64`: `D.u64 = signext(S1.u64) >> S0.u[5:0]` Each entry also says "Only one scalar broadcast constant is allowed." This is the RDNA 2 guide, not a gfx1013-specific document. The opcode numbers match the gfx1013 encodings that LLVM 15.0.7 `llvm-mc -mcpu=gfx1013` produces (VOP3 opcodes `0x2ff`, `0x300` and `0x301`). LLVM 15 also enforces the one-scalar limit for gfx1013: `v_lshlrev_b64 v[12:13], s44, s[46:47]` and `v_lshlrev_b64 v[12:13], s44, 0x41` both fail with `violates constant bus restrictions`, and `v_lshlrev_b64 v[12:13], 0x41, v[12:13]` assembles. - **Lowering.** Read the 64-bit `src1` through the existing `int64_operand` path as two 32-bit words, and emit the shift as two-word `uint` arithmetic. Then no 64-bit HLSL type or `Int64` shader capability is needed. The 64-bit comparisons in `lower()` already work this way. The amount `src0` uses the existing 32-bit operand rules: VGPR, SGPR, inline constant or literal. At most one of `src0` and `src1` may be an SGPR or literal, matching the ISA note. - **Destination.** The destination is a VGPR pair. Both words become defined 32-bit values that the existing readers accept. - **Refusals.** Keep VOP3 modifiers (`clamp`, `op_sel`, `abs`, `neg`) refused, and refuse a destination pair that overlaps a pending sample. **A second, independent check of the 6-bit amount, from the LLVM 15 compiler model rather than hardware.** With LLVM 15.0.7 `llc -march=amdgcn -mcpu=gfx1013 -O2`, an IR shift by `and i32 %s, 63` compiles to the bare `v_lshlrev_b64` / `v_lshrrev_b64` / `v_ashrrev_i64`, with the `and` removed. The same shift by `and i32 %s, 31` keeps the `v_and_b32_e32 v2, 31, v2`. So LLVM treats the instructions as reading exactly bits [5:0] of the amount, which agrees with the ISA text. I haven't checked this on gfx1013 hardware. ### Alternatives - Lower through `uint64_t`. That is simpler HLSL, but it needs the `Int64` capability and doesn't match how the translator already handles 64-bit values. - Leave the three forms rejected. This is safe, but programs that use them can't be translated at all. ### Verification - **Binary.** The fixture program assembles and disassembles with LLVM 15 (`pixel_aot_check.py binary` path), including all three mnemonics. - **Draw.** A new `draw-shift64` mode, registered with a `FORM_COVERAGE_RECORD` like the other draw tests, exports through the bit-exact `R32G32B32A32_UINT` target. It compares both result words with a Python reference on WARP. - Shift amounts: 0, 1, 31, 32, 33, 63, plus amounts with bits above bit 5 set (64, 65, `0xffffffc1`) to prove the 6-bit masking. - Source values include a set high bit, so `v_ashrrev_i64` sign-fills and `v_lshrrev_b64` zero-fills. - The amount comes from SGPR, VGPR and inline-constant sources. - **Negative controls, each of which must fail the comparison:** - The amount masked to 5 bits instead of 6. - The amount not masked at all. - `v_ashrrev_i64` lowered as a logical shift. - The two result words swapped. - **Rejection controls:** each refused modifier, the invalid destinations above, and two scalar or literal sources. I'll write and check the lowering on Linux with LLVM 15 (binary round-trip and HLSL output). The WARP draws will come from the Windows CI run on the PR. I can't run D3D12 locally, so I won't report hardware results. - [x] I checked for an existing issue or pull request for this change. - [x] I did not include game files, dumps, distribution links or credentials. AI-assisted.
R0Y00 commented 2026-11-24 06:49:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:37:28Z.


Please proceed with the three VOP3 shifts. Use the existing two-word integer representation, mask the amount to six bits, and use sign fill only for ASHR. Read both source words before writing the destination pair so the in-place LLVM form keeps the original value. Keep your refusal scope, including pending sample destinations and unsupported modifiers.

The proposed source-built LLVM 15 round-trip and WARP integer readback are the right checks. Include an in-place case, and keep 0/31/32/33/63/64/65 so the two-word implementation never relies on a 32-bit HLSL shift by 32. The bit-mask, sign-fill and swapped-word controls should each produce a mismatch.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110423071 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/928#issuecomment-7110423071). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:37:28Z. --- Please proceed with the three VOP3 shifts. Use the existing two-word integer representation, mask the amount to six bits, and use sign fill only for ASHR. Read both source words before writing the destination pair so the in-place LLVM form keeps the original value. Keep your refusal scope, including pending sample destinations and unsupported modifiers. The proposed source-built LLVM 15 round-trip and WARP integer readback are the right checks. Include an in-place case, and keep 0/31/32/33/63/64/65 so the two-word implementation never relies on a 32-bit HLSL shift by 32. The bit-mask, sign-fill and swapped-word controls should each produce a mismatch.
MasterDomino commented 2026-11-24 06:49:30 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T18:52:44Z.


Thanks, taking this now. It will be a PR from my fork shortly, following your notes: the two-word representation; a 6-bit amount; sign fill only for v_ashrrev_i64; both source words read before the pair is written; the in-place case; and the 0/31/32/33/63/64/65 amounts. It will include the LLVM 15 round trip, the WARP integer readback and the three mismatch controls.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110781083 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/928#issuecomment-7110781083). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T18:52:44Z. --- Thanks, taking this now. It will be a PR from my fork shortly, following your notes: the two-word representation; a 6-bit amount; sign fill only for `v_ashrrev_i64`; both source words read before the pair is written; the in-place case; and the 0/31/32/33/63/64/65 amounts. It will include the LLVM 15 round trip, the WARP integer readback and the three mismatch controls. AI-assisted.
MasterDomino commented 2026-11-24 06:49:30 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T19:02:36Z.


Up as #964, following your notes above: the two-word representation, a six-bit amount, sign fill only for v_ashrrev_i64, both source words read before the pair is written, the in-place case, and 0/31/32/33/63/64/65 plus wide amounts through the R32G32B32A32_UINT readback. The bit-mask, sign-fill and swapped-word mutations must each mismatch. The LLVM 15 round trip and controls pass locally; the WARP draws run first in the PR's CI.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7111011355 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/928#issuecomment-7111011355). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T19:02:36Z. --- Up as #964, following your notes above: the two-word representation, a six-bit amount, sign fill only for `v_ashrrev_i64`, both source words read before the pair is written, the in-place case, and 0/31/32/33/63/64/65 plus wide amounts through the `R32G32B32A32_UINT` readback. The bit-mask, sign-fill and swapped-word mutations must each mismatch. The LLVM 15 round trip and controls pass locally; the WARP draws run first in the PR's CI. AI-assisted.
R0Y00 commented 2026-11-24 06:49:35 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:52:20Z.


Completed by #964. Both Windows and both Linux jobs passed. The full LLVM 15 binary check and both WARP and RTX readback passed for the combined candidate, including count masking, cross-word boundaries and the distinguishing shift mutations.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112226618 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/928#issuecomment-7112226618). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T19:52:20Z. --- Completed by #964. Both Windows and both Linux jobs passed. The full LLVM 15 binary check and both WARP and RTX readback passed for the combined candidate, including count masking, cross-word boundaries and the distinguishing shift mutations.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#921
No description provided.