cpu: lower xsavec and xsavec64 in the XSAVE state translator #1260

Merged
tedin7 merged 5 commits from upstream-pr/1267 into main 2026-11-24 07:23:51 +00:00
tedin7 commented 2026-11-24 06:17:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:17:27Z.


Change

Lower xsavec and xsavec64 in the bounded XSAVE state translator (tools/cpu_xsave_aot.py). They use the existing local XState and write the compacted format: only components selected by XINUSE & RFBM are stored, XSTATE_BV = XINUSE & RFBM, XCOMP_BV = bit 63 | RFBM, and the reserved header bytes stay untouched. Alignment and request-mask faults are raised before the first store, so a rejected call leaves memory intact. With only x87/SSE/AVX the compacted offsets equal the standard ones (AVX at 576); packed offsets and 64-byte component alignment need components beyond XCR0[2:0] and are not covered.

AI-assisted. No issue is claimed.

Verification

Run on Linux (llvm-ml-19 + lld-link-19 for the fixture, MinGW for the lifted C++, Wine on a CPU with XSAVEC):

  • python -B tests/cpu/xsave_state_check.py rejection/alt-encoding part against the Linux-built fixture: 6 alternate-encoding lift checks, 39 unit rejection controls, 10 PE-patched rejection controls passed.
  • Native fixture vs lifted vs the Python reference, run through a Wine driver: 84 differential cases over 12 exports (including the 4 new xsavec exports x 7 XSTATE_BV subsets) matched; ALTER_OP diverged on all 6 altered exports (xsave64 instead of xsavec64: 7/7; request mask ignored: 7/7).
  • 24 misaligned-output checks (native and lifted, +16/+8/+1): #GP and output memory intact. 5 unsupported request masks (bits outside 2:0, high word set) fault with memory intact; 5 valid dynamic masks match.
  • Word mutations of XCOMP_BV[63], XSTATE_BV, a reserved header byte and the AVX slot are each rejected by the comparator.
  • Fails on current main: cpu_xsave_aot.py there stops with "unsupported XSAVE-family instruction ... xsavec [r8]". Mutated lifted outputs (XCOMP_BV without bit 63, request mask ignored, XSTATE_BV = RFBM, unused components written) each fail the new comparison (28, 9, 21, 21 cases).
  • git diff --check, tests/docs_links_check.py, tests/bidi_controls_check.py pass.

Not run here: the MSVC build and the full Windows harness. Outside --preset pr; to run on Windows Server 2025 (Debug and /O2): ctest --preset dev -R '^cpu_aot_xsave_state$'.

Evidence and follow-up

