fix: SSE2 MINSD/MAXSD DAZ, XSAVE AVX-only MXCSR, MMX read state #1639

Merged
tedin7 merged 4 commits from upstream-pr/1646 into main 2026-11-25 15:02:55 +00:00
tedin7 commented 2026-11-24 15:47:17 +00:00 (Migrated from github.com)

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


AI-assisted; commands listed were executed locally.

What

Three lifted-state defects found by comparing the lifters' C++ helpers with the instructions run natively, plus a lift-time MMX-state tracking fix:

  1. SSE2 MINSD/MAXSD under DAZ (tools/cpu_sse2_aot.py). The helper compared with C operators, so with MXCSR.DAZ set a denormal operand came back unchanged; the instruction returns a zero of the same sign. The helper now runs the instruction on run-time operands (as the scalar and packed float lifters already do).
  2. XSAVE with RFBM = AVX alone (tools/cpu_xsave_aot.py). XSAVE stores MXCSR and MXCSR_MASK when RFBM selects SSE or AVX (XSAVEC: SSE only, XSAVEOPT: either). The lifted XSAVE stored them with SSE alone, so bytes 24..31 of the buffer were left as they were. The lift-time "MXCSR defined before save" check and docstring cover the form too.
  3. MMX read-only MOVQ (tools/cpu_sse_fxsave_aot.py, tools/cpu_xsave_aot.py). MOVQ m64, mm and MOVQ r64, mm clear TOP and mark all tags valid like any MMX instruction; the lifters did it for writes only, so a following FXSAVE/XSAVE reported the restored TOP, tag word and stack order (and XSTATE_BV[0] for XSAVE). cpu_xsave_aot.py also now marks mmx_active on read-only MOVQ so an unclosed MMX read before ret is rejected, matching cpu_sse_fxsave_aot.py.

Tests

Each fix has a positive case that fails on origin/main and passes after, and a negative control in the checker:

  • cpu_aot_sse2_regs: new check_daz_extrema (4 denormal MAXSD/MINSD cases under DAZ, native and lifted). New read_mxcsr/write_mxcsr helpers are linked into the fixture, as sse2_packed_cvt does. Control: the C-comparison result differs from the expected one.
  • cpu_aot_xsave_state: new exports op_xrstor64_xsave64_avx and op_xrstor64_movq_read_xsave64; the reference model stores MXCSR for RFBM with SSE or AVX. Controls: output without MXCSR, and output without the MMX state change, are rejected by the comparator. Added rejection controls for vzeroupper_xsave64_avx_mxcsr_undefined, unclosed_mmx_read_gpr, and unclosed_mmx_read_mem.
  • cpu_aot_sse_fxsave: new exports op_fxrstor64_movq_store and op_fxrstor64_movq_gpr. Control: output of the same sequence without the MM read is rejected.

CMakeLists.txt: one line (target_sources(... sse2_mxcsr_test.asm)) and the three export lists; no new add_test (the existing tests were extended).

