cpu: lower XLATB in the shared lifter #409

Merged
denn0x merged 1 commit from upstream-pr/415 into main 2026-11-22 01:25:22 +00:00
denn0x commented 2026-11-22 00:56:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-22T00:56:55Z.


Change

Advances CPU translation coverage. XLATB 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, #403 and #412 also extend these. This change adds one elif branch after M.CALL, at an anchor none of them uses.

  • Trial merges: 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 #412.
  • Docs overlap with #403: the one textual overlap is with #403, in docs/experiments.md. Both add a paragraph after the address-size paragraph. I'll rebase whichever of the two lands second.

Lowering.

  • Semantics: xlatb loads AL from RBX + AL, with AL zero-extended. Bits 8 to 63 of RAX and the flags are unchanged.
    • iced decodes the instruction with base RBX and index AL. The generic address() would add all of RAX, so the branch builds the address itself.
  • 67h form: with a 67h prefix the base is EBX and the sum wraps at 32 bits, so the upper half of RBX is ignored.
  • REX.W: 48 d7 decodes to the same XLAT_M8 and lowers the same way.
  • Segments: FS and GS overrides stay rejected by the existing prefix check.

Fixture

tests/cpu/xlatb.asm builds four exports: xlat_basic, xlat_rexw (db 48h), xlat_addr32 (db 67h) and xlat_twice (two lookups in a row).

  • Decode check: emit asserts the number of XLAT_M8 instructions in each export and their base register (RBX, or EBX for the 67h form).
  • Calling convention: each export saves RBX in R11, points RBX at the table and restores it before returning.

Check. tests/cpu/xlatb.py check commits a page below 4 GiB, fills it with 0xcc and places a 256-byte permutation table in the middle.

  • Comparison: RAX and ZF/CF, for 21504 cases against the native DLL, the translation and a Python reference.
  • Inputs: every AL value, with noise in bits 8 to 63 of RAX, under four flag presets. For the 67h form, the upper half of RBX also carries noise.
  • Table: after the runs the check confirms the table is unchanged.

Negative controls. Three translations of the same image are mutated after lowering, and each must mismatch. A control that faults counts as a mismatch: ctypes reports the access violation as OSError.

Control Mutation Mismatches
signed AL sign-extended, so indices 128 to 255 read below the table 11508/21504
noaddr32 the 67h sum keeps the upper half of RBX 9216/21504, all faults
clear the loaded byte written over all of RAX 14336/21504

On main, lower() rejects d7 c3 with unsupported query operation at 0x1000: xlatb and 67 d7 c3 with ... xlat byte ptr [ebx].

Verification

Tested at d8c6c25 on 6549244. Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0, Python 3.13, AMD Ryzen 7 7700.

