cpu: add dedicated cpu_sha1_aot lifter for SHA1RNDS4, SHA1NEXTE, SHA1MSG1, and SHA1MSG2 #2368

Merged
Ammmae0x merged 1 commit from upstream-pr/2376 into main 2026-11-25 14:42:16 +00:00
Ammmae0x commented 2026-11-25 14:15:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T14:15:18Z.


Change

Adds a dedicated, standalone portable C++ AOT lifter (tools/cpu_sha1_aot.py, no <immintrin.h>) and differential MASM test suite (tests/cpu/sha1_aot.asm, tests/cpu/sha1_aot.def, tests/cpu/sha1_aot_check.py) registered as CTest cpu_aot_sha1 in CMakeLists.txt for the Intel SHA-1 NI instructions (docs/coverage/x64_zen2.tsv group Crypto):

  • Lifts SHA1RNDS4 (imm8 & 3 selecting f0..f3, upper bits imm8[7:2] ignored), SHA1NEXTE, SHA1MSG1, and SHA1MSG2 across register, self-operand, and flat 16-byte [rcx|rdx|r8] memory operands, plus movdqu/movdqa transport and terminal ret on volatile XMM0..XMM5.
  • Rejects SHA256* instructions, VEX/EVEX/non-legacy encodings, nonvolatile XMM6..15, undefined XMM reads, unaligned movdqa/sha1* displacements, displaced/indexed/RIP-relative/non-argument memory operands, stores outside [r8], instruction prefixes, branches, missing ret, and trailing instructions after ret.
  • Probes CPUID.07H.00H:EBX[29] (host_has_sha()) after running all translator, portable reference, NIST FIPS 180-4, aliasing, mutant, and altered-build checks unconditionally; exits 77 on hosts lacking SHA-NI without writing FORM_COVERAGE_RECORD, and runs full bit-for-bit native vs lifted differential checks plus FORM_COVERAGE_RECORD output on SHA-NI hosts.

AI-assisted.

Verification

Verified on rebased commit 948e9fd7 (parent upstream/main e33578e1) in both dev (Debug) and release (/O2) presets on a SHA-NI-capable Windows x64 host (0 skips):

cmake --build --preset dev --target cpu_sha1_aot_original cpu_sha1_aot_original_lifted cpu_sha1_aot_altered cpu_sha1_aot_altered_lifted
-> exit 0 (0 warnings/errors)

ctest --preset dev -R "^cpu_aot_sha1$" -E "cpu_native_archive_" --output-on-failure -V
-> 1/1 Passed
   9 SHA-1 NI forms accepted; 30 rejection controls passed
   2492 portable reference / NIST FIPS 180-4 / aliasing checks on lifted DLLs passed; 10 mutant controls + 7 altered-build controls caught
   2484 native vs lifted SHA-NI differential cases matched bit for bit
   FORM_COVERAGE_RECORD: movdqa, movdqu, ret, sha1msg1, sha1msg2, sha1nexte, sha1rnds4

cmake --build --preset release --target cpu_sha1_aot_original cpu_sha1_aot_original_lifted cpu_sha1_aot_altered cpu_sha1_aot_altered_lifted
-> exit 0 (0 warnings/errors)

ctest --preset release -R "^cpu_aot_sha1$" -E "cpu_native_archive_" --output-on-failure -V
-> 1/1 Passed
   9 SHA-1 NI forms accepted; 30 rejection controls passed
   2492 portable reference / NIST FIPS 180-4 / aliasing checks on lifted DLLs passed; 10 mutant controls + 7 altered-build controls caught
   2484 native vs lifted SHA-NI differential cases matched bit for bit
   FORM_COVERAGE_RECORD: movdqa, movdqu, ret, sha1msg1, sha1msg2, sha1nexte, sha1rnds4

out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> exit 0
out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> exit 0
out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0

8/8 spot mutations against tools/cpu_sha1_aot.py (6 Python lifter guard mutations: SHA-256 reject, VEX reject, nonvolatile vector reject, undefined XMM reject, store outside [r8], aligned displacement guard; plus 2 rebuilt C++ semantic mutations: op_sha1rnds4 round constant 0x6ed9eba1u -> 0x6ed9eba0u and op_sha1msg2 dropping the w16 dependency) were killed (exit non-zero) by tests/cpu/sha1_aot_check.py.

