cpu: lower BT, BTS, BTR and BTC in cpu_switch_aot #1202
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1209"
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 dicnunz on 2026-11-24T03:33:44Z.
Change
tools/cpu_switch_aot.py(the lifter behindtools/exe_aot.py's console-stdio profile and the CPU fuzz smoke from #894) rejectedBT,BTS,BTRandBTCas unsupported instructions. They now lower for 16-, 32- and 64-bit register and memory bit bases with a register or immediate bit offset, and act as flag producers for CF:BTSsets it,BTRclears it orBTCcomplements it (Intel SDM Vol. 2A "BT/BTC/BTR/BTS"). A 32-bit register destination zero-extends, a 16-bit one keeps bits 16 to 63, andBTwrites nothing.BandAE(JC,SETNC,CMOVC, ...) may read the flags. Other conditions are refused withonly CF is defined after BT|BTS|BTR|BTC.unsupported bit-string operand.LOCKstays refused.tools/cpu_sse_aot.pyreusesLifter, so its GPR path gets the same lowering.Verification
Tested commit:
2a175a8, one commit on4a47793(upstreammain).Windows CI on my fork,
Windows checksworkflow on2a175a8,windows-2025runner, MSVC 19.52.37029.0 and ML64 14.52.37029.0: https://github.com/dicnunz/Xbox2Windows/actions/runs/45311580908In both Windows jobs
cpu_aot_switch_bit_tests,cpu_aot_switch_rotates,cpu_aot_jump_tables,cpu_aot_flag_conditions,cpu_aot_fuzz_smokeandcpu_aot_fuzz_framespassed. The 7 skips are the capability skipsxg_swizzle_select,xg_swizzle_select_mutation,xg_swizzle_factory,xg_swizzle_factory_no_write,bvh_wave64_warp,wave_shuffle_warpandbc7_mode6_multiblock_warp, the same in every run.Also measured on Linux x86-64, which gives the counts below: the original fixture assembled by
llvm-ml18 and linked bylld-linkinto a PE32+ DLL, mapped into executable memory and called through a SysV-to-Windows-x64 thunk and the unchangedregister_probe.asm; the translation built byclang++18 (-fms-extensions, exportsms_abi) at-O0and-O2; the check script run unchanged:unsupported flag producer at RVA 0x1003.lifted_bt16_imm(0x0, 0xffff)), CF read one bit high (lifted_bt16_reg(0x0, 0x1)).tools/fuzz_cpu.py0xA902 20 leaf(12,520 comparisons) and0xF4A3 16 frames(10,016,reload_shiftmutant detected) pass with this change.Evidence and follow-up
tests/cpu/switch_bit_tests.asmis original source written for this test (MIT), registered with; coverage: source cpu_aot_switch_bit_tests. 39 exports: the four instructions at 16/32/64 bits with register offsets (offsets above the width and above 2^32 included), immediate offsets of 0, width minus 1 and above the width, memory bases with an immediate above the width at 32 and 64 bits,JB,JAE, andCMOVC/CMOVNCafter a flag-neutralMOVwith a 32-bit destination. 10 refused exports (bit string,LOCK, undefined source, andSETE,SETO,SETP,CMOVS,CMOVL,JBE) plus a directLiftercontrol.docs/experiments.mddocuments the rule and the command:Follow-up for another contributor: the bit-string form (register offset into memory) needs a signed offset added to the address at operand granularity.
Overlap
The three PRs below touch the same lines of
tools/cpu_switch_aot.py(the docstring paragraph after the flag rules,FLAG_PRODUCERS, the start ofLifter.condition(), the branch before shifts inLifter.lower()),CMakeLists.txtaftercpu_aot_switch_rotatesanddocs/experiments.mdafter the rotates command. Each is independent and based onmain; whichever lands later needs a rebase that keeps both sides (FLAG_PRODUCERS = {..., *SHIFTS, *BIT_TESTS, *BIT_COUNTS}). The combination (e6c6b1eon4a47793, branchclaude/blissful-darwin-l83vcqof my fork) passes all three fixtures and the leaf fuzz area on Linux.Checklist
This change was AI-assisted (Claude Code), including the fixture, the reference model and the review.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:43:31Z.
Review: COMMENTED
Reviewed
2a175a8don Linux (Windows build/test and native/AOT execution were not run locally).Diff audit
tools/cpu_switch_aot.py: lowersBT,BTS,BTR, andBTCfor 16/32/64-bit register bases (register or immediate offset masked tobits - 1) and memory bases with immediate offset (masked tobits - 1).memory + registeroperands (unsupported bit-string operand) rather than indexing a signed bit string beyond the loaded operand, andLOCKremains rejected (unsupported prefix).CFinfbbefore modifying the bit;BTclearswrites.condition()restricts consumers toB/AE(only CF is defined after ...).docs/experiments.md,CMakeLists.txt,tests/cpu/switch_bit_tests.{asm,def,_check.py}: consistent and title-neutral.tools/cpu_switch_aot.py,CMakeLists.txt, anddocs/experiments.mdwith #1208 and #1210; whichever lands later will need a rebase.Linux checks (
/root/.local/share/x2w-rev-venv/bin/python -B)tests/form_coverage_check.py: passedtests/docs_links_check.py: passed (15 Markdown files, 257 links)tests/bidi_controls_check.py: passed (957 files)tests/intake/{import_forms,paths,routing}_check.py: passedcpu_switch_aot.Lifter().lower(..., sets_flags=True)spot checks (4 cases:bt eax,ecx,bt [rax],ecxrefused,bt dword ptr [rax], 39,bts eax,ecx): passed.ctest -R '^cpu_aot_switch_bit_tests$'not run locally.