cpu: add dedicated cpu_sha256_aot lifter for SHA256RNDS2, SHA256MSG1, and SHA256MSG2 #2389
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2397"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T15:10:50Z.
Change
Add a dedicated, portable C++ AOT lifter
tools/cpu_sha256_aot.pyfor the three Intel SHA-256 NI instructions fromdocs/coverage/x64_zen2.tsvgroupCrypto:SHA256RNDS2(NP 0F 38 CB /r, register and 16-byte aligned flatm128): two SHA-256 rounds using implicitXMM0[63:0]asWK1:WK0(ignoringXMM0[127:64]and rejecting undefined implicitXMM0).SHA256MSG1(NP 0F 38 CC /r, register and 16-byte aligned flatm128): intermediate SHA-256 message schedule addingsigma0(W[i+1])usingsrc[31:0]for lane 3.SHA256MSG2(NP 0F 38 CD /r, register and 16-byte aligned flatm128): final SHA-256 message schedule with sequential dependency of lanes 2..3 on updated lanes 0..1.uint32_timplementation (zero<immintrin.h>SHA intrinsics),movdqa(16B aligned) /movdqutransport over flat[rcx|rdx|r8]loads,[r8]stores, reg-reg copies,ret, andhost_has_sha()(CPUID.07H.00H:EBX[29]).SHA1*,AES*/PCLMUL*, VEX/EVEX encodings, nonvolatileXMM6..15, undefined XMM reads (including implicitXMM0), unaligned/displaced/indexed/non-flat memory, stores outside[r8], prefixes, branches, and missing/trailingret.tests/cpu/sha256_aot.{asm,def,_check.py}(; coverage: record cpu_aot_sha256) and registercpu_aot_sha256inCMakeLists.txt.Verification
Verified on commit
364f8954(rebased onupstream/main0b31989c) across bothdev(Debug) andrelease(/O2) presets:cmake --build --preset dev --target cpu_sha256_aot_original cpu_sha256_aot_original_lifted cpu_sha256_aot_altered cpu_sha256_aot_altered_lifted-> exit 0ctest --preset dev -R "^cpu_aot_sha256$" -E "cpu_native_archive_" --output-on-failure -V->100% tests passed, 0 tests failed out of 1(0 skipped, 0.82s):3 SHA-256 NI forms accepted; 35 IR + 9 PE + CLI rejection controls passed1503 portable lifted + 480 /O2 cases (incl. NIST FIPS 180-4 single/multi-block & aliasing) passed; 8 mutants + 5 altered-build controls caught1493 native vs lifted SHA-NI differential cases matched bit for bitcmake --build --preset release --target cpu_sha256_aot_original cpu_sha256_aot_original_lifted cpu_sha256_aot_altered cpu_sha256_aot_altered_lifted-> exit 0ctest --preset release -R "^cpu_aot_sha256$" -E "cpu_native_archive_" --output-on-failure -V->100% tests passed, 0 tests failed out of 1(0 skipped, 1.06s)FORM_COVERAGE_RECORDverified in bothout/build/dev/form_coverage/cpu_aot_sha256.txtandout/build/release/form_coverage/cpu_aot_sha256.txt:movdqa, movdqu, ret, sha256msg1, sha256msg2, sha256rnds2out/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 464 links.(exit 0)out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 1722 tracked source, script and build/CI files: no bidirectional controls.(exit 0)Spot mutation checks against
tools/cpu_sha256_aot.py(8/8 killed bytests/cpu/sha256_aot_check.py, restored cleanly):SHA256MSG2lane 2 dependency onw0(/O2), read wrongSHA256MSG1source lane (/O2), swapSHA256RNDS2WKword (/O2), swapSHA256RNDS2output lanese1/e2(/O2), drop undefined implicitXMM0check, bypass SHA-1 rejection check, bypass 16B alignment check, and bypassr8-only store guard (all returned exit 1).Evidence and follow-up
tests/cpu/sha256_aot.{asm,def,_check.py}is a clean-room, source-built MASM fixture (MIT, repo-authored; no game files, dumps, or binaries)./O2build, mutants, andALTER_SHA256before anyhost_has_sha()exit-77 capability skip (0 skips on this SHA-NI-capable host).Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T16:29:53Z.
Review: COMMENTED
Review of head
364f8954(comment only).Checked:
git diff --stat origin/main...HEAD: 5 files, new lifter, asm fixture, check script and a 24-line CMake block. Same shape as the siblingcpu_*_aotlifters, so it is small and additive.gh pr list --state all --search "SHA256RNDS2 sha256").tests/cpu/sha256_aot_check.pyruns compiled original vs lifted executables against Python references (ref_sha256rnds2,ref_sha256msg1,ref_sha256msg2) on edge, carry-wrap, lane-isolation and random inputs. It also checks that the upper 64 bits of XMM0 are ignored, aliasing, memory-source forms, mutants, an altered binary and rejection cases.hashlib, which is an independent end-to-end reference.python3 -I -m py_compile.No blocking findings. Win2025 WARP dev+release will be run next.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T16:07:10Z.
APPROVED. Dedicated cpu_sha256_aot lifter for SHA256 ops.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T16:33:44Z.
Win2025 WARP receipt for head
8f0c8fb7after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
8f0c8fb7cf581d47e179c838fcc11fb09efb1eed:--preset dev):cmake --build --preset dev --target cpu_sha256_aot_altered cpu_sha256_aot_altered_lifted cpu_sha256_aot_original cpu_sha256_aot_original_lifted -- -j 2):3.58s(configure1.66s)ctest --preset dev -R 'cpu_aot_sha256' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (1.02s:cpu_aot_sha2560.91s)/O2(--preset release):cmake --build --preset release --target cpu_sha256_aot_altered cpu_sha256_aot_altered_lifted cpu_sha256_aot_original cpu_sha256_aot_original_lifted -- -j 2):1.02s(configure1.66s)ctest --preset release -R 'cpu_aot_sha256' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (0.89s:cpu_aot_sha2560.80s)sccache: 0/4 hits; wall15.3sAI-assisted; commands listed were executed locally.