cpu: lower FCOM, FUCOM and FNSTSW AX with a status-word consumer check #529

Merged
denn0x merged 2 commits from upstream-pr/535 into main 2026-11-22 10:23:52 +00:00
denn0x commented 2026-11-22 10:03:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-22T10:03:48Z.


Change

Refs #406. This is the first status-word PR. It follows option (b) of the decision on #406: fnstsw ax is accepted when static analysis can prove that every reachable consumer observes only defined condition bits. It follows #530 (the checked entry).

Accepted forms.

  • Comparisons into C0, C2 and C3: fcom and fcomp with st(i) or an m32 or m64 operand, fcompp, fucom and fucomp with st(i), and fucompp.
  • fnstsw ax.
  • In functions the x87 profile checks: sahf, jp and jnp.

Semantics. C3, C2 and C0 are 0 0 1 for less, 1 0 0 for equal, 0 0 0 for greater and 1 1 1 for unordered. The order and NaN rules are those of x87_compare, which fcomi already uses. TOP is (8 - depth) mod 8, because a function enters with TOP 0 and the depth before every instruction is fixed.

Static analysis (tools/x87_lower.py, check_flags). A forward fixpoint over the function computes five things before each reachable instruction:

  • the defined status flags;
  • the flags left undefined by an unknown status-word bit, which selects the diagnostic;
  • whether the integer lowering models PF;
  • which of C0, C2 and C3 are known;
  • which bits of AX are known.

At a join, a bit or flag stays known only if it is known on every incoming path. Following the SDM:

  • A comparison defines C0, C2 and C3. They are unknown at the entry.
  • fcomi, fcomip, fucomi and fucomip leave them unchanged ("not affected").
  • Every other x87 instruction leaves them undefined, and so does a call. This includes wait, fnstcw and fnstsw itself.
  • C1, the exception flags, the stack fault and the busy bit are never known.

After fnstsw ax, AX has only those bits known. Consumers follow these rules:

  • sahf: sets CF from C0, PF from C2, ZF from C3 and SF from the busy bit. Each flag is defined only when its bit is known. AF (bit 1 of TOP) is left undefined.
  • test ah, imm8 and and ah, imm8: define ZF, PF and SF only when the immediate selects known bits. and makes the bits it clears known.
  • Every other reader of AL, AH, AX, EAX or RAX: rejected if it sees an unknown bit, found through iced's register usage.
  • A return, a call, an indirect branch or an external edge: rejected while AX holds an unknown bit.

