cpu: lower repeated string fills in control-flow functions #592

Merged
Joacoorandom merged 1 commit from upstream-pr/598 into main 2026-11-22 18:35:53 +00:00
Joacoorandom commented 2026-11-22 15:00:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Joacoorandom on 2026-11-22T15:00:50Z.


Change

Add REP STOSB/STOSW/STOSD/STOSQ to the control-flow CPU lifter. Fill from the low 1/2/4/8 bytes of RAX, advance RDI by the element width, exhaust RCX and preserve arithmetic flags. Zero count accesses no destination. Writes remain volatile under /O2; existing register-definedness and nonvolatile-save checks apply.

#597 is merged. Rebased this branch onto current main, so the diff now contains the fill increment only (461a4f5). The original Windows verification was performed before the rebase. STD and non-repeated transfers remain rejected.

Verification

Native Windows 11 26300.9974, MSVC/ML64 19.44.35230, Python 3.12.8. Commit 97f6ae8.

cmake --build out/native --target cpu_switch_strings_lifted cpu_switch_strings_lifted_o2 cpu_switch_strings_mutants cpu_string_probe cpu_guarded_call cpu_switch_original_lifted cpu_switch_swapped_lifted cpu_register_probe cpu_flag_conditions_lifted cpu_frame_lifted cpu_calls_lifted cpu_call_entries_lifted --parallel 4
ctest --test-dir out/native --no-tests=error -R "^cpu_aot_(switch_strings|jump_tables|flag_conditions|stack_frames|direct_calls|call_entries)$" -V

Six selected CTests passed. The cumulative string comparison now covers ten exports, 3,804 native/AOT/reference cases and 63 access-violation comparisons, including /O2. This increment adds four fill exports, three distinct fill patterns, every element width, zero-count inaccessible destinations, guard bytes, final count/pointers and physical RSI/RDI/DF observations. Both compiled semantic negative controls continue to mismatch.

Linux:

python -B tests/form_coverage_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check

All passed.

Evidence and follow-up

Original MIT source-built fixtures and byte-array reference, reusing #597's harness. No title code or external project source. Pointer validity, ABI assumptions and exception-resumption limits are documented in the updated README/experiment entry. AI-assisted.

Checklist

  • One reviewable behavior.
  • Exact checks and results included.
  • Negative controls retained.
  • README and experiments updated.
  • No game files, distribution links or secrets.

Conflict-resolution update (2026-11-22)

Rebased onto current upstream main after #597 was merged, preserving each increment in stack order. Local checks passed: form_coverage_check.py, docs_links_check.py, bidi_controls_check.py, cpu/lower_prefixes_check.py, plus git diff --check. Previous native-Windows results describe the original commits; the official Windows CI on the new head provides independent revalidation. No workflow or unrelated files were edited.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6543894682 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/598). Originally posted by [Joacoorandom](https://github.com/Joacoorandom) on 2026-11-22T15:00:50Z. --- ## Change Add REP STOSB/STOSW/STOSD/STOSQ to the control-flow CPU lifter. Fill from the low 1/2/4/8 bytes of RAX, advance RDI by the element width, exhaust RCX and preserve arithmetic flags. Zero count accesses no destination. Writes remain volatile under /O2; existing register-definedness and nonvolatile-save checks apply. **#597 is merged.** Rebased this branch onto current `main`, so the diff now contains the fill increment only (`461a4f5`). The original Windows verification was performed before the rebase. STD and non-repeated transfers remain rejected. ## Verification Native Windows 11 26300.9974, MSVC/ML64 19.44.35230, Python 3.12.8. Commit `97f6ae8`. ```powershell cmake --build out/native --target cpu_switch_strings_lifted cpu_switch_strings_lifted_o2 cpu_switch_strings_mutants cpu_string_probe cpu_guarded_call cpu_switch_original_lifted cpu_switch_swapped_lifted cpu_register_probe cpu_flag_conditions_lifted cpu_frame_lifted cpu_calls_lifted cpu_call_entries_lifted --parallel 4 ctest --test-dir out/native --no-tests=error -R "^cpu_aot_(switch_strings|jump_tables|flag_conditions|stack_frames|direct_calls|call_entries)$" -V ``` Six selected CTests passed. The cumulative string comparison now covers ten exports, 3,804 native/AOT/reference cases and 63 access-violation comparisons, including /O2. This increment adds four fill exports, three distinct fill patterns, every element width, zero-count inaccessible destinations, guard bytes, final count/pointers and physical RSI/RDI/DF observations. Both compiled semantic negative controls continue to mismatch. Linux: ```sh python -B tests/form_coverage_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py git diff --check ``` All passed. ## Evidence and follow-up Original MIT source-built fixtures and byte-array reference, reusing #597's harness. No title code or external project source. Pointer validity, ABI assumptions and exception-resumption limits are documented in the updated README/experiment entry. AI-assisted. ## Checklist - [x] One reviewable behavior. - [x] Exact checks and results included. - [x] Negative controls retained. - [x] README and experiments updated. - [x] No game files, distribution links or secrets. ### Conflict-resolution update (2026-11-22) Rebased onto current upstream `main` after #597 was merged, preserving each increment in stack order. Local checks passed: `form_coverage_check.py`, `docs_links_check.py`, `bidi_controls_check.py`, `cpu/lower_prefixes_check.py`, plus `git diff --check`. Previous native-Windows results describe the original commits; the official Windows CI on the new head provides independent revalidation. No workflow or unrelated files were edited.
upstream-sync closed this pull request 2026-11-24 06:43:52 +00:00
legacy-code-archaeologist commented 2026-11-24 06:48:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T17:34:40Z.


