Skip to content

cpu: lower MOVBE in the shared lifter - #412

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
denn0x:cpu/lower-movbe
Nov 22, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
denn0x:cpu/lower-movbe

Conversation

@denn0x

@denn0x denn0x commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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 open cpu: PRs for the mnemonic. There is no prerequisite PR.

The shared interface is lower() in tools/ffx_version_query.py and CPU_FIXTURES in tools/form_coverage.py. #287, #289, #291, #326, #328, #331, #335, #368, #379, #386 and #403 also extend these. This change adds one elif branch after M.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 47 cpu_ tests.

Lowering.

  • Forms: movbe r16/r32/r64, m and movbe m, r16/r32/r64. The bytes are reversed in either direction, by an explicit byte loop at the operand width.
  • Flags: MOVBE changes no flag.
  • Register writes: a 16-bit destination keeps bits 16 to 63, and a 32-bit destination clears its upper half. Both go through the existing write(). The native fixture confirms both.

Fixture

tests/cpu/movbe.asm builds ten exports:

  • loads at each width;
  • r10w and r11 destinations with displacements;
  • stores at each width;
  • an r10 store through a scaled index;
  • a 32-bit load stored back eight bytes on.

emit asserts that each export contains the expected iced Code. 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 check compares 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, as cpu_aot_bmi1 does for BMI1.

Negative controls. Three translations of the same image are mutated after lowering, and each must mismatch:

Control Mutation Mismatches
noswap bytes copied in memory order 2592/2880
clear16 a 16-bit destination zero-extended 360/2880
flags ZF and CF cleared 2160/2880

On main, lower() rejects 0f 38 f0 01 c3 with unsupported query operation at 0x1000: movbe eax,[rcx] and 48 0f 38 f1 11 c3 with ... movbe [rcx],rdx.

Verification

Tested at 4732db9 on 6549244. 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).

ctest --preset dev --no-tests=error -R '^cpu_aot_movbe$' -V
95: 2880 cases over 10 exports (RAX, ZF/CF, data and guard bytes) matched the reference in native and translated DLLs
95: control noswap: 2592/2880 mismatches
95: control clear16: 360/2880 mismatches
95: control flags: 2160/2880 mismatches
1/1 Test #95: cpu_aot_movbe ....................   Passed    0.21 sec
  • Full suite: ctest --preset dev --no-tests=error --output-junit <repo>/out/test-results.xml gives 143 passed, 2 failed and 2 capability skips (bvh_wave64_warp, wave_shuffle_warp). The run includes the GPU tests.

  • Pure-Python checks: tests/form_coverage_check.py and tests/docs_links_check.py pass.

  • Fork CI: the Windows build-and-test, Linux Python and gfx1013 LLVM jobs passed at 4732db9 in the fork's Windows checks run 44967785705. cpu_aot_movbe ran there and passed, so the runner has MOVBE.

Coverage. python tools/form_coverage.py out/test-results.xml gives x64 56 of 948 forms, 55 without cpu_aot_movbe. The added form is movbe.

Evidence

The fixture is synthetic and original to this repository (MIT). docs/experiments.md documents the lowering, the fixture and its controls.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

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).
@R0Y00
R0Y00 merged commit 70bb419 into R0Y00:main Nov 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants