cpu: lower all 7 SHA-NI instructions #375

Merged
Vonsek merged 2 commits from upstream-pr/381 into main 2026-11-22 08:18:41 +00:00
Vonsek commented 2026-11-21 23:55:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T23:55:51Z.


Change

  • Lower all 7 SHA-NI instructions (plus legacy movdqu) in tools/ffx_version_query.py:
    • SHA-1: sha1msg1, sha1msg2, sha1nexte, sha1rnds4 (all 4 round-function selectors)
    • SHA-256: sha256msg1, sha256msg2, sha256rnds2 (using implicit xmm0 message-schedule/constant input)
  • Restrict lowering to EncodingKind.LEGACY XMM forms.
  • Probe CPUID leaf 7 subleaf 0 EBX bit 29 (SHA) before invoking the native fixture (exiting 77 with SKIP_RETURN_CODE 77 on hosts without SHA-NI).
  • Add source-built MASM differential fixture tests/cpu/crypto_sha.{asm,def,py}, CMake target cpu_crypto_sha_lifted, CTest cpu_aot_crypto_sha, coverage mapping in tools/form_coverage.py, and documentation in docs/experiments.md.

Verification

  • Confirmed pre-fix failure on cmake --build --preset dev --target cpu_crypto_sha_lifted:
    ValueError: unsupported query operation at 0x1000: movdqu xmm0,[rcx]
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_crypto_sha_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_crypto_sha|cpu_aot_bmi1)$" -V: 2/2 passed (10 SHA-NI cases matched native and translated DLLs + unmodeled-register sha1msg1 xmm3, xmm0 rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers the remaining 7 of 21 Crypto-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures, gated by a runtime CPUID check.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536028136 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/381). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T23:55:51Z. --- ## Change - Lower all 7 SHA-NI instructions (plus legacy `movdqu`) in `tools/ffx_version_query.py`: - SHA-1: `sha1msg1`, `sha1msg2`, `sha1nexte`, `sha1rnds4` (all 4 round-function selectors) - SHA-256: `sha256msg1`, `sha256msg2`, `sha256rnds2` (using implicit `xmm0` message-schedule/constant input) - Restrict lowering to `EncodingKind.LEGACY` XMM forms. - Probe CPUID leaf 7 subleaf 0 EBX bit 29 (`SHA`) before invoking the native fixture (exiting 77 with `SKIP_RETURN_CODE 77` on hosts without SHA-NI). - Add source-built MASM differential fixture `tests/cpu/crypto_sha.{asm,def,py}`, CMake target `cpu_crypto_sha_lifted`, CTest `cpu_aot_crypto_sha`, coverage mapping in `tools/form_coverage.py`, and documentation in `docs/experiments.md`. ## Verification - Confirmed pre-fix failure on `cmake --build --preset dev --target cpu_crypto_sha_lifted`: `ValueError: unsupported query operation at 0x1000: movdqu xmm0,[rcx]` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_crypto_sha_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_crypto_sha|cpu_aot_bmi1)$" -V`: 2/2 passed (`10 SHA-NI cases matched native and translated DLLs` + unmodeled-register `sha1msg1 xmm3, xmm0` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers the remaining 7 of 21 `Crypto`-grouped mnemonics in `docs/coverage/x64_zen2.tsv` using source-built fixtures, gated by a runtime CPUID check.
upstream-sync closed this pull request 2026-11-24 06:42:44 +00:00
R0Y00 commented 2026-11-24 06:42:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T08:18:36Z.

Review: APPROVED


Reviewed dd49224 and built the combined tree with main on an Intel Windows host. cpu_aot_crypto_sha executed all ten native/translated exports. I also compared all 16 output bytes for each export on 128 independently generated input triples (Python Random seed 381, separate initial output-buffer sentinels), including the four SHA1RNDS4 selectors and SHA256RNDS2's implicit XMM0 input. All 1,280 comparisons matched.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6011195826 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/381#pullrequestreview-6011195826). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T08:18:36Z. **Review:** APPROVED --- Reviewed dd49224 and built the combined tree with main on an Intel Windows host. cpu_aot_crypto_sha executed all ten native/translated exports. I also compared all 16 output bytes for each export on 128 independently generated input triples (Python Random seed 381, separate initial output-buffer sentinels), including the four SHA1RNDS4 selectors and SHA256RNDS2's implicit XMM0 input. All 1,280 comparisons matched.
chatgpt-codex-connector[bot commented 2026-11-24 06:48:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T23:58:54Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T00:03:16.684347Z a194ac6 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7071230055 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/381#issuecomment-7071230055). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T23:58:54Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"a194ac6941ef42231d3900468b59ee838d396437","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-22T00:03:16.684347Z">2026-11-22T00:03:16.684347Z</relative-time> | `a194ac6` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
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!375
No description provided.