Verification

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, ML64 14.44.35230) at commit 84f0128959cf11bf567d02eb9245fc672ee91afc:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_sse2_regs_altered cpu_sse2_regs_altered_lifted cpu_sse2_regs_original cpu_sse2_regs_original_lifted cpu_sse_fxsave_altered cpu_sse_fxsave_altered_lifted cpu_sse_fxsave_canonical_lifted cpu_sse_fxsave_original cpu_sse_fxsave_original_lifted cpu_xsave_state_altered cpu_xsave_state_altered_lifted cpu_xsave_state_canonical_altered_lifted cpu_xsave_state_canonical_lifted cpu_xsave_state_compacted_altered_lifted cpu_xsave_state_compacted_lifted cpu_xsave_state_original cpu_xsave_state_original_lifted -- -j 6): PASS (4.72s)
    • Test (ctest --preset dev -R '^(cpu_aot_sse2_regs|cpu_aot_sse_fxsave|cpu_aot_xsave_state)$' --parallel 4 --no-tests=error --output-on-failure): 3/3 passed (0.64s: cpu_aot_sse_fxsave 0.24s, cpu_aot_xsave_state 0.50s, cpu_aot_sse2_regs 0.56s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_sse2_regs_altered cpu_sse2_regs_altered_lifted cpu_sse2_regs_original cpu_sse2_regs_original_lifted cpu_sse_fxsave_altered cpu_sse_fxsave_altered_lifted cpu_sse_fxsave_canonical_lifted cpu_sse_fxsave_original cpu_sse_fxsave_original_lifted cpu_xsave_state_altered cpu_xsave_state_altered_lifted cpu_xsave_state_canonical_altered_lifted cpu_xsave_state_canonical_lifted cpu_xsave_state_compacted_altered_lifted cpu_xsave_state_compacted_lifted cpu_xsave_state_original cpu_xsave_state_original_lifted -- -j 6): PASS (2.15s)
    • Test (ctest --preset release -R '^(cpu_aot_sse2_regs|cpu_aot_sse_fxsave|cpu_aot_xsave_state)$' --parallel 4 --no-tests=error --output-on-failure): 3/3 passed (0.64s: cpu_aot_sse_fxsave 0.23s, cpu_aot_xsave_state 0.49s, cpu_aot_sse2_regs 0.55s)

Local checks:

  • python3 tests/docs_links_check.py: PASS (16 Markdown files, 348 links)
  • python3 tests/bidi_controls_check.py: PASS (1267 files)
  • git diff --check origin/main...HEAD: clean

