Skip to content

cpu: lower XLATB in the shared lifter - #415

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

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

Conversation

@denn0x

@denn0x denn0x commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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.

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

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

Lower AL = [RBX + AL] with AL zero-extended, bits 8 to 63 of RAX and
the flags unchanged. The 67h form uses EBX and wraps the sum at 32
bits; REX.W does not change the operation.

tests/cpu/xlatb.asm builds four exports that run on a permutation
table in a page below 4 GiB. The check compares RAX and ZF/CF for
21504 cases against the native DLL and a reference, and three mutated
translations must mismatch.

AI-assisted (Claude Code).
@R0Y00
R0Y00 merged commit ac48a50 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