cpu: lower AVX VEX.128 packed string compare instructions #946

Merged
Ammmae0x merged 2 commits from upstream-pr/953 into main 2026-11-23 19:09:53 +00:00
Ammmae0x commented 2026-11-23 18:33:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T18:33:34Z.


Change

Adds standalone VEX.128 (W=0) AVX packed string compare lowering in tools/cpu_avx_pcmpstr_aot.py and source-built differential tests in tests/cpu/avx_pcmpstr.{asm,def,py} (cpu_aot_avx_pcmpstr) covering four uncovered AVX mnemonics in docs/coverage/x64_zen2.tsv:

  • vpcmpestri, vpcmpestrm, vpcmpistri, vpcmpistrm (both xmm and flat m128 second operands)

Key modeled behaviors and explicit rejections:

  • vpcmpestrm and vpcmpistrm write the 128-bit mask to XMM0 and zero YMM0[255:128] per VEX.128 semantics.
  • vpcmpestri and vpcmpistri zero-extend the 32-bit ECX index into RCX.
  • vpcmpestri and vpcmpestrm read only the low 32 bits of RAX and RDX as signed lengths.
  • All four forms clear AF and PF and update CF, ZF, SF, and OF per the Intel SDM.
  • Explicitly rejects VEX.256 (L=1), VEX.W=1 (vpcmpestri64, vpcmpestrm64), EVEX, legacy SSE4.2 pcmp*str*, nonvolatile vector/GPR registers, writes to r8, reads through clobbered pointers, unsupported memory operands, prefixes, branches, undefined registers/flags, missing ret, and unreachable instructions after ret.

Verification

  • Configured and clean-rebuilt cpu_avx_pcmpstr_original, cpu_avx_pcmpstr_original_lifted, cpu_avx_pcmpstr_altered, and cpu_avx_pcmpstr_altered_lifted in both dev (Debug) and release (/O2) presets with 0 errors and 0 warnings.
  • ctest --preset dev --no-tests=error -R "^cpu_aot_(avx_pcmpstr|avx_horiz_fp|avx2_regs|avx_int_regs|avx_move_regs|sse41_42_misc)$" -V: 6/6 passed (cpu_aot_avx_pcmpstr: 1028 VEX.128 AVX packed string compare cases across 22 exports matched native and reference; ALTER_IMM diverged on {'vpcmpestri_ub_eqany_pos_lsb': 72, 'vpcmpestrm_sb_ranges_neg_exp': 87, 'vpcmpistri_ub_eqord_pos_lsb': 3, 'vpcmpistrm_sw_eqany_mneg_exp': 4}; output mutation control caught and 30 unit rejection controls and 5 PE-patched rejection controls passed).
  • ctest --preset release --no-tests=error -R "^cpu_aot_(avx_pcmpstr|avx_horiz_fp|avx2_regs|avx_int_regs|avx_move_regs|sse41_42_misc)$" -V: 6/6 passed (cpu_aot_avx_pcmpstr: 1,028 cases + 4 ALTER_IMM + 1 mutation + 30 unit + 5 PE-patched controls passed).
  • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: passed.
  • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: passed (13 Markdown files, 191 links).
  • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: passed (778 tracked files).

