Skip to content

rdna2spirv: a literal source of v_frexp_mant_f64 / v_frexp_exp_i32_f64 is bits 63:32 (SHADER-865) - #5636

Closed
AirKyzzZ wants to merge 5 commits into
ItsNotRexed:mainfrom
AirKyzzZ:shader/frexp-f64-literal-high-dword
Closed

AirKyzzZ wants to merge 5 commits into
ItsNotRexed:mainfrom
AirKyzzZ:shader/frexp-f64-literal-high-dword

Conversation

@AirKyzzZ

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-865, narrowed to the two ops no open PR covers (claim)

Depends on: #3642

What and why

A 32-bit literal used as an f64 source supplies bits 63:32 of the double, with bits 31:0 zero (docs/design.md, "f64 literal sources"). v_frexp_mant_f64 and v_frexp_exp_i32_f64 read it as the low dword instead, so v_frexp_mant_f64 v[0:1], 0x3ff80000 (1.5) worked on a tiny denormal. #3791 covers v_div_fixup_f64/v_div_fmas_f64 and #3642 covers v_rcp/rsq/sqrt_f64; this PR fixes the last two ops from the item.

Confirmed with gfx1013 llvm-mc (LLVM 23.1.6): for both ops, 1.5 encodes as the literal dword 0x3ff80000 and disassembles back to it, and 0x40000000 / 0x3ff00000 fold to inline 2.0 / 1.0, which is the high-dword reading.

Tested

macOS 27.0.1 (Apple M3 Pro), Python 3.14:

#3791 edits the same design.md row, so whichever of the two merges second needs a small rebase there. The first four commits here are #3642's; review only the last one. No game files. AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

kapitche and others added 5 commits November 22, 2026 22:44
…rce of v_rcp/rsq/sqrt_f64 is bits 63:32

test_valu_{rcp,rsq,sqrt,cvt_f32}_f64 now translate their cases and run them on tests/spirv_interp.py instead of a
self-built model. Doing so showed that a 32-bit literal on v_rcp_f64, v_rsq_f64 and v_sqrt_f64 was read as the low
dword of the operand; tools/shader_ir.py now flags it as the high dword like v_add_f64 and v_cvt_f32_f64.

The model-only mul/fma/fract/minmax/trig/frexp f64 files are removed: the ops are not translated (a refusal pin
replaces them), trig is not an RDNA2 instruction, and test_alu_frexp_f64.py already runs the frexp forms.
spirv_interp gains binary64 OpFDiv, OpFConvert and IEEE Sqrt/InverseSqrt edge cases.
…4 is bits 63:32 (SHADER-865)

Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI-assisted review. Tested 538a254 on Windows 11 with CPython 3.14.7. The CPU interpreter checks pass.

py -3.14 -I tests/semantic/test_frexp_f64_literal.py
py -3.14 -I tests/semantic/test_alu_frexp_f64.py

All 14 tests pass. The new test file reports 12 failed literal cases against parent 8f29a58. I also checked negative zero, a NaN with a payload, a negative absolute-value operand, and the literal 0x00000001. Both instructions return the expected words in all four cases. This check covers the translator and the interpreter on the CPU.

@AirKyzzZ

Copy link
Copy Markdown
Contributor Author

Closing: after the merge round, @Vonsek's #2863 (53ce204ee) already reads the f64 literal as bits 63:32 for v_frexp_mant_f64/v_frexp_exp_i32_f64 (and v_rcp/rsq/sqrt_f64) through f64_source_words, so this fix is on main. Thanks @shdann for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants