cpu: zero-extend 32-bit destinations of zero-count shifts #239
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/242"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Spaghetih on 2026-11-21T19:00:52Z.
## Change
Independent problem: a silent mistranslation in
lower()(tools/ffx_version_query.py), the shared integer lowering behind theffx_*translators,bink_heap_aotand theheap_layout/version_queryfixtures.An immediate SHL, SHR or SAR whose masked count is zero was lowered to
;. The flags are indeed unchanged in that case, but a 32-bit destination is still written, so the upper half of the 64-bit register clears. Measured on Windows with a MASM fixture, for RAX =0xdeadbeef12345678beforeshl eax, 0:c1 e0 00shl eax, 00x123456780xdeadbeef12345678c1 f8 00sar eax, 00x123456780xdeadbeef12345678c1 e0 20shl eax, 32(count masked to 0)0x123456780xdeadbeef12345678The zero-count case now emits the zero-extending write of the destination and leaves
zero/carryuntouched. A 64-bit destination is unchanged, as before.Shared interface:
lower(). #233, now merged, editedaddress()in the same function. This PR touches only the shift branch.The second commit adds
shift_count→cpu_aot_shift_counttoCPU_FIXTURESintools/form_coverage.py. Without it the coverage report lists the new fixture as unclassified. #252 classifies the fixtures already onmainat another position in the table. All three branches merge cleanly in sequence, andform_coverage_checkpasses on the combination.Verification
Commit
8ffdf5c, rebased on1485f17after #233 merged. The only conflict was the adjacent paragraph indocs/experiments.md, and both paragraphs are kept. The first figures below were measured at7320a70on3911995; the rebased head was re-run as noted. Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.14.6,iced-x861.21.0,pefile2024.8.26.132 native and translated zero-count shift cases matched the reference. Passed.tools/ffx_version_query.pyfrom3911995:AssertionError: lifted shl_zero(0xdeadbeef12345678) = 0xdeadbeef12345678, expected 0x12345678. Failed as expected.The native image runs against the same Python reference before the translation, so the expected values are checked on hardware and not only assumed.
ctestgave 113 passed, 0 failed and 3 capability skips:bvh_wave64_hardware,bvh_wave64_warp(lane range excludes 64) andwave_shuffle_warp. The hardware tests ran on an NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088.form_coverage_checkprintedform coverage checks passed.Local package check. I used a local copy of the loader and upscaler whose SHA-256 values match the
LOADERandUPSCALERprofiles.ffx_version_query.py,ffx_device_init.pyandffx_create_context.pygenerated byte-identical C++ before and after this change (171, 1290 and 109 lines). None of the selected package intervals uses a zero-count shift. In a separate build configured with-DFFX_UPSCALER_IMAGE, the 8ffx_*tests passed and the full suite gave 114 passed with the same 3 skips.Rebased head
8ffdf5c:cpu_aot_shift_count,cpu_aot_address_sizeandcpu_lower_prefixespass together. The fullctestgave 117 passed, 0 failed and the same 3 capability skips.form_coverage_checkpassed. The three package translations are still byte-identical to1485f17.A local differential sweep of 539 single-instruction forms through
lower()(ALU, SBB, INC/DEC, shifts, IMUL, MOVZX/MOVSXD, CMOVcc, SETE, LEA and CDQ, at 8/16/32/64 bits, including AH/DH) found no value mismatch other than the six zero-count forms fixed here:shl/shr/sar eaxwith counts 0 and 32. The only other difference was ZF after IMUL, which Intel documents as undefined. The sweep is not part of this PR.Evidence and follow-up
tests/cpu/shift_count.asm,.defand.pyare original source written for this repository under its MIT license. They need no game files. The fixture covers:shl,shrandsar eax, 0;shl eax, 32, whose count is masked to 0;shl rax, 64, a 64-bit destination that must stay unchanged;shl eax, 3, a nonzero control through the existing path;flags_zero, wherecmp ecx, edx; shl eax, 0; sete almust still observe the compare. A zero low half in the initial RAX would expose a lowering that recomputed ZF from the shift result.Inputs include
0xdeadbeef12345678,0xffffffff00000000and0x8000000000000001.docs/experiments.mddescribes the behavior and gives the command.Compilers rarely emit a literal zero count, so this is a correctness fix for the lowering rather than a change observed in a package interval.
Checklist
AI-assisted (Claude Code). Every result above was run locally on the configuration listed.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:14:48Z.
At
7320a706, Git reports a conflict only indocs/experiments.md. The shared lowerer and CMake changes merge automatically. Please retain both the #233 address-size results and the shift-count results, then reruncpu_aot_shift_countandcpu_aot_address_sizeon the rebased Windows build.Imported from R0Y00/Xbox2Windows. Originally posted by Spaghetih on 2026-11-21T19:37:05Z.
Done. The branch was rebased onto
1485f17(8ffdf5c), andccf1794adds theshift_countrow toCPU_FIXTURES. Indocs/experiments.mdboth paragraphs are kept, in order: the #233 address-size results, then the zero-count shift results.Re-checked just now against current
main7233cec:ccf1794merges without conflict (CMakeLists.txtanddocs/experiments.mdauto-merge), and the merged docs keep the prefix, address-size and shift paragraphs. On that merged Windows build (Windows 11 26200.9974, MSVC 14.44.35207, Python 3.14.6):Full
ctest --preset dev --no-tests=error: 119 passed, 0 failed, 3 capability skips (bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp). Windows CI onccf1794passed all three jobs.AI-assisted (Claude Code); run locally on the configuration above.