cpu: lower RDRAND and RDSEED in the shared lowering #795
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#795
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@legacy-code-archaeologist on GitHub · 2026-11-23 04:55 UTC · original
Claim and design question: lower
RDRANDandRDSEEDin the shared loweringrdrandandrdseedare in the Integer group ofdocs/coverage/x64_zen2.tsv. Neither has a passing fixture:tools/form_coverage.py --gaps x64_zen2lists both asunobservedafter a full^cpu_CTest run with records onmainafter #789.lower()intools/ffx_version_query.pyrejects both today. I found no open issue or PR that covers them, and I'd like to take them as one small PR, following the pattern agreed in #739.Proposed behavior (host entropy profile)
RDRAND r16/r32/r64calls_rdrand16_step,_rdrand32_stepor_rdrand64_step.RDSEEDcalls the matching_rdseed*_stepintrinsic.Proposed fixture (source-built MASM, property checks)
The value is non-deterministic, so the check compares properties rather than bytes:
/O2build still contains everyRDRANDandRDSEED, including one whose result is overwritten, using the branch walk from #789.Negative controls (mutations of the generated C++) must each fail:
constant(fixed value);nocarry(CF dropped);noext(no zero extension);wide16(the 16-bit form overwrites the upper bits);flags(ZF/OF left as preset).Separate tests:
cpu_aot_rdrandandcpu_aot_rdseedare separate tests with separate fixture sources. Each exits 77 only when its own CPUID bit is clear: RDRAND is CPUID.01H:ECX bit 30, RDSEED is CPUID.(EAX=07H,ECX=0):EBX bit 18.Questions before I start
docs/experiments.md.Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100.
AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-23 05:30 UTC · original
Yes, please proceed with the opt-in host-entropy profile. Execute the same instruction once per guest execution and expose its carry result; on CF=0 write zero at the selected width. Guest code retains control of retrying. Document the corresponding host CPUID bit as a precondition and keep these opcodes rejected in the default profile. The fixture should check width and cleared flags on both outcomes, and count natural failures without requiring a random failure in CI. A deterministic test-only failed-read control would let the fixture check the zero and carry rules even when the host succeeds every time. Keep the
/O2discarded-result check and the separate capability skips. Variation checks can catch a constant translation; they do not assess entropy quality.@R0Y00 on GitHub · 2026-11-23 06:42 UTC · original
Implemented in #807 (
df6a9c0). The opt-in host profile makes one attempt per guest instruction. The fixtures check both carry outcomes, zero on failure, destination width, cleared modeled flags and retention of discarded reads at /O2. RDRAND and RDSEED retain separate capability checks.