cpu: lift legacy SSE and VEX.128 AES-NI and PCLMULQDQ leaf functions to C++ #2669

Merged
Ammmae0x merged 2 commits from upstream-pr/2677 into main 2026-11-26 03:18:58 +00:00
Ammmae0x commented 2026-11-26 01:46:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:46:22Z.


Change

Add a pure portable x64-to-C++ leaf lifter (tools/cpu_aes_pclmul_aot.py) and source-built MASM/CTest differential suite (tests/cpu/aes_pclmul_aot.{asm,def,_check.py}, CTest cpu_aot_aes_pclmul) covering legacy SSE and VEX.128 register and flat [rcx|rdx|r8] m128 forms of AESENC/VAESENC, AESENCLAST/VAESENCLAST, AESDEC/VAESDEC, AESDECLAST/VAESDECLAST, AESIMC/VAESIMC, AESKEYGENASSIST/VAESKEYGENASSIST, and PCLMULQDQ/VPCLMULQDQ.

  • Implements GF(2^8) AES S-box/InvS-box, column-major ShiftRows/InvShiftRows, MixColumns/InvMixColumns, AESKEYGENASSIST RCON/SubWord/RotWord on words 1 and 3, and GF(2) carryless multiplication (imm8[0] and imm8[4], ignoring other bits) in pure portable C++ with zero AES/PCLMUL intrinsics and zero <wmmintrin.h>.
  • Models YMM[255:128] preservation for legacy SSE, YMM[255:128] zeroing for VEX.128 and VZEROUPPER, aliased source-before-destination reads, and atomic_signal_fence + volatile loads so /O2 preserves faulting memory reads (verified by op_aes_pclmul_discarded_read).
  • Rejects VEX.256 compute ops, EVEX/XOP, KeyLocker, nonvolatile XMM6-15/YMM6-15/ZMM, undefined XMM/YMM reads, displaced/indexed/RIP-relative/non-argument memory operands, non-[r8] stores, prefixes, branches, and missing/trailing instructions after ret.
  • Registers cpu_aot_aes_pclmul with SKIP_RETURN_CODE 77 (CPUID.01H:ECX[1,25,27,28] + XGETBV[2:1]) and FORM_COVERAGE_RECORD (; coverage: record cpu_aot_aes_pclmul).

