cpu: lower CPUID and XGETBV in an opt-in host-CPU profile #937
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#937
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 17:56 UTC · original
Claim and design question: lower
CPUIDandXGETBVin an opt-in host-CPU profilecpuid(Integer group) andxgetbv(XSAVE group) ofdocs/coverage/x64_zen2.tsvhave no passing fixture, and no translator accepts them: there is noM.CPUIDorM.XGETBVintools/. Startup and runtime-dispatch code usually executes both before it chooses an SSE, AVX or AVX2 path, so they sit on the way to #870. I found no open issue or PR about them and would like to take them as one small PR, following the pattern agreed in #739 and #795.Proposed behavior (opt-in host-CPU profile, the default profile keeps rejecting both)
CPUIDcalls__cpuidex(regs, eax, ecx)with the guest EAX and ECX. It writes EAX, EBX, ECX and EDX zero-extended into RAX, RBX, RCX and RDX. Flags are unchanged.XGETBVcalls_xgetbv(ecx)and writes the low half to EAX and the high half to EDX, zero-extended. Flags are unchanged.XGETBVneeds CPUID.01H:ECX bit 27 (OSXSAVE)./O2check from #789 and #807).Proposed fixture (source-built MASM, differential, separate tests and skips)
cpu_aot_cpuid(tests/cpu/cpuid.asm) compares native and translated outputs on one pinned logical processor. The thread is pinned because leaf 01H EBX[31:24] and the x2APIC leaves carry the processor's APIC ID. Leaves covered:The cases also include an unused subleaf, where ECX must be passed through and not cleared, and a read whose result is discarded.
cpu_aot_xgetbv(tests/cpu/xgetbv.asm) compares XCR0 (ECX=0) and, when CPUID.(0DH,1):EAX bit 2 is set, XINUSE (ECX=1). It exits 77 only when OSXSAVE is clear.Controls (mutations of the generated C++) must each break a property:
noext(upper halves kept);swap(EBX and EDX exchanged);nosubleaf(ECX forced to 0);constant(a fixed result);flags(ZF/CF changed);/O2plaincontrol withoutvolatile, if MSVC removes a discarded read there.Questions before I start
x64_zen2.tsv), so title code sees the console CPU's feature bits instead of the host's. With host pass-through, a title may take an AVX-512 or other path the console never had, or miss a feature it assumes. I'd keep the first PR to the documented host profile and leave a guest table as a follow-up runtime hook.host_cpu=True)? I'd make it separate, so each opt-in stays explicit.Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100 (OSXSAVE set, AVX2 present, no AVX-512).
AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-23 18:22 UTC · original
An opt-in host-CPU profile is a useful starting point. Please keep the current default. For the Windows differential, pin the native and translated runs to the same logical processor and restore the previous affinity afterward. Cover both CPUID inputs, all four zero-extended results, preserved flags, and a discarded-result case. Check OSXSAVE before XGETBV and isolate any invalid-index test in a subprocess. Please keep XINUSE/XGETBV(1) out of the first increment unless the two paths can independently establish the same observable state.
@R0Y00 on GitHub · 2026-11-23 20:09 UTC · original
Completed by #969 for the approved opt-in host profile and XCR0 scope. Both Windows jobs and both Linux jobs passed. The independent Windows Release tests passed all comparisons and controls, including pinned CPUID subleaves, unchanged flags and the discarded XGETBV result under /O2. XINUSE is outside this increment.