cpu: lower xsaveopt and xsaveopt64 in the XSAVE state translator #1320
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1327"
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 tedin7 on 2026-11-24T08:10:43Z.
Change
Lower
xsaveoptandxsaveopt64in the bounded XSAVE state translator (tools/cpu_xsave_aot.py), a direct follow-up of thexsaveclowering. They keep the standard format and apply the init optimization only: a component that is not in use is not written and itsXSTATE_BVbit is cleared,XSTATE_BV = (old & ~RFBM) | (XINUSE & RFBM), andMXCSR/MXCSR_MASKare stored wheneverRFBMselects SSE or AVX. SSE counts as in use whileMXCSRdiffers from0x1F80, so a restored non-defaultMXCSRkeeps its XMM slot. Alignment and request-mask faults are raised before the first store, so a rejected call leaves memory intact. The modified optimization (XMODIFIED) is not modeled: the lifted code writes every component that is in use, which is a superset of what a CPU may write.AI-assisted. No issue is claimed. 6 files because the fixture needs its export list in four places (asm, def, CMake, checker) next to the translator and the docs entry.
Verification
Run on Linux (llvm-ml-19 + lld-link-19 for the fixture, MinGW
-O0/-O2for the lifted C++, Wine on a host CPU with XSAVEOPT; the Python checks drive the DLLs through a small Wine caller because the repo harness needs Windows ctypes):ALTER_OP(standardxsave64in place ofxsaveopt64, request mask 7 in place of 2) diverged on 9/10 and 7/10 images.XSTATE_BV, theMXCSRwords and that every byte outside the components in use is still the sentinel, for lifted and native.FCW,ST0,XMM0,YMM_HI0andXSTATE_BVbytes (lifted and native),xsavein place ofxsaveopt,XSTATE_BVwithout theRFBMmask, a reference that ignores non-defaultMXCSR(fails at byte 160), live bytes in a component the reference leaves out, a host that omits live XMM.XSTATE_BVwithout& RFBM, noMXCSRliveness,MXCSRstored only for SSE.MXCSRrestores, 5 valid dynamic masks and 5 unsupported masks: #GP and the output buffer intact.xsaveoptrejection is replaced by default-profile and non-r8store rejections) and 10 PE-patched rejection controls pass.tools/cpu_xsave_aot.pythere stops withunsupported XSAVE-family instruction ... xsaveopt64 [r8]on the new fixture.git diff --check,tests/docs_links_check.py,tests/bidi_controls_check.pypass.Not run here: the MSVC build and the repo harness on Windows. Outside
--preset pr; to run on Windows (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. A native probe on the host CPU (xrstor64 of one buffer, xsave64 and xsaveopt64 into others, all 7 RFBM values x 8 XSTATE_BV x 2 MXCSR x 2 payloads) matched the layout above, with two host-specific facts the comparator tolerates: standard-format saves there did not reportXSTATE_BV[1]for a non-defaultMXCSRwith zero XMM (the lifted store keeps it, as xsavec does), and a zero-valued component restored with its bit set was reported as not in use (the fixtures use non-zero payloads).xsaveopt64to the same buffer that was just restored omitted the restored x87 area (modified optimization), so the fixtures restore fromrcxand save tor8. Existing note:xsavewithRFBM = 4does not storeMXCSRhere while the host does; left untouched, follow-up. Remaining follow-ups:xsaves,xrstors, compactedxrstor.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T08:18:15Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
0ecae4ec19ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:31:21Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:12:22Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at
0ecae4ec:--preset dev):ctest --preset dev -R "^cpu_aot_xsave_state$"— 1/1 PASS (0.33s, build3.56s)/O2(--preset release):ctest --preset release -R "^cpu_aot_xsave_state$"— 1/1 PASS (0.35s, build1.10s)Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:31:23Z.
AI-assisted fix for the MXCSR finding: MXCSR is now tracked separately from the SSE/AVX components, so vzeroupper no longer counts as defining it. A save that stores MXCSR is rejected (error names MXCSR) unless an xrstor selecting SSE or AVX loaded it, or --entry-state canonical is requested. xsave/xsavec accepted cases are unchanged. Regression cases are in tests/cpu/xsave_state_check.py. @codex review
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:34:11Z.
Re-verified after the MXCSR-tracking fix (
23376f943d495eed02efd688cf9c3290c0875714) on Windows Server 2025 (Build 26100, MSVC 14.44.35207):--preset dev):cpu_xsave_state_*build3.11s;ctest --preset dev -R '^cpu_aot_xsave_state$' --no-tests=error --output-on-failure: 1/1 passed (0.32s)/O2(--preset release):cpu_xsave_state_*build0.62s;ctest --preset release -R '^cpu_aot_xsave_state$' --no-tests=error --output-on-failure: 1/1 passed (0.31s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T08:35:57Z.
Codex Review: Didn't find any major issues. Nice work!
Reviewed commit:
23376f943dℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T08:12:38Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
23376f9ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T08:18:15Z.
Code review location:
tools/cpu_xsave_aot.py; line 833With the default
definedprofile,vzeroupper; mov eax, 4; xor edx, edx; xsaveopt64 [r8]; retis accepted becausevzerouppermarks AVX as defined, but no instruction defines MXCSR.op_xsaveoptnevertheless stores MXCSR forRFBM = 4, so it writesXState's default0x1F80instead of the incoming value. An isolated Linux/x86-64 native-versus-emitted-helper probe at both-O0and-O2produced0x3F80versus0x1F80at offset 24 for the same non-default entry state. Track MXCSR definition separately, including restores selecting SSE or AVX, or reject this case unless canonical entry was explicitly requested.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:31:21Z.
Code review location:
tools/cpu_xsave_aot.py; line 833Fixed in
23376f9.