ctest --preset dev --no-tests=error -R '^cpu_aot_xlatb$' -V
95: 21504 cases over 4 exports (RAX and ZF/CF) matched the reference in native and translated DLLs; table at 0x10000400
95: control signed: 11508/21504 mismatches (0 faults)
95: control noaddr32: 9216/21504 mismatches (9216 faults)
95: control clear: 14336/21504 mismatches (0 faults)
1/1 Test #95: cpu_aot_xlatb ....................   Passed    0.31 sec
  • Full suite: ctest --preset dev --no-tests=error --output-junit <repo>/out/test-results.xml gives 144 passed, 1 failed and 2 capability skips (bvh_wave64_warp, wave_shuffle_warp). The run includes the GPU tests. The failure is gpu_alias_lookup_writes_hardware, the RDNA 4 array-atomics probe recorded in #369 and #383, which fails the same way on main. This change touches no GPU code.
  • 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 d8c6c25 in the fork's Windows checks run 44968451823.

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

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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536562046 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/415). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-22T00:56:55Z. --- ## Change Advances CPU translation coverage. XLATB 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, #403 and #412 also extend these. This change adds one `elif` branch after `M.CALL`, at an anchor none of them uses. - **Trial merges:** 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 #412. - **Docs overlap with #403:** the one textual overlap is with #403, in `docs/experiments.md`. Both add a paragraph after the address-size paragraph. I'll rebase whichever of the two lands second. **Lowering.** - **Semantics:** `xlatb` loads AL from RBX + AL, with AL zero-extended. Bits 8 to 63 of RAX and the flags are unchanged. - iced decodes the instruction with base RBX and index AL. The generic `address()` would add all of RAX, so the branch builds the address itself. - **67h form:** with a 67h prefix the base is EBX and the sum wraps at 32 bits, so the upper half of RBX is ignored. - **REX.W:** `48 d7` decodes to the same `XLAT_M8` and lowers the same way. - **Segments:** FS and GS overrides stay rejected by the existing prefix check. ## Fixture `tests/cpu/xlatb.asm` builds four exports: `xlat_basic`, `xlat_rexw` (`db 48h`), `xlat_addr32` (`db 67h`) and `xlat_twice` (two lookups in a row). - **Decode check:** `emit` asserts the number of `XLAT_M8` instructions in each export and their base register (RBX, or EBX for the 67h form). - **Calling convention:** each export saves RBX in R11, points RBX at the table and restores it before returning. **Check.** `tests/cpu/xlatb.py check` commits a page below 4 GiB, fills it with `0xcc` and places a 256-byte permutation table in the middle. - **Comparison:** RAX and ZF/CF, for 21504 cases against the native DLL, the translation and a Python reference. - **Inputs:** every AL value, with noise in bits 8 to 63 of RAX, under four flag presets. For the 67h form, the upper half of RBX also carries noise. - **Table:** after the runs the check confirms the table is unchanged. **Negative controls.** Three translations of the same image are mutated after lowering, and each must mismatch. A control that faults counts as a mismatch: ctypes reports the access violation as `OSError`. | Control | Mutation | Mismatches | |---|---|---| | `signed` | AL sign-extended, so indices 128 to 255 read below the table | 11508/21504 | | `noaddr32` | the 67h sum keeps the upper half of RBX | 9216/21504, all faults | | `clear` | the loaded byte written over all of RAX | 14336/21504 | On `main`, `lower()` rejects `d7 c3` with `unsupported query operation at 0x1000: xlatb` and `67 d7 c3` with `... xlat byte ptr [ebx]`. ## Verification Tested at `d8c6c25` on `6549244`. Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0, Python 3.13, AMD Ryzen 7 7700. ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_xlatb$' -V ``` ```text 95: 21504 cases over 4 exports (RAX and ZF/CF) matched the reference in native and translated DLLs; table at 0x10000400 95: control signed: 11508/21504 mismatches (0 faults) 95: control noaddr32: 9216/21504 mismatches (9216 faults) 95: control clear: 14336/21504 mismatches (0 faults) 1/1 Test #95: cpu_aot_xlatb .................... Passed 0.31 sec ``` - **Full suite:** `ctest --preset dev --no-tests=error --output-junit <repo>/out/test-results.xml` gives 144 passed, 1 failed and 2 capability skips (`bvh_wave64_warp`, `wave_shuffle_warp`). The run includes the GPU tests. The failure is `gpu_alias_lookup_writes_hardware`, the RDNA 4 array-atomics probe recorded in #369 and #383, which fails the same way on `main`. This change touches no GPU code. - **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 `d8c6c25` in the fork's `Windows checks` run [44968451823](https://github.com/denn0x/Xbox2Windows/actions/runs/44968451823). **Coverage.** `python tools/form_coverage.py out/test-results.xml` gives x64 **56 of 948** forms, 55 without `cpu_aot_xlatb`. The added form is `xlatb`. ## 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)._
upstream-sync closed this pull request 2026-11-24 06:42:55 +00:00
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!409
No description provided.