cpu: lower MOVBE in the shared lifter #412

Manually merged
github merged 1 commit from gh-pr/412/head into gh-pr/412/base 2026-11-26 21:49:52 +00:00
Owner

@⁠denn0x on GitHub · 2026-11-22 00:45 UTC · original
denn0x:cpu/lower-movbe → main · +309 −0 · 7 files · 1 commits · merged 2026-11-22 02:41 UTC

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.

    • gpu_alias_lookup_writes_hardware is the RDNA 4 array-atomics probe recorded in #369 and #383, which fails the same way on main. This change touches no GPU code.
    • docs_links failed 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.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).

**@⁠denn0x** on GitHub · 2026-11-22 00:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/412) `denn0x:cpu/lower-movbe` → `main` · +309 −0 · 7 files · 1 commits · merged 2026-11-22 02:41 UTC ## 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). ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_movbe$' -V ``` ```text 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. - `gpu_alias_lookup_writes_hardware` is the RDNA 4 array-atomics probe recorded in #369 and #383, which fails the same way on `main`. This change touches no GPU code. - `docs_links` failed 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.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](https://github.com/denn0x/Xbox2Windows/actions/runs/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 - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:49:50 +00:00
github manually merged commit 4732db9740 into gh-pr/412/base 2026-11-26 21:49:52 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.