cpu: lift 16/32/64-bit MOVBE load and store leaf functions to C++ #2681

Merged
Ammmae0x merged 2 commits from upstream-pr/2689 into main 2026-11-26 03:12:58 +00:00
Ammmae0x commented 2026-11-26 02:06:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T02:06:23Z.


Change

Add a dedicated bounded x64-to-C++ leaf lifter (tools/cpu_movbe_aot.py) and source-built MASM/CTest differential suite (tests/cpu/movbe_aot.{asm,def,_check.py}, CTest cpu_aot_movbe_dedicated) covering all 6 MOVBE load and store forms (MOVBE_R16_M16, MOVBE_R32_M32, MOVBE_R64_M64 from flat [rcx|rdx|r8] or [rcx|rdx|r8 + 0..64]; MOVBE_M16_R16, MOVBE_M32_R32, MOVBE_M64_R64 strictly to [r8] or [r8 + 0..64]).

  • Models exact x64 semantics in pure portable C++: 16-bit MOVBE loads reverse 2 bytes and preserve destination bits [63:16] (requiring a defined destination register); 32-bit MOVBE loads reverse 4 bytes and zero-extend bits [63:32]; 64-bit loads and all stores reverse byte order; all 6 forms leave RFLAGS (CF/ZF/SF/OF/PF) completely unmodified.
  • Uses load_always() / store_always() with atomic_signal_fence and volatile observation so /O2 preserves faulting memory reads (verified by op_movbe_discarded_read).
  • Rejects stores outside [r8], negative or out-of-window displacements (> 64), indexed/scaled/RIP-relative memory operands, reg-reg MOVBE encodings, nonvolatile/high-byte GPRs, writes to argument GPRs, undefined GPR/flag reads, VEX/EVEX/XOP encodings, prefixes, branches, and missing/trailing instructions after ret.
  • Registers cpu_aot_movbe_dedicated with SKIP_RETURN_CODE 77 (CPUID.01H:ECX[22] MOVBE gate) and FORM_COVERAGE_RECORD (; coverage: record cpu_aot_movbe_dedicated).

