Skip to content

Translator: v_cvt_flr_i32_f32 and v_cvt_rpi_i32_f32 - #624

Merged
ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
LouisRiverstone:valu-cvt-flr-rpi
Nov 22, 2026
Merged

ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
LouisRiverstone:valu-cvt-flr-rpi

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

tools/rdna2spirv.py raises Unsupported on v_cvt_flr_i32_f32 and v_cvt_rpi_i32_f32, the floor and round-half-up float-to-int conversions. They aren't in the translated corpus, so this is future-proofing. Claimed in #374.

Change

  • tools/rdna2spirv.py follows the RDNA ISA pseudocode: f32_to_i32(floor(S0)) and f32_to_i32(floor(S0 + 0.5)).
    • The + 0.5 is an ordinary binary32 add, so it rounds. 0.49999997 gives 1, where an exact round-half-up would give 0.
    • f32_to_i32 saturates as v_cvt_i32_f32 does since Translator: saturate RDNA2 float-to-int conversions #300: at or past ±2³¹ and for ±inf it gives INT_MAX / INT_MIN, and NaN gives 0. Only an in-range value reaches OpConvertFToS, because SPIR-V leaves the rest undefined.
    • Source neg/abs apply before the rounding.
  • tests/semantic/test_alu_cvt_flr_rpi.py (new, stdlib unittest) checks against a plain-Python reference:
    • edge values: ±0, ±0.5, just under 0.5, ±1.5, ±2.5, 2²³ + 1, the values around ±2³¹, ±FLT_MAX, ±inf, quiet and signalling NaNs
    • 40 seeded values from 2⁻⁷ to 2³²
    • neg/abs on the source
  • docs/design.md: a contract row, next to "Float-to-int saturation".

Tested

  • python -I -m unittest discover -s tests/semantic: all pass. Without the translator change, the new file has errors (Unsupported).
  • python -m compileall -q tools tests passes. Not run on a GPU, and no game files used.

The + 0.5 rounding comes from the pseudocode and hasn't been measured on hardware. The contract row says so. v_cvt_rpi_i32_f32(0x3EFFFFFF) is the case that would tell the readings apart.

AI-assisted (Claude Code): it wrote the change and the tests, and ran the checks listed above.

LouisRiverstone and others added 3 commits November 21, 2026 22:19
Both raised Unsupported. RDNA ISA pseudocode: f32_to_i32(floor(S0)) and
f32_to_i32(floor(S0 + 0.5)), the + 0.5 rounded in binary32. The conversion
saturates as v_cvt_i32_f32 does (ItsNotRexed#300); only an in-range value reaches
OpConvertFToS.

tests/semantic/test_alu_cvt_flr_rpi.py checks both against a plain-Python
reference; docs/design.md gets a contract row.
cs_wqm_w32 (SHADER-34) and cs_w32_lane_wrap (SHADER-52) check 32-lane
EXEC/VCC masks and lane selects. On Mesa llvmpipe, whose compute
subgroups are 8 wide, they can't produce their words, and the
"GPU tests on llvmpipe" step in runtime.yml has failed on main since
91b36cf. Skip them where vk_compute_test reports a widest subgroup
below 32 lanes, the rule ps_bitmask_perm already uses, in check.py and
run_gpu_tests.py (which reuses check.py's helper). Devices with 32 or
more lanes still run and judge them.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D7JEiKsTUaHQbCTdc4Eghy
(cherry picked from commit be46677)

@IAmNotSiob IAmNotSiob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, saturation copies the v_cvt_i32_f32 one and only in-range values hit OpConvertFToS. note: rpi does floor(x + 0.5) with the add rounded in f32, so 0.49999997 → 1. that's the isa pseudocode literally, which is fine, just flagging it in case someone sees it on hw. tests pass with main (809). AI-assisted review (Claude Code).

@matheuskshn

Copy link
Copy Markdown
Contributor

Tested 9c229ed on Windows 11 / Python 3.12.14. All four tests in test_alu_cvt_flr_rpi.py passed, including the value immediately below 0.5, the saturation boundaries, NaNs, and source modifiers. That confirms the CPU model follows the documented rounded binary32 addition; the hardware question remains outside this run. AI-assisted.

# Conflicts:
#	docs/design.md
#	tools/rdna2spirv.py
main pins 48557ea again since the ItsNotRexed#666-ItsNotRexed#698 merge round, while
tools/rpf9dump/Program.cs (3816356) already uses ArchiveEntry.ResourceDrawableOffset
from 917e9b9, so the Windows 'check' job fails to compile rpf9dump on every
PR. Same one-line change as ItsNotRexed#713 / ItsNotRexed#732; whichever lands first, this merges
cleanly.
@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

CI note: the Windows check job failed here because main pins third_party/rpf9-explorer at 48557ea again since the #666–#698 merge round, while tools/rpf9dump/Program.cs (3816356) already uses ArchiveEntry.ResourceDrawableOffset from 917e9b9, so rpf9dump does not compile on any PR. I added the same one-line re-pin to 917e9b9 that #713 / #732 make (a separate commit, nothing else in it), so this PR gets a clean run; whichever lands first, the other merges cleanly.

@ItsNotRexed
ItsNotRexed merged commit adbc4f4 into ItsNotRexed:main Nov 22, 2026
9 checks passed
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.

5 participants