cpu: cover eight VEX word translator semantics that no test observed #548

Merged
Leyukaka merged 1 commit from upstream-pr/554 into main 2026-11-22 12:38:16 +00:00
Leyukaka commented 2026-11-22 11:34:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-22T11:34:56Z.


Change

This closes eight coverage gaps in the VEX.128 word translator, tools/cpu_vex_aot.py (#325). Each was a one-line mutation of the translator that passed every cpu_ test on main. Only the cpu_aot_vex_words fixture, its check and its CMake export list change; the translator does not.

tests/cpu/vex_words.asm gains byte_pack_reload:

  • vpunpcklbw/vpunpckhbw interleave bytes of both inputs, so the second source is no longer all zero;
  • vpsraw by 1 halves the high words, which include a negative word;
  • vpackuswb packs words above 255 and below 0;
  • after the store, vpsrlw by 32 and a vpxor with [r8] reload the packed bytes from the output buffer.

vex_words_check.py adds it to the existing native-versus-lifted loops: 4096 input pairs, outputs aliasing either input, RCX == RDX, and buffers 8 bytes off 16-byte alignment. A focused check also compares it with a Python reference in both native and both lifted builds, on one input pair aligned and one byte past alignment, and on all-zero inputs one byte past alignment.

Verification

On 3791a82 (branch on aefed61), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14:

ctest --preset dev --no-tests=error -R '^cpu_aot_vex_words$' -V

It passes. In the full suite, 260 of 261 tests pass (three of them capability skips). The exception is pixel_aot_hardware, which fails the same way on main at aefed61 and does not involve the CPU translators.

Each mutation was applied to tools/cpu_vex_aot.py one at a time, followed by a rebuild and the whole cpu_ family. On main, every cpu_ test passed for each one. A control that turned vpaddw into a subtraction was caught by cpu_aot_vex_words, so the run does detect a broken translator. On this branch, each mutation fails cpu_aot_vex_words:

Mutation Caught through
vpunpcklbw takes the wrong byte of the second source aligned case, byte 0
vpunpckhbw takes the wrong byte of the second source aligned case, byte 8
vpackuswb truncates its first source instead of saturating aligned case, byte 1
vpackuswb lets -3 to -1 wrap instead of clamping to 0 aligned case, byte 8
vpsraw by 1 shifts logically aligned case, byte 8
shift immediates lose bit 5 (32 becomes 0) aligned case, byte 0
memory sources based on R8 read RCX aligned case, byte 1
unaligned loads round the address down to 8 bytes misaligned case, byte 0

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. (No capability changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6541888944 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/554). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-22T11:34:56Z. --- ## Change This closes eight coverage gaps in the VEX.128 word translator, `tools/cpu_vex_aot.py` (#325). Each was a one-line mutation of the translator that passed every `cpu_` test on `main`. Only the `cpu_aot_vex_words` fixture, its check and its CMake export list change; the translator does not. `tests/cpu/vex_words.asm` gains `byte_pack_reload`: - `vpunpcklbw`/`vpunpckhbw` interleave bytes of both inputs, so the second source is no longer all zero; - `vpsraw` by 1 halves the high words, which include a negative word; - `vpackuswb` packs words above 255 and below 0; - after the store, `vpsrlw` by 32 and a `vpxor` with `[r8]` reload the packed bytes from the output buffer. `vex_words_check.py` adds it to the existing native-versus-lifted loops: 4096 input pairs, outputs aliasing either input, RCX == RDX, and buffers 8 bytes off 16-byte alignment. A focused check also compares it with a Python reference in both native and both lifted builds, on one input pair aligned and one byte past alignment, and on all-zero inputs one byte past alignment. ## Verification On `3791a82` (branch on `aefed61`), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_vex_words$' -V ``` It passes. In the full suite, 260 of 261 tests pass (three of them capability skips). The exception is `pixel_aot_hardware`, which fails the same way on `main` at `aefed61` and does not involve the CPU translators. Each mutation was applied to `tools/cpu_vex_aot.py` one at a time, followed by a rebuild and the whole `cpu_` family. On `main`, every `cpu_` test passed for each one. A control that turned `vpaddw` into a subtraction was caught by `cpu_aot_vex_words`, so the run does detect a broken translator. On this branch, each mutation fails `cpu_aot_vex_words`: | Mutation | Caught through | |---|---| | `vpunpcklbw` takes the wrong byte of the second source | aligned case, byte 0 | | `vpunpckhbw` takes the wrong byte of the second source | aligned case, byte 8 | | `vpackuswb` truncates its first source instead of saturating | aligned case, byte 1 | | `vpackuswb` lets -3 to -1 wrap instead of clamping to 0 | aligned case, byte 8 | | `vpsraw` by 1 shifts logically | aligned case, byte 8 | | shift immediates lose bit 5 (32 becomes 0) | aligned case, byte 0 | | memory sources based on R8 read RCX | aligned case, byte 1 | | unaligned loads round the address down to 8 bytes | misaligned case, byte 0 | ## 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. - [ ] I updated README/docs when a capability or build requirement changed. (No capability changed.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:43:39 +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!548
No description provided.