Lower GFX7 legacy min and max with a compare #140
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!140
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/140/head"
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?
@Yeetbot159 on GitHub · 2026-11-22 15:15 UTC · original
Yeetbot159:yeet/legacy-minmax→main· +186 −2 · 2 files · 2 commits · closed without mergingSummary
v_min_legacy_f32andv_max_legacy_f32are not HLSLminandmax. The HLSL functions return the other operand when one input is NaN. The legacy ops return source 1 when the compare is false, which is what happens when source 1 is NaN.src0 < src1 ? src0 : src1. Max issrc0 > src1 ? src0 : src1, except a tie of +0 and -0 returns source 0. The compare is false for NaN, so source 1 is kept.Test plan
cargo test -p tombox-xshader --lib gcn::testspassed (22 tests).legacy_min_returns_source1_when_source1_is_nanchecks the compare, the VOP3 form, a relocated branch, and that a modifier is an error.legacy_max_tie_of_signed_zero_keeps_source0checks the magnitude test and a NaN literal in source 0.legacy_minmax_refuses_to_clobber_a_live_scratch_registerchecks that an instruction already using s104 is rejected.@omonkeyz on GitHub · 2026-11-22 15:19 UTC · original
Thanks, the NaN analysis is right: DX9-style legacy min is
s0 < s1 ? s0 : s1and legacy max iss0 >= s1 ? s0 : s1. That>=is the simplification, please rework:v_cmp_ge_f32already gives exactly the legacy max. NaN makes it false, so you get source 1, and the +0/-0 tie makes it true, so you get source 0. That removes the magnitude test, the v254/v255 scratch, and the conflict with MUBUF addr64.v_cndmask_b32takes that pair as src2. So each op becomes two instructions,v_cmp_{lt,ge}_f32 s[104:105], src0, src1andv_cndmask_b32 vdst, src1, src0, s[104:105], with no vcc save/restore. Keep your check that nothing else uses s104:s105.@Yeetbot159 on GitHub · 2026-11-22 15:52 UTC · original
Legacy max is now
v_cmp_ge_f32 s[104:105], src0, src1followed byv_cndmask_b32 vdst, src1, src0, s[104:105]. The magnitude test, v254/v255 and the vcc save are gone. The NaN, signed-zero, branch and modifier tests still pass, andlegacy_minmax_on_warp_keeps_a_nan_in_either_sourcepassed on WARP, including a NaN in each source and the +0/-0 tie.@MiguelMatMar on GitHub · 2026-11-22 16:03 UTC · original
Independent hardware run:
legacy_minmax_on_warp_keeps_a_nan_in_either_sourcepasses on WARP and on hardware (TOMBOX_EXEC_HW=1, NVIDIA Ada / RTX 40-series), PR head5f1f9b7. That covers the NaN-in-either-source and +0/-0 tie cases on a real GPU as well.opcodes,syntheticandgcn_dimsalso pass.@omonkeyz on GitHub · 2026-11-22 16:10 UTC · original
Applied in
860d34band9d211b5(merged in1a1e283) with your authorship kept, thanks, it's much simpler now!Pull request closed