Verification

  • Commit: db59320d (based on upstream/main 72879797)
  • cmake --preset dev + cmake --build --preset dev --target cpu_aes_pclmul_aot_original cpu_aes_pclmul_aot_original_lifted cpu_aes_pclmul_aot_altered cpu_aes_pclmul_aot_altered_lifted -> 0 errors, 0 warnings
  • ctest --preset dev -N -> Total Tests: 2166 (cpu_aot_aes_pclmul registered)
  • ctest --preset dev --output-on-failure -R "^cpu_aot_aes_pclmul$" -E "cpu_native_archive_" -> 1/1 Passed (1.60s); out\build\dev\form_coverage\cpu_aot_aes_pclmul.txt recorded 27 forms
  • cmake --preset release + cmake --build --preset release --target cpu_aes_pclmul_aot_original cpu_aes_pclmul_aot_original_lifted cpu_aes_pclmul_aot_altered cpu_aes_pclmul_aot_altered_lifted -> 0 errors, 0 warnings
  • ctest --preset release --output-on-failure -R "^cpu_aot_aes_pclmul$" -E "cpu_native_archive_" -> 1/1 Passed (1.86s); out\build\release\form_coverage\cpu_aot_aes_pclmul.txt recorded 27 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 510 links. (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> Self-test passed. Checked 1894 tracked source, script and build/CI files: no bidirectional controls. (exit 0)
  • Spot-mutation gate: 3/3 mutations killed (GF(2^8) reduction polynomial 0x1B, PCLMULQDQ imm8[4] selector, VEX.128 zext256 upper-lane zeroing).
  • Negative controls: 18 ALTER_AES_PCLMUL diverging exports, 6 SDM mutant models, FIPS-197 Appendix B encrypt+decrypt round-trip, 26 IR + 4 raw + 9 PE-patched + CLI rejections, and discarded NULL-read fault preservation under /O2.

Evidence and follow-up

All assembly fixtures in tests/cpu/aes_pclmul_aot.asm are source-built MASM x64 routines authored under the repository MIT license, verified against an independent first-principles Python GF(2^8)/GF(2) model and FIPS-197 Appendix B vectors. Portable lifted, mutant, rejection, and /O2 /W4 /WX compilation checks run unconditionally before the CPUID/XGETBV native differential gate (exit 77 if unsupported).

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:6617643568 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2677). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T01:46:22Z. --- ## Change Add a pure portable x64-to-C++ leaf lifter (`tools/cpu_aes_pclmul_aot.py`) and source-built MASM/CTest differential suite (`tests/cpu/aes_pclmul_aot.{asm,def,_check.py}`, CTest `cpu_aot_aes_pclmul`) covering legacy SSE and VEX.128 register and flat `[rcx|rdx|r8]` m128 forms of `AESENC`/`VAESENC`, `AESENCLAST`/`VAESENCLAST`, `AESDEC`/`VAESDEC`, `AESDECLAST`/`VAESDECLAST`, `AESIMC`/`VAESIMC`, `AESKEYGENASSIST`/`VAESKEYGENASSIST`, and `PCLMULQDQ`/`VPCLMULQDQ`. - Implements GF(2^8) AES S-box/InvS-box, column-major ShiftRows/InvShiftRows, MixColumns/InvMixColumns, `AESKEYGENASSIST` RCON/SubWord/RotWord on words 1 and 3, and GF(2) carryless multiplication (`imm8[0]` and `imm8[4]`, ignoring other bits) in pure portable C++ with zero AES/PCLMUL intrinsics and zero `<wmmintrin.h>`. - Models YMM[255:128] preservation for legacy SSE, YMM[255:128] zeroing for VEX.128 and `VZEROUPPER`, aliased source-before-destination reads, and `atomic_signal_fence` + volatile loads so `/O2` preserves faulting memory reads (verified by `op_aes_pclmul_discarded_read`). - Rejects VEX.256 compute ops, EVEX/XOP, KeyLocker, nonvolatile XMM6-15/YMM6-15/ZMM, undefined XMM/YMM reads, displaced/indexed/RIP-relative/non-argument memory operands, non-`[r8]` stores, prefixes, branches, and missing/trailing instructions after `ret`. - Registers `cpu_aot_aes_pclmul` with `SKIP_RETURN_CODE 77` (CPUID.01H:ECX[1,25,27,28] + XGETBV[2:1]) and `FORM_COVERAGE_RECORD` (`; coverage: record cpu_aot_aes_pclmul`). ## Verification - Commit: `db59320d` (based on `upstream/main` `72879797`) - `cmake --preset dev` + `cmake --build --preset dev --target cpu_aes_pclmul_aot_original cpu_aes_pclmul_aot_original_lifted cpu_aes_pclmul_aot_altered cpu_aes_pclmul_aot_altered_lifted` -> 0 errors, 0 warnings - `ctest --preset dev -N` -> `Total Tests: 2166` (`cpu_aot_aes_pclmul` registered) - `ctest --preset dev --output-on-failure -R "^cpu_aot_aes_pclmul$" -E "cpu_native_archive_"` -> `1/1 Passed` (1.60s); `out\build\dev\form_coverage\cpu_aot_aes_pclmul.txt` recorded 27 forms - `cmake --preset release` + `cmake --build --preset release --target cpu_aes_pclmul_aot_original cpu_aes_pclmul_aot_original_lifted cpu_aes_pclmul_aot_altered cpu_aes_pclmul_aot_altered_lifted` -> 0 errors, 0 warnings - `ctest --preset release --output-on-failure -R "^cpu_aot_aes_pclmul$" -E "cpu_native_archive_"` -> `1/1 Passed` (1.86s); `out\build\release\form_coverage\cpu_aot_aes_pclmul.txt` recorded 27 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 510 links.` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> `Self-test passed. Checked 1894 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) - Spot-mutation gate: 3/3 mutations killed (GF(2^8) reduction polynomial `0x1B`, `PCLMULQDQ` `imm8[4]` selector, VEX.128 `zext256` upper-lane zeroing). - Negative controls: 18 `ALTER_AES_PCLMUL` diverging exports, 6 SDM mutant models, FIPS-197 Appendix B encrypt+decrypt round-trip, 26 IR + 4 raw + 9 PE-patched + CLI rejections, and discarded NULL-read fault preservation under `/O2`. ## Evidence and follow-up All assembly fixtures in `tests/cpu/aes_pclmul_aot.asm` are source-built MASM x64 routines authored under the repository MIT license, verified against an independent first-principles Python GF(2^8)/GF(2) model and FIPS-197 Appendix B vectors. Portable lifted, mutant, rejection, and `/O2 /W4 /WX` compilation checks run unconditionally before the CPUID/XGETBV native differential gate (exit 77 if unsupported). ## 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:16 +00:00
tedin7 commented 2026-11-26 04:04:16 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 27dd8acb (after merging current main).

