cpu: lower x64 string instructions in the shared lifter #362
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/368"
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 denn0x on 2026-11-21T23:37:41Z.
Change
Advances CPU translation coverage. The x64 string instructions are an independent problem: none of
movs,stos,lods,scas,cmps,cldorstdlowers today, and no open PR or issue claims them. There is no prerequisite PR. The shared interface islower()intools/ffx_version_query.pyandCPU_FIXTURESintools/form_coverage.py, which #287, #289, #291, #326, #328, #331 and #335 also extend. This change adds oneelifbranch, a separatestring_op()helper and a conditionalbool directiondeclaration on its own line. It leaves thezero/carrydeclaration and the existing branches untouched, so whichever of these lands later needs only a short merge.Lowering.
Code, not mnemonic. The SSE2 scalarmovsdandcmpsdshare their mnemonics and stay unsupported.rep movsbwith RDI = RSI + 1 therefore replicates the first byte as on the hardware.cmpscomputes [RSI] − [RDI] andscascomputes the accumulator − [RDI]. Like the rest oflower(), only ZF and CF are modelled. Whichever change later adds OF, SF or PF tolower()should extendscasandcmpstoo.lodsbandlodswmerge into RAX;lodsdzero-extends.cldandstdset adirectionflag that starts clear. The x64 software conventions expect DF clear on function exit and on entry to runtime and system calls.movs,stosandlods;Fixture
tests/cpu/string_ops.asmbuilds 62 exports:movs,stosandlodsunder REP;scasandcmpsunder REPE and REPNE;Each export takes destination, source, count and a state block. It sets RDI, RSI, RCX and RAX from them and sets the flags from a preset: CF only, ZF only, or neither. It reports ZF, CF, RAX, RSI, RDI and RCX. RSI and RDI are callee-saved and kept in R10 and R11.
tests/cpu/string_ops.py checkruns 39984 cases. Each one goes to the native DLL, the translation and a Python reference, which executes one element at a time.0x5a, between two 1 KiB guards. Memory is compared over the guards too.Negative controls. Three translations of the same image are mutated after lowering, and each must mismatch:
memmovemovsbecomes one whole-rangestd::memmoveswappedcmpsoperands swappedforwardstdignoredThe check also confirms each rejection by its diagnostic, using synthetic bytes:
67 f3 a4,67 ae,f2 a4,f2 48 ab,f2 ac,64 a4, and the SSE2movsd xmm0, xmm1andcmpeqsd. Onmain,lower()rejects the same bytes, for examplef3 a4 c3withunsupported query operation at 0x1000: rep movsb, soemitcannot translate the fixture.Verification
Tested at
a70c9econ9bdbb20. Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0, Python 3.13, AMD Ryzen 7 7700 (Zen 4).ctest --preset dev --no-tests=error --output-junit <repo>/out/test-results.xmlgives 144 passed, 1 failed and 2 capability skips (bvh_wave64_warp,wave_shuffle_warp, as onmainon this machine). The run includes the GPU tests. The failure isgpu_alias_lookup_writes_hardware, which #332 changed onmainjust before this rebase. This change touches no GPU code. On the RX 9070 XT (driver 32.0.32015.7029, debug layer enabled), the probe printsarray_atomics ... expected=64 actual=256,256,256,256, while the fixture's own add/sub and other checks reportmismatches=0. I'll follow that up separately. Before the rebase, onbc24dfd, the same suite gave 145 passed.ctest --preset dev --no-tests=error -R '^cpu_'gives 43/43 passed, including the existingcpu_lower_prefixesencodings.tests/form_coverage_check.pyandtests/docs_links_check.pypass.a70c9ecin the fork'sWindows checksrun 44962440518.Coverage.
python tools/form_coverage.py out/test-results.xmlgives x64 77 of 948 forms. The same JUnit file withoutcpu_aot_string_opsgives 55. The 22 added forms aremovs,stos,lods,scasandcmpsin four widths, pluscldandstd. The reference listsmovsdandcmpsdonce each, under Integer. A future SSE2 fixture that uses scalarmovsdwould therefore count the same form.Measured, not established: the fixture checks architectural results on one host CPU. It does not cover RCX wrap at 2^64, faults part-way through a repeated instruction, the restart behaviour after an interrupt, or the flags this lowering does not model (OF, SF, AF, PF).
Evidence
The fixture is synthetic and original to this repository (MIT).
docs/experiments.mddocuments the lowering, the fixture and its controls.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-22T02:08:00Z.
Rebased onto
c2fc84cas791dbcb, resolving thelower()signature conflict with #422 that I mentioned there.string_op()stays abovelower(), and the signature keepsx87=False. The other files merged unchanged.ctest --preset dev --no-tests=error -R '^cpu_' -j 8gives 46 of 46 passed, includingcpu_aot_string_opsand both x87 tests.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-22T02:49:11Z.
Rebased again onto
1606f7bas5b2fd02. The conflict was additive: #291'srotates_shiftsfixture now sits at the same spot inCMakeLists.txtandCPU_FIXTURES, and both entries are kept.ctest --preset dev --no-tests=error -R '^cpu_' -j 8gives 50 of 50 passed, includingcpu_aot_string_opsandcpu_aot_rotates_shifts.AI-assisted (Claude Code).