Evidence and follow-up

  • Fixture source: original MASM source (tests/cpu/avx_pcmpstr.asm) and Python test/reference script (tests/cpu/avx_pcmpstr.py) submitted under the repository MIT license; no external binaries, dumps, or title assets used.
  • cpu_aot_avx_pcmpstr uses SKIP_RETURN_CODE 77 when CPUID/XCR0 indicates the host lacks AVX; all checks above executed and passed on an AVX-capable Windows x64 host.
  • Follow-up: VEX.W=1 64-bit length variants (vpcmpestri64, vpcmpestrm64) remain out of scope.

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:6566187660 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/953). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-23T18:33:34Z. --- ## Change Adds standalone VEX.128 (`W=0`) AVX packed string compare lowering in `tools/cpu_avx_pcmpstr_aot.py` and source-built differential tests in `tests/cpu/avx_pcmpstr.{asm,def,py}` (`cpu_aot_avx_pcmpstr`) covering four uncovered `AVX` mnemonics in `docs/coverage/x64_zen2.tsv`: - `vpcmpestri`, `vpcmpestrm`, `vpcmpistri`, `vpcmpistrm` (both `xmm` and flat `m128` second operands) Key modeled behaviors and explicit rejections: - `vpcmpestrm` and `vpcmpistrm` write the 128-bit mask to `XMM0` and zero `YMM0[255:128]` per VEX.128 semantics. - `vpcmpestri` and `vpcmpistri` zero-extend the 32-bit `ECX` index into `RCX`. - `vpcmpestri` and `vpcmpestrm` read only the low 32 bits of `RAX` and `RDX` as signed lengths. - All four forms clear `AF` and `PF` and update `CF`, `ZF`, `SF`, and `OF` per the Intel SDM. - Explicitly rejects `VEX.256` (`L=1`), `VEX.W=1` (`vpcmpestri64`, `vpcmpestrm64`), EVEX, legacy SSE4.2 `pcmp*str*`, nonvolatile vector/GPR registers, writes to `r8`, reads through clobbered pointers, unsupported memory operands, prefixes, branches, undefined registers/flags, missing `ret`, and unreachable instructions after `ret`. ## Verification - Configured and clean-rebuilt `cpu_avx_pcmpstr_original`, `cpu_avx_pcmpstr_original_lifted`, `cpu_avx_pcmpstr_altered`, and `cpu_avx_pcmpstr_altered_lifted` in both `dev` (`Debug`) and `release` (`/O2`) presets with 0 errors and 0 warnings. - `ctest --preset dev --no-tests=error -R "^cpu_aot_(avx_pcmpstr|avx_horiz_fp|avx2_regs|avx_int_regs|avx_move_regs|sse41_42_misc)$" -V`: 6/6 passed (`cpu_aot_avx_pcmpstr`: `1028 VEX.128 AVX packed string compare cases across 22 exports matched native and reference; ALTER_IMM diverged on {'vpcmpestri_ub_eqany_pos_lsb': 72, 'vpcmpestrm_sb_ranges_neg_exp': 87, 'vpcmpistri_ub_eqord_pos_lsb': 3, 'vpcmpistrm_sw_eqany_mneg_exp': 4}; output mutation control caught` and `30 unit rejection controls and 5 PE-patched rejection controls passed`). - `ctest --preset release --no-tests=error -R "^cpu_aot_(avx_pcmpstr|avx_horiz_fp|avx2_regs|avx_int_regs|avx_move_regs|sse41_42_misc)$" -V`: 6/6 passed (`cpu_aot_avx_pcmpstr`: 1,028 cases + 4 `ALTER_IMM` + 1 mutation + 30 unit + 5 PE-patched controls passed). - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: passed. - `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py`: passed (13 Markdown files, 191 links). - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py`: passed (778 tracked files). ## Evidence and follow-up - Fixture source: original MASM source (`tests/cpu/avx_pcmpstr.asm`) and Python test/reference script (`tests/cpu/avx_pcmpstr.py`) submitted under the repository MIT license; no external binaries, dumps, or title assets used. - `cpu_aot_avx_pcmpstr` uses `SKIP_RETURN_CODE 77` when CPUID/XCR0 indicates the host lacks AVX; all checks above executed and passed on an AVX-capable Windows x64 host. - Follow-up: `VEX.W=1` 64-bit length variants (`vpcmpestri64`, `vpcmpestrm64`) remain out of scope. ## 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-24 06:45:34 +00:00
R0Y00 commented 2026-11-24 06:49:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:49:53Z.


I reproduced an optimized-build mismatch with a source-built VPCMPISTRM whose mask and flags are discarded. On the original branch, the native call faults on the unreadable memory source and the lifted call reaches the second store. The updated branch retains the guest read. Both versions now fault between the same two stores, and both complete the valid-buffer control. I also added a RET-only refusal so the uint64 return cannot come from the lowerer's initial RAX placeholder. The existing 1,028 comparisons and mutation controls still pass in both Windows presets.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110715764 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/953#issuecomment-7110715764). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:49:53Z. --- I reproduced an optimized-build mismatch with a source-built VPCMPISTRM whose mask and flags are discarded. On the original branch, the native call faults on the unreadable memory source and the lifted call reaches the second store. The updated branch retains the guest read. Both versions now fault between the same two stores, and both complete the valid-buffer control. I also added a RET-only refusal so the uint64 return cannot come from the lowerer's initial RAX placeholder. The existing 1,028 comparisons and mutation controls still pass in both Windows presets.
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!946
No description provided.