feat(shader): implement the VOPC f64 compares #365

Merged
DotDebian merged 1 commit from upstream-pr/365 into main 2026-10-03 08:01:18 +00:00
DotDebian commented 2026-10-02 15:17:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-02T15:17:18Z.


What

The 34 f64 compares threw "VOPC opcode is not implemented" (same in their VOP3 encodings): v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f64, the 16 v_cmpx_*_f64, v_cmp_class_f64 and v_cmpx_class_f64 (opcodes 0x20-0x2f, 0x30-0x3f, 0xa8, 0xb8).

  • The SPIR-V backend has no f64 type, and a compare does not need one. emitFloat64Compare works on the 64-bit pattern with the existing 64-bit integer IR: NaN is magnitude > 0x7ff0000000000000, and the order comes from a signed key (the magnitude, negated when the sign bit is set, so -0 and +0 share key 0) compared with SLessThan64 / IEqual64. Each predicate is a combination of less / equal / greater / unordered. The result is exact for every input, denormals included, and needs no shaderFloat64.
  • emitFloat64ClassCompare picks the class bit (sNaN, qNaN, -inf, -normal, -denormal, -0, +0, +denormal, +normal, +inf) from the exponent and fraction fields and tests it in the mask, like the f32 class compare.
  • readF64Bits reads an f64 source: register pair, abs / neg on bit 63, a 32-bit literal as the high half (the rule for f64 operands; readU32Pair zero-extends, which is the integer rule), and inline constant 248 as the double 1/(2*pi) (0x3fc45f306dc9c882) rather than the widened float.
  • Decoder: the new entries are not DPP-capable, like the other 64-bit compares; SDWA is rejected for them (64-bit operands have no SDWA form); a source modifier on the class mask throws.

Notes:

  • neg on a VOP3-encoded compare is still rejected by checkNativeVop3Modifiers (#260 changes that). readF64Bits already applies it, so nothing more is needed here once #260 is merged, but that path is not reachable by a test until then.
  • Denormals are compared as IEEE values. The recompiler does not model the MODE denorm bits for any width.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA RTX 5080.

New test agc_driver_vopc_compare_f64, built like agc_driver_vopc_compare: a wave32 compute shader runs 41 compares and packs one bit per lane (v_cndmask of VCC, or v_mov under the EXEC a cmpx leaves). It covers the 34 opcodes in the VOPC encoding, a 32-bit literal source, the inline constants 1.0, 1/(2*pi) and integer 1, and three VOP3 encodings with abs (v_cmp_lt, v_cmp_class, v_cmpx_ngt). 17 dispatches: every ordered pair of 20 edge values (quiet and signalling NaN, NaN whose fraction is only in the low or only in the high word, +-inf, +-0, denormals, values that differ in the low word only) with 16 class masks, then pseudo-random patterns. A C++ model on host double checks every bit.

  • Fails on main with "VOPC opcode is not implemented", passes with the change.
  • 12 deliberate faults in the implementation (literal half, 1/(2*pi) constant, abs, sign in the order key, NaN bounds, class fields, swapped predicates, swapped encodings) each make it fail.
  • Full ctest: 109/109.

The shader words are assembled by hand (no llvm-mc here); the encodings were checked against LLVM's VOPCInstructions.td (GFX10 column).

Not tested: Linux (lavapipe, RADV), neg (see above), any title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4718150423 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/365). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-02T15:17:18Z. --- ### What The 34 f64 compares threw "VOPC opcode is not implemented" (same in their VOP3 encodings): `v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f64`, the 16 `v_cmpx_*_f64`, `v_cmp_class_f64` and `v_cmpx_class_f64` (opcodes 0x20-0x2f, 0x30-0x3f, 0xa8, 0xb8). - The SPIR-V backend has no f64 type, and a compare does not need one. `emitFloat64Compare` works on the 64-bit pattern with the existing 64-bit integer IR: NaN is `magnitude > 0x7ff0000000000000`, and the order comes from a signed key (the magnitude, negated when the sign bit is set, so -0 and +0 share key 0) compared with `SLessThan64` / `IEqual64`. Each predicate is a combination of less / equal / greater / unordered. The result is exact for every input, denormals included, and needs no `shaderFloat64`. - `emitFloat64ClassCompare` picks the class bit (sNaN, qNaN, -inf, -normal, -denormal, -0, +0, +denormal, +normal, +inf) from the exponent and fraction fields and tests it in the mask, like the f32 class compare. - `readF64Bits` reads an f64 source: register pair, `abs` / `neg` on bit 63, a 32-bit literal as the high half (the rule for f64 operands; `readU32Pair` zero-extends, which is the integer rule), and inline constant 248 as the double 1/(2*pi) (`0x3fc45f306dc9c882`) rather than the widened float. - Decoder: the new entries are not DPP-capable, like the other 64-bit compares; SDWA is rejected for them (64-bit operands have no SDWA form); a source modifier on the class mask throws. Notes: - `neg` on a VOP3-encoded compare is still rejected by `checkNativeVop3Modifiers` (#260 changes that). `readF64Bits` already applies it, so nothing more is needed here once #260 is merged, but that path is not reachable by a test until then. - Denormals are compared as IEEE values. The recompiler does not model the MODE denorm bits for any width. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA RTX 5080. New test `agc_driver_vopc_compare_f64`, built like `agc_driver_vopc_compare`: a wave32 compute shader runs 41 compares and packs one bit per lane (`v_cndmask` of VCC, or `v_mov` under the EXEC a `cmpx` leaves). It covers the 34 opcodes in the VOPC encoding, a 32-bit literal source, the inline constants 1.0, 1/(2*pi) and integer 1, and three VOP3 encodings with `abs` (`v_cmp_lt`, `v_cmp_class`, `v_cmpx_ngt`). 17 dispatches: every ordered pair of 20 edge values (quiet and signalling NaN, NaN whose fraction is only in the low or only in the high word, +-inf, +-0, denormals, values that differ in the low word only) with 16 class masks, then pseudo-random patterns. A C++ model on host `double` checks every bit. - Fails on `main` with "VOPC opcode is not implemented", passes with the change. - 12 deliberate faults in the implementation (literal half, 1/(2*pi) constant, `abs`, sign in the order key, NaN bounds, class fields, swapped predicates, swapped encodings) each make it fail. - Full `ctest`: 109/109. The shader words are assembled by hand (no `llvm-mc` here); the encodings were checked against LLVM's `VOPCInstructions.td` (GFX10 column). Not tested: Linux (lavapipe, RADV), `neg` (see above), any title. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-02 15:17:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T15:17:45Z.


