fix(lift): SCVTF / UCVTF (scalar, fixed-point) #1686

Merged
HumanBean merged 1 commit from rainy/Longshot:fix/lift-scvtf-ucvtf-fixed-point into main 2026-11-19 07:16:02 +00:00
Contributor

Type: fix · Risk: low · Tested on: Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08) · Needs: a run on Windows, any GPU

TL;DR

One form of an ARM instruction that turns a fixed-point number into a floating-point number was missing from the translator, so a build lists it as untranslated and code that runs it stops. The game's own code never uses it, but a mod's code can. This PR translates it. A new game-free test runs it against a CPU emulator, fails on main and passes here. The full check suite on this branch has the same 40 failures as main, and one more pass. It also ran in the game on Linux.

Breakdown

  • Who it helps: mods whose code converts fixed-point numbers this way.
  • What was wrong: neither suyu's translator nor nx2/insn.py had the scalar fixed-point form of SCVTF and UCVTF.
  • What changes: the single- and double-precision forms, signed and unsigned, translate to C.
  • What does not change: the game's own code, which has none of these instructions, so its build output is the same.
  • How it was checked: a new game-free test against Unicorn that fails on main and passes here, and python -I -B tests/run_all.py --jobs 8, which has the same 40 failures as main and one more pass.
  • What is still open: a run in the game on this branch.
  • Risk: low. Only code that has this instruction translates differently.

Why

A code mod, sloperinaGZ 0.0.8, on snaildev99's mods/module-gaps branch is what showed this. The Arm Architecture Reference Manual lists the scalar form of SCVTF and UCVTF for vector fixed-point: SCVTF Sd, Sn, #fbits and SCVTF Dd, Dn, #fbits, encoding 0x5F00E400 with the size in immh. It converts the integer in the low bits of Vn, divided by 2^fbits, to floating point. suyu's translator has the general-register form but not this one, so a build names it as untranslated and the code traps when it reaches it. The game's own code never uses this form. The tracker has no issue or PR for SCVTF.

How to reproduce

Seen on: Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08). The translation does not depend on the GPU or driver.
Settings and switches: defaults
Steps: translate scvtf s29, s29, #1, encoding 5f3fe7bd, for example with the game-free test below run against main.
Expected: C that converts it.
Actual: no C. The build lists it as untranslated.

What changed

nx2/insn.py writes C for the scalar fixed-point SCVTF and UCVTF forms, as it does for other forms suyu lacks.

  • lift: emit in nx2/insn.py matches (w & 0xDF80FC00) == 0x5F00E400 with immh 01xx for S or 1xxx for D, and the new fixed_to_fp writes a call to suyu's own recomp_fixed_to_fp. That call honours the FPCR's rounding mode and sets IXC, and the rest of Vd is cleared. The half-precision immh 001x is not taken. The module docstring lists the form.
  • tests: tests/test_insn_fixed_convert.py runs 26 forms in each of the four FPCR rounding modes in Unicorn and in a small C harness built from insn.emit and suyu's helpers. It compares every register and IXC, and a variant with the fraction bits one off has to differ.

Measurements

Nothing to measure. The game's own code has none of these instructions, so its build output and speed are unchanged.

Flags and settings

None

Testing

Tested: python -I -B tests/run_all.py --jobs 8 on Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08). main @ 2f1c0c9c: 685 passed, 40 failed, 97 skipped. this branch @ bd146c3d: 686 passed, 40 failed, 97 skipped, 0 new failures compared by test name. The 40 failures also fail on main. They are:

