cpu: lower CPUID and XGETBV in an opt-in host-CPU profile #930

Closed
opened 2026-11-23 17:56:31 +00:00 by legacy-code-archaeologist · 2 comments
legacy-code-archaeologist commented 2026-11-23 17:56:31 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T17:56:31Z.


Claim and design question: lower CPUID and XGETBV in an opt-in host-CPU profile

cpuid (Integer group) and xgetbv (XSAVE group) of docs/coverage/x64_zen2.tsv have no passing fixture, and no translator accepts them: there is no M.CPUID or M.XGETBV in tools/. 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)

  • CPUID calls __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.
  • XGETBV calls _xgetbv(ecx) and writes the low half to EAX and the high half to EDX, zero-extended. Flags are unchanged.
  • Preconditions to document:
    • XGETBV needs CPUID.01H:ECX bit 27 (OSXSAVE).
    • An unsupported ECX raises #GP on the host as it does natively. The lowering does not filter it.
  • Each executed instruction runs once on the host, and the read stays observable when the guest discards its result (the /O2 check 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:

  • 00H, 01H, 07H with subleaves 0 and 1;
  • 0DH with subleaves 0 and 1;
  • 80000000H, 80000001H.

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);
  • an /O2 plain control without volatile, if MSVC removes a discarded read there.

Questions before I start

  1. Is passing the host CPU through the intended first contract? The other option is a fixed guest profile (for example a Zen 2 table matching 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.
  2. Should the profile be one opt-in keyword shared with the host-entropy profile, or a separate one (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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6565514993 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/937). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-23T17:56:31Z. --- ### Claim and design question: lower `CPUID` and `XGETBV` in an opt-in host-CPU profile `cpuid` (Integer group) and `xgetbv` (XSAVE group) of `docs/coverage/x64_zen2.tsv` have no passing fixture, and no translator accepts them: there is no `M.CPUID` or `M.XGETBV` in `tools/`. 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)** - `CPUID` calls `__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. - `XGETBV` calls `_xgetbv(ecx)` and writes the low half to EAX and the high half to EDX, zero-extended. Flags are unchanged. - Preconditions to document: - `XGETBV` needs CPUID.01H:ECX bit 27 (OSXSAVE). - An unsupported ECX raises #GP on the host as it does natively. The lowering does not filter it. - Each executed instruction runs once on the host, and the read stays observable when the guest discards its result (the `/O2` check 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: - 00H, 01H, 07H with subleaves 0 and 1; - 0DH with subleaves 0 and 1; - 80000000H, 80000001H. 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); - an `/O2` `plain` control without `volatile`, if MSVC removes a discarded read there. **Questions before I start** 1. Is passing the **host** CPU through the intended first contract? The other option is a fixed guest profile (for example a Zen 2 table matching `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. 2. Should the profile be one opt-in keyword shared with the host-entropy profile, or a separate one (`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 commented 2026-11-24 06:49:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:22:09Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110062114 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/937#issuecomment-7110062114). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:22:09Z. --- 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 commented 2026-11-24 06:49:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:09:25Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112646984 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/937#issuecomment-7112646984). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T20:09:25Z. --- 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.
Sign in to join this conversation.
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#930
No description provided.