tombox-xshader: emit v_fract_f32 as x - floor(x); fix v_ceil_f16 test literal #34

Closed
github-bot wants to merge 1 commit from gh-pr/34/head into gh-pr/34/base
Owner

@⁠artareias on GitHub · 2026-11-21 18:42 UTC · original
artareias:fix-v-fract-v-ceil-f16 → main · +3 −2 · 2 files · 69 commits · closed without merging

Problem

vop::basic::vop1_basic fails 11 cases. Two of the causes are addressed here.

v_fract_f32 with negative inputs. The emitter writes frac(x), which dxc lowers to the Frc operation. On an AMD Radeon RX 7600 and on WARP, frac(-3.7) returns 0.7 (the fractional part of |x|) instead of 0.3. The RDNA 2 ISA guide (V_FRACT_F32, p. 148) defines D = S0 + -floor(S0) and gives fract(-1.2) = 0.8.

v_ceil_f16 is a test bug, not an emitter bug. The test input is 0xbc00 - 0x3c00 + 0x8001. That evaluates to 0x10001, so the low 16 bits are 0x0001, the smallest positive subnormal. ceil of a positive value is 1.0 (0x3c00), which is what the emitter returned (V_CEIL_F16, p. 156). The test meant 0x8001, the smallest negative subnormal, whose ceil is -0.0 (0x8000).

Change

  • v_fract_f32 is now emitted as (x - floor(x)). v_fract_f16 is not touched; its tests already pass.
  • tests/exec_vop/basic.rs: the v_ceil_f16 input literal is now 0x8001.

Testing

Windows 10 19045, MSVC 14.44, rustc 1.100.0, AMD Radeon RX 7600 (TOMBOX_EXEC_HW=1) and WARP:

before after
vop1_basic failing cases (RX 7600) 11 9
vop1_basic failing cases (WARP) 11 9

Per-test run of all 61 exec tests on the RX 7600 before and after: no other test changes status.

Not changed

The 9 cases left in vop1_basic are NaN sign (v_log_f32, v_rsq_f32, v_sqrt_f32, v_fract_f32: result 0xffc00000 where 0x7fc00000 is expected), v_fract_f32(-0.0) (+0 vs -0), and one v_fract_f32 case that expects 0x3f7fffff (a clamp below 1.0) where x - floor(x) gives 1.0. The manual does not describe any of these, so I left the emitter and tests as they are.

🤖 Generated with Claude Code

**@⁠artareias** on GitHub · 2026-11-21 18:42 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/34) `artareias:fix-v-fract-v-ceil-f16` → `main` · +3 −2 · 2 files · 69 commits · closed without merging ## Problem `vop::basic::vop1_basic` fails 11 cases. Two of the causes are addressed here. **`v_fract_f32` with negative inputs.** The emitter writes `frac(x)`, which dxc lowers to the `Frc` operation. On an AMD Radeon RX 7600 and on WARP, `frac(-3.7)` returns `0.7` (the fractional part of `|x|`) instead of `0.3`. The RDNA 2 ISA guide (`V_FRACT_F32`, p. 148) defines `D = S0 + -floor(S0)` and gives `fract(-1.2) = 0.8`. **`v_ceil_f16` is a test bug, not an emitter bug.** The test input is `0xbc00 - 0x3c00 + 0x8001`. That evaluates to `0x10001`, so the low 16 bits are `0x0001`, the smallest *positive* subnormal. `ceil` of a positive value is `1.0` (`0x3c00`), which is what the emitter returned (`V_CEIL_F16`, p. 156). The test meant `0x8001`, the smallest negative subnormal, whose `ceil` is `-0.0` (`0x8000`). ## Change - `v_fract_f32` is now emitted as `(x - floor(x))`. `v_fract_f16` is not touched; its tests already pass. - `tests/exec_vop/basic.rs`: the `v_ceil_f16` input literal is now `0x8001`. ## Testing Windows 10 19045, MSVC 14.44, rustc 1.100.0, AMD Radeon RX 7600 (`TOMBOX_EXEC_HW=1`) and WARP: | | before | after | |---|---|---| | `vop1_basic` failing cases (RX 7600) | 11 | 9 | | `vop1_basic` failing cases (WARP) | 11 | 9 | Per-test run of all 61 `exec` tests on the RX 7600 before and after: no other test changes status. ## Not changed The 9 cases left in `vop1_basic` are NaN sign (`v_log_f32`, `v_rsq_f32`, `v_sqrt_f32`, `v_fract_f32`: result `0xffc00000` where `0x7fc00000` is expected), `v_fract_f32(-0.0)` (`+0` vs `-0`), and one `v_fract_f32` case that expects `0x3f7fffff` (a clamp below 1.0) where `x - floor(x)` gives `1.0`. The manual does not describe any of these, so I left the emitter and tests as they are. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_fract_f32 was emitted as frac(x), which dxc lowers to the Frc operation. On
an AMD Radeon RX 7600 and on WARP, frac(-3.7) returned 0.7 (the fractional part
of |x|) instead of 0.3. The RDNA 2 ISA guide (V_FRACT_F32, p. 148) defines
D = S0 + -floor(S0) and gives fract(-1.2) = 0.8. Emit (x - floor(x)) instead.
v_fract_f16 is not touched: its tests already pass.

The v_ceil_f16 failure was a test bug, not an emitter bug. The literal
`0xbc00 - 0x3c00 + 0x8001` evaluates to 0x10001, so the low half is 0x0001, the
smallest positive subnormal, and ceil of a positive value is 1.0 (0x3c00), which
is what the emitter returned (V_CEIL_F16, p. 156). The test meant 0x8001, the
smallest negative subnormal, whose ceil is -0.0 (0x8000). Use 0x8001.

Verified: vop::basic::vop1_basic goes from 11 to 9 failing cases on both the RX
7600 and WARP. The remaining 9 are NaN sign (v_log, v_rsq, v_sqrt, v_fract),
-0 for v_fract, and one v_fract case expecting 0x3f7fffff; the manual does not
describe those, so they are not changed here.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:07:57 +00:00
github-bot closed this pull request 2026-11-26 06:07:57 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:13 UTC · original

Main's history was rewritten, which auto-closed this PR (sorry for the noise). Already covered on main by tb_fract, which also clamps below 1.0 as the ISA does. Thanks!

**@⁠omonkeyz** on GitHub · 2026-11-22 13:13 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/34#issuecomment-7079651173) Main's history was rewritten, which auto-closed this PR (sorry for the noise). Already covered on main by tb_fract, which also clamps below 1.0 as the ISA does. Thanks!
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-21 18:42 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-21 18:42 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/34#pullrequestreview-6007325541) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.