Lift SETcc and CMOVcc in the jump-table translator #172
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/173"
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 Vonsek on 2026-11-21T17:56:32Z.
Change
tools/cpu_switch_aot.pyrejected everySETccandCMOVcc, and modelled flags only for a conditional jump placed directly after its producer. Compilers emit both instructions for comparisons, selects, min/max and clamps, often with aMOVbetween the compare and the consumer.Jcc,SETcc,CMOVcc) now looks back for its producer through instructions that leave the flags unchanged (MOV,MOVZX,MOVSX,MOVSXD,LEA,NOP,NOT,SETcc,CMOVcc), up to 16 instructions, inside one straight-line run that no edge enters. The supported producers are unchanged:CMP,TEST,ADD,SUB,AND,OR,XOR,INC,DEC. Any other flag writer in between (for exampleNEG) is rejected, as are the overflow and parity conditions.SETccwrites a memory byte or a low byte register and keeps bits 8 to 63 of that register.AH-DHare still rejected.CMOVccwith 32- or 64-bit operands. A 32-bitCMOVccclears bits 32 to 63 of the destination even when the condition is false. A memory source is loaded on both outcomes, as on hardware.tests/cpu/switch.asmgainsflag_select, an eight-entry LLVM-layout table toSETL,SETBE,SETGinto memory,SETNEafter a 16-bit compare, 32-bitCMOVA, 64-bitCMOVNSafterTEST,CMOVGEfrom memory with aMOVbetween compare and consumer, andCMOVEafterTESTwith an immediate. It compares EDX with bits 32 to 63 of RDX and returns RAX whole, so the upper-half behaviour of both instructions is observable.tests/cpu/switch_check.pyruns 4,000 inputs at the signed, unsigned and 16-bit boundaries through the original, the translation and a Python reference. TheSWAP_TABLEbuild exchanges theSETLandCMOVAentries and must follow the swapped reference. Four new rejection controls patch the linked DLL:SETO,SETL AH, aNEGbetweenCMPandCMOVGE, and a branch intoSETBE(flags across a join).docs/experiments.md(switch dispatch section) describe the new coverage.The test stays
cpu_aot_jump_tables;flag_selectis added to its export list inCMakeLists.txt.Verification
ctest --preset dev --no-tests=error -R '^cpu_aot_jump_tables$' -Vat the rebased head (main with #86; the earlier run at 173c476 gave the same result) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207, ML64 14.44.35230), Windows SDK 10.0.26100: passed. ML64 assemblesflag_selectin both the original andSWAP_TABLEbuilds without changes. Output:4000 SETcc/CMOVcc inputs match and the swapped table changed 762,13 rejection controls and the leaf-without-unwind translation passed,4 flag-consumer rejection controls passed, and the existing select,run_opsandshift_narrowcomparisons still pass. The fullctest --preset dev --no-tests=errorpassed 86/86, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped.switch.asmconverted to GNU syntax, assembled withllvm-mc -triple x86_64-pc-windows-msvc, linked withlld-link /dll /noentry /def:tests/cpu/switch.def, original and swapped. The translated C++ was built with clang as a shared library. All 4,000flag_selectinputs match the original and the reference, and the swapped table changed 762 results; the existing select, run_ops and shift_narrow checks still pass.switch_check.py rejectionspassed all 13 existing controls and the 4 new ones.tools/cpu_switch_aot.pyfrommain, translation stops withunsupported instruction at RVA 0x11c1: setl al.SETccfails atflag_select(0x6, 0x100000000); keeping the 64-bit destination for a false 32-bitCMOVccfails atflag_select(0x3, 0x0).x86_64-pc-windows-msvcat-O1and-O2contain 14SETcc/CMOVccinstructions, includingSETE R8Band both operand widths. Their translations matched the original code on 25,000 calls per level.Evidence and follow-up
SETcc/CMOVccafterNEG, shifts,IMULorBTproducers; 16-bitCMOVcc;ADC/SBB; flags carried across a conditional-jump fallthrough.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:33:52Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
3311b0b6a3ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:43:32Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:16:14Z.
GitHub reports a conflict on
173c4765. Please reconcile the conditional flag-producer logic and jump-table fixture with the current translator, keeping the existing jump-table controls. Run the focused jump-table CTest on the reconciled head before marking ready.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:24:20Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
3311b0bℹ️ 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.
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:43:34Z.
Rebased on main
7233cec(b5ef0f9, plus 1e9969a for the review finding). The only conflict was the README "CPU translation" row; the current row is kept with the SETcc/CMOVcc sentence added. The flag-producer logic and the jump-table fixture rebased cleanly onto the current translator, and the existing jump-table controls are unchanged.On Windows 11 26200.9974 (MSVC 14.44.35207, ML64 14.44.35230, SDK 10.0.26100):
ctest --preset dev --no-tests=error -R '^cpu_aot_jump_tables$' -Vpassed (select tables,run_ops,shift_narrow, 4,000flag_selectinputs,cmov_read, 13 rejection controls and 4 flag-consumer rejection controls), in Debug and in a Release build. The full suite passed 121/121.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:59:30Z.
At
1e9969a, onlydocs/experiments.mdconflicts. The translator merges automatically. Please retain the addr32 and conditional-move results in the combined document; the open inline review still needs resolution.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:33:52Z.
Code review location:
tools/cpu_switch_aot.py; line 511When an optimized translation's condition folds to false, this ordinary
memcpy-backed load can disappear despite being outside the ternary. For example, the emitted fragment formov rax, rdx; cmp ecx, ecx; cmovne eax, [r8], compiled with Clang 17 at-O2on Linux, contains no memory read: it returns normally forr8 == 0, whereas the original instruction faults. This violates the documented unconditional-memory-source behavior. Make the access non-elidable and add a constant-false, inaccessible-source control.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:43:32Z.
Code review location:
tools/cpu_switch_aot.py; line 511Fixed in 1e9969a. A
CMOVccmemory source is now read through avolatileload (load_always), so it is kept when the condition folds to false. The new exportcmov_read(mov rax, rdx; cmp ecx, ecx; cmovne eax, [r8]) is the constant-false, inaccessible-source control: with a valid R8 it must return the zero-extended low dword of RDX, and with a null R8 it must fault, in the original, the translation and the swapped-table build. In an MSVC Release build of the translation without the volatile load the null call returns (translation cmov_read with a null source did not fault); with it, the test passes in Debug and Release.