tombox-xshader: bit-exact RDNA2 f32 and f64 transcendentals (rcp, rsq, sqrt, log, exp, sin, cos; f64 rcp, rsq, sqrt) #180

Closed
github-bot wants to merge 3 commits from gh-pr/180/head into gh-pr/180/base
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-22 19:39 UTC · original
SchmashinPrunes:rdna2-f32-trans → main · +1832 −61 · 18 files · 3 commits · closed without merging

Follow-up to #150 (f16): the RDNA2 f32 and f64 transcendental VALU ops (v_rcp_f32, v_rcp_iflag_f32, v_rsq_f32, v_sqrt_f32, v_log_f32, v_exp_f32, v_sin_f32, v_cos_f32, v_rcp_f64, v_rsq_f64, v_sqrt_f64) now returns exactly what RDNA2 hardware returns, independent of the host GPU. Three commits: rcp/rsq/sqrt f32 from a datapath model derived here, log/exp/sin/cos ported from AMD's rocjitsu models (verified against RDNA2), and the f64 forms, which turn out to be the same unit's unrounded internal value.

Library / area: tombox-xshader: v_rcp_f32, v_rcp_iflag_f32, v_rsq_f32, v_sqrt_f32, v_log_f32, v_exp_f32, v_sin_f32, v_cos_f32, v_rcp_f64, v_rsq_f64, v_sqrt_f64

Exports changed (exports.txt rows): none

Source of the behaviour: results recorded on RDNA2 hardware, the gfx1036 iGPU of a Ryzen 5 9600X (ROCm/HIP 5.7.1), with tools/rdna2-hwprobe/trans_probe.py: every mantissa of [1, 2) and [2, 4) for rcp/rsq/sqrt, 25 more complete 2^23-input ranges for log/exp/sin/cos, 723,517,440 f64 results (below), and a 2^20-input sweep over the whole 32-bit range (x = i * 4099) in both denormal modes. Every sweep was run twice and kept only when both runs were identical. gfx1036 is RDNA2, not the console's gfx1013. No game or console files are involved.

Before

Main lowered these to host math (1.0 / x, rsqrt, sqrt, exp2, tb_log, sin/cos(2*pi*x)), so results depended on the host GPU and driver, and the ISA sweep accepted them within 1-4 ulp. RDNA2's results are faithful but not correctly rounded (v_rcp_f32 matches the correctly rounded result on 89.3% of inputs, |error| < 0.89 ulp), so no host function reproduces them.

rcp, rsq, sqrt: how the hardware computes them

v_rcp_f64, v_rsq_f64 and v_sqrt_f64 return the transcendental unit's internal value with no final rounding (34 bits for rcp, 35 for rsq/sqrt). The f32 result is that value minus 2^-27, rounded to nearest even at 24 bits (the offset is 0 in the one table entry whose results reach 1.0). That relation holds on all 8,388,608 mantissas of each op and parity, so the f64 outputs show the datapath directly, and it could be fitted exactly. Per table segment (rcp/rsq: top 5 mantissa bits; sqrt: exponent parity and top 4 bits), with t the remaining mantissa bits:

  • c0 + c1*t, with the product c1*t held with a 24-bit significand and the sum rounded to 2^-29;
  • plus S * H with S = ((t >> k)^2) >> 10 (k = 1, or 2 for sqrt), H = c2 + 2 * rne(c3 * (4t + 1) / 4Dn) (the cubic coefficient evaluated a quarter step into t and rounded to even), and the product held with a 24-bit significand;
  • every rounding ties-to-even.

32 rows (rcp), 2 x 32 (rsq) and 2 x 16 (sqrt) of 6 integers reproduce every recorded f64 and f32 output. The rest:

  • Denormal inputs and results are flushed to signed zero regardless of the MODE register (both denormal modes give identical results).
  • NaN inputs are returned unchanged; rsq/sqrt of a negative nonzero input give 0xffc00000; sqrt(-0) = -0, rsq(-0) = -inf, rcp(+-0) = +-inf, rcp(+-inf) = +-0.
  • v_rcp_iflag_f32 equals v_rcp_f32 on every recorded input.

