cpu: observe the CF that ANDN and BEXTR clear, and the BEXTR length mask #331

Merged
Leyukaka merged 2 commits from upstream-pr/336 into main 2026-11-21 22:56:12 +00:00
Leyukaka commented 2026-11-21 22:36:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T22:36:52Z.


Change

Refs #286. This closes two gaps in the cpu_aot_bmi1 checks merged with that PR. Only the fixture and the test change; the translator does not.

  • ANDN and BEXTR clear CF. Each was the first flag-writing instruction in its export. The translated function starts with carry = false, so a lowering that kept the incoming CF still passed. In all four exports (andn32/andn64/bextr32/bextr64), xor r9d, r9d and cmp r9, 1 now set CF to 1 just before the instruction. The exported (CF << 1) | ZF then shows whether CF was cleared. The expected values are unchanged.
  • BEXTR takes its length from bits 15..8 only. All controls fitted in 16 bits, so the & 0xffu on the length was not exercised. Three controls with bits above 15 are added: 0x10100, 0x232008 and 0xfe0410.

Verification

On c2ccfa6 (branch on b860dd5), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14:

ctest --preset dev --no-tests=error -R '^cpu_aot_bmi1$' -V
1156 binary and 136 unary BMI1 cases (values + ZF/CF) matched native and translated DLLs

The full suite passes 146 of 146 tests.

Mutations of the lowering in tools/ffx_version_query.py, each run against this branch's tests and against the tests on main:

Mutation This branch main
ANDN keeps the incoming CF fails: lifted andn32(0x0, 0x0) = (0x0, 0x3), expected (0x0, 0x1) passes
BEXTR keeps the incoming CF fails: lifted bextr32(0x0, 0x0) = (0x0, 0x3), expected (0x0, 0x1) passes
BEXTR length without & 0xff fails: lifted bextr32(0x2, 0x10100) = (0x2, 0x0), expected (0x0, 0x1) passes

Evidence and follow-up

The new compare uses R9, which each export overwrites with its flag word right after the instruction, so no other result changes. No open PR touches tests/cpu/bmi1.*.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535302888 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/336). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T22:36:52Z. --- ## Change Refs #286. This closes two gaps in the `cpu_aot_bmi1` checks merged with that PR. Only the fixture and the test change; the translator does not. - **ANDN and BEXTR clear CF.** Each was the first flag-writing instruction in its export. The translated function starts with `carry = false`, so a lowering that kept the incoming CF still passed. In all four exports (`andn32`/`andn64`/`bextr32`/`bextr64`), `xor r9d, r9d` and `cmp r9, 1` now set CF to 1 just before the instruction. The exported `(CF << 1) | ZF` then shows whether CF was cleared. The expected values are unchanged. - **BEXTR takes its length from bits 15..8 only.** All controls fitted in 16 bits, so the `& 0xffu` on the length was not exercised. Three controls with bits above 15 are added: `0x10100`, `0x232008` and `0xfe0410`. ## Verification On `c2ccfa6` (branch on `b860dd5`), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_bmi1$' -V 1156 binary and 136 unary BMI1 cases (values + ZF/CF) matched native and translated DLLs ``` The full suite passes 146 of 146 tests. Mutations of the lowering in `tools/ffx_version_query.py`, each run against this branch's tests and against the tests on `main`: | Mutation | This branch | `main` | |---|---|---| | ANDN keeps the incoming CF | fails: `lifted andn32(0x0, 0x0) = (0x0, 0x3), expected (0x0, 0x1)` | passes | | BEXTR keeps the incoming CF | fails: `lifted bextr32(0x0, 0x0) = (0x0, 0x3), expected (0x0, 0x1)` | passes | | BEXTR length without `& 0xff` | fails: `lifted bextr32(0x2, 0x10100) = (0x2, 0x0), expected (0x0, 0x1)` | passes | ## Evidence and follow-up The new compare uses R9, which each export overwrites with its flag word right after the instruction, so no other result changes. No open PR touches `tests/cpu/bmi1.*`. ## 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.
upstream-sync closed this pull request 2026-11-24 06:42:29 +00:00
Leyukaka commented 2026-11-24 06:48:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T22:51:53Z.


Added 33abca1, which closes four more gaps in the same test. Each one was a lower() mutation that passed the suite before this commit; I ran each to confirm it survives, and each now fails:

Mutation Failing case with this commit
BEXTR length masked with 0x7f bextr32(0x1, 0x8000) = (0x0, 0x1), expected (0x1, 0x0)
BEXTR start masked with 0x7f bextr32(0x1, 0x180) = (0x1, 0x0), expected (0x0, 0x1)
BEXTR saturating at len >= bits - 1 bextr32(0x80000000, 0x1f00) = (0x80000000, 0x0), expected (0x0, 0x1)
BLSMSK keeping the incoming ZF blsmsk32(0x0) = (0xffffffff, 0x3), expected (0xffffffff, 0x2)

The change:

  • blsmsk32 and blsmsk64 now follow cmp ecx, ecx, which sets ZF.
  • controls gains 0x8000, 0x0180, 0x1f00 and 0x3f00.

The three mutations from the description still fail. cpu_aot_bmi1 now reports 1292 binary and 136 unary cases, and the full suite passes 146 of 146 tests on Windows 11 build 26300.9974.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070480006 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/336#issuecomment-7070480006). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T22:51:53Z. --- Added `33abca1`, which closes four more gaps in the same test. Each one was a `lower()` mutation that passed the suite before this commit; I ran each to confirm it survives, and each now fails: | Mutation | Failing case with this commit | |---|---| | BEXTR length masked with `0x7f` | `bextr32(0x1, 0x8000) = (0x0, 0x1)`, expected `(0x1, 0x0)` | | BEXTR start masked with `0x7f` | `bextr32(0x1, 0x180) = (0x1, 0x0)`, expected `(0x0, 0x1)` | | BEXTR saturating at `len >= bits - 1` | `bextr32(0x80000000, 0x1f00) = (0x80000000, 0x0)`, expected `(0x0, 0x1)` | | BLSMSK keeping the incoming ZF | `blsmsk32(0x0) = (0xffffffff, 0x3)`, expected `(0xffffffff, 0x2)` | The change: - `blsmsk32` and `blsmsk64` now follow `cmp ecx, ecx`, which sets ZF. - `controls` gains `0x8000`, `0x0180`, `0x1f00` and `0x3f00`. The three mutations from the description still fail. `cpu_aot_bmi1` now reports 1292 binary and 136 unary cases, and the full suite passes 146 of 146 tests on Windows 11 build 26300.9974. _AI-assisted._
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!331
No description provided.