Repository navigation
cpu: lower MOVBE in the shared lifter - #412
Merged
Merged
Conversation
Lower the byte-reversing move between memory and a 16-, 32- or 64-bit register in both directions. MOVBE changes no flag; a 16-bit register destination keeps its upper bits and a 32-bit one clears them. tests/cpu/movbe.asm builds ten exports. The check compares RAX, ZF/CF, the data and the guard bytes for 2880 cases against the native DLL and a reference, and three mutated translations must mismatch. The test skips when CPUID reports no MOVBE. AI-assisted (Claude Code).
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Advances CPU translation coverage. MOVBE is an independent problem:
lower()rejects it today, and no open PR or issue claims it. I checked the diffs of the opencpu:PRs for the mnemonic. There is no prerequisite PR.The shared interface is
lower()intools/ffx_version_query.pyandCPU_FIXTURESintools/form_coverage.py. #287, #289, #291, #326, #328, #331, #335, #368, #379, #386 and #403 also extend these. This change adds oneelifbranch afterM.LEA, at an anchor none of them uses. A trial merge into this branch is clean for each of #287, #289, #291, #326, #328, #331 and #335, and for #368, #379, #386 and #403 together. The tree combined with those four passes all 47cpu_tests.Lowering.
movbe r16/r32/r64, mandmovbe m, r16/r32/r64. The bytes are reversed in either direction, by an explicit byte loop at the operand width.write(). The native fixture confirms both.Fixture
tests/cpu/movbe.asmbuilds ten exports:r10wandr11destinations with displacements;r10store through a scaled index;emitasserts that each export contains the expected icedCode. Each export first sets ZF and CF from a preset, so the check sees whether MOVBE leaves them alone. The destination register starts with the second argument, so the upper-bit behaviour of the 16- and 32-bit loads is observed.tests/cpu/movbe.py checkcompares RAX, ZF/CF, the data bytes and 64 guard bytes on each side for 2880 cases. The cases cover nine offsets, including misaligned ones, eight values and four flag presets. Each case runs against the native DLL, the translation and a Python reference.The test exits 77 (capability skip) when CPUID leaf 1 ECX bit 22 (
MOVBE) is clear, ascpu_aot_bmi1does for BMI1.Negative controls. Three translations of the same image are mutated after lowering, and each must mismatch:
noswapclear16flagsOn
main,lower()rejects0f 38 f0 01 c3withunsupported query operation at 0x1000: movbe eax,[rcx]and48 0f 38 f1 11 c3with... movbe [rcx],rdx.Verification
Tested at
4732db9on6549244. Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0, Python 3.13, AMD Ryzen 7 7700 (Zen 4, MOVBE present).Full suite:
ctest --preset dev --no-tests=error --output-junit <repo>/out/test-results.xmlgives 143 passed, 2 failed and 2 capability skips (bvh_wave64_warp,wave_shuffle_warp). The run includes the GPU tests.gpu_alias_lookup_writes_hardwareis the RDNA 4 array-atomics probe recorded in gpu_alias_lookup_writes_hardware: array atomics probe reads 256 per buffer on RX 9070 XT #369 and docs: record the RDNA 4 array-atomics probe measurements #383, which fails the same way onmain. This change touches no GPU code.docs_linksfailed because it ran before the new fixture was staged in git. After staging,ctest --preset dev --no-tests=error -R '^docs_links$'passes.Pure-Python checks:
tests/form_coverage_check.pyandtests/docs_links_check.pypass.Fork CI: the Windows build-and-test, Linux Python and gfx1013 LLVM jobs passed at
4732db9in the fork'sWindows checksrun 44967785705.cpu_aot_movberan there and passed, so the runner has MOVBE.Coverage.
python tools/form_coverage.py out/test-results.xmlgives x64 56 of 948 forms, 55 withoutcpu_aot_movbe. The added form ismovbe.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).