tombox-xshader: v_cvt_rpi_i32_f32 rounds x + 0.5 in f32, and rpi/flr map NaN to 0; gfx1036 gives the exact floor and a NaN saturated by its sign #374
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#374
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?
@KainanP on GitHub · 2026-11-24 18:18 UTC · original
crates/tombox-xshader/src/hlsl.rs(main):tb_cvt_ireturns 0 for a NaN. The reference intests/exec.rs(vector_vop1) also usescvt_i((x + 0.5).floor())and NaN → 0, so the test cannot catch either difference.What RDNA 2 silicon does. Lyrnc measured this on a gfx1036 with inline assembly, the same in all four FLOAT_MODE settings: https://github.com/Marvisak/VIctory/pull/605#issuecomment-7123302580. A second gfx1036 run (and RDNA 4) agrees: https://github.com/xcl-dev/xcl/pull/639#issuecomment-7127563021
v_cvt_rpi_i32_f32is the floor of the exact x + 0.5. 0.49999997 (0x3EFFFFFF) gives 0, not 1. 8388609.0 gives 8388609, not 8388610. -8388609.0 gives -8388609.v_cvt_rpi_i32_f32andv_cvt_flr_i32_f32of a NaN give0x7FFFFFFFfor a positive NaN and0x80000000for a negative one, quiet or signalling.v_cvt_i32_f32/v_cvt_u32_f32of a NaN still give 0.Prior art. xcl-dev/xcl#1020 fixes the same two points.
rpibecomesr = floor(x); r + (x - r >= 0.5), which is exact in f32 below 2^23; from 2^23 up x is already an integer. NaN goes through a sign-bit select. It was verified on gfx1036 and RDNA 4 and caught 13 mismatches before the fix. VIctory#605 does the same.Suggested test rows:
0x3EFFFFFF,0x4B000001,0x4B000003,0xCB000001, and ±qNaN / ±sNaN for both rpi and flr, with the expected values above.Not covered: console hardware (gfx1036 is a desktop RDNA 2 APU of the same generation), and
flrof a negative denormal, which depends on the denormal mode.AI-assisted (Claude Code). I read the code at main; the hardware values are quoted from the linked threads.