The existing flag rule (from #476) then applies to every function with fnstsw, sahf, jp or jnp. A reader of a flag that an unknown bit left undefined is rejected with ... depends on a status-word bit that is not known on every path from the entry.

PF. The integer lowering now sets PF only after sahf and the 8-bit forms of test and and. It does so only in a function with a jp or jnp that the x87 profile has checked. jp and jnp are rejected when any other instruction may have written PF last, for example fucomi, cmp or test eax, eax. The PF of fcomi is left for a follow-up, together with fcmovu and fcmovnu.

wait. I kept the SDM's "undefined" for wait, although iced lists it as leaving the condition bits alone. As a result, fstsw ax (wait; fnstsw ax) after a comparison is rejected. This choice is easy to relax if you prefer iced's reading.

Generated code. The status variable and parity are declared only in functions that use them. I compared every generated source against the parent commit, built in the same build directory: all 222 earlier generated .cpp files are byte-identical.

Fixture

tests/cpu/x87_status.asm and .def are generated by tests/cpu/x87_status.py asm, and emit checks every decoded x87 instruction against its sequence. After each fnstsw ax, a record reads AH through every accepted consumer, with only flag-neutral movs in between:

  • sahf, then je, jne, jb, jae, ja, jbe, jp and jnp;
  • test ah with 01h, 04h and 40h (C0, C2 and C3) and each TOP bit, then jne;
  • test ah with 45h, 44h, 05h and 41h, then jp;
  • and ah, 45h, stored, then jp, then cmp ah with 40h, 01h and 00h, each followed by je.

The record then clears EAX. The model compares with the Fraction model of cpu_aot_x87_compare and shares no code with tools/x87_soft.h.

The 22 exports cover:

  • each register form with st(1), fcompp, fucompp, fcom st(2), fucomp st(2), a value against itself, and the four memory forms;
  • fucom st(7) at depth 8, where TOP is 0 again;
  • fcom followed by fcomi, and fucom followed by fucomip, so C0, C2 and C3 must come from the earlier comparison;
  • two comparisons, each read through its own fnstsw;
  • a join of fcom st(1) and fucom st(2), chosen by an input dword;
  • the translated half of the requested control: a branch on C3 whose successors test C0 and C2 (see Rejections for the other half);
  • on all 256 byte values, the record on AH loaded by mov, and jp after test al, al, test byte ptr [m], 0A5h and and al, 3Ch.

Cases. 17843 cases:

  • every pair of the 34 special encodings;
  • values against themselves, their neighbour in the lowest significand bit, their negation and the next exponent;
  • pseudo-denormal and normal twins, random values, and the m64 and m32 special encodings.

At fnstsw, 4856 cases compared less, 2265 equal, 4914 greater and 5296 unordered, at TOP 0, 5, 6 and 7. As the decision asked, every record tells ordered inputs from unordered ones through PF with sahf; jp (PF is C2). It also runs the compiler idioms test ah, 44h; jp (not taken only for equal) and test ah, 05h; jp and test ah, 41h; jp.

Native-only exports. Two exports read bits that the profile does not know:

  • status_word stores the whole word after fcom. In 1759 runs its known bits matched the model. The other bits took 0x0000, 0x0001 (IE) and 0x0002 (DE).
  • split_sticky is the branch export with test al, 1 (IE) on the C3 successor, after fucom. An unordered fucom left IE clear for a quiet NaN and set it for a signaling NaN, so that byte does not follow from C0, C2 and C3.

Translation rejects both, at the store of AX and at test al, 1.

Negative controls. Seven mutated translations must each mismatch:

Control Mutation Mismatches
c2drop an unordered result leaves C2 clear 5340/17843
c0c3 less sets C3 and equal sets C0 7263/17843
top0 fnstsw stores TOP as 0 10895/17843
sahfpf sahf loads PF from bit 4 8707/17843
oddparity test and and set PF for odd parity 16084/17843
andparity only the 22 and statements set PF for odd parity 16084/17843
fcomiclear fcomi and fucomip clear C0, C2 and C3 779/17843

andparity mismatches in every case that reads PF, because each record has a jp straight after its and. The split cases have no record and do not read PF.

Rejections. Translation rejects 32 sequences with the expected diagnostic:

  • Condition bits that are unknown at the reader:
    • fnstsw ax without a comparison;
    • fnstsw ax after fadd, after fld and fstp, after fnstcw, after wait (fstsw ax), as a second fnstsw ax, or after a call;
    • a join where one path skips the comparison.
  • The requested control: the twin of the split export whose other successor tests C1.
  • Direct reads of unknown bits:
    • test al, 1 and test ax, 4500h;
    • and ah, 47h with a store of AH;
    • a store of AX;
    • a return with the status word in AX, also in the checked entry after fldcw;
    • an external edge with the status word in AX.
  • PF:
    • jp after fucomi, cmp or test eax, eax, or before any flag writer;
    • sahf in a function without x87 instructions;
    • lahf.
  • Forms outside the profile:
    • fnstsw with an m16 operand;
    • the alias encodings DC D1 (fcom), DC D9 and DE D1 (fcomp);
    • ftst, fxam and ficom;
    • comparisons without enough stack values.

Eight twins must still translate:

  • sahf; jb after fcom;
  • fcomi between fcom and fnstsw;
  • the branch whose successors test C0 and C2;
  • test al, al; jp;
  • and ah, 45h with a store of AH;
  • a return after xor eax, eax;
  • sahf on AH from mov;
  • fnstsw ax in the checked entry after fldcw.

Changes to existing tests. Rejection cases that the profile now accepts are replaced by instructions that stay outside it, and each list keeps its length:

Test Replaced Now
cpu_aot_x87_add fcom st(1), fnstsw ax ftst, fnstsw m16
cpu_aot_x87_sub fcom st(1) fxam
cpu_aot_x87_mul fcomp st(1) fprem1
cpu_aot_x87_compare sahf; fcom st(1), fucom st(1), fucompp; fnstsw ax jo; ficomp m32, fcom as DC D1, fucompp with one value; fnstsw m16
cpu_aot_x87_fnstcw fnstsw ax fninit
cpu_aot_x87_fldcw fnstsw ax in the checked entry fnstsw m16 in the checked entry

jp and jnp after fucomi in cpu_aot_x87_compare are still rejected, now by the PF rule. Their needle names that rule. fnstsw m16 in cpu_aot_x87_fnstcw now reports unsupported x87 operand. Case and control counts of these tests are unchanged. The matching sentences in docs/experiments.md are updated.

Verification

Tested at 4a80919 on main at 119bdd6. The machine runs Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0 and Python 3.13 on an AMD Ryzen 7 7700 (AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD).

cmake --build --preset dev --target cpu_x87_status_lifted
ctest --preset dev --no-tests=error -R '^cpu_aot_x87_status$' -V
17843 cases over 22 exports (output block and guards) matched the reference in native and translated DLLs; each export returned with control 0x027f and an empty stack
C3, C2 and C0 at FNSTSW: less 4856, equal 2265, greater 4914, unordered 5296; TOP values [0, 5, 6, 7]
processor: AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD
x87_call kept a live caller ST(0) value and control word around all 22 native and translated exports
native status_word: the known bits matched in 1759 runs; C1, the exception flags, the stack fault and the busy bit (mask 0x82ff) took 0x0000 889, 0x0001 531, 0x0002 339
native split_sticky: after an unordered FUCOM the IE byte was 2 and 3 (a signaling NaN sets IE, a quiet NaN does not); 3518 native runs
translation rejects split_sticky at TEST AL, 1 and status_word at the store of AX, which read bits that FNSTSW AX leaves unknown
control c2drop: 5340/17843 mismatches
control c0c3: 7263/17843 mismatches
control top0: 10895/17843 mismatches
control sahfpf: 8707/17843 mismatches
control oddparity: 16084/17843 mismatches
control andparity: 16084/17843 mismatches
control fcomiclear: 779/17843 mismatches
rejected 32 sequences outside the profile: FNSTSW AX with no comparison, then SAHF and JB; FADD between FCOM and FNSTSW; FLD ST(0) and FSTP ST(0) between FCOM and FNSTSW; FNSTCW between FCOM and FNSTSW; FSTSW AX (WAIT and FNSTSW AX) after FCOM; a second FNSTSW AX; a call between FCOMPP and FNSTSW; a join where one path skips FCOM; a branch whose other successor tests C1; TEST AL, 1 (IE); TEST AX, 4500h; AND AH, 47h, then a store of AH (C1); a store of AX; a return with the status word in AX; a return with the status word in AX in the checked entry, after FLDCW; a jump to an external edge with the status word in AX; FUCOMI, then JP; CMP, then JP; TEST EAX, EAX, then JP; JP before any flag writer; SAHF in a function without x87; LAHF; FNSTSW m16; FCOM alias DC D1; FCOMP alias DC D9; FCOMP alias DE D1; FTST; FXAM; FICOM m16; FCOMPP with one value; FUCOM ST(2) with two values; FCOM m32 on an empty stack
translated 8 sequences that read only known bits: FNSTSW AX after FCOM, then SAHF and JB; FCOMI between FCOM and FNSTSW; a branch whose successors test C0 and C2; TEST AL, AL, then JP; AND AH, 45h, then a store of AH; a return after XOR EAX, EAX; SAHF on AH from MOV; FNSTSW AX after FCOM in the checked entry, after FLDCW
  • x87 regressions: all seventeen x87 tests pass at 4a80919 (ctest --preset dev --no-tests=error -R '^cpu_aot_x87_'), including the six with replaced rejection cases.
  • Full suite: ctest --preset dev --no-tests=error -j 8 --output-junit test-results.xml gives 242 passed, 2 failed and 2 capability skips (bvh_wave64_warp, wave_shuffle_warp) out of 246 at 4a80919. The run includes the GPU tests on an AMD Radeon RX 9070 XT. The two failures are gpu_alias_lookup_writes_hardware, the RDNA 4 array-atomics probe recorded in #369, and dxr_opacity_hardware, the RDNA 4 result recorded in #216. main at 119bdd6 gives the same two failures and skips in the same session (241 passed out of 245). This change touches no GPU code.
  • Pure-Python checks: tests/form_coverage_check.py, tests/docs_links_check.py and tests/bidi_controls_check.py pass at 4a80919, locally and in the Linux job of the fork CI run below.
  • Fork CI: the Windows build-and-test, Windows /O2 build-and-test, Linux Python and gfx1013 LLVM jobs passed at 4a80919 in the fork's Windows checks run 45009545338. Both Windows jobs ran and passed all seventeen x87 tests (202 passed and 2 capability skips, bvh_wave64_warp and wave_shuffle_warp, out of 204 in each).

Coverage. python tools/form_coverage.py out/build/dev/test-results.xml gives x64 432 of 948 forms at 4a80919, and 424 at main in the same session. The added forms are fcom, fcomp, fcompp, fucom, fucomp, fucompp, fnstsw and sahf; jp and jnp were already covered by cpu_aot_flag_conditions.

Not measured:

  • Intel CPUs. All measurements are on one AMD Zen 4 part.
  • TOP 1 to 4 (depths 4 to 7). The exports reach depths 0 to 3 and 8.
  • Memory-form status stores, sticky exception flags, fninit and fclex, ftst, fxam and ficom. These can follow with their own semantics and native cases, as the decision on #406 suggests.

Overlap

I trial-merged this branch with the 54 open PRs other than #534. Each one conflicts in the same files against main and against main with this branch merged: the 5 that merge cleanly into main also merge cleanly with it, and this branch adds no conflict to the others. It conflicts with #534 (OF after fcomi) in tools/x87_lower.py and the cpu_aot_x87_compare paragraph of docs/experiments.md; I will rebase whichever of the two lands second. The changes stay inside tools/x87_lower.py, the x87 branch of tools/ffx_version_query.py, the new fixture, the replaced rejection cases of six x87 tests, a CMake block after the cpu_aot_x87_fldcw test, and the x87 section of docs/experiments.md.

Evidence

The fixture is synthetic and original to this repository (MIT). docs/experiments.md documents the forms, the analysis, the controls and the reproduction command.

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

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6541074127 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/535). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-22T10:03:48Z. --- ## Change Refs #406. This is the first status-word PR. It follows option (b) of the [decision on #406](https://github.com/R0Y00/Xbox2Windows/issues/406): `fnstsw ax` is accepted when static analysis can prove that every reachable consumer observes only defined condition bits. It follows #530 (the checked entry). **Accepted forms.** - Comparisons into C0, C2 and C3: `fcom` and `fcomp` with `st(i)` or an m32 or m64 operand, `fcompp`, `fucom` and `fucomp` with `st(i)`, and `fucompp`. - `fnstsw ax`. - In functions the x87 profile checks: `sahf`, `jp` and `jnp`. **Semantics.** C3, C2 and C0 are `0 0 1` for less, `1 0 0` for equal, `0 0 0` for greater and `1 1 1` for unordered. The order and NaN rules are those of `x87_compare`, which `fcomi` already uses. TOP is `(8 - depth) mod 8`, because a function enters with TOP 0 and the depth before every instruction is fixed. **Static analysis (`tools/x87_lower.py`, `check_flags`).** A forward fixpoint over the function computes five things before each reachable instruction: - the defined status flags; - the flags left undefined by an unknown status-word bit, which selects the diagnostic; - whether the integer lowering models PF; - which of C0, C2 and C3 are known; - which bits of AX are known. At a join, a bit or flag stays known only if it is known on every incoming path. Following the SDM: - A comparison defines C0, C2 and C3. They are unknown at the entry. - `fcomi`, `fcomip`, `fucomi` and `fucomip` leave them unchanged ("not affected"). - Every other x87 instruction leaves them undefined, and so does a call. This includes `wait`, `fnstcw` and `fnstsw` itself. - C1, the exception flags, the stack fault and the busy bit are never known. After `fnstsw ax`, AX has only those bits known. Consumers follow these rules: - **`sahf`:** sets CF from C0, PF from C2, ZF from C3 and SF from the busy bit. Each flag is defined only when its bit is known. AF (bit 1 of TOP) is left undefined. - **`test ah, imm8` and `and ah, imm8`:** define ZF, PF and SF only when the immediate selects known bits. `and` makes the bits it clears known. - **Every other reader of AL, AH, AX, EAX or RAX:** rejected if it sees an unknown bit, found through iced's register usage. - **A return, a call, an indirect branch or an external edge:** rejected while AX holds an unknown bit. The existing flag rule (from #476) then applies to every function with `fnstsw`, `sahf`, `jp` or `jnp`. A reader of a flag that an unknown bit left undefined is rejected with `... depends on a status-word bit that is not known on every path from the entry`. **PF.** The integer lowering now sets PF only after `sahf` and the 8-bit forms of `test` and `and`. It does so only in a function with a `jp` or `jnp` that the x87 profile has checked. `jp` and `jnp` are rejected when any other instruction may have written PF last, for example `fucomi`, `cmp` or `test eax, eax`. The PF of `fcomi` is left for a follow-up, together with `fcmovu` and `fcmovnu`. **`wait`.** I kept the SDM's "undefined" for `wait`, although iced lists it as leaving the condition bits alone. As a result, `fstsw ax` (`wait; fnstsw ax`) after a comparison is rejected. This choice is easy to relax if you prefer iced's reading. **Generated code.** The status variable and `parity` are declared only in functions that use them. I compared every generated source against the parent commit, built in the same build directory: all 222 earlier generated `.cpp` files are byte-identical. ## Fixture `tests/cpu/x87_status.asm` and `.def` are generated by `tests/cpu/x87_status.py asm`, and `emit` checks every decoded x87 instruction against its sequence. After each `fnstsw ax`, a record reads AH through every accepted consumer, with only flag-neutral `mov`s in between: - `sahf`, then `je`, `jne`, `jb`, `jae`, `ja`, `jbe`, `jp` and `jnp`; - `test ah` with 01h, 04h and 40h (C0, C2 and C3) and each TOP bit, then `jne`; - `test ah` with 45h, 44h, 05h and 41h, then `jp`; - `and ah, 45h`, stored, then `jp`, then `cmp ah` with 40h, 01h and 00h, each followed by `je`. The record then clears EAX. The model compares with the `Fraction` model of `cpu_aot_x87_compare` and shares no code with `tools/x87_soft.h`. **The 22 exports** cover: - each register form with `st(1)`, `fcompp`, `fucompp`, `fcom st(2)`, `fucomp st(2)`, a value against itself, and the four memory forms; - `fucom st(7)` at depth 8, where TOP is 0 again; - `fcom` followed by `fcomi`, and `fucom` followed by `fucomip`, so C0, C2 and C3 must come from the earlier comparison; - two comparisons, each read through its own `fnstsw`; - a join of `fcom st(1)` and `fucom st(2)`, chosen by an input dword; - the translated half of the requested control: a branch on C3 whose successors test C0 and C2 (see Rejections for the other half); - on all 256 byte values, the record on AH loaded by `mov`, and `jp` after `test al, al`, `test byte ptr [m], 0A5h` and `and al, 3Ch`. **Cases.** 17843 cases: - every pair of the 34 special encodings; - values against themselves, their neighbour in the lowest significand bit, their negation and the next exponent; - pseudo-denormal and normal twins, random values, and the m64 and m32 special encodings. At `fnstsw`, 4856 cases compared less, 2265 equal, 4914 greater and 5296 unordered, at TOP 0, 5, 6 and 7. As the decision asked, every record tells ordered inputs from unordered ones through PF with `sahf; jp` (PF is C2). It also runs the compiler idioms `test ah, 44h; jp` (not taken only for equal) and `test ah, 05h; jp` and `test ah, 41h; jp`. **Native-only exports.** Two exports read bits that the profile does not know: - **`status_word`** stores the whole word after `fcom`. In 1759 runs its known bits matched the model. The other bits took `0x0000`, `0x0001` (IE) and `0x0002` (DE). - **`split_sticky`** is the branch export with `test al, 1` (IE) on the C3 successor, after `fucom`. An unordered `fucom` left IE clear for a quiet NaN and set it for a signaling NaN, so that byte does not follow from C0, C2 and C3. Translation rejects both, at the store of AX and at `test al, 1`. **Negative controls.** Seven mutated translations must each mismatch: | Control | Mutation | Mismatches | |---|---|---| | `c2drop` | an unordered result leaves C2 clear | 5340/17843 | | `c0c3` | less sets C3 and equal sets C0 | 7263/17843 | | `top0` | `fnstsw` stores TOP as 0 | 10895/17843 | | `sahfpf` | `sahf` loads PF from bit 4 | 8707/17843 | | `oddparity` | `test` and `and` set PF for odd parity | 16084/17843 | | `andparity` | only the 22 `and` statements set PF for odd parity | 16084/17843 | | `fcomiclear` | `fcomi` and `fucomip` clear C0, C2 and C3 | 779/17843 | `andparity` mismatches in every case that reads PF, because each record has a `jp` straight after its `and`. The `split` cases have no record and do not read PF. **Rejections.** Translation rejects 32 sequences with the expected diagnostic: - **Condition bits that are unknown at the reader:** - `fnstsw ax` without a comparison; - `fnstsw ax` after `fadd`, after `fld` and `fstp`, after `fnstcw`, after `wait` (`fstsw ax`), as a second `fnstsw ax`, or after a call; - a join where one path skips the comparison. - **The requested control:** the twin of the `split` export whose other successor tests C1. - **Direct reads of unknown bits:** - `test al, 1` and `test ax, 4500h`; - `and ah, 47h` with a store of AH; - a store of AX; - a return with the status word in AX, also in the checked entry after `fldcw`; - an external edge with the status word in AX. - **PF:** - `jp` after `fucomi`, `cmp` or `test eax, eax`, or before any flag writer; - `sahf` in a function without x87 instructions; - `lahf`. - **Forms outside the profile:** - `fnstsw` with an m16 operand; - the alias encodings DC D1 (`fcom`), DC D9 and DE D1 (`fcomp`); - `ftst`, `fxam` and `ficom`; - comparisons without enough stack values. Eight twins must still translate: - `sahf; jb` after `fcom`; - `fcomi` between `fcom` and `fnstsw`; - the branch whose successors test C0 and C2; - `test al, al; jp`; - `and ah, 45h` with a store of AH; - a return after `xor eax, eax`; - `sahf` on AH from `mov`; - `fnstsw ax` in the checked entry after `fldcw`. **Changes to existing tests.** Rejection cases that the profile now accepts are replaced by instructions that stay outside it, and each list keeps its length: | Test | Replaced | Now | |---|---|---| | `cpu_aot_x87_add` | `fcom st(1)`, `fnstsw ax` | `ftst`, `fnstsw m16` | | `cpu_aot_x87_sub` | `fcom st(1)` | `fxam` | | `cpu_aot_x87_mul` | `fcomp st(1)` | `fprem1` | | `cpu_aot_x87_compare` | `sahf`; `fcom st(1)`, `fucom st(1)`, `fucompp`; `fnstsw ax` | `jo`; `ficomp m32`, `fcom` as DC D1, `fucompp` with one value; `fnstsw m16` | | `cpu_aot_x87_fnstcw` | `fnstsw ax` | `fninit` | | `cpu_aot_x87_fldcw` | `fnstsw ax` in the checked entry | `fnstsw m16` in the checked entry | `jp` and `jnp` after `fucomi` in `cpu_aot_x87_compare` are still rejected, now by the PF rule. Their needle names that rule. `fnstsw m16` in `cpu_aot_x87_fnstcw` now reports `unsupported x87 operand`. Case and control counts of these tests are unchanged. The matching sentences in `docs/experiments.md` are updated. ## Verification Tested at `4a80919` on `main` at `119bdd6`. The machine runs Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0 and Python 3.13 on an AMD Ryzen 7 7700 (`AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD`). ```powershell cmake --build --preset dev --target cpu_x87_status_lifted ctest --preset dev --no-tests=error -R '^cpu_aot_x87_status$' -V ``` ```text 17843 cases over 22 exports (output block and guards) matched the reference in native and translated DLLs; each export returned with control 0x027f and an empty stack C3, C2 and C0 at FNSTSW: less 4856, equal 2265, greater 4914, unordered 5296; TOP values [0, 5, 6, 7] processor: AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD x87_call kept a live caller ST(0) value and control word around all 22 native and translated exports native status_word: the known bits matched in 1759 runs; C1, the exception flags, the stack fault and the busy bit (mask 0x82ff) took 0x0000 889, 0x0001 531, 0x0002 339 native split_sticky: after an unordered FUCOM the IE byte was 2 and 3 (a signaling NaN sets IE, a quiet NaN does not); 3518 native runs translation rejects split_sticky at TEST AL, 1 and status_word at the store of AX, which read bits that FNSTSW AX leaves unknown control c2drop: 5340/17843 mismatches control c0c3: 7263/17843 mismatches control top0: 10895/17843 mismatches control sahfpf: 8707/17843 mismatches control oddparity: 16084/17843 mismatches control andparity: 16084/17843 mismatches control fcomiclear: 779/17843 mismatches rejected 32 sequences outside the profile: FNSTSW AX with no comparison, then SAHF and JB; FADD between FCOM and FNSTSW; FLD ST(0) and FSTP ST(0) between FCOM and FNSTSW; FNSTCW between FCOM and FNSTSW; FSTSW AX (WAIT and FNSTSW AX) after FCOM; a second FNSTSW AX; a call between FCOMPP and FNSTSW; a join where one path skips FCOM; a branch whose other successor tests C1; TEST AL, 1 (IE); TEST AX, 4500h; AND AH, 47h, then a store of AH (C1); a store of AX; a return with the status word in AX; a return with the status word in AX in the checked entry, after FLDCW; a jump to an external edge with the status word in AX; FUCOMI, then JP; CMP, then JP; TEST EAX, EAX, then JP; JP before any flag writer; SAHF in a function without x87; LAHF; FNSTSW m16; FCOM alias DC D1; FCOMP alias DC D9; FCOMP alias DE D1; FTST; FXAM; FICOM m16; FCOMPP with one value; FUCOM ST(2) with two values; FCOM m32 on an empty stack translated 8 sequences that read only known bits: FNSTSW AX after FCOM, then SAHF and JB; FCOMI between FCOM and FNSTSW; a branch whose successors test C0 and C2; TEST AL, AL, then JP; AND AH, 45h, then a store of AH; a return after XOR EAX, EAX; SAHF on AH from MOV; FNSTSW AX after FCOM in the checked entry, after FLDCW ``` - **x87 regressions:** all seventeen x87 tests pass at `4a80919` (`ctest --preset dev --no-tests=error -R '^cpu_aot_x87_'`), including the six with replaced rejection cases. - **Full suite:** `ctest --preset dev --no-tests=error -j 8 --output-junit test-results.xml` gives 242 passed, 2 failed and 2 capability skips (`bvh_wave64_warp`, `wave_shuffle_warp`) out of 246 at `4a80919`. The run includes the GPU tests on an AMD Radeon RX 9070 XT. The two failures are `gpu_alias_lookup_writes_hardware`, the RDNA 4 array-atomics probe recorded in #369, and `dxr_opacity_hardware`, the RDNA 4 result recorded in #216. `main` at `119bdd6` gives the same two failures and skips in the same session (241 passed out of 245). This change touches no GPU code. - **Pure-Python checks:** `tests/form_coverage_check.py`, `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass at `4a80919`, locally and in the Linux job of the fork CI run below. - **Fork CI:** the Windows build-and-test, Windows `/O2` build-and-test, Linux Python and gfx1013 LLVM jobs passed at `4a80919` in the fork's `Windows checks` run [45009545338](https://github.com/denn0x/Xbox2Windows/actions/runs/45009545338). Both Windows jobs ran and passed all seventeen x87 tests (202 passed and 2 capability skips, `bvh_wave64_warp` and `wave_shuffle_warp`, out of 204 in each). **Coverage.** `python tools/form_coverage.py out/build/dev/test-results.xml` gives x64 **432 of 948** forms at `4a80919`, and 424 at `main` in the same session. The added forms are `fcom`, `fcomp`, `fcompp`, `fucom`, `fucomp`, `fucompp`, `fnstsw` and `sahf`; `jp` and `jnp` were already covered by `cpu_aot_flag_conditions`. **Not measured:** - Intel CPUs. All measurements are on one AMD Zen 4 part. - TOP 1 to 4 (depths 4 to 7). The exports reach depths 0 to 3 and 8. - Memory-form status stores, sticky exception flags, `fninit` and `fclex`, `ftst`, `fxam` and `ficom`. These can follow with their own semantics and native cases, as the decision on #406 suggests. ## Overlap I trial-merged this branch with the 54 open PRs other than #534. Each one conflicts in the same files against `main` and against `main` with this branch merged: the 5 that merge cleanly into `main` also merge cleanly with it, and this branch adds no conflict to the others. It conflicts with #534 (OF after `fcomi`) in `tools/x87_lower.py` and the `cpu_aot_x87_compare` paragraph of `docs/experiments.md`; I will rebase whichever of the two lands second. The changes stay inside `tools/x87_lower.py`, the x87 branch of `tools/ffx_version_query.py`, the new fixture, the replaced rejection cases of six x87 tests, a CMake block after the `cpu_aot_x87_fldcw` test, and the x87 section of `docs/experiments.md`. ## Evidence The fixture is synthetic and original to this repository (MIT). `docs/experiments.md` documents the forms, the analysis, the controls and the reproduction command. ## 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. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted (Claude Code)._
upstream-sync closed this pull request 2026-11-24 06:43:33 +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!529
No description provided.