Commit Graph

6 Commits

Author SHA1 Message Date
82cb279597 rdna2spirv: fix TwoSum overflow in Gen.f64_add_mode via FastTwoSum 2026-11-22 21:17:31 +02:00
9a6add98e8 hw_oracle: native RDNA2 measurement of MODE.FP_ROUND f16/f64 (SHADER-132) 2026-11-22 17:16:34 +01:00
3a1ea887e4 tests: correct exponents in the fma_mix tiny-product comments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:53:25 +01:00
b43e88ab93 SHADER-35: fma_mix tiny product and overflow; exp/log ignore MODE
fma_mix_odd: a tiny product takes the residual sign from its operands (independent of denormal flushing), an f32 overflow with finite operands gives +-FLT_MAX toward zero. v_exp_f16 and v_log_f16 narrow to nearest even like the measured transcendentals (cos too; all three unmeasured). Docs and test comments corrected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:37:11 +01:00
608ba1b54e SHADER-35: RX 6800 findings for MODE f16 rounding
rcp/rsq/sqrt/sin/cos f16 ignore the rounding mode (always nearest even); v_fma_mix{lo,hi}_f16 toward zero rounds the exact fma once (round-to-odd f32 from the product/sum residual, then truncate); the v_add_f64 omod test no longer claims an omod order (omod vs denormal mode is unmodelled, noted in design.md). Tests with the measured words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:12:40 +01:00
e157fddad9 Translator: MODE f16/f64 rounding (s_setreg FP_ROUND[3:2]) (SHADER-35)
The game sets MODE.FP_ROUND[3:2] (f16/f64 rounding) inside its shaders: 9,417 writes in 6,333 of 26,503
shaders, 6,694 toward zero (3) and 2,723 back to nearest even (0); no other MODE field, no s_denorm_mode or
s_round_mode. The translator ignored it.

- The field is kept in a per-invocation Function variable (%mode_r16) when the program writes it.
- Every VALU f16 result (f16_out, v_pk_*_f16 via f16_pack2, v_cvt_f16_f32, v_sin/cos_f16, v_interp_p2_f16,
  v_fma_mix{lo,hi}_f16) goes through f16_res: main's integer f16_bits, or f16_bits(rtz=True) while the mode
  is toward zero. Integer ops only either way (SHADER-56).
- f16 add/sub and v_pk_add_f16 step the f32 sum one ulp toward zero when its exact TwoSum error shows it
  rounded away from zero (2 - 2^-24 is an f32 tie that rounds to 2.0; toward zero it is 0x3FFF). f16 FMAs
  need nothing extra: fma_f16_odd's round-to-odd f32 value (SHADER-55) narrows exactly in either direction.
- v_add_f64 steps one ulp toward zero the same way (finite overflow -> +-DBL_MAX), on the raw sum, before
  clamp/omod.
- Other MODE writes (other bits, partial field, +inf/-inf, register values), s_denorm_mode and s_round_mode
  raise Unsupported; none occur in the corpus.
- Shaders that never write MODE emit the same code.

tests/test_mode_round.py; tests/spirv_interp.py gains binary64 arithmetic, double <-> v2uint bitcasts and
vector Fma/FMin/FMax/FClamp. docs/design.md: Known approximations and the f16 rounding row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 03:11:57 +01:00