cpu: lift BSWAP in the switch translator #1367
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1374"
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 tedin7 on 2026-11-24T09:40:08Z.
Change
tools/cpu_switch_aot.pynow liftsBSWAPof a 32- or 64-bit register. The bytes are reversed in place, a 32-bit result zero-extends into the 64-bit register like any 32-bit write, and no flag changes, so aSETcc,JccorCMOVccafter it reads the flags of the instruction before it. The 16-bit form (operand-size prefix) is refused because the Intel SDM leaves its result undefined, as areBSWAP RSP(a dynamic frame), an unwritten register and a repeat prefix.switch_bit_countsusedBSWAPas a rejection control; it now usesXLATB, which the translator still refuses. No other behavior changes.AI-assisted. No store or atomic is involved, so there is no memory-window question.
Verification
Windows (not run by me):
ctest --preset dev -R '^cpu_aot_switch_(bswap|bit_counts)$'and the same with--preset release. This test is outside--preset pr.Linux x86-64 (what ran), with
llvm-ml-19,lld-link-19andclang++-19at-O0and-O2. The original PE was mapped into memory and called through the Windows x64 convention together with the register probe, since Wine has no 32-bit support on this machine:switch_bswap_check.py: 33 exports x 829 inputs = 27,357 comparisons of the original, the translation and a Python reference (int.to_bytes/int.from_bytes), 4 rejection controls, 0 mismatches at both optimization levels. Register probe sentinels (RBX, RSI) match.origin/main: the same fixture is refused withunsupported flag producerbecauseBSWAPis not lifted.bswap64_rdx, flags overwritten afterBSWAP) each fail at the first input that exposes them.switch_bit_counts_check.check_rejections: 8 of 8 controls pass.py_compileof the three Python files,tests/docs_links_check.py,tests/bidi_controls_check.py,git diff --check,x2w_pipe.py preflight: pass.Not run: MSVC, ML64, Wine, Intel hardware, the other
cpu_aot_*Windows tests.Evidence and follow-up
The fixture is original assembly written for this change (MIT, no external input). It covers 15 registers (RAX to R15 without RSP) at 32 and 64 bits, each between two
CMPs whose sixteen conditions are stored, plus a 64-then-32-bit sequence andJBandCMOVLafterBSWAP. Inputs include zero, one, 0x80, 0x0123456789abcdef, all ones, single bits and values with zero upper bytes.docs/experiments.mddocuments the new capability and its measurements.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:44:19Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit
384ee4acec19ed0a62f76b5633326f316424dcdc:--preset dev):cpu_switch_bswap*,cpu_switch_bit_counts*):3.57s(configure1.53s)ctest --preset dev -R '^(cpu_aot_switch_bswap|cpu_aot_switch_bit_counts)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_switch_bit_counts0.52s,cpu_aot_switch_bswap0.91s)/O2(--preset release):cpu_switch_bswap*,cpu_switch_bit_counts*):0.95s(configure1.64s)ctest --preset release -R '^(cpu_aot_switch_bswap|cpu_aot_switch_bit_counts)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_switch_bit_counts0.49s,cpu_aot_switch_bswap0.85s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T09:44:31Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
384ee4aℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.