log, exp, sin, cos: AMD's models

AMD's rocjitsu emulator (ROCm/rocm-systems, emulation/rocjitsu/lib/util/include/util/amdgpu_*.h, MIT, added in ROCm/rocm-systems#12510) has integer models of all of these, fitted to RDNA3/4 (gfx1100, gfx1201) captures. Compiled unchanged against the gfx1036 recordings (with quiet_snan = false), its log, exp, sin and cos reproduce every recorded result: 25 complete 2^23-input ranges picked to reach every branch (log just below and above 1, the small-input sine path, large arguments, both signs, the denormal-adjacent binade) and the whole-range sweep in both denormal modes. Denormal mode 0 is mode 3 with denormal inputs and results flushed, which the translator's existing MODE wrapper already does. So these four are ported as they are (trans32/amd.rs, with AMD's notice in trans32/LICENSE-rocjitsu.txt).

Its rcp, rsq and sqrt also match RDNA2, but they are a fitted cubic plus sparse one-ulp correction tables (about 2,800 entries for rcp), described there as "an empirical mapping, not a claim about the hardware implementation". The datapath model above needs no corrections, so this PR uses it; the cubic coefficients agree with rocjitsu's where they overlap (e.g. 1925, 1705 for the first rcp segments). AnyPS5 used rocjitsu's reciprocal on RDNA2 (gfx1031).

f64 rcp, rsq, sqrt

v_rcp_f64, v_rsq_f64 and v_sqrt_f64 are not double-precision operations on RDNA2: they run the same unit and write its ~35-bit internal value into the double without rounding (main computed them with host 1.0 / x and sqrt and accepted 2^29 ulp). The unit reads the top 29 mantissa bits (truncated), so the datapath above sees a 24-bit t: the linear term uses all 24 bits (rsq table entry 31 ignores the top two of the six extra bits), the cubic coefficient the top 20 (rne(c3 * (TH + 1) / 4Dn); that same form is what makes f32 exact, so the tables lost the per-row phi of the old floor form), and the square term the same 17 bits as f32. The rest, from whole-range sweeps in both denormal modes:

  • denormal inputs are normalized and results exact in mode 3; flushed in mode 0 (the translator's existing MODE wrapper does that part);
  • rcp, and rsq with an even exponent, return the power of two minus one ulp when only the 23 ignored mantissa bits are set; rcp returns the power of two plus one ulp for an all-ones mantissa (in the result format, denormals included; not when the power overflows or is flushed);
  • exact powers of two: rcp and rsq exact, sqrt one 2^-26 step high (v_sqrt_f64(4.0) = 0x4000000004000000 on the hardware);
  • NaN inputs unchanged; rsq/sqrt of a negative give 0xfff8000000000000.

Recorded and reproduced, 723,517,440 results with 0 mismatches: the whole-range sweep (x = (i * 4099) << 32 | lo, three lo patterns, both modes), every mantissa of [1, 2) and [2, 4) for each of the 32 combinations of the low-word bits that reach the datapath (two patterns of the linear-only bits), the same at a 1-in-4096 sample for all 64 extra-bit values, and all 2^23 low-bit patterns at both mantissa corners. rocjitsu computes these three with host doubles.

Change

  • crate::trans32 (new, public): the integer models and the HLSL that implements the same algorithms (tb_t32(op, bits) and tb_t64(op, lo, hi), 64-bit integers only): the rcp/rsq/sqrt datapath from the tables for both widths (eval, eval64), and amd.rs for log/exp/sin/cos.
  • src/hlsl.rs: the eight f32 mnemonics go through tb_t32 and the three f64 ones through tb_t64 (abs/neg as bit operations, omod/clamp through the existing f64 result path; TOMBOX_XS_F64_NATIVE=1 restores the host math). For the f32 ones: (VOP3 abs/neg applied as bit operations, so NaN payloads survive; with an output modifier or clamp the exact result goes through the existing fres path). TOMBOX_XS_F32_NATIVE=1 restores the host math for perf A/B, mirroring TOMBOX_XS_F16_NATIVE.
  • tests/exec.rs vector_f64: v_sqrt_f64 of 4, 0.25, 16 and 1 expects the hardware's value (one 2^-26 step above the exact root).
  • tests/exec_vop/basic.rs: rsq(-1), sqrt(-4) and log(-1) expect 0xffc00000 (the hardware's NaN) instead of 0x7fc00000.
  • tools/rdna2-hwprobe: trans32_solve.cpp (derives the tables from the f64 outputs; re-running it regenerates the committed tables byte for byte), trans32_gen.py (writes trans32/tables.rs and the hardware digests in trans32/rdna2_hw.rs), and README.txt sections with the commands and the f64 rules.

Tests (Windows 11 Pro, WARP, DXC 1.9.2609, on 27122f7)

  • trans32::tests (CPU): the models reproduce FNV-1a-64 digests of 41 recorded f32 ranges, the f32 whole-range sweep of all eight ops in both denormal modes, and 78 f64 records (whole-range sweeps in both modes, both mantissa corners, 64 exhaustive [1, 4) mantissa sets); plus special values. 39 s in a debug build, 8 s in release.
  • exec_mem::trans32 (WARP): f32_transcendentals_exact_on_every_mantissa (136 blocks of 2^20 inputs, as before) and f64_rcp_rsq_sqrt_exact_across_mantissas_and_corners (45 cases: every mantissa of [1, 2) and [2, 4) with six low-word patterns, and the whole-range sweep with three), each thread hashing 1024 results; both rerun with runtime inputs.
  • ISA sweep: all eleven mnemonics compared exactly (Cmp::X, both dwords for f64).
  • Mutation checks, each failing only the op it breaks on WARP: rsq offset -512 to -511 (rsq 17 cases), the sin/cos quadratic weight 2 to 3 (sin 17, cos 25), the log cubic term 2 * fr + 1 to + 3 (17), exp's final rounding input sum to sum + 1 (17), and in tb_t64 the rsq entry-31 mask & 15 to & 31 together with the rcp low-bit corner nudge flipped (rcp 2 cases, rsq 8; sqrt still verifies).
cargo check --locked -p tombox-pe -p tombox-archive -p tombox-rpf -p tombox-disasm -p tombox-xshader --all-targets    ok
cargo test -p tombox-xshader --lib trans32                   5 passed (debug, 39 s)
cargo test -p tombox-xshader --release --test exec trans     3 passed (f32 136 cases, f64 45 cases, each rerun with runtime inputs)
cargo test -p tombox-xshader --release --no-fail-fast        every target passes (exec 103 passed / 2 ignored, isa_sweep 2, opcodes 23)

rust-workspace-check fails on main too (missing crates/compat/wldp/data/*.bin), unrelated to this PR.

Not covered

f64 denormal results are exact wherever the hardware produces one (rcp results only reach 2^-1024), so no rounding rule for lost bits was needed or measured. All recordings are from gfx1036; the console's gfx1013 was not available.

  • cargo test -p tombox-xshader passes
  • No game or console files and no binaries included
  • No fake success

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-22 19:39 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/180) `SchmashinPrunes:rdna2-f32-trans` → `main` · +1832 −61 · 18 files · 3 commits · closed without merging Follow-up to #150 (f16): the RDNA2 f32 and f64 transcendental VALU ops (`v_rcp_f32`, `v_rcp_iflag_f32`, `v_rsq_f32`, `v_sqrt_f32`, `v_log_f32`, `v_exp_f32`, `v_sin_f32`, `v_cos_f32`, `v_rcp_f64`, `v_rsq_f64`, `v_sqrt_f64`) now returns exactly what RDNA2 hardware returns, independent of the host GPU. Three commits: rcp/rsq/sqrt f32 from a datapath model derived here, log/exp/sin/cos ported from AMD's rocjitsu models (verified against RDNA2), and the f64 forms, which turn out to be the same unit's unrounded internal value. **Library / area:** tombox-xshader: `v_rcp_f32`, `v_rcp_iflag_f32`, `v_rsq_f32`, `v_sqrt_f32`, `v_log_f32`, `v_exp_f32`, `v_sin_f32`, `v_cos_f32`, `v_rcp_f64`, `v_rsq_f64`, `v_sqrt_f64` **Exports changed (exports.txt rows):** none **Source of the behaviour:** results recorded on RDNA2 hardware, the gfx1036 iGPU of a Ryzen 5 9600X (ROCm/HIP 5.7.1), with `tools/rdna2-hwprobe/trans_probe.py`: every mantissa of [1, 2) and [2, 4) for rcp/rsq/sqrt, 25 more complete 2^23-input ranges for log/exp/sin/cos, 723,517,440 f64 results (below), and a 2^20-input sweep over the whole 32-bit range (`x = i * 4099`) in both denormal modes. Every sweep was run twice and kept only when both runs were identical. gfx1036 is RDNA2, not the console's gfx1013. No game or console files are involved. ### Before Main lowered these to host math (`1.0 / x`, `rsqrt`, `sqrt`, `exp2`, `tb_log`, `sin/cos(2*pi*x)`), so results depended on the host GPU and driver, and the ISA sweep accepted them within 1-4 ulp. RDNA2's results are faithful but not correctly rounded (`v_rcp_f32` matches the correctly rounded result on 89.3% of inputs, |error| < 0.89 ulp), so no host function reproduces them. ### rcp, rsq, sqrt: how the hardware computes them `v_rcp_f64`, `v_rsq_f64` and `v_sqrt_f64` return the transcendental unit's internal value with no final rounding (34 bits for rcp, 35 for rsq/sqrt). The f32 result is that value minus 2^-27, rounded to nearest even at 24 bits (the offset is 0 in the one table entry whose results reach 1.0). That relation holds on all 8,388,608 mantissas of each op and parity, so the f64 outputs show the datapath directly, and it could be fitted exactly. Per table segment (rcp/rsq: top 5 mantissa bits; sqrt: exponent parity and top 4 bits), with `t` the remaining mantissa bits: - `c0 + c1*t`, with the product `c1*t` held with a 24-bit significand and the sum rounded to 2^-29; - plus `S * H` with `S = ((t >> k)^2) >> 10` (k = 1, or 2 for sqrt), `H = c2 + 2 * rne(c3 * (4t + 1) / 4Dn)` (the cubic coefficient evaluated a quarter step into t and rounded to even), and the product held with a 24-bit significand; - every rounding ties-to-even. 32 rows (rcp), 2 x 32 (rsq) and 2 x 16 (sqrt) of 6 integers reproduce every recorded f64 and f32 output. The rest: - Denormal inputs and results are flushed to signed zero regardless of the MODE register (both denormal modes give identical results). - NaN inputs are returned unchanged; rsq/sqrt of a negative nonzero input give `0xffc00000`; `sqrt(-0) = -0`, `rsq(-0) = -inf`, `rcp(+-0) = +-inf`, `rcp(+-inf) = +-0`. - `v_rcp_iflag_f32` equals `v_rcp_f32` on every recorded input. ### log, exp, sin, cos: AMD's models AMD's rocjitsu emulator (ROCm/rocm-systems, `emulation/rocjitsu/lib/util/include/util/amdgpu_*.h`, MIT, added in ROCm/rocm-systems#12510) has integer models of all of these, fitted to RDNA3/4 (gfx1100, gfx1201) captures. Compiled unchanged against the gfx1036 recordings (with `quiet_snan = false`), its log, exp, sin and cos reproduce every recorded result: 25 complete 2^23-input ranges picked to reach every branch (log just below and above 1, the small-input sine path, large arguments, both signs, the denormal-adjacent binade) and the whole-range sweep in both denormal modes. Denormal mode 0 is mode 3 with denormal inputs and results flushed, which the translator's existing MODE wrapper already does. So these four are ported as they are (`trans32/amd.rs`, with AMD's notice in `trans32/LICENSE-rocjitsu.txt`). Its rcp, rsq and sqrt also match RDNA2, but they are a fitted cubic plus sparse one-ulp correction tables (about 2,800 entries for rcp), described there as "an empirical mapping, not a claim about the hardware implementation". The datapath model above needs no corrections, so this PR uses it; the cubic coefficients agree with rocjitsu's where they overlap (e.g. 1925, 1705 for the first rcp segments). AnyPS5 used rocjitsu's reciprocal on RDNA2 (gfx1031). ### f64 rcp, rsq, sqrt `v_rcp_f64`, `v_rsq_f64` and `v_sqrt_f64` are not double-precision operations on RDNA2: they run the same unit and write its ~35-bit internal value into the double without rounding (main computed them with host `1.0 / x` and `sqrt` and accepted 2^29 ulp). The unit reads the top 29 mantissa bits (truncated), so the datapath above sees a 24-bit `t`: the linear term uses all 24 bits (rsq table entry 31 ignores the top two of the six extra bits), the cubic coefficient the top 20 (`rne(c3 * (TH + 1) / 4Dn)`; that same form is what makes f32 exact, so the tables lost the per-row phi of the old floor form), and the square term the same 17 bits as f32. The rest, from whole-range sweeps in both denormal modes: - denormal inputs are normalized and results exact in mode 3; flushed in mode 0 (the translator's existing MODE wrapper does that part); - rcp, and rsq with an even exponent, return the power of two minus one ulp when only the 23 ignored mantissa bits are set; rcp returns the power of two plus one ulp for an all-ones mantissa (in the result format, denormals included; not when the power overflows or is flushed); - exact powers of two: rcp and rsq exact, sqrt one 2^-26 step high (`v_sqrt_f64(4.0) = 0x4000000004000000` on the hardware); - NaN inputs unchanged; rsq/sqrt of a negative give `0xfff8000000000000`. Recorded and reproduced, 723,517,440 results with 0 mismatches: the whole-range sweep (`x = (i * 4099) << 32 | lo`, three `lo` patterns, both modes), every mantissa of [1, 2) and [2, 4) for each of the 32 combinations of the low-word bits that reach the datapath (two patterns of the linear-only bits), the same at a 1-in-4096 sample for all 64 extra-bit values, and all 2^23 low-bit patterns at both mantissa corners. rocjitsu computes these three with host doubles. ### Change - `crate::trans32` (new, public): the integer models and the HLSL that implements the same algorithms (`tb_t32(op, bits)` and `tb_t64(op, lo, hi)`, 64-bit integers only): the rcp/rsq/sqrt datapath from the tables for both widths (`eval`, `eval64`), and `amd.rs` for log/exp/sin/cos. - `src/hlsl.rs`: the eight f32 mnemonics go through `tb_t32` and the three f64 ones through `tb_t64` (abs/neg as bit operations, omod/clamp through the existing f64 result path; `TOMBOX_XS_F64_NATIVE=1` restores the host math). For the f32 ones: (VOP3 abs/neg applied as bit operations, so NaN payloads survive; with an output modifier or clamp the exact result goes through the existing `fres` path). `TOMBOX_XS_F32_NATIVE=1` restores the host math for perf A/B, mirroring `TOMBOX_XS_F16_NATIVE`. - `tests/exec.rs` `vector_f64`: `v_sqrt_f64` of 4, 0.25, 16 and 1 expects the hardware's value (one 2^-26 step above the exact root). - `tests/exec_vop/basic.rs`: `rsq(-1)`, `sqrt(-4)` and `log(-1)` expect `0xffc00000` (the hardware's NaN) instead of `0x7fc00000`. - `tools/rdna2-hwprobe`: `trans32_solve.cpp` (derives the tables from the f64 outputs; re-running it regenerates the committed tables byte for byte), `trans32_gen.py` (writes `trans32/tables.rs` and the hardware digests in `trans32/rdna2_hw.rs`), and README.txt sections with the commands and the f64 rules. ### Tests (Windows 11 Pro, WARP, DXC 1.9.2609, on 27122f7) - `trans32::tests` (CPU): the models reproduce FNV-1a-64 digests of 41 recorded f32 ranges, the f32 whole-range sweep of all eight ops in both denormal modes, and 78 f64 records (whole-range sweeps in both modes, both mantissa corners, 64 exhaustive [1, 4) mantissa sets); plus special values. 39 s in a debug build, 8 s in release. - `exec_mem::trans32` (WARP): `f32_transcendentals_exact_on_every_mantissa` (136 blocks of 2^20 inputs, as before) and `f64_rcp_rsq_sqrt_exact_across_mantissas_and_corners` (45 cases: every mantissa of [1, 2) and [2, 4) with six low-word patterns, and the whole-range sweep with three), each thread hashing 1024 results; both rerun with runtime inputs. - ISA sweep: all eleven mnemonics compared exactly (`Cmp::X`, both dwords for f64). - Mutation checks, each failing only the op it breaks on WARP: rsq offset -512 to -511 (rsq 17 cases), the sin/cos quadratic weight 2 to 3 (sin 17, cos 25), the log cubic term `2 * fr + 1` to `+ 3` (17), exp's final rounding input `sum` to `sum + 1` (17), and in `tb_t64` the rsq entry-31 mask `& 15` to `& 31` together with the rcp low-bit corner nudge flipped (rcp 2 cases, rsq 8; sqrt still verifies). ``` cargo check --locked -p tombox-pe -p tombox-archive -p tombox-rpf -p tombox-disasm -p tombox-xshader --all-targets ok cargo test -p tombox-xshader --lib trans32 5 passed (debug, 39 s) cargo test -p tombox-xshader --release --test exec trans 3 passed (f32 136 cases, f64 45 cases, each rerun with runtime inputs) cargo test -p tombox-xshader --release --no-fail-fast every target passes (exec 103 passed / 2 ignored, isa_sweep 2, opcodes 23) ``` `rust-workspace-check` fails on main too (missing `crates/compat/wldp/data/*.bin`), unrelated to this PR. ### Not covered f64 denormal results are exact wherever the hardware produces one (rcp results only reach 2^-1024), so no rounding rule for lost bits was needed or measured. All recordings are from gfx1036; the console's gfx1013 was not available. - [x] `cargo test -p tombox-xshader` passes - [x] No game or console files and no binaries included - [x] No fake success 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_rcp_f32, v_rcp_iflag_f32, v_rsq_f32 and v_sqrt_f32 were lowered to host
math (1.0 / x, rsqrt, sqrt) and the ISA sweep accepted them within 1 ulp.
They now return what RDNA2 hardware (gfx1036) returns on every input
that was recorded: every mantissa of [1, 4) and a 2^20-input sweep over
the whole 32-bit range, in both denormal modes.

v_rcp_f64 / v_rsq_f64 / v_sqrt_f64 expose the transcendental unit's
internal value before rounding, and the f32 result is that value minus
2^-27 rounded to 24 bits. From those outputs the datapath was recovered
exactly: per table segment a cubic c0 + c1 t + S (c2 + c3 t) with
S = ((t >> k)^2) >> 10, c1 t held with a 24-bit significand, the coarse
sum rounded to 2^-29, c3 t quantized in steps of 2 and H S held with a
24-bit significand, all ties to even. 32 / 64 / 32 table rows (rcp /
rsq / sqrt) reproduce every f64 and f32 output. Denormal inputs and
results are flushed whatever MODE says; NaNs pass through unchanged.

crate::trans32 holds the integer model and emits the same algorithm as
HLSL (tb_t32, int64 only). trans32::tests checks the model against
digests of the recorded hardware results; exec_mem::trans32 runs the
translated shaders on WARP over every mantissa of [1, 2) (rcp) or [1, 4)
(rsq, sqrt) plus the whole-range sweep; the ISA sweep compares these
mnemonics exactly. TOMBOX_XS_F32_NATIVE=1 restores the host math, like
TOMBOX_XS_F16_NATIVE. tools/rdna2-hwprobe/trans32_solve.cpp derives the
tables from probe data and trans32_gen.py writes them with the digests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xsrj8HzdWhzzYYavNNpHjk
v_log_f32, v_exp_f32, v_sin_f32 and v_cos_f32 were lowered to host math
(log2, exp2, sin/cos of 2*pi*x) and accepted within 2-4 ulp. They now go
through tb_t32 like rcp/rsq/sqrt and return what RDNA2 returns.

The models are ported from AMD rocjitsu (ROCm/rocm-systems, MIT, notice
in trans32/LICENSE-rocjitsu.txt), which was fitted to RDNA3/4 captures.
Compiled unchanged, those models reproduce every gfx1036 result recorded
here: 25 complete 2^23-input ranges chosen to reach every branch (near
one for log, the small-input sine path, large arguments, both signs) and
the 2^20-input whole-range sweep in both denormal modes. Denormal mode 0
equals mode 3 with inputs and results flushed, which the existing MODE
wrapper already applies.

trans32::tests now checks all eight ops against digests of 41 recorded
ranges and 16 whole-range sweeps; exec_mem::trans32 runs the translated
shaders for all eight on WARP; the ISA sweep compares them exactly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xsrj8HzdWhzzYYavNNpHjk
v_rcp_f64, v_rsq_f64 and v_sqrt_f64 were host double math (1 / x,
1 / sqrt, sqrt) and the ISA sweep accepted them within 2^29 ulp. On
RDNA2 they are the f32 transcendental unit's ~35-bit internal value,
written to the double unrounded, so they differ from host math in almost
every bit below 2^-35. They now go through tb_t64 and return what
gfx1036 returns on every recorded input.

The unit reads the top 29 mantissa bits, so the f32 datapath sees a
24-bit t: the linear term uses all of it (except rsq table entry 31,
which ignores the top two extra bits), the cubic coefficient its top 20
bits as rne(M * (TH + 1) / (4 Dn)) (2 Dn for sqrt), the square term the
same 17 bits as f32. That cubic form is also exact for f32, so the
tables drop the per-row phi of the old floor form. Denormal inputs are
normalized and results exact in mode 3 (flushed in mode 0, by the
existing MODE wrapper); rcp and even-exponent rsq return the power of
two minus one ulp when only the ignored low mantissa bits are set, and
rcp the power of two plus one ulp for an all-ones mantissa; exact
powers of two are exact for rcp/rsq and one 2^-26 step high for sqrt.

The model reproduces 723,517,440 recorded f64 results (whole-range
sweeps in both modes, every [1, 4) mantissa for all 32 values of the
low-word bits that reach the datapath, both mantissa corners for every
low-bit pattern). trans32::tests checks digests of 78 of those records;
exec_mem::trans32 runs the translated shaders on WARP over 45 cases of
2^20 inputs; the ISA sweep compares both dwords exactly; vector_f64 now
expects the hardware's sqrt of powers of two. TOMBOX_XS_F64_NATIVE=1
restores the host math.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xsrj8HzdWhzzYYavNNpHjk
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:59 +00:00
github-bot closed this pull request 2026-11-26 06:12:59 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 23:03 UTC · original

Applied in 233d56f, 13ae0c6 and 227e258 (merged in f850f50) with your authorship kept, thanks. Your f64 rcp/rsq/sqrt commit is included. I added a THIRD_PARTY/CREDITS line for the rocjitsu models (05c1caf), and the licence file stays with the module. The full tombox-xshader suite passes on WARP, including exec at 103/0. It ships after the lead's current Trackmania baseline run.

**@⁠omonkeyz** on GitHub · 2026-11-22 23:03 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/180#issuecomment-7087277826) Applied in 233d56f, 13ae0c6 and 227e258 (merged in f850f50) with your authorship kept, thanks. Your f64 rcp/rsq/sqrt commit is included. I added a THIRD_PARTY/CREDITS line for the rocjitsu models (05c1caf), and the licence file stays with the module. The full tombox-xshader suite passes on WARP, including exec at 103/0. It ships after the lead's current Trackmania baseline run.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.