Skip to content

[upstream #1020] Recompiler: v_cvt_rpi rounds the exact x + 0.5; v_cvt_rpi / v_cvt_flr saturate NaN by sign - #116

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1020
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1020

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Branch fix/cvt-rpi-flr, commit 7aa6682 (on e50836b). AI-assisted (Claude Code).

The hardware result

Measured on RDNA2 silicon (gfx1036), identical in all four FLOAT_MODE settings:
Marvisak/VIctory#605 (comment)

  • v_cvt_rpi_i32_f32 is the floor of the exact x + 0.5. XCL emitted floor(x + 0.5f), which rounds the sum first: 0.49999997 (0x3EFFFFFF) gave 1 instead of 0, 2^23 + 1 gave 2^23 + 2, and 2^24 - 1 gave 2^24.
  • v_cvt_rpi_i32_f32 and v_cvt_flr_i32_f32 give 0x7FFFFFFF for a positive NaN and 0x80000000 for a negative NaN, quiet or signalling. XCL gave 0. v_cvt_i32_f32 keeps giving 0 for any NaN, as before.

The fix

emit.rs: two helpers in the prelude, cvt_rpi and cvt_flr.

  • cvt_rpi takes floor(x) and adds 1 when x - floor(x) >= 0.5. Both operations are exact in f32. This only applies below 2^23, because from 2^23 up every f32 is already an integer.
  • nan_by_sign saturates a NaN based on its sign bit.
  • A flr of a negative denormal depends on the denormal mode, so it is left as XCL already treats denormals. The test does not cover it.

Test

gpu_cvt_rpi_flr_round_exactly_and_saturate_nan_by_sign (crates/xcl/src/gpu/recomp/tests.rs) runs 16 rows of the measured table through rpi, flr and i32 across 64 lanes and compares bits.

  • On main e50836b it fails with 13 mismatches.
  • On the branch it passes.

Tested

RTX 3070, driver 616.56, Windows 11. Each branch has its own target dir.

  • Branch, cargo test --workspace --no-fail-fast -- --test-threads=4: 705 passed, 0 failed, 41 ignored, with the usual two no-wave64 skips.
  • main e50836b, same command: 704 passed, 0 failed, 41 ignored.

Two earlier full runs on the branch, made right after the disk filled and was cleaned up, each failed the same three hle::d3d12x tests. On rerun they did not come back:

  • 3 back-to-back hle::d3d12x:: runs: 105/105 each time.
  • 3 lib runs: clean.
  • 2 workspace runs: clean.

The root failure is placed_title_textures_share_vram_and_preserve_pixels (title_textures.rs:1897, "cubemap extra_pages must be reused at same va"). The other two failures are PoisonErrors from the shared lock that this test's panic left poisoned. That test depends on global VRAM allocator state, and this change does not touch that code. It is worth reporting as a separate flake finding.

Regression run
We have no retail title; this changes crates/xcl/src/gpu/recomp/emit.rs, so it needs one. Could someone with a title post the xcl-smoke blocks for main and this head?

main:

PR:

Not tested

  • Retail titles; AMD hardware (the expected values are the RDNA2 measurement cited in the test, not a run of this code on AMD).
  • v_cvt_flr of a negative denormal: it depends on the float mode (0 flushed, -1 kept), so it stays as XCL already treats denormals and isn't tested.

AI use

  • AI-assisted (Claude Code): checked the hardware reports against the code, wrote the fix, the test and this description, and ran the tests above.

🤖 Generated with Claude Code


Mirror of xcl-dev#1020 (auto-synced, do not edit).

…N by sign

Measured on RDNA2 silicon (gfx1036, the same in all four FLOAT_MODE
settings; Marvisak/VIctory#605 (comment)):

- v_cvt_rpi_i32_f32 is the floor of the exact x + 0.5. XCL's
  floor(x + 0.5f) rounds the sum first: 0.49999997 gave 1, 2^23 + 1
  gave 2^23 + 2, 2^24 - 1 gave 2^24.
- v_cvt_rpi_i32_f32 and v_cvt_flr_i32_f32 give 0x7FFFFFFF for a
  positive NaN and 0x80000000 for a negative one, quiet or signalling.
  XCL gave 0, which stays right for v_cvt_i32_f32 / v_cvt_u32_f32.

cvt_rpi takes floor(x) and adds 1 when x - floor(x) >= 0.5, both exact
in f32, below 2^23 (from there every f32 is an integer); nan_by_sign
saturates a NaN on the bits. A flr of a negative denormal depends on
the denormal mode and is left as XCL treats denormals.

gpu_cvt_rpi_flr_round_exactly_and_saturate_nan_by_sign uses the
measured table as expected values; it fails on main with 13 mismatches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1020 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1020 branch November 25, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants