cpu: observe SAR sign fill and the CF a zero-count shift keeps #352

Manually merged
github merged 1 commit from gh-pr/352/head into gh-pr/352/base 2026-11-26 21:45:14 +00:00
Owner

@⁠Leyukaka on GitHub · 2026-11-21 23:06 UTC · original
Leyukaka:shift-flag-controls → main · +34 −2 · 3 files · 1 commits · merged 2026-11-21 23:25 UTC

Change

This closes two gaps in the immediate-shift lowering of lower() in tools/ffx_version_query.py. Each was a mutation of the lowering that passed every cpu_ test on main. Only the cpu_aot_shift_count fixture and its test change.

  • SAR sign fill. No fixture lowered by lower() ran an immediate sar with a nonzero count. sar_zero is the zero-count control, and the other nonzero shifts that lower() handles in fixtures are shl. narrow.asm and switch.asm use sar by cl, but tools/cpu_switch_aot.py lowers those itself. The new sar_three export runs sar eax, 3 on the existing values. For example, 0x80000000 must give 0xf0000000.
  • CF after a zero-count shift. flags_zero observes only ZF through sete. The new carry_zero export runs cmp ecx, edx; shl eax, 0 and reads CF through jae, on five pairs on each side of the compare.

Verification

On 35e6d0a (branch on bc24dfd), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14:

ctest --preset dev --no-tests=error -R '^cpu_aot_shift_count$' -V
160 native and translated zero-count shift cases matched the reference

The full suite passes 146 of 146 tests.

Each mutation was applied to tools/ffx_version_query.py, followed by a rebuild and the whole cpu_ family:

Mutation On main On this branch
lhs = f"int{bits}_t(a)" if op == M.SAR else "a" becomes lhs = "a" every cpu_ test passes cpu_aot_shift_count fails
a zero-count shift also emits carry = false; every cpu_ test passes cpu_aot_shift_count fails

Evidence and follow-up

The fixture keeps its conventions: sar_three is a unary export like shl_three, and carry_zero takes the same three arguments as flags_zero; its R8 only feeds the shifted EAX that the export discards. No open PR touches tests/cpu/shift_count.*.

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. (No capability changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-21 23:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/352) `Leyukaka:shift-flag-controls` → `main` · +34 −2 · 3 files · 1 commits · merged 2026-11-21 23:25 UTC ## Change This closes two gaps in the immediate-shift lowering of `lower()` in `tools/ffx_version_query.py`. Each was a mutation of the lowering that passed every `cpu_` test on `main`. Only the `cpu_aot_shift_count` fixture and its test change. - **SAR sign fill.** No fixture lowered by `lower()` ran an immediate `sar` with a nonzero count. `sar_zero` is the zero-count control, and the other nonzero shifts that `lower()` handles in fixtures are `shl`. `narrow.asm` and `switch.asm` use `sar` by `cl`, but `tools/cpu_switch_aot.py` lowers those itself. The new `sar_three` export runs `sar eax, 3` on the existing values. For example, `0x80000000` must give `0xf0000000`. - **CF after a zero-count shift.** `flags_zero` observes only ZF through `sete`. The new `carry_zero` export runs `cmp ecx, edx; shl eax, 0` and reads CF through `jae`, on five pairs on each side of the compare. ## Verification On `35e6d0a` (branch on `bc24dfd`), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_shift_count$' -V 160 native and translated zero-count shift cases matched the reference ``` The full suite passes 146 of 146 tests. Each mutation was applied to `tools/ffx_version_query.py`, followed by a rebuild and the whole `cpu_` family: | Mutation | On `main` | On this branch | |---|---|---| | `lhs = f"int{bits}_t(a)" if op == M.SAR else "a"` becomes `lhs = "a"` | every `cpu_` test passes | `cpu_aot_shift_count` fails | | a zero-count shift also emits `carry = false;` | every `cpu_` test passes | `cpu_aot_shift_count` fails | ## Evidence and follow-up The fixture keeps its conventions: `sar_three` is a unary export like `shl_three`, and `carry_zero` takes the same three arguments as `flags_zero`; its R8 only feeds the shifted EAX that the export discards. No open PR touches `tests/cpu/shift_count.*`. ## 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. - [ ] I updated README/docs when a capability or build requirement changed. (No capability changed.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
No fixture lowered by lower() ran an immediate SAR with a nonzero count,
and the zero-count shift test observed only ZF. sar_three shifts a signed
32-bit source by 3, and carry_zero reads the CF that shl eax, 0 must keep
from the compare.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:45:11 +00:00
github manually merged commit 35e6d0a5c3 into gh-pr/352/base 2026-11-26 21:45:14 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.