Recompiler: v_min_f32 / v_max_f32 / v_min_f16 / v_max_f16 (and 3-op forms) emit plain HLSL min/max, violating RDNA2 -0.0 < +0.0 ordering on NVIDIA/WARP #1282
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#1282
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@hyperland956-lgtm on GitHub · 2026-11-24 14:15 UTC · original
Summary
In
crates/xcl/src/gpu/recomp/emit.rs, scalar and 3-operand float min/max instructions emit plain HLSLmin()/max():emit.rs:2987-2992:v_min_f16,v_max_f16,v_min3_f16,v_max3_f16emit.rs:3362-3363, 3374-3375:v_min_f32,v_max_f32,v_min3_f32,v_max3_f32On RDNA2 in IEEE mode,
v_min_*andv_max_*strictly order-0.0 < +0.0:v_min(+0.0, -0.0) == -0.0andv_min(-0.0, +0.0) == -0.0v_max(-0.0, +0.0) == +0.0andv_max(+0.0, -0.0) == +0.0Plain HLSL
min(a, b)/max(a, b)lowers to DXILFMin/FMax, which does not guarantee signed-zero ordering across D3D12 drivers (on NVIDIA and WARP,min(+0.0, -0.0)can return+0.0andmax(-0.0, +0.0)can return-0.0, depending on operand order). Note that XCL already handles-0.0explicitly for float atomics (#38), and #679 / #719 addressfma_legacyand NaN behavior inmin/max, but signed-zero ordering forv_min_*/v_max_*is not yet covered.Suggested fix
Add small helper functions (e.g.,
fmin_ieee(float a, float b)/fmax_ieee(float a, float b)and f16 equivalents) that preserve NaN-suppressingmin/maxwhile resolving thea == 0.0 && b == 0.0case via sign-bit OR (for min:asfloat(asuint(a) | asuint(b))) and sign-bit AND (for max:asfloat(asuint(a) & asuint(b))), and use them forv_min_*,v_max_*,v_min3_*, andv_max3_*.Synthetic GPU test
Run
v_min_f32,v_max_f32,v_min_f16,v_max_f16,v_min3_f32,v_max3_f32on both(+0.0, -0.0)and(-0.0, +0.0)and assert on raw bit patterns (0x80000000/0x8000for min,0x00000000/0x0000for max) on NVIDIA and WARP.AI use: source-level audit of
xcl-main(crates/xcl/src/gpu/recomp/emit.rs) with Gemini; not built or run on Windows.@upipibi on GitHub · 2026-11-24 14:23 UTC · original
A measurement for this. On an RTX 3070 (driver 616.56, Windows 11),
main's HLSLmin/maxalready give the ISA's signed-zero results:min(±0, ∓0) = -0andmax(±0, ∓0) = +0, in both operand orders;v_min/max_f32,v_min3/max3_f32,v_min/max_f16,v_pk_min/max_f16andv_min/max_f64;gpu_min_max_order_minus_zero_below_plus_zero, wave32 and split wave64).WARP skips that test because it has neither 32- nor 64-lane waves, so the WARP half of this issue is untested. On AMD,
FMin/FMaxare compiled to the nativev_min/v_max, which order the zeros themselves.So I would rather land the test than the helpers. It pins the behaviour, and fails on any driver that breaks it. Wrapping every min/max in bit operations would add HLSL per instruction for no change on these drivers, the opposite of what #1269 asks for. I'll open the test as its own PR.
AI-assisted (Claude Code).