fix(lift): SCVTF / UCVTF (scalar, fixed-point) #1686
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1686
Loading…
Reference in a new issue
No description provided.
Delete branch "rainy/Longshot:fix/lift-scvtf-ucvtf-fixed-point"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
nx2/insn.pyhad the scalar fixed-point form of SCVTF and UCVTF.python -I -B tests/run_all.py --jobs 8, which has the same 40 failures as main and one more pass.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, #fbitsandSCVTF Dd, Dn, #fbits, encoding0x5F00E400with 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, encoding5f3fe7bd, 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.pywrites C for the scalar fixed-point SCVTF and UCVTF forms, as it does for other forms suyu lacks.emitinnx2/insn.pymatches(w & 0xDF80FC00) == 0x5F00E400with immh 01xx for S or 1xxx for D, and the newfixed_to_fpwrites a call to suyu's ownrecomp_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/test_insn_fixed_convert.pyruns 26 forms in each of the four FPCR rounding modes in Unicorn and in a small C harness built frominsn.emitand 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 8on 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 @
2f1c0c9cin this environmenttests/test_bug_report_defaults.pytests/test_bug_report.pytests/test_capture_read_once.pytests/test_crash_groups.pytests/test_crash_record.pytests/test_crt_options.pytests/test_damage_debug_menu.pytests/test_dev_packs.pytests/test_display_startup_failure.pytests/test_dlss_feature_size.pytests/test_failed_compile_keeps_objects.pytests/test_guest_imported.pytests/test_hardware_report.pytests/test_high_fps_fixes.pytests/test_host_guest_writes.pytests/test_hud_layout_row.pytests/test_invalidate_quick.pytests/test_libc_hooks.pytests/test_link_path_comma.pytests/test_linux_preflight.pytests/test_linux_pressure.pytests/test_linux_update.pytests/test_log_open_failure.pytests/test_missing_nup.pytests/test_mods_size_table.pytests/test_pending_guest_import.pytests/test_pipeline_play_cache.pytests/test_prepare_cache_save.pytests/test_present_thread.pytests/test_profiling_mode.pytests/test_psychov35_fsr3_fg.pytests/test_readback_timeout_source.pytests/test_run_all_changed.pytests/test_slow_frames.pytests/test_song_note_cue.pytests/test_switch_table.pytests/test_upscaler_rows.pytests/test_vcore_escape.pytests/test_walk_key.pytests/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.pyfails (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:
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
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/that reads changed source updated in this PR, not weakened.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.
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):
nx2/insn.py:274):(w & 0xDF80FC00) == 0x5F00E400matches01 U 111110 immh immb 111001, with U left out of the mask.(w >> 21) & 3keeps 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 == 0x0F00E400under mask0x9F80FC00) only takes the vector form, where bit 28 is clear, so no word that suyu translated before is now taken here.2*esize - immh:immbcomes 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, andvreg[rd][1] = 0clears 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 beforereturn 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.pyis a lift source, somake_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.pychecks 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.unicornis already inrequirements.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.