Verification of 97f6ae8 on an Intel Core i7-6820HQ (Skylake). Windows 11 26100.9168, MSVC/ML64 19.52.37029, dev preset:

ctest --preset dev --no-tests=error -R "^cpu_" -j 4
100% tests passed, 0 tests failed out of 114
cpu_aot_switch_strings:
3 whole-PE rejection controls and 5 unsupported forms rejected
3804 native/AOT/reference cases passed: bytes, guards, remaining count, pointers, CF, RSI/RDI and DF
63 nonzero-count access violations preserved, including /O2
2 compiled /O2 semantic mutations detected: memmove overlap, truncated REP count

The fixture's built-in mutations cover the copy foundation from #597. To check that the fill increment in this commit is pinned, I mutated tools/cpu_switch_aot.py one detail at a time, rebuilt, and ran cpu_aot_switch_strings. Afterwards I restored the file, verified its hash, and confirmed the test passed again.

Mutation Result
STOSW element width 1 instead of 2 fails (detected)
STOSQ element width 4 instead of 8 fails (detected)
fill value masked to AL for every width fails (detected)

Now that #597 has landed, 97f6ae8 no longer merges cleanly with main (git merge-tree), so the branch needs the update mentioned in the description.

AI-assisted: run and summarized with Claude Code; outputs copied from the local runs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7082944396 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/598#issuecomment-7082944396). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T17:34:40Z. --- Verification of `97f6ae8` on an Intel Core i7-6820HQ (Skylake). Windows 11 26100.9168, MSVC/ML64 19.52.37029, `dev` preset: ```text ctest --preset dev --no-tests=error -R "^cpu_" -j 4 100% tests passed, 0 tests failed out of 114 cpu_aot_switch_strings: 3 whole-PE rejection controls and 5 unsupported forms rejected 3804 native/AOT/reference cases passed: bytes, guards, remaining count, pointers, CF, RSI/RDI and DF 63 nonzero-count access violations preserved, including /O2 2 compiled /O2 semantic mutations detected: memmove overlap, truncated REP count ``` The fixture's built-in mutations cover the copy foundation from #597. To check that the fill increment in this commit is pinned, I mutated `tools/cpu_switch_aot.py` one detail at a time, rebuilt, and ran `cpu_aot_switch_strings`. Afterwards I restored the file, verified its hash, and confirmed the test passed again. | Mutation | Result | |---|---| | `STOSW` element width 1 instead of 2 | fails (detected) | | `STOSQ` element width 4 instead of 8 | fails (detected) | | fill value masked to AL for every width | fails (detected) | Now that #597 has landed, `97f6ae8` no longer merges cleanly with `main` (`git merge-tree`), so the branch needs the update mentioned in the description. AI-assisted: run and summarized with Claude Code; outputs copied from the local runs.
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!592
No description provided.