Repository navigation
Conversation
…ls (SHADER-377) With the game's MODE (denorm_mode_32 = 0) RDNA2 reads a denormal f32 operand as a zero of its sign and flushes a denormal v_mul_f32/v_fma_f32 result, while the translator left denormals to the driver (NVIDIA keeps them). The new option applies the rule, through the existing Gen.flush_f32, to v_cmp_*_f32, v_max/min/med3/max3/ min3_f32, v_mul_f32, v_fma_f32 (and v_fmac/fmaak/fmamk), v_cvt_flr_i32_f32 and v_sqrt_f32. Off by default: the translation of the fixtures is byte-identical. tests/semantic/test_f32_denorm_flush.py runs each case with the option off and on; expected words are derived from the rule by hand, not from a GPU run. A contract row in docs/design.md records the scope, the assumptions and what is not covered. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DeAwAMB8x9HUxUYPTxsWtt
e08e798 to
2aa8511
Compare
Flyander
left a comment
There was a problem hiding this comment.
Both the multiply and FMA paths flush the result before applying the output modifier. This loses subnormal values that the modifier should raise back into the normal range.
| self.emit(f"{r} = {F2[op]} %float {x} {y}") | ||
| self.dst(a[0], self.tou(self.clamp_mods(r, mods))) | ||
| if op == "v_mul_f32": | ||
| r = self.res_fm(r) |
There was a problem hiding this comment.
[P2] Apply OMOD before flushing the multiply result. With --f32-denorm-flush, FLT_MIN * 0.5 is subnormal; an output modifier such as mul:2 should raise it back to FLT_MIN before output flushing. This preflush turns the value into zero first, so the modifier cannot recover it. RDNA2 specifies OMOD before output denormal flushing.
| r = self.tmp() | ||
| self.emit_fma(r, x, y, z) | ||
| self.dst(a[0], self.tou(self.clamp_mods(r, mods))) | ||
| self.dst(a[0], self.tou(self.res_fm(self.clamp_mods(self.res_fm(r), mods)))) |
There was a problem hiding this comment.
[P2] Apply OMOD before flushing the FMA result too. self.res_fm(r) flushes the FMA output before clamp_mods applies OMOD, so a subnormal FMA result scaled back into the normal range incorrectly becomes zero. Keep the output flush after the modifier, as required by the RDNA2 result order.
There was a problem hiding this comment.
Thanks. The order (flush before omod/clamp) follows Vonsek's gfx1036 measurement in #2938 ("a denormal intermediate the hardware flushes before the omod/clamp"), but I can't confirm it covers mul:2 on a denormal product. Not measured for v_mul/v_fma, so I'll mark it as an assumption in the design.md row. @Vonsek, could you run v_mul_f32_e64 v4, 0x00800000, 0.5 mul:2 on gfx1036? 0x00800000 means Flyander is right, 0 means the current order is.
SHADER-377 (claimed by @xxkliff in #2078; finding by @Vonsek).
What
--f32-denorm-flushmodels the game's MODE (denorm_mode_32 = 0, f32 denormals flushed) in the translator. With it, a denormal f32 operand reads as a zero of its sign and a denormalv_mul_f32/v_fma_f32result is flushed to a zero of its sign, forv_cmp_*_f32,v_max/min/med3/max3/min3_f32,v_mul_f32,v_fma_f32,v_cvt_flr_i32_f32andv_sqrt_f32. It reusesGen.flush_f32(SHADER-118) through two small helpers,Gen.src_fmandGen.res_fm.Off by default: the corpus translation does not change. For the 31 fixtures in
tests/semantic/fixtures/disasmthat translate without a header, the SPIR-V is byte-identical before and after.make_game.pydoes not pass the option.Tests
tests/semantic/test_f32_denorm_flush.py: 12 tests, each op run with the option off and on.python -m unittest discover -s tests/semantic: 1683 tests, OK (2 skipped).python -m compileall -q make_game.py tools tests: OK.test_docs_repo_paths,test_docs_list_items,test_docs_linkspass.test_docs_design_rowsalready fails onmain(repeated rows, being fixed under PROC-75/PROC-97); the new row has a unique topic.What this is not
tools/hw_oracle), not taken from a hardware run.v_fmac_f32,v_fmaak_f32andv_fmamk_f32followv_fma_f32(same FMA unit; not in the measured list). Written in thedocs/design.mdrow.v_add_f32,v_sub_f32,v_subrev_f32,v_cvt_rpi_i32_f32,v_floor/ceil/fract_f32(TEST-328), f16 and f64 ops. A test pins thatv_add_f32keeps its denormal.AI-assisted (Claude). The contract row is in
docs/design.md.