Skip to content

Fix FPU_CVT_W_S: truncate toward zero and saturate like R5900 CVT.W.S - #215

Open
TheTharin wants to merge 1 commit into
ran-j:mainfrom
TheTharin:fix/cvt-w-s-truncation
Open

Fix FPU_CVT_W_S: truncate toward zero and saturate like R5900 CVT.W.S#215
TheTharin wants to merge 1 commit into
ran-j:mainfrom
TheTharin:fix/cvt-w-s-truncation

Conversation

@TheTharin

Copy link
Copy Markdown

The macro used nearbyintf(), which follows the host rounding mode (round-to-nearest by default) and has no overflow handling. R5900 CVT.W.S always truncates toward zero and clamps out-of-range results to INT32_MAX/INT32_MIN, matching the PCSX2 interpreter's CVT_W (pcsx2/FPU.cpp) and the C cast semantics PS2 compilers rely on when emitting cvt.w.s for (int)float casts.

Divergence example: game code doing (int)2.7f currently gets 3 instead of 2.
Found while recompiling Rogue Galaxy (SCUS-97490) — the game's main ELF alone contains 1013 cvt.w.s instructions.

Adds FpuMacros tests covering truncation, host-rounding-mode independence, and overflow saturation including the +/-2^31 edges.

Related:
#162 — adds the first FPU test suite in the repo (covers the CVT.W.S macro only).

The macro used nearbyintf(), which follows the host rounding mode
(round-to-nearest by default) and has no overflow handling. R5900
CVT.W.S always truncates toward zero and clamps out-of-range results
to INT32_MAX/INT32_MIN, matching the PCSX2 interpreter's CVT_W
(pcsx2/FPU.cpp) and the C cast semantics PS2 compilers rely on when
emitting cvt.w.s for (int)float casts.

Adds FpuMacros tests covering truncation, host-rounding-mode
independence, and overflow saturation including the +/-2^31 edges.
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.

1 participant