The fixture is source-built MASM (tests/cpu/xsave_state.asm), no external binaries. Observed on the Linux host CPU: XSAVEC leaves header bytes [528..575] untouched and stores MXCSR only with the SSE slot; the native comparison treats those bytes, extra initialized x87/SSE slots and x87 pointer fields as implementation-defined. Follow-up: xsaves, xrstors, xsaveopt, and compacted xrstor.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575905639 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:17:27Z. --- ## Change Lower `xsavec` and `xsavec64` in the bounded XSAVE state translator (`tools/cpu_xsave_aot.py`). They use the existing local `XState` and write the compacted format: only components selected by `XINUSE & RFBM` are stored, `XSTATE_BV = XINUSE & RFBM`, `XCOMP_BV = bit 63 | RFBM`, and the reserved header bytes stay untouched. Alignment and request-mask faults are raised before the first store, so a rejected call leaves memory intact. With only x87/SSE/AVX the compacted offsets equal the standard ones (AVX at 576); packed offsets and 64-byte component alignment need components beyond XCR0[2:0] and are not covered. AI-assisted. No issue is claimed. ## Verification Run on Linux (llvm-ml-19 + lld-link-19 for the fixture, MinGW for the lifted C++, Wine on a CPU with XSAVEC): - `python -B tests/cpu/xsave_state_check.py` rejection/alt-encoding part against the Linux-built fixture: 6 alternate-encoding lift checks, 39 unit rejection controls, 10 PE-patched rejection controls passed. - Native fixture vs lifted vs the Python reference, run through a Wine driver: 84 differential cases over 12 exports (including the 4 new xsavec exports x 7 XSTATE_BV subsets) matched; `ALTER_OP` diverged on all 6 altered exports (xsave64 instead of xsavec64: 7/7; request mask ignored: 7/7). - 24 misaligned-output checks (native and lifted, +16/+8/+1): #GP and output memory intact. 5 unsupported request masks (bits outside 2:0, high word set) fault with memory intact; 5 valid dynamic masks match. - Word mutations of XCOMP_BV[63], XSTATE_BV, a reserved header byte and the AVX slot are each rejected by the comparator. - Fails on current main: `cpu_xsave_aot.py` there stops with "unsupported XSAVE-family instruction ... xsavec [r8]". Mutated lifted outputs (XCOMP_BV without bit 63, request mask ignored, XSTATE_BV = RFBM, unused components written) each fail the new comparison (28, 9, 21, 21 cases). - `git diff --check`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py` pass. Not run here: the MSVC build and the full Windows harness. Outside `--preset pr`; to run on Windows Server 2025 (Debug and `/O2`): `ctest --preset dev -R '^cpu_aot_xsave_state$'`. ## Evidence and follow-up The fixture is source-built MASM (`tests/cpu/xsave_state.asm`), no external binaries. Observed on the Linux host CPU: XSAVEC leaves header bytes [528..575] untouched and stores MXCSR only with the SSE slot; the native comparison treats those bytes, extra initialized x87/SSE slots and x87 pointer fields as implementation-defined. Follow-up: `xsaves`, `xrstors`, `xsaveopt`, and compacted `xrstor`. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
chatgpt-codex-connector[bot commented 2026-11-24 06:47:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T06:27:34Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d03af0446

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034660456 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#pullrequestreview-6034660456). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T06:27:34Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `3d03af0446` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-24 06:47:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:37:32Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034749322 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#pullrequestreview-6034749322). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:37:32Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 06:47:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:37:33Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034749566 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#pullrequestreview-6034749566). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:37:33Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 06:50:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:21:17Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at 3d03af04:

  • Debug (--preset dev): ctest --preset dev -R "^cpu_aot_xsave_state$" — 1/1 PASS (0.27s, build 3.75s)
  • Release /O2 (--preset release): ctest --preset release -R "^cpu_aot_xsave_state$" — 1/1 PASS (0.31s, build 1.20s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123846222 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#issuecomment-7123846222). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:21:17Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at `3d03af04`: - Debug (`--preset dev`): `ctest --preset dev -R "^cpu_aot_xsave_state$"` — **1/1 PASS** (`0.27s`, build `3.75s`) - Release `/O2` (`--preset release`): `ctest --preset release -R "^cpu_aot_xsave_state$"` — **1/1 PASS** (`0.31s`, build `1.20s`)
tedin7 commented 2026-11-24 06:50:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:37:36Z.


AI-assisted follow-up for the two P2 findings in tests/cpu/xsave_state_check.py (afbcbcff):

  • The native xsavec comparison now relaxes only components the reference leaves initialized; active x87/SSE payloads (FCW, ST, XMM) stay compared. New controls: a flipped FCW, ST0 or XMM0 byte fails the native comparison (the old comparator accepted all three), and an initialized component carrying extra host bytes still passes.
  • The lifted DLL exports host_has_xsavec() (CPUID.(0DH,1):EAX[1]); without it the native xsavec fixtures are skipped and the lifted path is still checked. A control checks that the gated native set contains no xsavec export and the fault controls run on it.

Checked on Linux with llvm-ml-19, lld-link-19, MinGW and Wine: 84 native/lifted/reference cases, 24 misalignment checks, dynamic-mask checks and the rejection controls pass.

PR #1267 fuori preset pr: ctest --preset dev -R '^cpu_aot_xsave_state$' va rieseguito sul nodo Windows.

@codex review

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124126128 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#issuecomment-7124126128). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:37:36Z. --- AI-assisted follow-up for the two P2 findings in tests/cpu/xsave_state_check.py (afbcbcff): - The native xsavec comparison now relaxes only components the reference leaves initialized; active x87/SSE payloads (FCW, ST, XMM) stay compared. New controls: a flipped FCW, ST0 or XMM0 byte fails the native comparison (the old comparator accepted all three), and an initialized component carrying extra host bytes still passes. - The lifted DLL exports host_has_xsavec() (CPUID.(0DH,1):EAX[1]); without it the native xsavec fixtures are skipped and the lifted path is still checked. A control checks that the gated native set contains no xsavec export and the fault controls run on it. Checked on Linux with llvm-ml-19, lld-link-19, MinGW and Wine: 84 native/lifted/reference cases, 24 misalignment checks, dynamic-mask checks and the rejection controls pass. PR #1267 fuori preset pr: ctest --preset dev -R '^cpu_aot_xsave_state$' va rieseguito sul nodo Windows. @codex review
tedin7 commented 2026-11-24 06:50:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:46:46Z.


Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at afbcbcff:

  • Debug (--preset dev): ctest --preset dev -R "^cpu_aot_xsave_state$" — 1/1 PASS (0.26s, build 3.75s)
  • Release /O2 (--preset release): ctest --preset release -R "^cpu_aot_xsave_state$" — 1/1 PASS (0.30s, build 1.32s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124281738 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#issuecomment-7124281738). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:46:46Z. --- Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at `afbcbcff`: - Debug (`--preset dev`): `ctest --preset dev -R "^cpu_aot_xsave_state$"` — **1/1 PASS** (`0.26s`, build `3.75s`) - Release `/O2` (`--preset release`): `ctest --preset release -R "^cpu_aot_xsave_state$"` — **1/1 PASS** (`0.30s`, build `1.32s`)
chatgpt-codex-connector[bot commented 2026-11-24 06:50:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T06:21:27Z.


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-24T07:12:58.972844Z e8f1a64 Manual request
ℹ️ 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:7123848967 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#issuecomment-7123848967). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T06:21:27Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"e8f1a64e27adbdab72d08b9d4f8776752fde4284","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-24T07:12:58.972844Z">2026-11-24T07:12:58.972844Z</relative-time> | `e8f1a64` | Manual request | <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>
chatgpt-codex-connector[bot commented 2026-11-24 06:50:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T06:27:34Z.

Code review location: tests/cpu/xsave_state_check.py; line 662

@@ -624,7 +652,21 @@ def assert_equal_output(label: str, name: str, idx, got: bytes, want: bytes) ->
         return
     # Per Intel SDM Vol. 1 Ch. 13.5.1, XSAVE may report XSTATE_BV[1:0] = 1 for initialized
     # legacy x87/SSE components when RFBM selects them (e.g. hybrid E-cores vs P-cores).
-    if label == "native":
+    if label == "native" and name in XSAVEC_EXPORTS:
+        # The CPU may also store initialized x87/SSE slots, and MXCSR is only specified with the SSE slot.
+        got_bv = struct.unpack_from("<Q", got, 512)[0]
+        loose = bytearray(want)
+        for bit, spans in ((1, ((0, 24), (32, 160))), (2, ((160, 416),))):
+            if got_bv & bit:
+                for lo, hi in spans:
+                    loose[lo:hi] = got[lo:hi]

P2 Badge Keep active x87 and SSE payloads in the native comparison

For the existing XSTATE_BV=7 fixture input, this fallback replaces the expected x87 control/ST and XMM bytes with the observed bytes, so the native comparison stops validating both live components. Flipping byte 0 (FCW) or byte 160 (XMM0) in an otherwise correct result is accepted by assert_equal_output('native', ...), even though neither difference is an initialized-component or pointer-field exception. This allows shared lowering/reference mistakes to pass the native differential check. Limit the relaxation to additional initialized components and explicitly probed fields; the new controls using the mutation label do not exercise this permissive branch.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4676298072 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#discussion_r4676298072). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T06:27:34Z. **Code review location:** `tests/cpu/xsave_state_check.py`; line 662 ~~~~diff @@ -624,7 +652,21 @@ def assert_equal_output(label: str, name: str, idx, got: bytes, want: bytes) -> return # Per Intel SDM Vol. 1 Ch. 13.5.1, XSAVE may report XSTATE_BV[1:0] = 1 for initialized # legacy x87/SSE components when RFBM selects them (e.g. hybrid E-cores vs P-cores). - if label == "native": + if label == "native" and name in XSAVEC_EXPORTS: + # The CPU may also store initialized x87/SSE slots, and MXCSR is only specified with the SSE slot. + got_bv = struct.unpack_from("<Q", got, 512)[0] + loose = bytearray(want) + for bit, spans in ((1, ((0, 24), (32, 160))), (2, ((160, 416),))): + if got_bv & bit: + for lo, hi in spans: + loose[lo:hi] = got[lo:hi] ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Keep active x87 and SSE payloads in the native comparison** For the existing `XSTATE_BV=7` fixture input, this fallback replaces the expected x87 control/ST and XMM bytes with the observed bytes, so the native comparison stops validating both live components. Flipping byte 0 (FCW) or byte 160 (XMM0) in an otherwise correct result is accepted by `assert_equal_output('native', ...)`, even though neither difference is an initialized-component or pointer-field exception. This allows shared lowering/reference mistakes to pass the native differential check. Limit the relaxation to additional initialized components and explicitly probed fields; the new controls using the `mutation` label do not exercise this permissive branch. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 06:50:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T06:27:35Z.

Code review location: tests/cpu/xsave_state_check.py; line 730

@@ -679,6 +721,23 @@ def check_fault_controls(
                 _ = buf_a
                 misalign_checks += 1
 
+        for name in XSAVEC_EXPORTS:
+            for label, is_native, fn in (("native", True, native_fns[name]), ("lifted", False, lifted_fns[name])):
+                buf_a, ptr_a, _, _, _ = alloc_aligned_buffer(valid_a)
+                buf_out, ptr_out, pre, p_off, post = alloc_aligned_buffer(FILL, offset=off)
+                try:
+                    if is_native:
+                        harness.call_native(fn, ptr_a, ptr_a, ptr_out)

P2 Badge Check XSAVEC support before invoking its native fixtures

On an XSAVE/OSXSAVE/AVX-capable Windows host without XSAVEC, such as Haswell or a VM masking that feature, check_differential() passes its capability gate because host_has_xsave() checks only CPUID.1 and XCR0. These new native calls then raise an illegal-instruction exception instead of the expected alignment #GP, causing the previously supported cpu_aot_xsave_state test to fail rather than report a capability skip. Probe CPUID.(0xD,1):EAX[1] and gate the native XSAVEC cases, or return the configured skip code when that feature is unavailable.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4676298080 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#discussion_r4676298080). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T06:27:35Z. **Code review location:** `tests/cpu/xsave_state_check.py`; line 730 ~~~~diff @@ -679,6 +721,23 @@ def check_fault_controls( _ = buf_a misalign_checks += 1 + for name in XSAVEC_EXPORTS: + for label, is_native, fn in (("native", True, native_fns[name]), ("lifted", False, lifted_fns[name])): + buf_a, ptr_a, _, _, _ = alloc_aligned_buffer(valid_a) + buf_out, ptr_out, pre, p_off, post = alloc_aligned_buffer(FILL, offset=off) + try: + if is_native: + harness.call_native(fn, ptr_a, ptr_a, ptr_out) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Check XSAVEC support before invoking its native fixtures** On an XSAVE/OSXSAVE/AVX-capable Windows host without XSAVEC, such as Haswell or a VM masking that feature, `check_differential()` passes its capability gate because `host_has_xsave()` checks only CPUID.1 and XCR0. These new native calls then raise an illegal-instruction exception instead of the expected alignment #GP, causing the previously supported `cpu_aot_xsave_state` test to fail rather than report a capability skip. Probe CPUID.(0xD,1):EAX[1] and gate the native XSAVEC cases, or return the configured skip code when that feature is unavailable. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 06:50:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:37:32Z.

Code review location: tests/cpu/xsave_state_check.py; line 662

@@ -624,7 +652,21 @@ def assert_equal_output(label: str, name: str, idx, got: bytes, want: bytes) ->
         return
     # Per Intel SDM Vol. 1 Ch. 13.5.1, XSAVE may report XSTATE_BV[1:0] = 1 for initialized
     # legacy x87/SSE components when RFBM selects them (e.g. hybrid E-cores vs P-cores).
-    if label == "native":
+    if label == "native" and name in XSAVEC_EXPORTS:
+        # The CPU may also store initialized x87/SSE slots, and MXCSR is only specified with the SSE slot.
+        got_bv = struct.unpack_from("<Q", got, 512)[0]
+        loose = bytearray(want)
+        for bit, spans in ((1, ((0, 24), (32, 160))), (2, ((160, 416),))):
+            if got_bv & bit:
+                for lo, hi in spans:
+                    loose[lo:hi] = got[lo:hi]

Fixed in afbcbcff.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4676369034 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#discussion_r4676369034). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:37:32Z. **Code review location:** `tests/cpu/xsave_state_check.py`; line 662 ~~~~diff @@ -624,7 +652,21 @@ def assert_equal_output(label: str, name: str, idx, got: bytes, want: bytes) -> return # Per Intel SDM Vol. 1 Ch. 13.5.1, XSAVE may report XSTATE_BV[1:0] = 1 for initialized # legacy x87/SSE components when RFBM selects them (e.g. hybrid E-cores vs P-cores). - if label == "native": + if label == "native" and name in XSAVEC_EXPORTS: + # The CPU may also store initialized x87/SSE slots, and MXCSR is only specified with the SSE slot. + got_bv = struct.unpack_from("<Q", got, 512)[0] + loose = bytearray(want) + for bit, spans in ((1, ((0, 24), (32, 160))), (2, ((160, 416),))): + if got_bv & bit: + for lo, hi in spans: + loose[lo:hi] = got[lo:hi] ~~~~ --- Fixed in afbcbcff.
tedin7 commented 2026-11-24 06:50:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:37:33Z.

Code review location: tests/cpu/xsave_state_check.py; line 730

@@ -679,6 +721,23 @@ def check_fault_controls(
                 _ = buf_a
                 misalign_checks += 1
 
+        for name in XSAVEC_EXPORTS:
+            for label, is_native, fn in (("native", True, native_fns[name]), ("lifted", False, lifted_fns[name])):
+                buf_a, ptr_a, _, _, _ = alloc_aligned_buffer(valid_a)
+                buf_out, ptr_out, pre, p_off, post = alloc_aligned_buffer(FILL, offset=off)
+                try:
+                    if is_native:
+                        harness.call_native(fn, ptr_a, ptr_a, ptr_out)

Fixed in afbcbcff.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4676369299 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#discussion_r4676369299). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:37:33Z. **Code review location:** `tests/cpu/xsave_state_check.py`; line 730 ~~~~diff @@ -679,6 +721,23 @@ def check_fault_controls( _ = buf_a misalign_checks += 1 + for name in XSAVEC_EXPORTS: + for label, is_native, fn in (("native", True, native_fns[name]), ("lifted", False, lifted_fns[name])): + buf_a, ptr_a, _, _, _ = alloc_aligned_buffer(valid_a) + buf_out, ptr_out, pre, p_off, post = alloc_aligned_buffer(FILL, offset=off) + try: + if is_native: + harness.call_native(fn, ptr_a, ptr_a, ptr_out) ~~~~ --- Fixed in afbcbcff.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T06:49:00Z.

Code review location: tools/cpu_xsave_aot.py; line 606

@@ -574,6 +596,20 @@
     }
     std::atomic_signal_fence(std::memory_order_seq_cst);
 }
+
+static inline void op_xsavec(const XState& state, word address, word rax_val, word rdx_val, bool is64) {
+    // Every fault check precedes the first store, so a rejected call leaves memory intact.
+    if ((address & 63ull) != 0ull) raise_gp();
+    if (static_cast<std::uint32_t>(rdx_val) != 0u || (static_cast<std::uint32_t>(rax_val) & ~7u) != 0u) raise_gp();
+    const std::uint64_t rfbm = static_cast<std::uint64_t>(rax_val) & 7ull;
+    const std::uint64_t used = rfbm & state.xinuse;
+    op_xsave(state, address, used, 0ull, is64);

P2 Badge Include non-default MXCSR in compacted-save liveness

With a valid restore image containing XSTATE_BV[1]=0 and MXCSR=0x3F80, op_xrstor loads the non-default MXCSR but clears the SSE in-use bit. Passing used to op_xsave then skips bytes 24–31 and marks SSE initialized, so the newly supported compacted save loses live rounding-control state; the standard save still writes MXCSR. A native Linux/Xeon 8272CL probe saves 0x3F80 with XSTATE_BV[1]=1, whereas the lifted/model path leaves the 0x5A fill bytes, and the native comparator accepts that mismatch. Include MXCSR in the SSE liveness calculation and add a vector with non-default MXCSR and the input SSE bit clear.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4676454356 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#discussion_r4676454356). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T06:49:00Z. **Code review location:** `tools/cpu_xsave_aot.py`; line 606 ~~~~diff @@ -574,6 +596,20 @@ } std::atomic_signal_fence(std::memory_order_seq_cst); } + +static inline void op_xsavec(const XState& state, word address, word rax_val, word rdx_val, bool is64) { + // Every fault check precedes the first store, so a rejected call leaves memory intact. + if ((address & 63ull) != 0ull) raise_gp(); + if (static_cast<std::uint32_t>(rdx_val) != 0u || (static_cast<std::uint32_t>(rax_val) & ~7u) != 0u) raise_gp(); + const std::uint64_t rfbm = static_cast<std::uint64_t>(rax_val) & 7ull; + const std::uint64_t used = rfbm & state.xinuse; + op_xsave(state, address, used, 0ull, is64); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Include non-default MXCSR in compacted-save liveness** With a valid restore image containing `XSTATE_BV[1]=0` and `MXCSR=0x3F80`, `op_xrstor` loads the non-default MXCSR but clears the SSE in-use bit. Passing `used` to `op_xsave` then skips bytes 24–31 and marks SSE initialized, so the newly supported compacted save loses live rounding-control state; the standard save still writes MXCSR. A native Linux/Xeon 8272CL probe saves `0x3F80` with `XSTATE_BV[1]=1`, whereas the lifted/model path leaves the `0x5A` fill bytes, and the native comparator accepts that mismatch. Include MXCSR in the SSE liveness calculation and add a vector with non-default MXCSR and the input SSE bit clear. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 07:00:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T06:49:00Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: afbcbcff20

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034851088 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#pullrequestreview-6034851088). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T06:49:00Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `afbcbcff20` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-24 07:07:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:05:55Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6035029192 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#pullrequestreview-6035029192). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:05:55Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 07:07:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:06:01Z.


AI-assisted follow-up for the P2 finding in tools/cpu_xsave_aot.py (e8f1a64e):

  • xsavec now treats SSE as in use when MXCSR differs from 0x1F80 (SDM vol.1 13.6), so a restore image with XSTATE_BV[1]=0 and MXCSR=0x3F80 saves MXCSR and sets XSTATE_BV[1]. The reverse case (default MXCSR, XMM clear) still compacts SSE away. Standard xsave is unchanged: a native probe shows it leaves XSTATE_BV[1] clear in that case.
  • Three new restore images (XSTATE_BV 0, 4 and 1 with non-default MXCSR) and an independent oracle written from the SDM rule, not from the model. A control that ignores MXCSR fails at the MXCSR word (byte 24) and in the XSTATE_BV word. The native comparator no longer accepts a host-reported SSE component with non-default MXCSR that the reference omits.
  • Checked on Linux (llvm-ml-19, lld-link-19, MinGW, Wine, host with XSAVEC): the new checks fail on the previous lowering at the XSTATE_BV word and pass now; 120 native/lifted/reference cases, ALTER_OP, misalignment, dynamic-mask and mutation controls pass.

PR #1267 fuori preset pr: ctest --preset dev -R '^cpu_aot_xsave_state$' va rieseguito sul nodo Windows.

@codex review

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124615193 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#issuecomment-7124615193). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:06:01Z. --- AI-assisted follow-up for the P2 finding in tools/cpu_xsave_aot.py (e8f1a64e): - `xsavec` now treats SSE as in use when MXCSR differs from 0x1F80 (SDM vol.1 13.6), so a restore image with XSTATE_BV[1]=0 and MXCSR=0x3F80 saves MXCSR and sets XSTATE_BV[1]. The reverse case (default MXCSR, XMM clear) still compacts SSE away. Standard `xsave` is unchanged: a native probe shows it leaves XSTATE_BV[1] clear in that case. - Three new restore images (XSTATE_BV 0, 4 and 1 with non-default MXCSR) and an independent oracle written from the SDM rule, not from the model. A control that ignores MXCSR fails at the MXCSR word (byte 24) and in the XSTATE_BV word. The native comparator no longer accepts a host-reported SSE component with non-default MXCSR that the reference omits. - Checked on Linux (llvm-ml-19, lld-link-19, MinGW, Wine, host with XSAVEC): the new checks fail on the previous lowering at the XSTATE_BV word and pass now; 120 native/lifted/reference cases, ALTER_OP, misalignment, dynamic-mask and mutation controls pass. PR #1267 fuori preset pr: ctest --preset dev -R '^cpu_aot_xsave_state$' va rieseguito sul nodo Windows. @codex review
tedin7 commented 2026-11-24 07:07:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:05:55Z.

Code review location: tools/cpu_xsave_aot.py; line 606

@@ -574,6 +596,20 @@
     }
     std::atomic_signal_fence(std::memory_order_seq_cst);
 }
+
+static inline void op_xsavec(const XState& state, word address, word rax_val, word rdx_val, bool is64) {
+    // Every fault check precedes the first store, so a rejected call leaves memory intact.
+    if ((address & 63ull) != 0ull) raise_gp();
+    if (static_cast<std::uint32_t>(rdx_val) != 0u || (static_cast<std::uint32_t>(rax_val) & ~7u) != 0u) raise_gp();
+    const std::uint64_t rfbm = static_cast<std::uint64_t>(rax_val) & 7ull;
+    const std::uint64_t used = rfbm & state.xinuse;
+    op_xsave(state, address, used, 0ull, is64);

Fixed in e8f1a64e.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4676599335 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#discussion_r4676599335). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:05:55Z. **Code review location:** `tools/cpu_xsave_aot.py`; line 606 ~~~~diff @@ -574,6 +596,20 @@ } std::atomic_signal_fence(std::memory_order_seq_cst); } + +static inline void op_xsavec(const XState& state, word address, word rax_val, word rdx_val, bool is64) { + // Every fault check precedes the first store, so a rejected call leaves memory intact. + if ((address & 63ull) != 0ull) raise_gp(); + if (static_cast<std::uint32_t>(rdx_val) != 0u || (static_cast<std::uint32_t>(rax_val) & ~7u) != 0u) raise_gp(); + const std::uint64_t rfbm = static_cast<std::uint64_t>(rax_val) & 7ull; + const std::uint64_t used = rfbm & state.xinuse; + op_xsave(state, address, used, 0ull, is64); ~~~~ --- Fixed in e8f1a64e.
upstream-sync closed this pull request 2026-11-24 08:01:22 +00:00
tedin7 commented 2026-11-24 08:01:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:09:04Z.


Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at e8f1a64e:

  • Debug (--preset dev): ctest --preset dev -R "^cpu_aot_xsave_state$" — 1/1 PASS (0.27s, build 3.40s)
  • Release /O2 (--preset release): ctest --preset release -R "^cpu_aot_xsave_state$" — 1/1 PASS (0.26s, build 0.98s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124674829 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#issuecomment-7124674829). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:09:04Z. --- Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at `e8f1a64e`: - Debug (`--preset dev`): `ctest --preset dev -R "^cpu_aot_xsave_state$"` — **1/1 PASS** (`0.27s`, build `3.40s`) - Release `/O2` (`--preset release`): `ctest --preset release -R "^cpu_aot_xsave_state$"` — **1/1 PASS** (`0.26s`, build `0.98s`)
chatgpt-codex-connector[bot commented 2026-11-24 08:01:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T07:12:57Z.


Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: e8f1a64e27

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124744872 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#issuecomment-7124744872). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T07:12:57Z. --- <!-- codex-review-receipt:v1 --> Codex Review: Didn't find any major issues. Already looking forward to the next diff. **Reviewed commit:** `e8f1a64e27` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-24 08:01:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:24:34Z.


Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at 6c6b9f2d:

  • Debug (--preset dev): ctest --preset dev -R "^cpu_aot_xsave_state$" — 1/1 PASS (0.26s, build 3.10s)
  • Release /O2 (--preset release): ctest --preset release -R "^cpu_aot_xsave_state$" — 1/1 PASS (0.25s, build 0.62s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124960207 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1267#issuecomment-7124960207). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:24:34Z. --- Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at `6c6b9f2d`: - Debug (`--preset dev`): `ctest --preset dev -R "^cpu_aot_xsave_state$"` — **1/1 PASS** (`0.26s`, build `3.10s`) - Release `/O2` (`--preset release`): `ctest --preset release -R "^cpu_aot_xsave_state$"` — **1/1 PASS** (`0.25s`, build `0.62s`)
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!1260
No description provided.