Tests that also fail on main @ 2f1c0c9c in this environment
  • tests/test_bug_report_defaults.py
  • tests/test_bug_report.py
  • tests/test_capture_read_once.py
  • tests/test_crash_groups.py
  • tests/test_crash_record.py
  • tests/test_crt_options.py
  • tests/test_damage_debug_menu.py
  • tests/test_dev_packs.py
  • tests/test_display_startup_failure.py
  • tests/test_dlss_feature_size.py
  • tests/test_failed_compile_keeps_objects.py
  • tests/test_guest_imported.py
  • tests/test_hardware_report.py
  • tests/test_high_fps_fixes.py
  • tests/test_host_guest_writes.py
  • tests/test_hud_layout_row.py
  • tests/test_invalidate_quick.py
  • tests/test_libc_hooks.py
  • tests/test_link_path_comma.py
  • tests/test_linux_preflight.py
  • tests/test_linux_pressure.py
  • tests/test_linux_update.py
  • tests/test_log_open_failure.py
  • tests/test_missing_nup.py
  • tests/test_mods_size_table.py
  • tests/test_pending_guest_import.py
  • tests/test_pipeline_play_cache.py
  • tests/test_prepare_cache_save.py
  • tests/test_present_thread.py
  • tests/test_profiling_mode.py
  • tests/test_psychov35_fsr3_fg.py
  • tests/test_readback_timeout_source.py
  • tests/test_run_all_changed.py
  • tests/test_slow_frames.py
  • tests/test_song_note_cue.py
  • tests/test_switch_table.py
  • tests/test_upscaler_rows.py
  • tests/test_vcore_escape.py
  • tests/test_walk_key.py
  • tests/test_vbytes.py (timed out at 600 s)

With the fix's source file reverted to main, python -I -B tests/test_insn_fixed_convert.py fails (nx2/insn.py has no C for scvtf s29, s29, #1 (5f3fe7bd)). It passes on this branch. In the game, built from this branch on Linux with an RTX 4090: the game boots and plays as on main.

Not testable by hand: the console case can only be reached by a code mod. The game's own code has no SCVTF or UCVTF of this form, so a run of the unmodified game cannot reach it. The Unicorn test stands in for it. A build plus a run in the game shows that nothing else changes.

Not tested: Windows (no build or run there) and other GPUs. The same change also ran in the game on snaildev99's mods/module-gaps branch, where a mod's code ran these instructions without a trap.

Must be tested:

  • Linux, any GPU: build the game on this branch, check that the build reports no new untranslated instructions, then load a save and play a few minutes, expecting the game as on main (by hand: the author, before this PR leaves WIP)
  • Windows, any GPU: the same steps, expecting the same result (Test Farm: @Beanstalk windows, build this branch, load a save and play a few minutes)

Risks

What could break: only code that has this instruction, which now runs instead of trapping.

Turning it off: revert the commit

Compatibility: Nothing changes. The game's own lifted code is the same.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what
    can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and
    in Risks.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • A game-free test added for the fix, failing on main and passing here.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
