cpu: lower RCL, RCR, CLC, STC and CMC in the shared lifter #373
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/379"
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:51:09Z.
Change
Advances CPU translation coverage. The rotations through the carry flag and the carry-flag instructions are an independent problem:
lower()rejectsrcl,rcr,clc,stcandcmctoday. No open PR or issue claims them; #291 coversrol,ror,shldandshrdonly. 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, #335 and #368 also extend. This change addselifbranches only, so whichever lands later needs a short merge.Lowering.
rclandrcrin 8-, 16-, 32- and 64-bit register and memory forms, includingah, with a count of 1, an immediate or CL.lower()omits.clc,stcandcmcclear, set and complement CF.Fixture
tests/cpu/carry_rotates.asmis generated bypython tests/cpu/carry_rotates.py asm tests/cpu/carry_rotates.asm tests/cpu/carry_rotates.defand builds 102 exports:rclandrcrfor every destination (al,ah,ax,eax,rax, and byte to qword memory) with counts 1 and CL, plus immediates 0, 5, 9, 17, 33 and 65 foral,ax,eax,raxand a dword in memory.clc,stc,cmc, andstcfollowed bycmc.shl+rclandshr+rcr.Calling shape. Each export sets ZF and CF with
add r8, r8from one of four presets, which cover every ZF/CF combination. It then reports RAX, the memory operand and ZF/CF.Check.
tests/cpu/carry_rotates.py checkcompares 84000 cases against the native DLL, the translation and a Python reference written from the SDM pseudocode. CL counts run 0 to 70, plus 96, 128 and 255. The values include all-ones, single high and low bits, and upper-half noise for the 32-bit zero-extension.Negative controls. Three translations of the same image are mutated after lowering, and each must mismatch:
nomasknocarryrol/rorstcstcclears CFA first version also had a control that dropped the modulo 9/17 reduction. It matched every case, which is how I noticed that the reduction cannot change the result, so it was replaced by
nomask. Onmain,lower()rejectsd1 d0 c3withunsupported query operation at 0x1000: rcl eax,1, soemitcannot translate the fixture.Verification
Tested at
9ce4ecdon9bdbb20. 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). The run includes the GPU tests. The failure isgpu_alias_lookup_writes_hardware, which also fails onmainat9bdbb20on this RX 9070 XT; see the comment on #332. This change touches no GPU code.tests/form_coverage_check.pyandtests/docs_links_check.pypass.9ce4ecdin the fork'sWindows checksrun 44963535724.ctest --preset dev --no-tests=error -R '^cpu_'gives 44/44 passed.Coverage.
python tools/form_coverage.py out/test-results.xmlgives x64 60 of 948 forms. The same JUnit file withoutcpu_aot_carry_rotatesgives 55. The five added forms arercl,rcr,clc,stcandcmc.Measured, not established: results on one host CPU. OF and the other unmodelled flags are not compared.
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 grahamster2 on 2026-11-22T03:01:05Z.
Independent check on Windows: differential fuzzing of this PR merged locally onto main
73ed4b7, run with Windows 11 build 26200, MSVC 19.50 and ML64. It generated 1,250 random functions with RCL/RCR at 8, 16, 32 and 64 bits on registers (including AH, CH and DH) and memory operands, with counts of 1, imm8 and CL, including 8, 9, 16, 17, 33 and 63 and CL values with high bits set, mixed with CLC/STC/CMC and the CF/ZF consumers the lifter models. Each ran natively and translated on 200 inputs, comparing RAX and a 256-byte buffer. Result: 0 mismatches. The harness detects deliberate faults in rotate carry, SHRD's zero flag, the count mask and MOVBE byte order.