Evidence and follow-up

  • tests/cpu/sha1_aot.asm and tests/cpu/sha1_aot.def are source-built synthetic MASM fixtures (MIT License) with ; coverage: record cpu_aot_sha1 and ALTER_SHA1 negative-control variants.
  • NIST FIPS 180-4 SHA-1 test vectors (empty string, "abc", 56-byte, and 112-byte messages) are verified end-to-end through both the register-operand and memory-operand lifted exports against Python's hashlib.sha1.
  • Existing cpu_aot_crypto_sha and cpu_mul_div targets remain untouched.

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 or build requirement changed.)
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6606510231 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2376). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T14:15:18Z. --- ## Change Adds a dedicated, standalone portable C++ AOT lifter (`tools/cpu_sha1_aot.py`, no `<immintrin.h>`) and differential MASM test suite (`tests/cpu/sha1_aot.asm`, `tests/cpu/sha1_aot.def`, `tests/cpu/sha1_aot_check.py`) registered as CTest `cpu_aot_sha1` in `CMakeLists.txt` for the Intel SHA-1 NI instructions (`docs/coverage/x64_zen2.tsv` group Crypto): - Lifts `SHA1RNDS4` (`imm8 & 3` selecting f0..f3, upper bits `imm8[7:2]` ignored), `SHA1NEXTE`, `SHA1MSG1`, and `SHA1MSG2` across register, self-operand, and flat 16-byte `[rcx|rdx|r8]` memory operands, plus `movdqu`/`movdqa` transport and terminal `ret` on volatile `XMM0..XMM5`. - Rejects `SHA256*` instructions, VEX/EVEX/non-legacy encodings, nonvolatile `XMM6..15`, undefined XMM reads, unaligned `movdqa`/`sha1*` displacements, displaced/indexed/RIP-relative/non-argument memory operands, stores outside `[r8]`, instruction prefixes, branches, missing `ret`, and trailing instructions after `ret`. - Probes `CPUID.07H.00H:EBX[29]` (`host_has_sha()`) after running all translator, portable reference, NIST FIPS 180-4, aliasing, mutant, and altered-build checks unconditionally; exits 77 on hosts lacking SHA-NI without writing `FORM_COVERAGE_RECORD`, and runs full bit-for-bit native vs lifted differential checks plus `FORM_COVERAGE_RECORD` output on SHA-NI hosts. AI-assisted. ## Verification Verified on rebased commit `948e9fd7` (parent `upstream/main` `e33578e1`) in both `dev` (Debug) and `release` (`/O2`) presets on a SHA-NI-capable Windows x64 host (0 skips): ```text cmake --build --preset dev --target cpu_sha1_aot_original cpu_sha1_aot_original_lifted cpu_sha1_aot_altered cpu_sha1_aot_altered_lifted -> exit 0 (0 warnings/errors) ctest --preset dev -R "^cpu_aot_sha1$" -E "cpu_native_archive_" --output-on-failure -V -> 1/1 Passed 9 SHA-1 NI forms accepted; 30 rejection controls passed 2492 portable reference / NIST FIPS 180-4 / aliasing checks on lifted DLLs passed; 10 mutant controls + 7 altered-build controls caught 2484 native vs lifted SHA-NI differential cases matched bit for bit FORM_COVERAGE_RECORD: movdqa, movdqu, ret, sha1msg1, sha1msg2, sha1nexte, sha1rnds4 cmake --build --preset release --target cpu_sha1_aot_original cpu_sha1_aot_original_lifted cpu_sha1_aot_altered cpu_sha1_aot_altered_lifted -> exit 0 (0 warnings/errors) ctest --preset release -R "^cpu_aot_sha1$" -E "cpu_native_archive_" --output-on-failure -V -> 1/1 Passed 9 SHA-1 NI forms accepted; 30 rejection controls passed 2492 portable reference / NIST FIPS 180-4 / aliasing checks on lifted DLLs passed; 10 mutant controls + 7 altered-build controls caught 2484 native vs lifted SHA-NI differential cases matched bit for bit FORM_COVERAGE_RECORD: movdqa, movdqu, ret, sha1msg1, sha1msg2, sha1nexte, sha1rnds4 out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> exit 0 out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> exit 0 out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0 ``` 8/8 spot mutations against `tools/cpu_sha1_aot.py` (6 Python lifter guard mutations: SHA-256 reject, VEX reject, nonvolatile vector reject, undefined XMM reject, store outside `[r8]`, aligned displacement guard; plus 2 rebuilt C++ semantic mutations: `op_sha1rnds4` round constant `0x6ed9eba1u -> 0x6ed9eba0u` and `op_sha1msg2` dropping the `w16` dependency) were killed (exit non-zero) by `tests/cpu/sha1_aot_check.py`. ## Evidence and follow-up - `tests/cpu/sha1_aot.asm` and `tests/cpu/sha1_aot.def` are source-built synthetic MASM fixtures (MIT License) with `; coverage: record cpu_aot_sha1` and `ALTER_SHA1` negative-control variants. - NIST FIPS 180-4 SHA-1 test vectors (empty string, `"abc"`, 56-byte, and 112-byte messages) are verified end-to-end through both the register-operand and memory-operand lifted exports against Python's `hashlib.sha1`. - Existing `cpu_aot_crypto_sha` and `cpu_mul_div` targets remain untouched. ## 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. (No capability or build requirement changed.) - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-25 15:01:50 +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!2368
No description provided.