Progress report (313de1c → bd75a89)

📈 GPU shader instructions: 62.52% (+2.91%, +34 implemented instructions)

✅ 34 implemented
Encoding Name
VOPC V_CMPX_CLASS_F64
VOPC V_CMPX_EQ_F64
VOPC V_CMPX_F_F64
VOPC V_CMPX_GE_F64
VOPC V_CMPX_GT_F64
VOPC V_CMPX_LE_F64
VOPC V_CMPX_LG_F64
VOPC V_CMPX_LT_F64
VOPC V_CMPX_NEQ_F64
VOPC V_CMPX_NGE_F64
VOPC V_CMPX_NGT_F64
VOPC V_CMPX_NLE_F64
VOPC V_CMPX_NLG_F64
VOPC V_CMPX_NLT_F64
VOPC V_CMPX_O_F64
VOPC V_CMPX_TRU_F64
VOPC V_CMPX_U_F64
VOPC V_CMP_CLASS_F64
VOPC V_CMP_EQ_F64
VOPC V_CMP_F_F64
VOPC V_CMP_GE_F64
VOPC V_CMP_GT_F64
VOPC V_CMP_LE_F64
VOPC V_CMP_LG_F64
VOPC V_CMP_LT_F64
VOPC V_CMP_NEQ_F64
VOPC V_CMP_NGE_F64
VOPC V_CMP_NGT_F64
VOPC V_CMP_NLE_F64
VOPC V_CMP_NLG_F64
VOPC V_CMP_NLT_F64
VOPC V_CMP_O_F64
VOPC V_CMP_TRU_F64
VOPC V_CMP_U_F64
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5955475931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/365#issuecomment-5955475931). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T15:17:45Z. --- <!-- progress-report --> ### Progress report (313de1c → bd75a89) 📈 **GPU shader instructions**: 62.52% (+2.91%, +34 implemented instructions) <details> <summary>✅ 34 implemented</summary> | Encoding | Name | | - | - | | VOPC | `V_CMPX_CLASS_F64` | | VOPC | `V_CMPX_EQ_F64` | | VOPC | `V_CMPX_F_F64` | | VOPC | `V_CMPX_GE_F64` | | VOPC | `V_CMPX_GT_F64` | | VOPC | `V_CMPX_LE_F64` | | VOPC | `V_CMPX_LG_F64` | | VOPC | `V_CMPX_LT_F64` | | VOPC | `V_CMPX_NEQ_F64` | | VOPC | `V_CMPX_NGE_F64` | | VOPC | `V_CMPX_NGT_F64` | | VOPC | `V_CMPX_NLE_F64` | | VOPC | `V_CMPX_NLG_F64` | | VOPC | `V_CMPX_NLT_F64` | | VOPC | `V_CMPX_O_F64` | | VOPC | `V_CMPX_TRU_F64` | | VOPC | `V_CMPX_U_F64` | | VOPC | `V_CMP_CLASS_F64` | | VOPC | `V_CMP_EQ_F64` | | VOPC | `V_CMP_F_F64` | | VOPC | `V_CMP_GE_F64` | | VOPC | `V_CMP_GT_F64` | | VOPC | `V_CMP_LE_F64` | | VOPC | `V_CMP_LG_F64` | | VOPC | `V_CMP_LT_F64` | | VOPC | `V_CMP_NEQ_F64` | | VOPC | `V_CMP_NGE_F64` | | VOPC | `V_CMP_NGT_F64` | | VOPC | `V_CMP_NLE_F64` | | VOPC | `V_CMP_NLG_F64` | | VOPC | `V_CMP_NLT_F64` | | VOPC | `V_CMP_O_F64` | | VOPC | `V_CMP_TRU_F64` | | VOPC | `V_CMP_U_F64` | </details>
github-actions[bot] commented 2026-10-03 07:58:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T07:58:47Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#446 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp L53
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5966972014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/365#issuecomment-5966972014). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-03T07:58:47Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #446 | `core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp` [L53](https://github.com/boykopovar/AnyPS5/blob/e1bfb3973f5d15094a4ea019ce1518e847041b8f/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp#L53) | | |
Sign in to join this conversation.
No reviewers
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
boykopovar/AnyPS5!365
No description provided.