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>
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>
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>