Notes

  • Not changed, for a decision: the lifted XSAVE family raises #GP for request masks above 7 (hardware masks with XCR0), and XSAVEC/XSAVEOPT treat a non-default MXCSR as SSE in use while some AMD hosts do not; both are documented contract limits of the lifter.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6585711288 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1646). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:47:17Z. --- AI-assisted; commands listed were executed locally. ## What Three lifted-state defects found by comparing the lifters' C++ helpers with the instructions run natively, plus a lift-time MMX-state tracking fix: 1. **SSE2 MINSD/MAXSD under DAZ** (`tools/cpu_sse2_aot.py`). The helper compared with C operators, so with MXCSR.DAZ set a denormal operand came back unchanged; the instruction returns a zero of the same sign. The helper now runs the instruction on run-time operands (as the scalar and packed float lifters already do). 2. **XSAVE with RFBM = AVX alone** (`tools/cpu_xsave_aot.py`). XSAVE stores MXCSR and MXCSR_MASK when RFBM selects SSE or AVX (XSAVEC: SSE only, XSAVEOPT: either). The lifted XSAVE stored them with SSE alone, so bytes 24..31 of the buffer were left as they were. The lift-time "MXCSR defined before save" check and docstring cover the form too. 3. **MMX read-only MOVQ** (`tools/cpu_sse_fxsave_aot.py`, `tools/cpu_xsave_aot.py`). `MOVQ m64, mm` and `MOVQ r64, mm` clear TOP and mark all tags valid like any MMX instruction; the lifters did it for writes only, so a following FXSAVE/XSAVE reported the restored TOP, tag word and stack order (and XSTATE_BV[0] for XSAVE). `cpu_xsave_aot.py` also now marks `mmx_active` on read-only `MOVQ` so an unclosed MMX read before `ret` is rejected, matching `cpu_sse_fxsave_aot.py`. ## Tests Each fix has a positive case that fails on `origin/main` and passes after, and a negative control in the checker: - `cpu_aot_sse2_regs`: new `check_daz_extrema` (4 denormal MAXSD/MINSD cases under DAZ, native and lifted). New `read_mxcsr`/`write_mxcsr` helpers are linked into the fixture, as `sse2_packed_cvt` does. Control: the C-comparison result differs from the expected one. - `cpu_aot_xsave_state`: new exports `op_xrstor64_xsave64_avx` and `op_xrstor64_movq_read_xsave64`; the reference model stores MXCSR for RFBM with SSE or AVX. Controls: output without MXCSR, and output without the MMX state change, are rejected by the comparator. Added rejection controls for `vzeroupper_xsave64_avx_mxcsr_undefined`, `unclosed_mmx_read_gpr`, and `unclosed_mmx_read_mem`. - `cpu_aot_sse_fxsave`: new exports `op_fxrstor64_movq_store` and `op_fxrstor64_movq_gpr`. Control: output of the same sequence without the MM read is rejected. CMakeLists.txt: one line (`target_sources(... sse2_mxcsr_test.asm)`) and the three export lists; no new `add_test` (the existing tests were extended). ## Verification Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, ML64 14.44.35230) at commit `84f0128959cf11bf567d02eb9245fc672ee91afc`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_sse2_regs_altered cpu_sse2_regs_altered_lifted cpu_sse2_regs_original cpu_sse2_regs_original_lifted cpu_sse_fxsave_altered cpu_sse_fxsave_altered_lifted cpu_sse_fxsave_canonical_lifted cpu_sse_fxsave_original cpu_sse_fxsave_original_lifted cpu_xsave_state_altered cpu_xsave_state_altered_lifted cpu_xsave_state_canonical_altered_lifted cpu_xsave_state_canonical_lifted cpu_xsave_state_compacted_altered_lifted cpu_xsave_state_compacted_lifted cpu_xsave_state_original cpu_xsave_state_original_lifted -- -j 6`): PASS (`4.72s`) - Test (`ctest --preset dev -R '^(cpu_aot_sse2_regs|cpu_aot_sse_fxsave|cpu_aot_xsave_state)$' --parallel 4 --no-tests=error --output-on-failure`): **3/3 passed** (`0.64s`: `cpu_aot_sse_fxsave` `0.24s`, `cpu_aot_xsave_state` `0.50s`, `cpu_aot_sse2_regs` `0.56s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_sse2_regs_altered cpu_sse2_regs_altered_lifted cpu_sse2_regs_original cpu_sse2_regs_original_lifted cpu_sse_fxsave_altered cpu_sse_fxsave_altered_lifted cpu_sse_fxsave_canonical_lifted cpu_sse_fxsave_original cpu_sse_fxsave_original_lifted cpu_xsave_state_altered cpu_xsave_state_altered_lifted cpu_xsave_state_canonical_altered_lifted cpu_xsave_state_canonical_lifted cpu_xsave_state_compacted_altered_lifted cpu_xsave_state_compacted_lifted cpu_xsave_state_original cpu_xsave_state_original_lifted -- -j 6`): PASS (`2.15s`) - Test (`ctest --preset release -R '^(cpu_aot_sse2_regs|cpu_aot_sse_fxsave|cpu_aot_xsave_state)$' --parallel 4 --no-tests=error --output-on-failure`): **3/3 passed** (`0.64s`: `cpu_aot_sse_fxsave` `0.23s`, `cpu_aot_xsave_state` `0.49s`, `cpu_aot_sse2_regs` `0.55s`) Local checks: - `python3 tests/docs_links_check.py`: PASS (16 Markdown files, 348 links) - `python3 tests/bidi_controls_check.py`: PASS (1267 files) - `git diff --check origin/main...HEAD`: clean ## Notes - Not changed, for a decision: the lifted XSAVE family raises #GP for request masks above 7 (hardware masks with XCR0), and XSAVEC/XSAVEOPT treat a non-default MXCSR as SSE in use while some AMD hosts do not; both are documented contract limits of the lifter.
chatgpt-codex-connector[bot commented 2026-11-24 16:03:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T15:55:53Z.


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-24T16:02:42.534215Z 84f0128 Draft marked ready
ℹ️ 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:7136850906 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1646#issuecomment-7136850906). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T15:55:53Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"84f0128959cf11bf567d02eb9245fc672ee91afc","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-24T16:02:42.534215Z">2026-11-24T16:02:42.534215Z</relative-time> | `84f0128` | Draft marked ready | <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>
upstream-sync closed this pull request 2026-11-25 16:05:03 +00:00
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!1639
No description provided.