Verification

  • Commit: 51b1c90d (based on upstream/main b2564017)
  • cmake --preset dev + cmake --build --preset dev --target cpu_movbe_aot_original cpu_movbe_aot_original_lifted cpu_movbe_aot_altered cpu_movbe_aot_altered_lifted -> 0 errors, 0 warnings
  • ctest --preset dev -N -> Total Tests: 2178 (cpu_aot_movbe_dedicated registered)
  • ctest --preset dev --output-on-failure -R "^cpu_aot_movbe_dedicated$" -E "cpu_native_archive_" -> 1/1 Passed (1.27s); out\build\dev\form_coverage\cpu_aot_movbe_dedicated.txt recorded 11 forms (including movbe)
  • cmake --preset release + cmake --build --preset release --target cpu_movbe_aot_original cpu_movbe_aot_original_lifted cpu_movbe_aot_altered cpu_movbe_aot_altered_lifted -> 0 errors, 0 warnings
  • ctest --preset release --output-on-failure -R "^cpu_aot_movbe_dedicated$" -E "cpu_native_archive_" -> 1/1 Passed (1.35s); out\build\release\form_coverage\cpu_aot_movbe_dedicated.txt recorded 11 forms
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py -> form coverage checks passed (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 515 links. (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> Self-test passed. Checked 1906 tracked source, script and build/CI files: no bidirectional controls. (exit 0)
  • Spot-mutation gate: 3/3 mutations killed (bswap16 no-swap, update_gpr_width 16-bit upper-bit clear, non-[r8] store guard).
  • Negative controls: 12 ALTER_MOVBE diverging exports, 4 mutant models, 33 IR + 5 raw-byte + 11 PE-patched + CLI rejections, RFLAGS preservation across 3 flag patterns, and discarded NULL-read fault preservation under /O2.

Evidence and follow-up

All assembly fixtures in tests/cpu/movbe_aot.asm are source-built MASM x64 routines authored under the repository MIT license. Portable lifted, mutant, rejection, and /O2 /W4 /WX compilation checks run unconditionally before the CPUID.01H:ECX[22] native differential gate (exit 77 on hosts without MOVBE).

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6617907283 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2689). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T02:06:23Z. --- ## Change Add a dedicated bounded x64-to-C++ leaf lifter (`tools/cpu_movbe_aot.py`) and source-built MASM/CTest differential suite (`tests/cpu/movbe_aot.{asm,def,_check.py}`, CTest `cpu_aot_movbe_dedicated`) covering all 6 `MOVBE` load and store forms (`MOVBE_R16_M16`, `MOVBE_R32_M32`, `MOVBE_R64_M64` from flat `[rcx|rdx|r8]` or `[rcx|rdx|r8 + 0..64]`; `MOVBE_M16_R16`, `MOVBE_M32_R32`, `MOVBE_M64_R64` strictly to `[r8]` or `[r8 + 0..64]`). - Models exact x64 semantics in pure portable C++: 16-bit `MOVBE` loads reverse 2 bytes and preserve destination bits `[63:16]` (requiring a defined destination register); 32-bit `MOVBE` loads reverse 4 bytes and zero-extend bits `[63:32]`; 64-bit loads and all stores reverse byte order; all 6 forms leave RFLAGS (CF/ZF/SF/OF/PF) completely unmodified. - Uses `load_always()` / `store_always()` with `atomic_signal_fence` and volatile observation so `/O2` preserves faulting memory reads (verified by `op_movbe_discarded_read`). - Rejects stores outside `[r8]`, negative or out-of-window displacements (`> 64`), indexed/scaled/RIP-relative memory operands, reg-reg `MOVBE` encodings, nonvolatile/high-byte GPRs, writes to argument GPRs, undefined GPR/flag reads, VEX/EVEX/XOP encodings, prefixes, branches, and missing/trailing instructions after `ret`. - Registers `cpu_aot_movbe_dedicated` with `SKIP_RETURN_CODE 77` (CPUID.01H:ECX[22] MOVBE gate) and `FORM_COVERAGE_RECORD` (`; coverage: record cpu_aot_movbe_dedicated`). ## Verification - Commit: `51b1c90d` (based on `upstream/main` `b2564017`) - `cmake --preset dev` + `cmake --build --preset dev --target cpu_movbe_aot_original cpu_movbe_aot_original_lifted cpu_movbe_aot_altered cpu_movbe_aot_altered_lifted` -> 0 errors, 0 warnings - `ctest --preset dev -N` -> `Total Tests: 2178` (`cpu_aot_movbe_dedicated` registered) - `ctest --preset dev --output-on-failure -R "^cpu_aot_movbe_dedicated$" -E "cpu_native_archive_"` -> `1/1 Passed` (1.27s); `out\build\dev\form_coverage\cpu_aot_movbe_dedicated.txt` recorded 11 forms (including `movbe`) - `cmake --preset release` + `cmake --build --preset release --target cpu_movbe_aot_original cpu_movbe_aot_original_lifted cpu_movbe_aot_altered cpu_movbe_aot_altered_lifted` -> 0 errors, 0 warnings - `ctest --preset release --output-on-failure -R "^cpu_aot_movbe_dedicated$" -E "cpu_native_archive_"` -> `1/1 Passed` (1.35s); `out\build\release\form_coverage\cpu_aot_movbe_dedicated.txt` recorded 11 forms - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py` -> `form coverage checks passed` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 515 links.` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> `Self-test passed. Checked 1906 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) - Spot-mutation gate: 3/3 mutations killed (`bswap16` no-swap, `update_gpr_width` 16-bit upper-bit clear, non-`[r8]` store guard). - Negative controls: 12 `ALTER_MOVBE` diverging exports, 4 mutant models, 33 IR + 5 raw-byte + 11 PE-patched + CLI rejections, RFLAGS preservation across 3 flag patterns, and discarded NULL-read fault preservation under `/O2`. ## Evidence and follow-up All assembly fixtures in `tests/cpu/movbe_aot.asm` are source-built MASM x64 routines authored under the repository MIT license. Portable lifted, mutant, rejection, and `/O2 /W4 /WX` compilation checks run unconditionally before the CPUID.01H:ECX[22] native differential gate (exit 77 on hosts without MOVBE). ## 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.
upstream-sync closed this pull request 2026-11-26 04:04:21 +00:00
tedin7 commented 2026-11-26 04:04:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:12:22Z.

Review: COMMENTED


Review of head 5073b0ea (comment only).

Checked:

  • Scope: new bounded MOVBE load/store leaf lifter (tools/cpu_movbe_aot.py) and source-built MASM/CTest differential suite cpu_aot_movbe_dedicated. The sibling cpu_aot_movbe (shared lifter, #412) is untouched; no other open or merged PR covers this slice (gh pr list --state all --search MOVBE).
  • Semantics in the docstring match x64: 16-bit load keeps bits [63:16], 32-bit load zero-extends, 64-bit and stores byte-swap, flags unchanged.
  • The test guards the behavior: it compares the original and the lifted binaries, has an altered build (ALTER_MOVBE) and reference-model quirks as negative controls, covers flag preservation and a discarded faulting read under /O2, and has rejection cases.
  • CMake: the new block is self-contained, foreach/endforeach balanced, SKIP_RETURN_CODE 77 and FORM_COVERAGE_RECORD set.

Commands run:

  • git diff --check origin/main...HEAD: clean
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • Win2025 x2w_pipe.py win2025 2689 --regex cpu_aot_movbe: dev 2/2 and release 2/2 passed (receipt follows in the next comment)
  • CI on this head: green

Not run: the Python suite on Linux (it needs MASM and the Windows build).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068049180 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2689#pullrequestreview-6068049180). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:12:22Z. **Review:** COMMENTED --- Review of head 5073b0ea (comment only). Checked: - Scope: new bounded MOVBE load/store leaf lifter (`tools/cpu_movbe_aot.py`) and source-built MASM/CTest differential suite `cpu_aot_movbe_dedicated`. The sibling `cpu_aot_movbe` (shared lifter, #412) is untouched; no other open or merged PR covers this slice (`gh pr list --state all --search MOVBE`). - Semantics in the docstring match x64: 16-bit load keeps bits [63:16], 32-bit load zero-extends, 64-bit and stores byte-swap, flags unchanged. - The test guards the behavior: it compares the original and the lifted binaries, has an altered build (`ALTER_MOVBE`) and reference-model quirks as negative controls, covers flag preservation and a discarded faulting read under /O2, and has rejection cases. - CMake: the new block is self-contained, `foreach`/`endforeach` balanced, `SKIP_RETURN_CODE 77` and `FORM_COVERAGE_RECORD` set. Commands run: - `git diff --check origin/main...HEAD`: clean - `python3 tests/docs_links_check.py`: pass - `python3 tests/bidi_controls_check.py`: pass - Win2025 `x2w_pipe.py win2025 2689 --regex cpu_aot_movbe`: dev 2/2 and release 2/2 passed (receipt follows in the next comment) - CI on this head: green Not run: the Python suite on Linux (it needs MASM and the Windows build). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:12:23Z.


Win2025 WARP receipt for head 5073b0ea after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 5073b0eaa94b4e01a4cf621f69852eac6a7480e5:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_movbe_aot_altered cpu_movbe_aot_altered_lifted cpu_movbe_aot_original cpu_movbe_aot_original_lifted -- -j 2): 4.14s (configure 5.06s)
    • Test (ctest --preset dev -R 'cpu_aot_movbe' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (2.19s: cpu_aot_movbe 0.54s, cpu_aot_movbe_dedicated 1.95s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_movbe_aot_altered cpu_movbe_aot_altered_lifted cpu_movbe_aot_original cpu_movbe_aot_original_lifted -- -j 2): 4.98s (configure 4.05s)
    • Test (ctest --preset release -R 'cpu_aot_movbe' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (2.23s: cpu_aot_movbe 0.41s, cpu_aot_movbe_dedicated 1.97s)
  • sccache: 30/41 hits; wall 32.6s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181491089 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2689#issuecomment-7181491089). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:12:23Z. --- Win2025 WARP receipt for head 5073b0ea after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `5073b0eaa94b4e01a4cf621f69852eac6a7480e5`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_movbe_aot_altered cpu_movbe_aot_altered_lifted cpu_movbe_aot_original cpu_movbe_aot_original_lifted -- -j 2`): `4.14s` (configure `5.06s`) - Test (`ctest --preset dev -R 'cpu_aot_movbe' --parallel 2 --no-tests=error --output-on-failure`): **2/2 passed** (`2.19s`: `cpu_aot_movbe` `0.54s`, `cpu_aot_movbe_dedicated` `1.95s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_movbe_aot_altered cpu_movbe_aot_altered_lifted cpu_movbe_aot_original cpu_movbe_aot_original_lifted -- -j 2`): `4.98s` (configure `4.05s`) - Test (`ctest --preset release -R 'cpu_aot_movbe' --parallel 2 --no-tests=error --output-on-failure`): **2/2 passed** (`2.23s`: `cpu_aot_movbe` `0.41s`, `cpu_aot_movbe_dedicated` `1.97s`) - `sccache`: 30/41 hits; wall `32.6s` AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2681
No description provided.