**Type:** fix · **Risk:** low · **Tested on:** Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08) · **Needs:** a run on Windows, any GPU ## TL;DR One form of an ARM instruction that turns a fixed-point number into a floating-point number was missing from the translator, so a build lists it as untranslated and code that runs it stops. The game's own code never uses it, but a mod's code can. This PR translates it. A new game-free test runs it against a CPU emulator, fails on main and passes here. The full check suite on this branch has the same 40 failures as main, and one more pass. It also ran in the game on Linux. ## Breakdown - **Who it helps:** mods whose code converts fixed-point numbers this way. - **What was wrong:** neither suyu's translator nor `nx2/insn.py` had the scalar fixed-point form of SCVTF and UCVTF. - **What changes:** the single- and double-precision forms, signed and unsigned, translate to C. - **What does not change:** the game's own code, which has none of these instructions, so its build output is the same. - **How it was checked:** a new game-free test against Unicorn that fails on main and passes here, and `python -I -B tests/run_all.py --jobs 8`, which has the same 40 failures as main and one more pass. - **What is still open:** a run in the game on this branch. - **Risk:** low. Only code that has this instruction translates differently. ## Why A code mod, sloperinaGZ 0.0.8, on snaildev99's mods/module-gaps branch is what showed this. The Arm Architecture Reference Manual lists the scalar form of SCVTF and UCVTF for vector fixed-point: `SCVTF Sd, Sn, #fbits` and `SCVTF Dd, Dn, #fbits`, encoding `0x5F00E400` with the size in immh. It converts the integer in the low bits of Vn, divided by 2^fbits, to floating point. suyu's translator has the general-register form but not this one, so a build names it as untranslated and the code traps when it reaches it. The game's own code never uses this form. The tracker has no issue or PR for SCVTF. ## How to reproduce **Seen on:** Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08). The translation does not depend on the GPU or driver. **Settings and switches:** defaults **Steps:** translate `scvtf s29, s29, #1`, encoding `5f3fe7bd`, for example with the game-free test below run against main. **Expected:** C that converts it. **Actual:** no C. The build lists it as untranslated. ## What changed `nx2/insn.py` writes C for the scalar fixed-point SCVTF and UCVTF forms, as it does for other forms suyu lacks. - lift: `emit` in `nx2/insn.py` matches `(w & 0xDF80FC00) == 0x5F00E400` with immh 01xx for S or 1xxx for D, and the new `fixed_to_fp` writes a call to suyu's own `recomp_fixed_to_fp`. That call honours the FPCR's rounding mode and sets IXC, and the rest of Vd is cleared. The half-precision immh 001x is not taken. The module docstring lists the form. - tests: `tests/test_insn_fixed_convert.py` runs 26 forms in each of the four FPCR rounding modes in Unicorn and in a small C harness built from `insn.emit` and suyu's helpers. It compares every register and IXC, and a variant with the fraction bits one off has to differ. ## Measurements Nothing to measure. The game's own code has none of these instructions, so its build output and speed are unchanged. ### Flags and settings None ## Testing **Tested:** `python -I -B tests/run_all.py --jobs 8` on Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08). main @ 2f1c0c9c: 685 passed, 40 failed, 97 skipped. this branch @ bd146c3d: 686 passed, 40 failed, 97 skipped, 0 new failures compared by test name. The 40 failures also fail on main. They are: <details> <summary>Tests that also fail on main @ 2f1c0c9c in this environment</summary> - `tests/test_bug_report_defaults.py` - `tests/test_bug_report.py` - `tests/test_capture_read_once.py` - `tests/test_crash_groups.py` - `tests/test_crash_record.py` - `tests/test_crt_options.py` - `tests/test_damage_debug_menu.py` - `tests/test_dev_packs.py` - `tests/test_display_startup_failure.py` - `tests/test_dlss_feature_size.py` - `tests/test_failed_compile_keeps_objects.py` - `tests/test_guest_imported.py` - `tests/test_hardware_report.py` - `tests/test_high_fps_fixes.py` - `tests/test_host_guest_writes.py` - `tests/test_hud_layout_row.py` - `tests/test_invalidate_quick.py` - `tests/test_libc_hooks.py` - `tests/test_link_path_comma.py` - `tests/test_linux_preflight.py` - `tests/test_linux_pressure.py` - `tests/test_linux_update.py` - `tests/test_log_open_failure.py` - `tests/test_missing_nup.py` - `tests/test_mods_size_table.py` - `tests/test_pending_guest_import.py` - `tests/test_pipeline_play_cache.py` - `tests/test_prepare_cache_save.py` - `tests/test_present_thread.py` - `tests/test_profiling_mode.py` - `tests/test_psychov35_fsr3_fg.py` - `tests/test_readback_timeout_source.py` - `tests/test_run_all_changed.py` - `tests/test_slow_frames.py` - `tests/test_song_note_cue.py` - `tests/test_switch_table.py` - `tests/test_upscaler_rows.py` - `tests/test_vcore_escape.py` - `tests/test_walk_key.py` - `tests/test_vbytes.py` (timed out at 600 s) </details> With the fix's source file reverted to main, `python -I -B tests/test_insn_fixed_convert.py` fails (`nx2/insn.py has no C for scvtf s29, s29, #1 (5f3fe7bd)`). It passes on this branch. In the game, built from this branch on Linux with an RTX 4090: the game boots and plays as on main. **Not testable by hand:** the console case can only be reached by a code mod. The game's own code has no SCVTF or UCVTF of this form, so a run of the unmodified game cannot reach it. The Unicorn test stands in for it. A build plus a run in the game shows that nothing else changes. **Not tested:** Windows (no build or run there) and other GPUs. The same change also ran in the game on snaildev99's mods/module-gaps branch, where a mod's code ran these instructions without a trap. **Must be tested:** - Linux, any GPU: build the game on this branch, check that the build reports no new untranslated instructions, then load a save and play a few minutes, expecting the game as on main (by hand: the author, before this PR leaves WIP) - Windows, any GPU: the same steps, expecting the same result (Test Farm: @Beanstalk windows, build this branch, load a save and play a few minutes) ## Risks **What could break:** only code that has this instruction, which now runs instead of trapping. **Turning it off:** revert the commit **Compatibility:** Nothing changes. The game's own lifted code is the same. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] A game-free test added for the fix, failing on `main` and passing here. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened.
fix(lift): SCVTF / UCVTF (scalar, fixed-point)
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 7s
Website / Website on Cloudflare (pull_request_target) Has been skipped
bd146c3d4b
The Advanced SIMD scalar form with fraction bits (Arm ARM: SCVTF (vector,
fixed-point) and UCVTF (vector, fixed-point), scalar; Sd, Sn, #fbits and
Dd, Dn, #fbits) was in neither suyu's translator nor nx2/insn.py: a build
names it as untranslated and code that runs one traps. The game's own code
has none; a mod's code module can.

S and D, signed and unsigned, through suyu's own recomp_fixed_to_fp (the
FPCR's rounding, IXC), the rest of Vd cleared; the half-precision immh is
not taken. tests/test_insn_fixed_convert.py runs 26 forms in the 4 rounding
modes against Unicorn; it fails on main.

Assisted-by: Grok Bot
Author
Contributor

Tested in game: Linux (Omarchy, kernel 7.2.15), Intel Core Ultra 7 270K Plus, RTX 4090 driver 615.78.08, a build of this branch on v3.0.0-rc.8: the game boots and plays as on main.

Tested in game: Linux (Omarchy, kernel 7.2.15), Intel Core Ultra 7 270K Plus, RTX 4090 driver 615.78.08, a build of this branch on v3.0.0-rc.8: the game boots and plays as on main.
HumanBean left a comment

From the code and the evidence, this looks ready to merge. Nothing blocks it.

Semantics, checked against the Arm ARM (SCVTF/UCVTF (vector, fixed-point), scalar):

  • Decode (nx2/insn.py:274): (w & 0xDF80FC00) == 0x5F00E400 matches 01 U 111110 immh immb 111001, with U left out of the mask. (w >> 21) & 3 keeps immh 1xxx (D) and 01xx (S). It drops 001x (H, FEAT_FP16) and 0000 (unallocated). suyu's own fixed-point convert (arm64_to_c.h, fixed_key == 0x0F00E400 under mask 0x9F80FC00) only takes the vector form, where bit 28 is clear, so no word that suyu translated before is now taken here.
  • fbits = 2*esize - immh:immb comes out as 1..32 for S and 1..64 for D, as the ARM says. The integer is Vn's low esize bits (masked), signed when U = 0.
  • recomp_fixed_to_fp(bits, width, width, fbits, signed, fpcr, &fpsr) is the helper suyu already uses for the general-register fixed-point form. It rounds in FPCR.RMode (all four modes), sets only IXC, and uses no host FP. Overflow and saturation cannot happen: |int| / 2^fbits stays between 2^-64 and 2^64, a finite normal in S and in D, so FZ/DN don't apply. INT_MIN and fbits = 64 are handled. The 32-bit result comes back zero-extended, and vreg[rd][1] = 0 clears the rest of Vd, as a scalar write does.

Does anything else change? No other instruction's C changes. emit() is consulted for every word before suyu, but the new test is the last one before return None, and its mask is exact. Every other word goes to suyu as before, and the only extra cost is one AND and compare per word in the translate, which is negligible. One thing "build output unchanged" leaves out: nx2/insn.py is a lift source, so make_game.py's lift key changes and the first build after updating translates the game again, once. Any change to this file does that, and the lifted C comes out the same, so it is not a regression. It could go in the PR's Risks in a line.

Test: tests/test_insn_fixed_convert.py checks results, not text. It runs Unicorn's "max" CPU against the emitted C, compiled with suyu's own helper texts cut from the header. 26 forms (S/D, signed/unsigned, fbits at 1 and at the top, rd == rn, register 31) run in all four rounding modes with random state and edge values (0, ±1, the most negative, the largest, values that round, garbage in Vn's upper bits for S). It compares every X register, both halves of every V register and IXC. It also checks that the H, vector, FCVTZS and SQSHRN neighbours are not taken, and that a variant with fbits one off fails. unicorn is already in requirements.txt.

Measurements: none needed. The game's code doesn't reach this form, the lifted C for every other word is the same, and the per-word cost is one mask test. The game-free test fails on main and passes here, and the author's run in the game on Linux / RTX 4090 boots and plays as on main.

From the code and the evidence, this looks ready to merge. Nothing blocks it. **Semantics, checked against the Arm ARM (SCVTF/UCVTF (vector, fixed-point), scalar):** - Decode (`nx2/insn.py:274`): `(w & 0xDF80FC00) == 0x5F00E400` matches `01 U 111110 immh immb 111001`, with U left out of the mask. `(w >> 21) & 3` keeps immh 1xxx (D) and 01xx (S). It drops 001x (H, FEAT_FP16) and 0000 (unallocated). suyu's own fixed-point convert (`arm64_to_c.h`, `fixed_key == 0x0F00E400` under mask `0x9F80FC00`) only takes the vector form, where bit 28 is clear, so no word that suyu translated before is now taken here. - fbits = `2*esize - immh:immb` comes out as 1..32 for S and 1..64 for D, as the ARM says. The integer is Vn's low esize bits (masked), signed when U = 0. - `recomp_fixed_to_fp(bits, width, width, fbits, signed, fpcr, &fpsr)` is the helper suyu already uses for the general-register fixed-point form. It rounds in FPCR.RMode (all four modes), sets only IXC, and uses no host FP. Overflow and saturation cannot happen: |int| / 2^fbits stays between 2^-64 and 2^64, a finite normal in S and in D, so FZ/DN don't apply. INT_MIN and fbits = 64 are handled. The 32-bit result comes back zero-extended, and `vreg[rd][1] = 0` clears the rest of Vd, as a scalar write does. **Does anything else change?** No other instruction's C changes. `emit()` is consulted for every word before suyu, but the new test is the last one before `return None`, and its mask is exact. Every other word goes to suyu as before, and the only extra cost is one AND and compare per word in the translate, which is negligible. One thing "build output unchanged" leaves out: `nx2/insn.py` is a lift source, so `make_game.py`'s lift key changes and the first build after updating translates the game again, once. Any change to this file does that, and the lifted C comes out the same, so it is not a regression. It could go in the PR's Risks in a line. **Test:** `tests/test_insn_fixed_convert.py` checks results, not text. It runs Unicorn's "max" CPU against the emitted C, compiled with suyu's own helper texts cut from the header. 26 forms (S/D, signed/unsigned, fbits at 1 and at the top, rd == rn, register 31) run in all four rounding modes with random state and edge values (0, ±1, the most negative, the largest, values that round, garbage in Vn's upper bits for S). It compares every X register, both halves of every V register and IXC. It also checks that the H, vector, FCVTZS and SQSHRN neighbours are not taken, and that a variant with fbits one off fails. `unicorn` is already in `requirements.txt`. Measurements: none needed. The game's code doesn't reach this form, the lifted C for every other word is the same, and the per-word cost is one mask test. The game-free test fails on main and passes here, and the author's run in the game on Linux / RTX 4090 boots and plays as on main.
HumanBean deleted branch fix/lift-scvtf-ucvtf-fixed-point 2026-11-19 07:16:02 +00:00
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 7s
Website / Website on Cloudflare (pull_request_target) Has been skipped
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1686
No description provided.