Looks sound:

  • New dedicated leaf lifter tools/cpu_aes_pclmul_aot.py follows the same pattern as the merged cpu_sha256_aot (#2397). It is separate from the earlier lowering in #380, which covers one fixture; this adds a general leaf lifter plus a source-built MASM fixture, so it is not a duplicate slice.
  • The test registers cpu_aot_aes_pclmul with SKIP_RETURN_CODE 77 and FORM_COVERAGE_RECORD, and has an ALTER_AES_PCLMUL altered build, built-in mutants that must be caught, FIPS-197 vectors, YMM[255:128] checks, a /O2 discarded-read check and rejection cases. No game or startup claim is made.
  • No AES/PCLMUL intrinsics are used in the lifted output (checked with a text search of the lifter).

Commands run locally (Linux):

  • python3 -B tests/docs_links_check.py, python3 -B tests/bidi_controls_check.py -> ok
  • git diff --check origin/main...HEAD -> clean
  • python3 -m py_compile on the lifter and the check -> ok
  • The differential check needs MASM, the PE toolchain and iced-x86, so it cannot run on Linux. Its result comes from the Windows receipt below.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068063525 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2677#pullrequestreview-6068063525). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:14:11Z. **Review:** COMMENTED --- Review of head 27dd8acb (after merging current main). Looks sound: - New dedicated leaf lifter `tools/cpu_aes_pclmul_aot.py` follows the same pattern as the merged `cpu_sha256_aot` (#2397). It is separate from the earlier lowering in #380, which covers one fixture; this adds a general leaf lifter plus a source-built MASM fixture, so it is not a duplicate slice. - The test registers `cpu_aot_aes_pclmul` with `SKIP_RETURN_CODE 77` and `FORM_COVERAGE_RECORD`, and has an `ALTER_AES_PCLMUL` altered build, built-in mutants that must be caught, FIPS-197 vectors, YMM[255:128] checks, a `/O2` discarded-read check and rejection cases. No game or startup claim is made. - No AES/PCLMUL intrinsics are used in the lifted output (checked with a text search of the lifter). Commands run locally (Linux): - `python3 -B tests/docs_links_check.py`, `python3 -B tests/bidi_controls_check.py` -> ok - `git diff --check origin/main...HEAD` -> clean - `python3 -m py_compile` on the lifter and the check -> ok - The differential check needs MASM, the PE toolchain and iced-x86, so it cannot run on Linux. Its result comes from the Windows receipt below. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:37 +00:00 (Migrated from github.com)

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


Win2025 WARP receipt for head 27dd8acb after updating with main.

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_aes_pclmul_aot_altered cpu_aes_pclmul_aot_altered_lifted cpu_aes_pclmul_aot_original cpu_aes_pclmul_aot_original_lifted -- -j 2): 7.11s (configure 3.98s)
    • Test (ctest --preset dev -R '^cpu_aot_aes_pclmul$' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (3.49s: cpu_aot_aes_pclmul 3.23s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_aes_pclmul_aot_altered cpu_aes_pclmul_aot_altered_lifted cpu_aes_pclmul_aot_original cpu_aes_pclmul_aot_original_lifted -- -j 2): 3.51s (configure 4.66s)
    • Test (ctest --preset release -R '^cpu_aot_aes_pclmul$' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (2.86s: cpu_aot_aes_pclmul 2.62s)
  • sccache: 5/13 hits; wall 30.1s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181593780 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2677#issuecomment-7181593780). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:18:28Z. --- Win2025 WARP receipt for head 27dd8acb after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `27dd8acbf172670140956b815a951156f1be5abd`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_aes_pclmul_aot_altered cpu_aes_pclmul_aot_altered_lifted cpu_aes_pclmul_aot_original cpu_aes_pclmul_aot_original_lifted -- -j 2`): `7.11s` (configure `3.98s`) - Test (`ctest --preset dev -R '^cpu_aot_aes_pclmul$' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`3.49s`: `cpu_aot_aes_pclmul` `3.23s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_aes_pclmul_aot_altered cpu_aes_pclmul_aot_altered_lifted cpu_aes_pclmul_aot_original cpu_aes_pclmul_aot_original_lifted -- -j 2`): `3.51s` (configure `4.66s`) - Test (`ctest --preset release -R '^cpu_aot_aes_pclmul$' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`2.86s`: `cpu_aot_aes_pclmul` `2.62s`) - `sccache`: 5/13 hits; wall `30.1s` 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!2669
No description provided.