Repository navigation
Recompiler: v_min/v_max order -0.0 < +0.0 as RDNA2 does in IEEE mode - #1348
DavidM1911 wants to merge 1 commit into
Conversation
v_min_f32/f16 and v_max_f32/f16 (and the 3-operand forms) emitted plain HLSL min()/max(), which lowers to DXIL FMin/FMax: on NVIDIA and WARP the signed-zero result depends on operand order, while RDNA2 IEEE mode deterministically returns -0 for min and +0 for max when the operands are +0/-0 in either order. f32 goes through fmin_ieee/fmax_ieee: NaN-suppressing min/max as before, with the both-zero case settled on the sign bits (min: OR keeps -0, max: AND keeps +0). The f16 path converts through f32, and f16 -> f32 -> f16 loses the sign of zero entirely (v_add_f16(-0,-0) already yields +0), so the zero cases are settled on the raw halves instead: min16z*/max16z* return -0 when a -0 operand is present and nothing is negative (max mirrors it, +0 winning over -0), and defer to the float result otherwise. New GPU test gpu_min_max_f32_f16_order_negative_zero covers both operand orders for all eight instructions on wave32 and wave64. Fixes xcl-dev#1282
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
Adding to the report above with what it does not cover: an Ada data point, WARP, and the f64 forms. Tested (head
Not tested: AMD / wave64, a release build, a retail title. Run and written with Claude Code (Claude Opus 5.5). |
|
An Ampere data point to add to the two reports above. The RTX 3060 has the same architecture as the author's RTX 3060 Ti, but this run used a different driver. Tested (head
Not tested
Run and written with Claude Code (Claude Opus 5.5). |
|
An RDNA4 / Linux (Wine + vkd3d-proton) data point for head Tested
Not tested
AI use
|
The ISA defines v_med3_f32/v_med3_f16 over v_min_f32/v_max_f32, which order -0 below +0 (#448 settled those), so of three zeros the median is the sign two of them share; DXIL's plain FMin/FMax chain gives either zero. The zero the chain leaves now takes that majority's sign (11 instructions). A NaN still gives the minimum of the three. Noticed while porting the idea of xcl-dev/xcl#1348 (DavidM1911). Tests: hardware execution tests in valu_tests for both operand orders and the halves. Written with an AI assistant.
|
Two contributors checked independently and found that #1577 solves the same problem (for #1282) in a different way: #1607, group D3. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table. |
v_min_f32/v_max_f32/v_min_f16/v_max_f16and the 3-operand forms emitted plain HLSLmin()/max()→ DXILFMin/FMax, whose-0.0/+0.0result depends on operand order on NVIDIA/WARP. RDNA2 IEEE mode orders-0.0 < +0.0deterministically:v_min(+0,-0) = v_min(-0,+0) = -0,v_maxmirrors to+0.What is in it
fmin_ieee/fmax_ieeeHLSL helpers: NaN-suppressingmin/maxas before, with the both-zero case settled on the sign bits (min: OR keeps-0;max: AND keeps+0). Used for all four f32 forms.f16 -> f32 -> f16loses the sign of zero entirely (measured:v_add_f16(-0,-0)already yields+0on this pipeline), somin16z2/3/max16z2/3settle the zero cases on the raw halves:-0when a-0operand is present and nothing is negative,+0for max when a+0is present and nothing is positive; NaNs and nonzero results defer to the float path.abs/negmodifiers are already bitwise viahb().gpu_min_max_f32_f16_order_negative_zero: both operand orders for all eight instructions, wave32 and wave64.Note: #1301 adds a test-only version of the f32 coverage; this PR includes the f32 fix plus the f16 handling that test does not cover.
Fixes #1282
Tested
cargo test -p xcl --lib recomp: 190 passed, 0 failed, 18 ignored (RTX 3060 Ti, Windows 11, DXC 1.8.2502.11). New test passes on both wave sizes.Regression run
main
930e8b4:head
052af4d:Not tested
macOS / Linux (crate does not build there). f16
-0through other arithmetic ops (e.g.v_add_f16) remains as before — out of scope here.AI use
Devin (Cognition), frontier model. Implemented the fix and tests; ran the suite and smoke above.