cpu: lower PUSHF, PUSHFQ, POPF, and POPFQ instructions #1466

Merged
Ammmae0x merged 5 commits from upstream-pr/1473 into main 2026-12-02 12:19:16 +00:00
Ammmae0x commented 2026-11-24 12:24:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T12:24:12Z.


Change

Lower the uncovered x64 Integer group instructions pushf, pushfq, popf, and popfq from docs/coverage/x64_zen2.tsv in tools/ffx_version_query.py:

  • Add bounded private frame-stack tracking (flag_stack_depths) starting rsp at frame + FRAME_WORDS (FLAG_STACK_LIMIT = 128 bytes), stepping rsp by 2 (pushf/popf) or 8 (pushfq/popfq), enforcing depth 0 at every ret, call, indirect branch, and external exit, and rejecting underflow, overflow, mismatched depths at control-flow joins, disallowed instruction prefixes, explicit rsp register tampering or lea aliases, and [rsp + disp] accesses outside the pushed region.
  • Add path-sensitive flag definedness and DF=0 exit analysis (flag_definedness) supporting entry_state="defined" (default Windows x64 ABI: status flags undefined, DF=0 at entry) and entry_state="canonical" (status flags defined at entry), requiring defined {CF, PF, AF, ZF, SF, OF} before pushf/pushfq, tracking per-byte DF taint across stack pushes and [rsp] stores, and rejecting any ret, call, indirect branch, or external exit where DF may be 1.
  • Lower pushf/pushfq and popf/popfq with ring-3 RFLAGS bit normalization (preserving bit 1 and IF in 0x0202, updating CF/PF/AF/ZF/SF/DF/OF/NT in popf and additionally ID in popfq, and clearing IOPL/reserved bits), and record the slice in docs/experiments.md and CMakeLists.txt.

Verification

Verified on commit f5933122 (rebased cleanly onto upstream/main 06e2ff78) in both dev (Debug) and release (/O2) presets with zero compiler errors or warnings:

  • Test list check:
    & .\tools\dev.ps1; ctest --preset dev -N -> 923 total tests (cpu_aot_integer_flags, cpu_aot_integer_pushf_popf present).
  • dev build and targeted tests:
    cmake --build --preset dev --target cpu_integer_pushf_popf_original cpu_integer_pushf_popf_original_lifted cpu_integer_pushf_popf_altered_lifted cpu_integer_pushf_popf_controls cpu_integer_flags_original cpu_integer_flags_original_lifted cpu_integer_flags_altered_lifted cpu_integer_flags_controls
    ctest --preset dev --no-tests=error -R "^cpu_aot_integer_(pushf_popf|flags)$" -V
    -> 2 passed, 0 failed, 0 skipped (cpu_aot_integer_flags: 460 differential cases + 4 alternate-encoding checks + 38 unit and 11 PE-patched rejection controls; cpu_aot_integer_pushf_popf: 513 differential cases across 22 exports + 5 alternate-encoding/entry-state checks + 36 unit and 11 PE-patched rejection controls + dead-read, ALTER_IMM, 8 mutated-C++, and output-mutation controls).
  • release (/O2) build and targeted tests:
    cmake --build --preset release --target cpu_integer_pushf_popf_original cpu_integer_pushf_popf_original_lifted cpu_integer_pushf_popf_altered_lifted cpu_integer_pushf_popf_controls cpu_integer_flags_original cpu_integer_flags_original_lifted cpu_integer_flags_altered_lifted cpu_integer_flags_controls
    ctest --preset release --no-tests=error -R "^cpu_aot_integer_(pushf_popf|flags)$" -V
    -> 2 passed, 0 failed, 0 skipped.
  • Repository invariant checks:
    .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0; pushf, pushfq, popf, popfq covered under cpu_aot_integer_pushf_popf).
    .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py -> Checked 16 Markdown files and 333 links. (exit 0).
    .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py -> Checked 1210 tracked source, script and build/CI files: no bidirectional controls. (exit 0).

Evidence and follow-up

  • Fixture source: tests/cpu/integer_pushf_popf.asm and tests/cpu/integer_pushf_popf.def are original MASM x64 test fixtures written for this repository.
  • Follow-up: sahf outside the x87 profile, TF/AC trap semantics, and title CPU code execution remain out of scope for this slice.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5472085737 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T12:24:12Z. --- ## Change Lower the uncovered x64 `Integer` group instructions `pushf`, `pushfq`, `popf`, and `popfq` from `docs/coverage/x64_zen2.tsv` in `tools/ffx_version_query.py`: - Add bounded private frame-stack tracking (`flag_stack_depths`) starting `rsp` at `frame + FRAME_WORDS` (`FLAG_STACK_LIMIT = 128` bytes), stepping `rsp` by `2` (`pushf`/`popf`) or `8` (`pushfq`/`popfq`), enforcing depth `0` at every `ret`, call, indirect branch, and external exit, and rejecting underflow, overflow, mismatched depths at control-flow joins, disallowed instruction prefixes, explicit `rsp` register tampering or `lea` aliases, and `[rsp + disp]` accesses outside the pushed region. - Add path-sensitive flag definedness and `DF=0` exit analysis (`flag_definedness`) supporting `entry_state="defined"` (default Windows x64 ABI: status flags undefined, `DF=0` at entry) and `entry_state="canonical"` (status flags defined at entry), requiring defined `{CF, PF, AF, ZF, SF, OF}` before `pushf`/`pushfq`, tracking per-byte `DF` taint across stack pushes and `[rsp]` stores, and rejecting any `ret`, call, indirect branch, or external exit where `DF` may be `1`. - Lower `pushf`/`pushfq` and `popf`/`popfq` with ring-3 `RFLAGS` bit normalization (preserving bit `1` and `IF` in `0x0202`, updating `CF`/`PF`/`AF`/`ZF`/`SF`/`DF`/`OF`/`NT` in `popf` and additionally `ID` in `popfq`, and clearing `IOPL`/reserved bits), and record the slice in `docs/experiments.md` and `CMakeLists.txt`. ## Verification Verified on commit `f5933122` (rebased cleanly onto `upstream/main` `06e2ff78`) in both `dev` (Debug) and `release` (`/O2`) presets with zero compiler errors or warnings: - Test list check: `& .\tools\dev.ps1; ctest --preset dev -N` -> `923` total tests (`cpu_aot_integer_flags`, `cpu_aot_integer_pushf_popf` present). - `dev` build and targeted tests: `cmake --build --preset dev --target cpu_integer_pushf_popf_original cpu_integer_pushf_popf_original_lifted cpu_integer_pushf_popf_altered_lifted cpu_integer_pushf_popf_controls cpu_integer_flags_original cpu_integer_flags_original_lifted cpu_integer_flags_altered_lifted cpu_integer_flags_controls` `ctest --preset dev --no-tests=error -R "^cpu_aot_integer_(pushf_popf|flags)$" -V` -> `2 passed, 0 failed, 0 skipped` (`cpu_aot_integer_flags`: 460 differential cases + 4 alternate-encoding checks + 38 unit and 11 PE-patched rejection controls; `cpu_aot_integer_pushf_popf`: 513 differential cases across 22 exports + 5 alternate-encoding/entry-state checks + 36 unit and 11 PE-patched rejection controls + dead-read, `ALTER_IMM`, 8 mutated-C++, and output-mutation controls). - `release` (`/O2`) build and targeted tests: `cmake --build --preset release --target cpu_integer_pushf_popf_original cpu_integer_pushf_popf_original_lifted cpu_integer_pushf_popf_altered_lifted cpu_integer_pushf_popf_controls cpu_integer_flags_original cpu_integer_flags_original_lifted cpu_integer_flags_altered_lifted cpu_integer_flags_controls` `ctest --preset release --no-tests=error -R "^cpu_aot_integer_(pushf_popf|flags)$" -V` -> `2 passed, 0 failed, 0 skipped`. - Repository invariant checks: `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0; `pushf`, `pushfq`, `popf`, `popfq` covered under `cpu_aot_integer_pushf_popf`). `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py` -> `Checked 16 Markdown files and 333 links.` (exit 0). `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` -> `Checked 1210 tracked source, script and build/CI files: no bidirectional controls.` (exit 0). ## Evidence and follow-up - Fixture source: `tests/cpu/integer_pushf_popf.asm` and `tests/cpu/integer_pushf_popf.def` are original MASM x64 test fixtures written for this repository. - Follow-up: `sahf` outside the x87 profile, `TF`/`AC` trap semantics, and title CPU code execution remain out of scope for this slice. ## 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.
R0Y00 commented 2026-11-24 13:29:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:29:02Z.

Review: CHANGES_REQUESTED


The existing native/lifted fixture passes in Release. The analysis marks arbitrary writes to pushed flag words as possible DF, but it does not constrain the unmodeled control bits. In particular, generated POPF/POPFQ drops TF although a guest flag image can make it observable. Please limit the accepted stack edits to flag images proven to leave unmodeled control bits clear, or model those effects explicitly. A static rejection control for an input-derived flag word is sufficient for the restricted slice.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6040039010 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#pullrequestreview-6040039010). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T13:29:02Z. **Review:** CHANGES_REQUESTED --- The existing native/lifted fixture passes in Release. The analysis marks arbitrary writes to pushed flag words as possible DF, but it does not constrain the unmodeled control bits. In particular, generated POPF/POPFQ drops TF although a guest flag image can make it observable. Please limit the accepted stack edits to flag images proven to leave unmodeled control bits clear, or model those effects explicitly. A static rejection control for an input-derived flag word is sufficient for the restricted slice.
Ammmae0x commented 2026-11-24 15:02:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T14:28:29Z.


Updated flag_definedness in tools/ffx_version_query.py (commit 7332169b) to propagate per-byte may-be-1 bitmasks across GP registers and pushed flag-stack edits, statically rejecting popf unless TF (0x0100) is proven clear and popfq unless both TF and AC (0x040100) are proven clear.

Also masked input-derived flag words in tests/cpu/integer_pushf_popf.asm, added positive masked-stack-edit and unconstrained TF/AC rejection controls (42 unit rejections, 13 PE-patched DLL rejections) in tests/cpu/integer_pushf_popf_check.py and docs/experiments.md, and re-verified cpu_aot_integer_pushf_popf and cpu_aot_integer_flags on both dev and release presets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7134433502 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#issuecomment-7134433502). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T14:28:29Z. --- Updated `flag_definedness` in `tools/ffx_version_query.py` (commit `7332169b`) to propagate per-byte may-be-1 bitmasks across GP registers and pushed flag-stack edits, statically rejecting `popf` unless `TF` (`0x0100`) is proven clear and `popfq` unless both `TF` and `AC` (`0x040100`) are proven clear. Also masked input-derived flag words in `tests/cpu/integer_pushf_popf.asm`, added positive masked-stack-edit and unconstrained `TF`/`AC` rejection controls (42 unit rejections, 13 PE-patched DLL rejections) in `tests/cpu/integer_pushf_popf_check.py` and `docs/experiments.md`, and re-verified `cpu_aot_integer_pushf_popf` and `cpu_aot_integer_flags` on both `dev` and `release` presets. AI-assisted.
ChazY11 commented 2026-11-24 16:03:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T15:13:58Z.


The fixture carries its own mutation matrix; I confirmed the case counts and re-ran it

Independent reviewer, not the author. Reviewed the current head; nothing pushed to the branch.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, MASM from the same toolset.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R 'pushf|popf' -V
cpu_aot_integer_pushf_popf ... Passed 1.37 s

9 alternate-encoding/entry-state checks, 42 unit rejection controls, and 13 PE-patched rejection controls passed
513 native/lifted/reference PUSHF/PUSHFQ/POPF/POPFQ cases across 22 exports matched bit-for-bit
  (CF/PF/AF/ZF/SF/DF/OF/NT/ID each seen both ways)
ALTER_IMM diverged on {op_add8_al_pushf: 21, op_add32_imm_pushfq: 23, op_sub32_imm_pushf: 30, op_cmp64_imm_pushfq: 26}
C++ mutations diverged on {ctrl_bit1_cleared: 30, ctrl_if_cleared: 30, ctrl_af_bit5: 6, ctrl_pf_full_width: 8,
                           ctrl_df_ignored: 3, ctrl_of_dropped: 3, ctrl_id_dropped: 4, ctrl_rsp_step_wrong: 4}
dead-read and output mutation controls passed

What I checked rather than assumed

  • The three quoting sites (native, lifted, reference) are all present, so "513 matched" is a three-way agreement and not
    a comparison of the new path against itself.
  • Each of the eight C++ controls reports a different divergence count (30, 30, 6, 8, 3, 3, 4, 4). A control that
    produced the same number as another would suggest it was hitting a shared early-out rather than its own flag; the
    distinct counts say each one perturbs something specific. ctrl_rsp_step_wrong at 4 is the smallest and is the one I
    would have expected to be easiest to miss — it is caught.
  • ctrl_af_bit5 at 6 and ctrl_pf_full_width at 8 are the two width/bit-position errors, which are exactly the mistakes
    a hand-written flag packer makes; both are caught, so the bit layout is asserted rather than only the flag values.

What I did not verify

The individual case set behind "513 cases across 22 exports" — I did not enumerate the exports or check that the flag
matrix covers each flag in both directions per export. The summary claims it; confirming it would mean instrumenting the
fixture, which is yours to decide.

Verdict

Reviewed the current head. Builds clean, the case runs in 1.37 s, and the in-tree controls already cover eight distinct
partial implementations plus the immediate-form and dead-read cases. No objection from me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135676263 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#issuecomment-7135676263). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T15:13:58Z. --- ## The fixture carries its own mutation matrix; I confirmed the case counts and re-ran it Independent reviewer, not the author. Reviewed the current head; nothing pushed to the branch. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, MASM from the same toolset. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R 'pushf|popf' -V ``` ```text cpu_aot_integer_pushf_popf ... Passed 1.37 s 9 alternate-encoding/entry-state checks, 42 unit rejection controls, and 13 PE-patched rejection controls passed 513 native/lifted/reference PUSHF/PUSHFQ/POPF/POPFQ cases across 22 exports matched bit-for-bit (CF/PF/AF/ZF/SF/DF/OF/NT/ID each seen both ways) ALTER_IMM diverged on {op_add8_al_pushf: 21, op_add32_imm_pushfq: 23, op_sub32_imm_pushf: 30, op_cmp64_imm_pushfq: 26} C++ mutations diverged on {ctrl_bit1_cleared: 30, ctrl_if_cleared: 30, ctrl_af_bit5: 6, ctrl_pf_full_width: 8, ctrl_df_ignored: 3, ctrl_of_dropped: 3, ctrl_id_dropped: 4, ctrl_rsp_step_wrong: 4} dead-read and output mutation controls passed ``` ### What I checked rather than assumed - The three quoting sites (native, lifted, reference) are all present, so "513 matched" is a three-way agreement and not a comparison of the new path against itself. - Each of the eight C++ controls reports a **different** divergence count (30, 30, 6, 8, 3, 3, 4, 4). A control that produced the same number as another would suggest it was hitting a shared early-out rather than its own flag; the distinct counts say each one perturbs something specific. `ctrl_rsp_step_wrong` at 4 is the smallest and is the one I would have expected to be easiest to miss — it is caught. - `ctrl_af_bit5` at 6 and `ctrl_pf_full_width` at 8 are the two width/bit-position errors, which are exactly the mistakes a hand-written flag packer makes; both are caught, so the bit layout is asserted rather than only the flag values. ### What I did not verify The individual case set behind "513 cases across 22 exports" — I did not enumerate the exports or check that the flag matrix covers each flag in both directions per export. The summary claims it; confirming it would mean instrumenting the fixture, which is yours to decide. ### Verdict Reviewed the current head. Builds clean, the case runs in 1.37 s, and the in-tree controls already cover eight distinct partial implementations plus the immediate-form and dead-read cases. No objection from me.
tedin7 commented 2026-11-24 16:11:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:11:38Z.

Review: COMMENTED


Review of head 7332169b. Result: no defect found in the lowering or in the static analysis. Findings below are test-coverage gaps (P2) and one undocumented entry-state assumption. The earlier change request (unmodeled TF/AC reachable through guest-controlled flag words) is addressed by flag_definedness; I re-checked it independently (below).

Verified

Linux x86-64 only. The MASM fixture was translated line by line to GNU as (intel syntax, .seh_* for the PE copy that the lowering tool reads, ms-ABI shim for the native copy). Lifted C++ was built with g++ -O2 plus a small shim for the MSVC-only constructs (__unaligned, __declspec, RaiseException, <intrin.h>).

  • integer_pushf_popf_check.py emit on the rebuilt fixture, then native vs lifted vs the independent Python RFLAGS model, all 22 differential exports: 513/513 cases equal, 0 mismatches. Guard bytes intact.
  • check_alt_encodings_and_rejections on the rebuilt PE: 9 alternate-encoding/entry-state checks, 42 unit rejection controls, and 13 PE-patched rejection controls passed.
  • Encodings, checked on hardware: 66 9C / 48 9C / 66 48 9C / 48 66 9C / 67 9C change RSP by 2 / 8 / 8 / 2 / 8. iced decodes them as PUSHFW / PUSHFQ / PUSHFQ / PUSHFW / PUSHFQ (same for POPF), which is what FLAG_STACK_DELTAS assumes. REX.W beats 66h, and 67h is ignored. The lowering accepts the 67 form consistently.
  • Differential fuzz of the lowering: about 1800 random accepted programs (ADD/SUB/CMP seed, 0-3 mixed flag/data ops, PUSHF/PUSHFQ + masked stack edits via and/or/mov on [rsp] + POPF/POPFQ, then a PUSHF/PUSHFQ capture), 10 random inputs each, native vs lifted: 0 mismatches. A DF leak at return was also checked natively: none.
  • Soundness probe of the TF/AC may-be-1 analysis: 2800 random register/stack-edit programs (mov/and/or/xor/shl/shr/btr/bts/movzx/ah ops, optional conditional arm, guest-memory loads, 16- and 64-bit stack edits). For each program accepted by flag_definedness (about 1100), the word that POPF/POPFQ would pop was captured natively (pop r11 in place of popfq) on 60 inputs: TF/AC were never set. The probe is sensitive: it reports unsound acceptances for mutants that treat a guest-memory load as zero (40-46 per 200 programs), clear all bits in BTR, or use AND instead of OR/XOR.
  • No regression on existing paths: the lowered C++ for 31 existing exports (integer_flags, flag_conditions, cmov_setcc, bit_ops, carry_rotates, branch) is byte-identical between origin/main and this head.
  • CMakeLists.txt wiring mirrors the integer_flags block (variants, ALTER_IMM, controls library, SKIP_RETURN_CODE 77); .def lists the 23 exports in the .asm; counts quoted in docs/experiments.md (23 exports, 22 differential, 513, 9/42/13) match what I reproduced.
  • Reference model in integer_pushf_popf_check.py is written from the architectural rules (bit 1 and IF forced, NT/ID writable, IOPL/RF/VM/VIF/VIP dropped, 16-bit POPF keeps bits 16+), not copied from the lowering. Good.

Mutation of the PR (each applied to all occurrences in the lowered C++ and rebuilt, 513 cases re-run): dropping OF from PUSHF, IF from PUSHF, SF/PF/AF from POPF, DF/NT from POPF, NT/ID from POPFQ, DF/NT from PUSHFQ, and a wrong POPF step are all detected. Two are not, see P2-1.

Findings

P2-1 (proven): 16-bit PUSHF never pushes DF=1 or NT=1 in the fixture.
tools/ffx_version_query.py, PUSHF statement in lower (the (static_cast<uint16_t>(direction) << 10) and (static_cast<uint16_t>(nt_flag) << 14) terms). Removing either term from every lowered PUSHF leaves all 513 cases and the 8 mutated-C++ controls passing. All PUSHF exports run with DF=0/NT=0; NT/DF are only observed through pushfq. The code is correct (native == lifted below); the test would not notice a regression.
Repro (fixture addition, tests/cpu/integer_pushf_popf.asm, inputs a0 in {0, 0x400, 0x4000, 0x4400, 0x8D5}):

mov r9, QWORD PTR [rcx]
and r9, -040101h
mov rax, QWORD PTR [rcx+8]
add rax, 0
pushfq
mov QWORD PTR [rsp], r9
popfq
pushf
movzx eax, WORD PTR [rsp]
popf
mov QWORD PTR [r8], rax
cld
ret

Native / lifted: 0x202 / 0x202, 0x602 / 0x602 (DF), 0x4202 / 0x4202 (NT), 0x4602 / 0x4602, 0xad7 / 0xad7. With the two terms removed the lifted result is 0x202 for the DF and NT inputs.

P2-2 (proven by mutation): several may-be-1 propagation paths are untested.
_read_op_may_one / _update_may_one_state / the joins in flag_definedness (tools/ffx_version_query.py). These mutations all leave the 42 unit controls, 13 PE controls and 9 accept cases passing:

  • load from non-RSP memory returns 0 instead of all-ones (unsound; my probe then accepts 40-46 of 200 programs that pop TF/AC natively). The unconstrained_* controls only use an input register (rcx), never mov reg, [mem];
  • register or/xor combining with &, btr reg, imm clearing everything, shl/shr wrong, high-byte (ah) read shifted wrongly, btr [rsp], imm replaced by 0;
  • join of the may-be-1 stack bytes with & (the only join control, unconstrained_join_one_arm_popfq, is decided by the register join).
    The AND/MOV/stack-OR/AC/TF/DF paths are covered (mutants killed). Suggested minimal controls: one rejection with mov rcx, [rdx] feeding mov [rsp], rcx; popfq; one pair (accept/reject) each for a masked-then-ored register, shl/shr, btr; and one join where one arm edits the pushed word and the other does not.

P2-3 (proven, low likelihood): entry NT/ID (and AC) are assumed 0.
lower initialises nt_flag=false, id_flag=false and the pushed word never carries AC. Native add rax,0 / pushfq / mov rax,[rsp] / popfq / ret returns 0x206 normally, 0x200206 if the caller enters with ID set and 0x4206 with NT set; the lifted function returns 0x206 in all three cases. The doc section states the entry assumptions for status flags and DF only. Either state this assumption (NT/ID/AC clear at entry) or seed them from the guest.

nit: entry_state="canonical" has no in-tree caller.
It is only passed by one alt_accept case in integer_pushf_popf_check.py; with it, an entry pushfq observes fabricated all-clear status flags. Consider dropping the option or documenting where it will be used.

Not verified

  • Linux only. Not run: MSVC/MASM build, cmake --preset dev / release, ctest (cpu_aot_integer_pushf_popf, cpu_aot_integer_flags), MSVC /O2 code generation of the lifted C++, PE unwind data produced by MASM PROC FRAME (I used .seh_proc), and the other tests that share tools/ffx_version_query.py beyond the byte-identical-output comparison above.
  • Windows behaviour of POPF/POPFQ with TF/AC set (traps, alignment checking) and ring-3 behaviour of IF/IOPL under Windows; the Linux CPU result for IF/IOPL/RF/VM matches the model but is not a Windows measurement.
  • The fixture was translated to GNU as, so assembler-specific encodings chosen by MASM (for example pushf as 66 9C) were checked separately by byte, not by running the MASM output.

Commands executed locally: gh pr view, gh pr diff, git fetch pull/1473/head, git worktree add, x86_64-w64-mingw32-gcc -shared -nostdlib (PE copy of the translated fixture), gcc -shared -nostdlib (native copy), python tests/cpu/integer_pushf_popf_check.py entry points (emit, check_alt_encodings_and_rejections), g++ -O2 -shared -fPIC on the emitted C++, ctypes differential runs, and the mutation/fuzz scripts described above.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042978993 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#pullrequestreview-6042978993). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T16:11:38Z. **Review:** COMMENTED --- Review of head `7332169b`. Result: no defect found in the lowering or in the static analysis. Findings below are test-coverage gaps (P2) and one undocumented entry-state assumption. The earlier change request (unmodeled TF/AC reachable through guest-controlled flag words) is addressed by `flag_definedness`; I re-checked it independently (below). ## Verified Linux x86-64 only. The MASM fixture was translated line by line to GNU as (intel syntax, `.seh_*` for the PE copy that the lowering tool reads, ms-ABI shim for the native copy). Lifted C++ was built with g++ -O2 plus a small shim for the MSVC-only constructs (`__unaligned`, `__declspec`, `RaiseException`, `<intrin.h>`). - `integer_pushf_popf_check.py` `emit` on the rebuilt fixture, then native vs lifted vs the independent Python RFLAGS model, all 22 differential exports: 513/513 cases equal, 0 mismatches. Guard bytes intact. - `check_alt_encodings_and_rejections` on the rebuilt PE: `9 alternate-encoding/entry-state checks, 42 unit rejection controls, and 13 PE-patched rejection controls passed`. - Encodings, checked on hardware: `66 9C` / `48 9C` / `66 48 9C` / `48 66 9C` / `67 9C` change RSP by 2 / 8 / 8 / 2 / 8. iced decodes them as PUSHFW / PUSHFQ / PUSHFQ / PUSHFW / PUSHFQ (same for POPF), which is what `FLAG_STACK_DELTAS` assumes. REX.W beats 66h, and `67h` is ignored. The lowering accepts the `67` form consistently. - Differential fuzz of the lowering: about 1800 random accepted programs (ADD/SUB/CMP seed, 0-3 mixed flag/data ops, PUSHF/PUSHFQ + masked stack edits via `and`/`or`/`mov` on `[rsp]` + POPF/POPFQ, then a PUSHF/PUSHFQ capture), 10 random inputs each, native vs lifted: 0 mismatches. A DF leak at return was also checked natively: none. - Soundness probe of the TF/AC may-be-1 analysis: 2800 random register/stack-edit programs (mov/and/or/xor/shl/shr/btr/bts/movzx/ah ops, optional conditional arm, guest-memory loads, 16- and 64-bit stack edits). For each program accepted by `flag_definedness` (about 1100), the word that POPF/POPFQ would pop was captured natively (`pop r11` in place of `popfq`) on 60 inputs: TF/AC were never set. The probe is sensitive: it reports unsound acceptances for mutants that treat a guest-memory load as zero (40-46 per 200 programs), clear all bits in BTR, or use AND instead of OR/XOR. - No regression on existing paths: the lowered C++ for 31 existing exports (`integer_flags`, `flag_conditions`, `cmov_setcc`, `bit_ops`, `carry_rotates`, `branch`) is byte-identical between `origin/main` and this head. - `CMakeLists.txt` wiring mirrors the `integer_flags` block (variants, `ALTER_IMM`, controls library, `SKIP_RETURN_CODE 77`); `.def` lists the 23 exports in the `.asm`; counts quoted in `docs/experiments.md` (23 exports, 22 differential, 513, 9/42/13) match what I reproduced. - Reference model in `integer_pushf_popf_check.py` is written from the architectural rules (bit 1 and IF forced, NT/ID writable, IOPL/RF/VM/VIF/VIP dropped, 16-bit POPF keeps bits 16+), not copied from the lowering. Good. Mutation of the PR (each applied to all occurrences in the lowered C++ and rebuilt, 513 cases re-run): dropping OF from PUSHF, IF from PUSHF, SF/PF/AF from POPF, DF/NT from POPF, NT/ID from POPFQ, DF/NT from PUSHFQ, and a wrong POPF step are all detected. Two are not, see P2-1. ## Findings **P2-1 (proven): 16-bit PUSHF never pushes DF=1 or NT=1 in the fixture.** `tools/ffx_version_query.py`, PUSHF statement in `lower` (the `(static_cast<uint16_t>(direction) << 10)` and `(static_cast<uint16_t>(nt_flag) << 14)` terms). Removing either term from every lowered PUSHF leaves all 513 cases and the 8 mutated-C++ controls passing. All PUSHF exports run with DF=0/NT=0; NT/DF are only observed through `pushfq`. The code is correct (native == lifted below); the test would not notice a regression. Repro (fixture addition, `tests/cpu/integer_pushf_popf.asm`, inputs `a0` in {0, 0x400, 0x4000, 0x4400, 0x8D5}): ``` mov r9, QWORD PTR [rcx] and r9, -040101h mov rax, QWORD PTR [rcx+8] add rax, 0 pushfq mov QWORD PTR [rsp], r9 popfq pushf movzx eax, WORD PTR [rsp] popf mov QWORD PTR [r8], rax cld ret ``` Native / lifted: `0x202 / 0x202`, `0x602 / 0x602` (DF), `0x4202 / 0x4202` (NT), `0x4602 / 0x4602`, `0xad7 / 0xad7`. With the two terms removed the lifted result is `0x202` for the DF and NT inputs. **P2-2 (proven by mutation): several may-be-1 propagation paths are untested.** `_read_op_may_one` / `_update_may_one_state` / the joins in `flag_definedness` (`tools/ffx_version_query.py`). These mutations all leave the 42 unit controls, 13 PE controls and 9 accept cases passing: - load from non-RSP memory returns 0 instead of all-ones (unsound; my probe then accepts 40-46 of 200 programs that pop TF/AC natively). The `unconstrained_*` controls only use an input register (`rcx`), never `mov reg, [mem]`; - register `or`/`xor` combining with `&`, `btr reg, imm` clearing everything, `shl`/`shr` wrong, high-byte (`ah`) read shifted wrongly, `btr [rsp], imm` replaced by 0; - join of the may-be-1 stack bytes with `&` (the only join control, `unconstrained_join_one_arm_popfq`, is decided by the register join). The AND/MOV/stack-OR/AC/TF/DF paths are covered (mutants killed). Suggested minimal controls: one rejection with `mov rcx, [rdx]` feeding `mov [rsp], rcx; popfq`; one pair (accept/reject) each for a masked-then-`or`ed register, `shl`/`shr`, `btr`; and one join where one arm edits the pushed word and the other does not. **P2-3 (proven, low likelihood): entry NT/ID (and AC) are assumed 0.** `lower` initialises `nt_flag=false, id_flag=false` and the pushed word never carries AC. Native `add rax,0 / pushfq / mov rax,[rsp] / popfq / ret` returns `0x206` normally, `0x200206` if the caller enters with ID set and `0x4206` with NT set; the lifted function returns `0x206` in all three cases. The doc section states the entry assumptions for status flags and DF only. Either state this assumption (NT/ID/AC clear at entry) or seed them from the guest. **nit: `entry_state="canonical"` has no in-tree caller.** It is only passed by one `alt_accept` case in `integer_pushf_popf_check.py`; with it, an entry `pushfq` observes fabricated all-clear status flags. Consider dropping the option or documenting where it will be used. ## Not verified - Linux only. Not run: MSVC/MASM build, `cmake --preset dev` / `release`, `ctest` (`cpu_aot_integer_pushf_popf`, `cpu_aot_integer_flags`), MSVC /O2 code generation of the lifted C++, PE unwind data produced by MASM `PROC FRAME` (I used `.seh_proc`), and the other tests that share `tools/ffx_version_query.py` beyond the byte-identical-output comparison above. - Windows behaviour of POPF/POPFQ with TF/AC set (traps, alignment checking) and ring-3 behaviour of IF/IOPL under Windows; the Linux CPU result for IF/IOPL/RF/VM matches the model but is not a Windows measurement. - The fixture was translated to GNU as, so assembler-specific encodings chosen by MASM (for example `pushf` as `66 9C`) were checked separately by byte, not by running the MASM output. Commands executed locally: `gh pr view`, `gh pr diff`, `git fetch pull/1473/head`, `git worktree add`, `x86_64-w64-mingw32-gcc -shared -nostdlib` (PE copy of the translated fixture), `gcc -shared -nostdlib` (native copy), `python tests/cpu/integer_pushf_popf_check.py` entry points (`emit`, `check_alt_encodings_and_rejections`), `g++ -O2 -shared -fPIC` on the emitted C++, ctypes differential runs, and the mutation/fuzz scripts described above. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 20:23:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:23:52Z.

Review: COMMENTED


Re-review of head a346a3f189ca1a4990a9ea757558776cbbc5d80b. My previous review was at 7332169b; the PR added one commit (a346a3f1, +162/-13 in 4 files: docs, the .asm/.def fixture and the check). Comment only, not an approval.

Verdict: 0 P1 / 0 P2. All three P2 findings and the nit from my last review are closed. Two P3 notes remain.

Linux limits. Linux x86-64, Python 3, iced-x86 and pefile in a venv. Not run: MSVC/MASM build, cmake --preset dev|release, ctest (cpu_aot_integer_pushf_popf, cpu_aot_integer_flags), MSVC /O2 code, PE unwind data, and the 13 PE-patched rejection controls (they need the built DLL). The author's counts (519 cases over 23 differential exports, 15 alternate-encoding checks, 50 unit rejections, 10 C++ mutation controls) are theirs; what I reproduced is listed below.

Previous findings

  • P2-1 (16-bit PUSHF never saw DF=1 / NT=1): fixed. op_pushf_df_nt is the repro I gave, with inputs 0, 0x400, 0x4000, 0x4400, 0x08D5, 0x204400, plus controls ctrl_pushf_df_dropped and ctrl_pushf_nt_dropped. I hand-encoded the same sequence, lowered it with the real flag_stack_depths / flag_definedness / lower, compiled with g++ -O2 (small shim for the MSVC-only constructs) and ran it against the native instructions: 40 cases, 0 mismatches. Removing the DF term from the lowered PUSHF: 16/40 mismatch (for example 0x4ed7 native vs 0x4ad7). Removing the NT term: 16/40 mismatch (0x4ed7 vs 0x0ed7).
  • P2-2 (untested may-be-1 paths): fixed. The new accept/reject pairs cover non-RSP loads, ch high-byte reads, register OR/XOR/SHL/SHR/BTR, btr [rsp], imm (a direct flag_definedness pair) and a one-arm stack join. I extracted check_alt_encodings_and_rejections up to the PE-patch section and ran it at this SHA: "15 accept; 50 unit rejections" pass. Mutations of tools/ffx_version_query.py, each followed by that run and then restored:
Mutation result
load from non-RSP memory returns 0 caught (non_rsp_mem_load_popfq)
register OR combined with AND caught (or_tf_reg_popfq)
register XOR combined with AND caught
register BTR clears everything caught (btr_reg_wrong_bit_popfq)
SHL treated as SHR caught (shl_tf_reg_popfq)
SHR treated as SHL caught (an accept case now rejected)
btr [rsp], imm result forced to 0 caught (btr_stack_bad)
stack OR combined with AND caught (ac_or_stack_popfq)
stack-byte join with AND / register join with AND caught (join_stack_one_arm_ac_popfq)
DF join old_df or after_df changed to and not caught (P3 below)
  • P2-3 (entry NT/ID/AC assumed 0): fixed as documentation. docs/experiments.md now says DF, NT, ID and AC are assumed clear at entry. That is an honest statement of the profile. The lowering still does not read them from the caller.
  • nit (entry_state="canonical" has no caller): addressed. The doc says the option is tested in the suite, and it is (rex_w_pushfq_popfq runs with canonical).

Remaining notes (non-blocking)

  1. P3: the DF join in flag_definedness (old_df or after_df) is not pinned by any control; changing it to and leaves all 15 + 50 controls green. A control with one arm that sets DF and one that clears it, reaching a ret, would pin it.
  2. P3: the branch is 691 commits behind origin/main. git merge-tree --write-tree origin/main HEAD is clean (exit 0), so no conflict, but please rebase before anyone relies on the CI result.

Other checks: git diff --check origin/main...HEAD: clean. tests/docs_links_check.py (16 files, 333 links at this base) and tests/bidi_controls_check.py (1210 files): clean. tests/form_coverage_check.py: passed. The .def lists 24 exports and the .asm has 24 PROC FRAME blocks, matching the doc's "24 functions". 513 + 6 new cases = 519, as quoted.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046778793 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#pullrequestreview-6046778793). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:23:52Z. **Review:** COMMENTED --- Re-review of head `a346a3f189ca1a4990a9ea757558776cbbc5d80b`. My previous review was at `7332169b`; the PR added one commit (`a346a3f1`, +162/-13 in 4 files: docs, the `.asm`/`.def` fixture and the check). Comment only, not an approval. **Verdict: 0 P1 / 0 P2. All three P2 findings and the nit from my last review are closed.** Two P3 notes remain. **Linux limits.** Linux x86-64, Python 3, iced-x86 and pefile in a venv. Not run: MSVC/MASM build, `cmake --preset dev|release`, `ctest` (`cpu_aot_integer_pushf_popf`, `cpu_aot_integer_flags`), MSVC /O2 code, PE unwind data, and the 13 PE-patched rejection controls (they need the built DLL). The author's counts (519 cases over 23 differential exports, 15 alternate-encoding checks, 50 unit rejections, 10 C++ mutation controls) are theirs; what I reproduced is listed below. **Previous findings** - **P2-1 (16-bit PUSHF never saw DF=1 / NT=1): fixed.** `op_pushf_df_nt` is the repro I gave, with inputs `0, 0x400, 0x4000, 0x4400, 0x08D5, 0x204400`, plus controls `ctrl_pushf_df_dropped` and `ctrl_pushf_nt_dropped`. I hand-encoded the same sequence, lowered it with the real `flag_stack_depths` / `flag_definedness` / `lower`, compiled with g++ -O2 (small shim for the MSVC-only constructs) and ran it against the native instructions: 40 cases, 0 mismatches. Removing the DF term from the lowered PUSHF: 16/40 mismatch (for example `0x4ed7` native vs `0x4ad7`). Removing the NT term: 16/40 mismatch (`0x4ed7` vs `0x0ed7`). - **P2-2 (untested may-be-1 paths): fixed.** The new accept/reject pairs cover non-RSP loads, `ch` high-byte reads, register OR/XOR/SHL/SHR/BTR, `btr [rsp], imm` (a direct `flag_definedness` pair) and a one-arm stack join. I extracted `check_alt_encodings_and_rejections` up to the PE-patch section and ran it at this SHA: "15 accept; 50 unit rejections" pass. Mutations of `tools/ffx_version_query.py`, each followed by that run and then restored: | Mutation | result | |---|---| | load from non-RSP memory returns 0 | caught (`non_rsp_mem_load_popfq`) | | register OR combined with AND | caught (`or_tf_reg_popfq`) | | register XOR combined with AND | caught | | register BTR clears everything | caught (`btr_reg_wrong_bit_popfq`) | | SHL treated as SHR | caught (`shl_tf_reg_popfq`) | | SHR treated as SHL | caught (an accept case now rejected) | | `btr [rsp], imm` result forced to 0 | caught (`btr_stack_bad`) | | stack OR combined with AND | caught (`ac_or_stack_popfq`) | | stack-byte join with AND / register join with AND | caught (`join_stack_one_arm_ac_popfq`) | | DF join `old_df or after_df` changed to `and` | **not caught** (P3 below) | - **P2-3 (entry NT/ID/AC assumed 0): fixed as documentation.** `docs/experiments.md` now says DF, NT, ID and AC are assumed clear at entry. That is an honest statement of the profile. The lowering still does not read them from the caller. - **nit (`entry_state="canonical"` has no caller): addressed.** The doc says the option is tested in the suite, and it is (`rex_w_pushfq_popfq` runs with `canonical`). **Remaining notes (non-blocking)** 1. P3: the DF join in `flag_definedness` (`old_df or after_df`) is not pinned by any control; changing it to `and` leaves all 15 + 50 controls green. A control with one arm that sets DF and one that clears it, reaching a `ret`, would pin it. 2. P3: the branch is 691 commits behind `origin/main`. `git merge-tree --write-tree origin/main HEAD` is clean (exit 0), so no conflict, but please rebase before anyone relies on the CI result. **Other checks:** `git diff --check origin/main...HEAD`: clean. `tests/docs_links_check.py` (16 files, 333 links at this base) and `tests/bidi_controls_check.py` (1210 files): clean. `tests/form_coverage_check.py`: passed. The `.def` lists 24 exports and the `.asm` has 24 `PROC FRAME` blocks, matching the doc's "24 functions". 513 + 6 new cases = 519, as quoted. AI-assisted; commands listed were executed locally.
Ammmae0x commented 2026-11-24 21:01:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T20:14:18Z.


Updated PR #1473 (commit a346a3f1) to address the P2 findings:

  1. P2-1 (16-bit pushf capturing DF=1/NT=1): Added op_pushf_df_nt in tests/cpu/integer_pushf_popf.asm, tests/cpu/integer_pushf_popf.def, and tests/cpu/integer_pushf_popf_check.py, plus ctrl_pushf_df_dropped and ctrl_pushf_nt_dropped C++ mutation controls (diverging on 3 cases each).
  2. P2-2 (flag_definedness may-be-1 propagation coverage): Added accept/reject pairs in tests/cpu/integer_pushf_popf_check.py for non-RSP memory loads (mov rcx, [rdx]), high-byte ch reads (mov byte ptr [rsp+1], ch), masked-then-or/xor registers, shl/shr, btr reg, imm, a direct flag_definedness accept/reject pair for btr [rsp], imm, and a single-arm post-push [rsp] or join (join_stack_one_arm_ac_popfq).
  3. P2-3 (entry assumption): Documented in docs/experiments.md that lower assumes NT, ID, and AC are 0 at function entry alongside DF = 0.

Verified cpu_aot_integer_pushf_popf (519 cases across 23 differential exports, 15 alternate-encoding/entry-state checks, 50 unit rejection controls, 13 PE-patched rejection controls, 10 C++ mutation controls) and cpu_aot_integer_flags in both dev and release, plus form_coverage_check.py, docs_links_check.py, and bidi_controls_check.py. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7143234091 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#issuecomment-7143234091). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T20:14:18Z. --- Updated PR #1473 (commit `a346a3f1`) to address the P2 findings: 1. **P2-1 (16-bit `pushf` capturing `DF=1`/`NT=1`)**: Added `op_pushf_df_nt` in `tests/cpu/integer_pushf_popf.asm`, `tests/cpu/integer_pushf_popf.def`, and `tests/cpu/integer_pushf_popf_check.py`, plus `ctrl_pushf_df_dropped` and `ctrl_pushf_nt_dropped` C++ mutation controls (diverging on 3 cases each). 2. **P2-2 (`flag_definedness` `may-be-1` propagation coverage)**: Added accept/reject pairs in `tests/cpu/integer_pushf_popf_check.py` for non-RSP memory loads (`mov rcx, [rdx]`), high-byte `ch` reads (`mov byte ptr [rsp+1], ch`), masked-then-`or`/`xor` registers, `shl`/`shr`, `btr reg, imm`, a direct `flag_definedness` accept/reject pair for `btr [rsp], imm`, and a single-arm post-push `[rsp]` `or` join (`join_stack_one_arm_ac_popfq`). 3. **P2-3 (entry assumption)**: Documented in `docs/experiments.md` that `lower` assumes `NT`, `ID`, and `AC` are `0` at function entry alongside `DF = 0`. Verified `cpu_aot_integer_pushf_popf` (519 cases across 23 differential exports, 15 alternate-encoding/entry-state checks, 50 unit rejection controls, 13 PE-patched rejection controls, 10 C++ mutation controls) and `cpu_aot_integer_flags` in both `dev` and `release`, plus `form_coverage_check.py`, `docs_links_check.py`, and `bidi_controls_check.py`. AI-assisted.
pigalot commented 2026-11-27 23:01:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T23:01:21Z.

Review: APPROVED


Independently reviewed a346a3f1 integrated over main 4b0350ea (tree 36f290b3). The merge is clean (CMakeLists.txt, docs/experiments.md and tools/ffx_version_query.py auto-merged) and git diff --cached --check origin/main is clean.

Earlier finding (R0Y00, changes requested on f5933122): addressed. flag_definedness now tracks may-be-1 masks for the GP registers and the pushed flag bytes. It rejects POPF unless TF is proven clear, and POPFQ unless TF and AC are proven clear. The input-derived rejection controls R0Y00 asked for are there (unconstrained_input_mem_write_popf(q), also as PE-patched controls). Removing the TF/AC check, or treating the registers as 0 at entry, fails cpu_aot_integer_pushf_popf (table below).

What I ran. Full dev and release builds of the trial merge, then:

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(cpu_aot_integer_pushf_popf|cpu_aot_integer_flags)$'
ctest --test-dir out/build/dev --no-tests=error -j 8 -E 'hardware|startup_audio' -R '^cpu_'
  • The two tests: 2 of 2 pass in Debug and in Release /O2. cpu_aot_integer_pushf_popf reports 519 native/lifted/reference cases over 23 exports matched, 15 alternate-encoding/entry-state checks, 50 unit and 13 PE-patched rejection controls. cpu_aot_integer_flags reports 460 LAHF cases matched.
  • Neighbours: tools/ffx_version_query.py is shared, so I ran every ^cpu_ test in dev. 302 tests: 301 pass and cpu_aot_sysdesc is the existing skip.
  • On main: cpu_aot_integer_pushf_popf is not registered.

Mutants in tools/ffx_version_query.py, each applied alone. For each one I rebuilt the fixture targets in dev, ran cpu_aot_integer_pushf_popf, and restored the file from its raw bytes. git diff --quiet was clean afterwards.

Mutant Result
POPF/POPFQ TF/AC check dropped killed
POPFQ does not check AC killed
GP registers treated as 0 at entry killed
PUSHF image never carries DF killed (df_leak_* control accepted)
POPF never sets DF killed
[rsp] access 8 bytes past the pushed depth allowed killed
join depth mismatch accepted killed
lowered POPF drops NT killed (lifted output mismatch)
lowered POPFQ drops ID killed
the new LAHF-after-POPF break removed killed (fixture no longer translates)
POPF/POPFQ removed from PF_DEFINERS killed (fixture no longer translates)
register masks kept across a call or host op survives
stack-byte join keeps only the arm that arrives last survives
flag stack accepted alongside x87 survives
RSP in a binding accepted alongside the flag stack survives

The two analysis survivors are coverage gaps, not defects. The real tool rejects both programs below. I ran them through lower with the real module and with each mutant loaded in memory:

  • xor eax,eax, a host op that writes rax, add r9d,1, pushfq, mov [rsp],rax, popfq, ret, with host_ops={0x1002: "rax = load<word>(rcx);"}. The real tool rejects it ("popfq may set unmodeled control flag(s) TF, AC"). With the register masks kept across the host op, it is accepted.
  • join_stack_one_arm_ac_popfq mirrored, with the AC edit on the taken arm: add rax,rcx; pushfq; test ecx,ecx; je BAD; jmp JOIN; BAD: or qword [rsp],0x40000; JOIN: popfq; cld; ret (4801c89c85c97402eb0848810c24000004009dfcc3). The real tool rejects it. With only the last-arriving arm kept, it is accepted. The shipped control is still rejected under that mutant, because there the AC edit is on the fall-through.

Adding these two programs as rejection controls would pin both paths. The x87 and RSP-binding refusals have no control. Each would need a one-line case.

Non-blocking. The registration is in CMakeLists.txt. tests/cmake/ fragments arrived after this PR opened (#2655), so I'm not asking for a move.

Verdict: approve on a346a3f1. R0Y00's changes-requested review on f5933122 still stands, so I am not merging. That is R0Y00's call.

Environment: AMD Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on a346a3f1.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6094127495 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#pullrequestreview-6094127495). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T23:01:21Z. **Review:** APPROVED --- Independently reviewed `a346a3f1` integrated over `main` `4b0350ea` (tree `36f290b3`). The merge is clean (`CMakeLists.txt`, `docs/experiments.md` and `tools/ffx_version_query.py` auto-merged) and `git diff --cached --check origin/main` is clean. **Earlier finding (R0Y00, changes requested on `f5933122`): addressed.** `flag_definedness` now tracks may-be-1 masks for the GP registers and the pushed flag bytes. It rejects POPF unless TF is proven clear, and POPFQ unless TF and AC are proven clear. The input-derived rejection controls R0Y00 asked for are there (`unconstrained_input_mem_write_popf(q)`, also as PE-patched controls). Removing the TF/AC check, or treating the registers as 0 at entry, fails `cpu_aot_integer_pushf_popf` (table below). **What I ran.** Full `dev` and `release` builds of the trial merge, then: ```powershell ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(cpu_aot_integer_pushf_popf|cpu_aot_integer_flags)$' ctest --test-dir out/build/dev --no-tests=error -j 8 -E 'hardware|startup_audio' -R '^cpu_' ``` - **The two tests:** 2 of 2 pass in Debug and in Release `/O2`. `cpu_aot_integer_pushf_popf` reports 519 native/lifted/reference cases over 23 exports matched, 15 alternate-encoding/entry-state checks, 50 unit and 13 PE-patched rejection controls. `cpu_aot_integer_flags` reports 460 LAHF cases matched. - **Neighbours:** `tools/ffx_version_query.py` is shared, so I ran every `^cpu_` test in `dev`. 302 tests: 301 pass and `cpu_aot_sysdesc` is the existing skip. - **On `main`:** `cpu_aot_integer_pushf_popf` is not registered. **Mutants** in `tools/ffx_version_query.py`, each applied alone. For each one I rebuilt the fixture targets in `dev`, ran `cpu_aot_integer_pushf_popf`, and restored the file from its raw bytes. `git diff --quiet` was clean afterwards. | Mutant | Result | |---|---| | POPF/POPFQ TF/AC check dropped | killed | | POPFQ does not check AC | killed | | GP registers treated as 0 at entry | killed | | PUSHF image never carries DF | killed (`df_leak_*` control accepted) | | POPF never sets DF | killed | | `[rsp]` access 8 bytes past the pushed depth allowed | killed | | join depth mismatch accepted | killed | | lowered POPF drops NT | killed (lifted output mismatch) | | lowered POPFQ drops ID | killed | | the new LAHF-after-POPF break removed | killed (fixture no longer translates) | | POPF/POPFQ removed from `PF_DEFINERS` | killed (fixture no longer translates) | | register masks kept across a call or host op | **survives** | | stack-byte join keeps only the arm that arrives last | **survives** | | flag stack accepted alongside x87 | **survives** | | RSP in a binding accepted alongside the flag stack | **survives** | The two analysis survivors are coverage gaps, not defects. The real tool rejects both programs below. I ran them through `lower` with the real module and with each mutant loaded in memory: - `xor eax,eax`, a host op that writes `rax`, `add r9d,1`, `pushfq`, `mov [rsp],rax`, `popfq`, `ret`, with `host_ops={0x1002: "rax = load<word>(rcx);"}`. The real tool rejects it ("popfq may set unmodeled control flag(s) TF, AC"). With the register masks kept across the host op, it is accepted. - `join_stack_one_arm_ac_popfq` mirrored, with the AC edit on the taken arm: `add rax,rcx; pushfq; test ecx,ecx; je BAD; jmp JOIN; BAD: or qword [rsp],0x40000; JOIN: popfq; cld; ret` (`4801c89c85c97402eb0848810c24000004009dfcc3`). The real tool rejects it. With only the last-arriving arm kept, it is accepted. The shipped control is still rejected under that mutant, because there the AC edit is on the fall-through. Adding these two programs as rejection controls would pin both paths. The x87 and RSP-binding refusals have no control. Each would need a one-line case. **Non-blocking.** The registration is in `CMakeLists.txt`. `tests/cmake/` fragments arrived after this PR opened (#2655), so I'm not asking for a move. **Verdict:** approve on `a346a3f1`. R0Y00's changes-requested review on `f5933122` still stands, so I am not merging. That is R0Y00's call. Environment: AMD Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved. CI: `Build and test on Windows`, `Assemble and translate gfx1013 fixtures` and `Run platform-independent Python checks on Linux` pass on `a346a3f1`. This reply was AI-assisted.
JohnConnorNPC commented 2026-11-28 08:15:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T08:15:05Z.


Thanks for the careful TF/AC work. This is a review of head a346a3f1, posted as a comment only: I'd merge it with the nits below, but R0Y00's CHANGES_REQUESTED review on f5933122 still stands, so the PR needs R0Y00's re-review before it can merge.

What I checked (trial merge onto main 1f07b2c1, pure Python, iced-x86 1.21.0). Not run: MSVC/MASM build, Wine, the native differential and the 13 PE-patched controls.

  • git merge-tree --write-tree origin/main a346a3f1 → rc=0, and git diff --check is clean. The branch is 2298 commits behind main.
  • R0Y00's TF/AC request is addressed: POPF requires TF to be proven clear and POPFQ requires TF|AC (0x40100). With bad_bits = 0 the unit check fails (btr_stack_bad was unexpectedly accepted by flag_definedness).
  • On the merged tree, the DLL-free part of integer_pushf_popf_check.py gives 15 accepts and 50 unit rejections. The integer_flags_check.py unit rejections (38), the x87_compare rejections and tests/form_coverage_check.py all pass. A static recount gives 23 exports and 519 cases, which matches the doc.
  • CI ran ctest --preset pr, and that preset's filter doesn't include integer_pushf_popf. The name appears 0 times in the Windows job log, so CI hasn't run the new test.

Should fix. For each of these, a one-line mutant of flag_definedness keeps the unit check green at 15/50 and accepts a program that the real tool rejects:

  1. Register reset across a host op or call (mutant after_regs = before_regs). Witness 31c0488b014183c1019c488904249dc3, with a host op at 0x1002 that loads rax from guest memory. The real tool gives popfq may set unmodeled control.
  2. Stack-byte join (mutant keeps only after_stack). Witness 4801c89c85c97402eb0848810c24000004009dfcc3, with the AC edit on the taken arm. The real tool rejects it. join_stack_one_arm_ac_popfq puts the edit on the fall-through, so it can't catch this.
  3. DF join, tedin7's P3-1 (mutant old_df and after_df). Witness 83c0019c9d85c97403fdeb01fcc3, with std on one arm and cld on the other. The real tool gives direction flag may be set.
    Adding the three witnesses as rejection controls would pin these.

Nits: the x87 and RSP-binding refusals have no control, and both mutants stay green. The integer_flags controls out_of_scope_pushf and out_of_scope_pushfq now reach the new flag-stack diagnostics, and its doc paragraph still lists pushf/popf/pushfq/popfq among the forms that "also reject". "per the Windows x64 ABI" covers DF only; NT, ID and AC being clear is a profile assumption. The test is registered in CMakeLists.txt, while main now uses tests/cmake/ fragments.

This comment was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7236461583 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#issuecomment-7236461583). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-28T08:15:05Z. --- Thanks for the careful TF/AC work. This is a review of head a346a3f1, posted as a comment only: I'd merge it with the nits below, but R0Y00's CHANGES_REQUESTED review on f5933122 still stands, so the PR needs R0Y00's re-review before it can merge. What I checked (trial merge onto main 1f07b2c1, pure Python, iced-x86 1.21.0). Not run: MSVC/MASM build, Wine, the native differential and the 13 PE-patched controls. - `git merge-tree --write-tree origin/main a346a3f1` → rc=0, and `git diff --check` is clean. The branch is 2298 commits behind main. - R0Y00's TF/AC request is addressed: POPF requires TF to be proven clear and POPFQ requires TF|AC (`0x40100`). With `bad_bits = 0` the unit check fails (`btr_stack_bad was unexpectedly accepted by flag_definedness`). - On the merged tree, the DLL-free part of `integer_pushf_popf_check.py` gives 15 accepts and 50 unit rejections. The `integer_flags_check.py` unit rejections (38), the x87_compare rejections and `tests/form_coverage_check.py` all pass. A static recount gives 23 exports and 519 cases, which matches the doc. - CI ran `ctest --preset pr`, and that preset's filter doesn't include `integer_pushf_popf`. The name appears 0 times in the Windows job log, so CI hasn't run the new test. Should fix. For each of these, a one-line mutant of `flag_definedness` keeps the unit check green at 15/50 and accepts a program that the real tool rejects: 1. Register reset across a host op or call (mutant `after_regs = before_regs`). Witness `31c0488b014183c1019c488904249dc3`, with a host op at 0x1002 that loads rax from guest memory. The real tool gives `popfq may set unmodeled control`. 2. Stack-byte join (mutant keeps only `after_stack`). Witness `4801c89c85c97402eb0848810c24000004009dfcc3`, with the AC edit on the taken arm. The real tool rejects it. `join_stack_one_arm_ac_popfq` puts the edit on the fall-through, so it can't catch this. 3. DF join, tedin7's P3-1 (mutant `old_df and after_df`). Witness `83c0019c9d85c97403fdeb01fcc3`, with `std` on one arm and `cld` on the other. The real tool gives `direction flag may be set`. Adding the three witnesses as rejection controls would pin these. Nits: the x87 and RSP-binding refusals have no control, and both mutants stay green. The integer_flags controls `out_of_scope_pushf` and `out_of_scope_pushfq` now reach the new flag-stack diagnostics, and its doc paragraph still lists `pushf`/`popf`/`pushfq`/`popfq` among the forms that "also reject". "per the Windows x64 ABI" covers DF only; NT, ID and AC being clear is a profile assumption. The test is registered in CMakeLists.txt, while main now uses `tests/cmake/` fragments. This comment was AI-assisted.
pigalot commented 2026-11-28 08:36:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T08:36:53Z.


I checked JohnConnorNPC's three surviving flag_definedness mutants on a346a3f1:

  • 1 (register reset) and 2 (stack-byte join): these were the two analysis survivors in my approval, and witness 2 is the one I posted there.
  • 3 (DF join) wasn't in my table, so I reproduced it. I loaded tools/ffx_version_query.py in memory, changed only the join's old_df or after_df to old_df and after_df, and lowered 83c0019c9d85c97403fdeb01fcc3, which is add eax,1; pushfq; popfq; test ecx,ecx; je L; std; jmp J; L: cld; J: ret. The real tool rejects it with direction flag may be set at ret, and the mutant accepts it. The shipped df_leak_* controls are all straight-line, so none of them reaches the join.

I agree that the three witnesses would make good rejection controls. I'm still treating these as coverage gaps rather than defects, so my approval of a346a3f1 stands. R0Y00's changes request on f5933122 still needs R0Y00's re-review.

The CI point is also correct. The pr preset's include list on main doesn't match integer_pushf_popf, so CI hasn't run the new test. My approval relied on local dev and release runs.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7236696607 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#issuecomment-7236696607). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-28T08:36:53Z. --- I checked JohnConnorNPC's three surviving `flag_definedness` mutants on `a346a3f1`: - **1 (register reset)** and **2 (stack-byte join)**: these were the two analysis survivors in my approval, and witness 2 is the one I posted there. - **3 (DF join)** wasn't in my table, so I reproduced it. I loaded `tools/ffx_version_query.py` in memory, changed only the join's `old_df or after_df` to `old_df and after_df`, and lowered `83c0019c9d85c97403fdeb01fcc3`, which is `add eax,1; pushfq; popfq; test ecx,ecx; je L; std; jmp J; L: cld; J: ret`. The real tool rejects it with `direction flag may be set at ret`, and the mutant accepts it. The shipped `df_leak_*` controls are all straight-line, so none of them reaches the join. I agree that the three witnesses would make good rejection controls. I'm still treating these as coverage gaps rather than defects, so my approval of `a346a3f1` stands. R0Y00's changes request on `f5933122` still needs R0Y00's re-review. The CI point is also correct. The `pr` preset's include list on `main` doesn't match `integer_pushf_popf`, so CI hasn't run the new test. My approval relied on local `dev` and `release` runs. This reply was AI-assisted.
Ammmae0x commented 2026-11-28 10:52:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-28T10:52:36Z.


Addressed the remaining coverage and doc items in 5e007e1a (merged with upstream/main ec71c290):

  • Added the 3 flag_definedness join/host-op witness controls in tests/cpu/integer_pushf_popf_check.py: host-op GP register reset (31c0488b014183c1019c488904249dc3 with host_ops={0x1002: "rax = load<word>(rcx);"}), stack-byte join on taken arm (4801c89c85c97402eb0848810c24000004009dfcc3), and DF join across std/cld arms (83c0019c9d85c97403fdeb01fcc3).
  • Added the two profile-boundary rejection controls: x87 operations alongside flag-stack instructions (fld1; fstp st(0); ...; pushfq under x87=True) and explicit RSP binding alongside flag-stack instructions.
  • Updated docs/experiments.md: removed pushf/popf/pushfq/popfq from the integer_flags rejection list, clarified that DF=0 at entry follows the Windows x64 ABI while NT/ID/AC clear at entry is a profile assumption, and updated the control counts.

Verified locally on Windows in both dev and release (/O2): cpu_aot_integer_flags and cpu_aot_integer_pushf_popf passed (519 differential cases, 15 alt checks, 52 unit + 4 host/profile controls, 13 PE-patched controls), all 5 targeted ffx_version_query.py mutants killed, and form_coverage_check.py / docs_links_check.py / bidi_controls_check.py exited 0.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7238179344 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#issuecomment-7238179344). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-28T10:52:36Z. --- Addressed the remaining coverage and doc items in `5e007e1a` (merged with `upstream/main` `ec71c290`): - Added the 3 `flag_definedness` join/host-op witness controls in `tests/cpu/integer_pushf_popf_check.py`: host-op GP register reset (`31c0488b014183c1019c488904249dc3` with `host_ops={0x1002: "rax = load<word>(rcx);"}`), stack-byte join on taken arm (`4801c89c85c97402eb0848810c24000004009dfcc3`), and DF join across `std`/`cld` arms (`83c0019c9d85c97403fdeb01fcc3`). - Added the two profile-boundary rejection controls: x87 operations alongside flag-stack instructions (`fld1; fstp st(0); ...; pushfq` under `x87=True`) and explicit `RSP` binding alongside flag-stack instructions. - Updated `docs/experiments.md`: removed `pushf`/`popf`/`pushfq`/`popfq` from the `integer_flags` rejection list, clarified that `DF=0` at entry follows the Windows x64 ABI while `NT`/`ID`/`AC` clear at entry is a profile assumption, and updated the control counts. Verified locally on Windows in both `dev` and `release` (`/O2`): `cpu_aot_integer_flags` and `cpu_aot_integer_pushf_popf` passed (519 differential cases, 15 alt checks, 52 unit + 4 host/profile controls, 13 PE-patched controls), all 5 targeted `ffx_version_query.py` mutants killed, and `form_coverage_check.py` / `docs_links_check.py` / `bidi_controls_check.py` exited 0. AI-assisted.
pigalot commented 2026-11-28 11:02:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T11:02:28Z.

Review: APPROVED


Retested 5e007e1a integrated over main ec71c290 (tree 5ff54a06). The trial merge is clean and git diff --cached --check origin/main is clean. This follows my approval of a346a3f1.

What changed since a346a3f1. Two commits, both by the author:

  • 04aaba0c merges main ec71c290. git show --remerge-diff 04aaba0c is empty, so nothing was resolved by hand. The PR's diff of tools/ffx_version_query.py against its base is line-for-line the same as at a346a3f1.
  • 5e007e1a touches only tests/cpu/integer_pushf_popf_check.py (+37) and docs/experiments.md. No lowering or analysis code changed.

Earlier notes, checked at this head. These were the coverage gaps from my review of a346a3f1, plus the DF-join one from tedin7 and JohnConnorNPC that I reproduced in a comment. None was blocking.

Gap at a346a3f1 New control Mutant at 5e007e1a
register masks kept across a host op or call host-op block (31c0488b014183c1019c488904249dc3) killed: POPFQ accepted RAX after host-op overwrite
stack-byte join keeps only the last-arriving arm join_stack_taken_arm_ac_popfq killed
DF join or changed to and df_join_one_arm_std_popfq killed
flag stack accepted alongside x87 x87 block killed: flag-stack sequence accepted alongside x87
RSP in a binding accepted alongside the flag stack RSP-binding block killed

Each mutant was applied alone to tools/ffx_version_query.py. For each one I rebuilt the lifted and controls targets in dev, ran cpu_aot_integer_pushf_popf, and restored the file from its raw bytes. git diff --quiet was clean afterwards. At a346a3f1 the first four survived the same run (my review's table), and the DF-join mutant accepted the witness that is now df_join_one_arm_std_popfq (my later comment). That is the negative control for the new cases.

R0Y00's finding on f5933122 (unmodeled TF/AC reachable through an edited flag word) was addressed at a346a3f1, and that code is unchanged here.

What I ran.

cmake --build --preset <dev|release> --target cpu_integer_pushf_popf_original cpu_integer_pushf_popf_original_lifted cpu_integer_pushf_popf_altered cpu_integer_pushf_popf_altered_lifted cpu_integer_pushf_popf_controls cpu_integer_flags_original cpu_integer_flags_original_lifted cpu_integer_flags_altered cpu_integer_flags_altered_lifted cpu_integer_flags_controls
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(cpu_aot_integer_pushf_popf|cpu_aot_integer_flags)$'
ctest --test-dir out/build/dev --no-tests=error -j 8 -E 'hardware|startup_audio' -R '^cpu_'
  • The two tests: 2 of 2 pass in Debug and in Release /O2, no skips. cpu_aot_integer_pushf_popf reports 519 native/lifted/reference cases over 23 exports matched, 15 alternate-encoding/entry-state checks, 52 unit and 13 PE-patched rejection controls (50 unit controls at a346a3f1). cpu_aot_integer_flags reports 460 LAHF cases matched.
  • Neighbours: tools/ffx_version_query.py is shared, so after a full dev build I ran every ^cpu_ test. 302 tests: 301 pass and cpu_aot_sysdesc is the existing skip.
  • Docs: the counts in docs/experiments.md (52 unit controls, four host/profile controls, 13 PE-patched) match the test output and the check file.

One more surviving mutant (non-blocking). Changing the register join in flag_definedness from a | b to a & b leaves cpu_aot_integer_pushf_popf green. unconstrained_join_one_arm_popfq does not pin it: the worklist takes the branch target first, the unmasked value reaches the pushed bytes, and the stack join's | keeps it there, so that control is still rejected under the mutant. A witness with the wide value on the fall-through instead:

xor eax,eax; test ecx,ecx; je J; mov rax,rcx; J: add r9d,1; pushfq; mov [rsp],rax; popfq; ret (31c085c974034889c84183c1019c488904249dc3, binding rcx = a;)

I loaded the tool in memory with and without the mutant and called lower on it. The real tool rejects it (popfq may set unmodeled control flag(s) TF, AC); the mutant accepts it. This is a coverage gap, not a defect, and one more rejection control would close it.

Also non-blocking. CI's pr preset include list does not match cpu_aot_integer_pushf_popf, so CI has not run the new test; the results above are from local runs. The registration is still in CMakeLists.txt rather than a tests/cmake/ fragment.

Verdict: approve on 5e007e1a. I am not merging it: R0Y00's changes-requested review on f5933122 still stands.

Environment: AMD Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 5e007e1a.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6097359645 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#pullrequestreview-6097359645). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-28T11:02:28Z. **Review:** APPROVED --- Retested `5e007e1a` integrated over `main` `ec71c290` (tree `5ff54a06`). The trial merge is clean and `git diff --cached --check origin/main` is clean. This follows my approval of `a346a3f1`. **What changed since `a346a3f1`.** Two commits, both by the author: - `04aaba0c` merges `main` `ec71c290`. `git show --remerge-diff 04aaba0c` is empty, so nothing was resolved by hand. The PR's diff of `tools/ffx_version_query.py` against its base is line-for-line the same as at `a346a3f1`. - `5e007e1a` touches only `tests/cpu/integer_pushf_popf_check.py` (+37) and `docs/experiments.md`. No lowering or analysis code changed. **Earlier notes, checked at this head.** These were the coverage gaps from my review of `a346a3f1`, plus the DF-join one from tedin7 and JohnConnorNPC that I reproduced in a comment. None was blocking. | Gap at `a346a3f1` | New control | Mutant at `5e007e1a` | |---|---|---| | register masks kept across a host op or call | host-op block (`31c0488b014183c1019c488904249dc3`) | killed: `POPFQ accepted RAX after host-op overwrite` | | stack-byte join keeps only the last-arriving arm | `join_stack_taken_arm_ac_popfq` | killed | | DF join `or` changed to `and` | `df_join_one_arm_std_popfq` | killed | | flag stack accepted alongside x87 | x87 block | killed: `flag-stack sequence accepted alongside x87` | | RSP in a binding accepted alongside the flag stack | RSP-binding block | killed | Each mutant was applied alone to `tools/ffx_version_query.py`. For each one I rebuilt the lifted and controls targets in `dev`, ran `cpu_aot_integer_pushf_popf`, and restored the file from its raw bytes. `git diff --quiet` was clean afterwards. At `a346a3f1` the first four survived the same run (my review's table), and the DF-join mutant accepted the witness that is now `df_join_one_arm_std_popfq` (my later comment). That is the negative control for the new cases. R0Y00's finding on `f5933122` (unmodeled TF/AC reachable through an edited flag word) was addressed at `a346a3f1`, and that code is unchanged here. **What I ran.** ```powershell cmake --build --preset <dev|release> --target cpu_integer_pushf_popf_original cpu_integer_pushf_popf_original_lifted cpu_integer_pushf_popf_altered cpu_integer_pushf_popf_altered_lifted cpu_integer_pushf_popf_controls cpu_integer_flags_original cpu_integer_flags_original_lifted cpu_integer_flags_altered cpu_integer_flags_altered_lifted cpu_integer_flags_controls ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(cpu_aot_integer_pushf_popf|cpu_aot_integer_flags)$' ctest --test-dir out/build/dev --no-tests=error -j 8 -E 'hardware|startup_audio' -R '^cpu_' ``` - **The two tests:** 2 of 2 pass in Debug and in Release `/O2`, no skips. `cpu_aot_integer_pushf_popf` reports 519 native/lifted/reference cases over 23 exports matched, 15 alternate-encoding/entry-state checks, 52 unit and 13 PE-patched rejection controls (50 unit controls at `a346a3f1`). `cpu_aot_integer_flags` reports 460 LAHF cases matched. - **Neighbours:** `tools/ffx_version_query.py` is shared, so after a full `dev` build I ran every `^cpu_` test. 302 tests: 301 pass and `cpu_aot_sysdesc` is the existing skip. - **Docs:** the counts in `docs/experiments.md` (52 unit controls, four host/profile controls, 13 PE-patched) match the test output and the check file. **One more surviving mutant (non-blocking).** Changing the register join in `flag_definedness` from `a | b` to `a & b` leaves `cpu_aot_integer_pushf_popf` green. `unconstrained_join_one_arm_popfq` does not pin it: the worklist takes the branch target first, the unmasked value reaches the pushed bytes, and the stack join's `|` keeps it there, so that control is still rejected under the mutant. A witness with the wide value on the fall-through instead: `xor eax,eax; test ecx,ecx; je J; mov rax,rcx; J: add r9d,1; pushfq; mov [rsp],rax; popfq; ret` (`31c085c974034889c84183c1019c488904249dc3`, binding `rcx = a;`) I loaded the tool in memory with and without the mutant and called `lower` on it. The real tool rejects it (`popfq may set unmodeled control flag(s) TF, AC`); the mutant accepts it. This is a coverage gap, not a defect, and one more rejection control would close it. **Also non-blocking.** CI's `pr` preset include list does not match `cpu_aot_integer_pushf_popf`, so CI has not run the new test; the results above are from local runs. The registration is still in `CMakeLists.txt` rather than a `tests/cmake/` fragment. **Verdict:** approve on `5e007e1a`. I am not merging it: R0Y00's changes-requested review on `f5933122` still stands. Environment: AMD Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved. CI: `Build and test on Windows`, `Assemble and translate gfx1013 fixtures` and `Run platform-independent Python checks on Linux` pass on `5e007e1a`. This reply was AI-assisted.
JohnConnorNPC commented 2026-11-29 13:24:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T13:24:31Z.


Re-review of head 5e007e1a, trial-merged onto main c04e0dd6 (git merge-tree --write-tree exits 0, git diff --check clean). Pure Python on Linux (iced-x86), no MSVC/MASM build, so the native/lifted differential and the 13 PE-patched controls are not re-run here.

Since my comment on a346a3f1:

  • 04aaba0c is a clean merge of main (git show --remerge-diff 04aaba0c prints nothing). After it, the PR's diff of tools/ffx_version_query.py and tests/cpu/integer_pushf_popf_check.py has the same git patch-id as at a346a3f1.
  • 5e007e1a adds the controls I asked for. I applied each one-line mutant of flag_definedness to a fresh copy of the merged tree and ran the DLL-free part of the check. Each now fails for its own control:
    • register reset across a host op (after_regs = before_regs): UNIT FAIL: POPFQ accepted RAX after host-op overwrite
    • stack-byte join keeps the last arm: join_stack_taken_arm_ac_popfq: translator unexpectedly accepted rejected control
    • DF join or → and: df_join_one_arm_std_popfq: translator unexpectedly accepted rejected control
    • x87 refusal removed: flag-stack sequence accepted alongside x87
    • RSP-binding refusal removed: flag-stack sequence accepted with explicit RSP binding
  • Unmutated, the same run gives UNIT OK: 15 accept, 52 unit rejections. The integer_flags unit check gives 38 unit rejections, and the x87_compare rejections pass. form_coverage_check, docs_links_check and bidi_controls_check exit 0. A static recount still gives 23 exports and 519 cases, which matches the doc.
  • Docs: the integer_flags paragraph no longer lists the flag-stack forms as rejected, and the entry-state sentence now limits the ABI claim to DF. The new counts (52 unit, four host/profile, 13 PE-patched) match the check file.

MUST: none.

SHOULD: none from me. I won't repeat the register-join note from the latest approval.

NIT: the integer_flags controls are still named out_of_scope_pushf/popf/pushfq/popfq (integer_flags_check.py), although these forms are now in scope and fail on flag-stack balance. Renaming them is optional.

From my side this is ready to merge. It stays blocked on the changes request from f5933122. That request (TF/AC on an edited flag word) was addressed at a346a3f1, and that code is unchanged at this head, so it needs a re-review or a dismissal by the reviewer who opened it.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7256515266 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#issuecomment-7256515266). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-29T13:24:31Z. --- Re-review of head `5e007e1a`, trial-merged onto `main` `c04e0dd6` (`git merge-tree --write-tree` exits 0, `git diff --check` clean). Pure Python on Linux (iced-x86), no MSVC/MASM build, so the native/lifted differential and the 13 PE-patched controls are not re-run here. Since my comment on `a346a3f1`: - `04aaba0c` is a clean merge of `main` (`git show --remerge-diff 04aaba0c` prints nothing). After it, the PR's diff of `tools/ffx_version_query.py` and `tests/cpu/integer_pushf_popf_check.py` has the same `git patch-id` as at `a346a3f1`. - `5e007e1a` adds the controls I asked for. I applied each one-line mutant of `flag_definedness` to a fresh copy of the merged tree and ran the DLL-free part of the check. Each now fails for its own control: - register reset across a host op (`after_regs = before_regs`): `UNIT FAIL: POPFQ accepted RAX after host-op overwrite` - stack-byte join keeps the last arm: `join_stack_taken_arm_ac_popfq: translator unexpectedly accepted rejected control` - DF join `or` → `and`: `df_join_one_arm_std_popfq: translator unexpectedly accepted rejected control` - x87 refusal removed: `flag-stack sequence accepted alongside x87` - RSP-binding refusal removed: `flag-stack sequence accepted with explicit RSP binding` - Unmutated, the same run gives `UNIT OK: 15 accept, 52 unit rejections`. The `integer_flags` unit check gives `38 unit rejections`, and the x87_compare rejections pass. `form_coverage_check`, `docs_links_check` and `bidi_controls_check` exit 0. A static recount still gives 23 exports and 519 cases, which matches the doc. - Docs: the `integer_flags` paragraph no longer lists the flag-stack forms as rejected, and the entry-state sentence now limits the ABI claim to DF. The new counts (52 unit, four host/profile, 13 PE-patched) match the check file. MUST: none. SHOULD: none from me. I won't repeat the register-join note from the latest approval. NIT: the `integer_flags` controls are still named `out_of_scope_pushf`/`popf`/`pushfq`/`popfq` (`integer_flags_check.py`), although these forms are now in scope and fail on flag-stack balance. Renaming them is optional. From my side this is ready to merge. It stays blocked on the changes request from `f5933122`. That request (TF/AC on an edited flag word) was addressed at `a346a3f1`, and that code is unchanged at this head, so it needs a re-review or a dismissal by the reviewer who opened it. AI-assisted.
Ammmae0x commented 2026-12-01 03:21:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-12-01T03:21:56Z.


@R0Y00 Friendly re-review ping: your CHANGES_REQUESTED review on f5933122 is currently the only merge block on this PR.

Head 5e007e1a addresses unmodeled control-bit constraints (TF/AC may-be-1 tracking across GP registers and pushed flag bytes plus input-derived rejection controls). All 5 CI checks pass, git merge-tree --write-tree onto upstream/main (1c634037) exits 0, and @pigalot has reviewed and approved 5e007e1a.

Could you re-review when you have a moment so this can land? Thank you!

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7299629603 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#issuecomment-7299629603). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-12-01T03:21:56Z. --- @R0Y00 Friendly re-review ping: your `CHANGES_REQUESTED` review on `f5933122` is currently the only merge block on this PR. Head `5e007e1a` addresses unmodeled control-bit constraints (`TF`/`AC` may-be-1 tracking across GP registers and pushed flag bytes plus input-derived rejection controls). All 5 CI checks pass, `git merge-tree --write-tree` onto `upstream/main` (`1c634037`) exits `0`, and `@pigalot` has reviewed and approved `5e007e1a`. Could you re-review when you have a moment so this can land? Thank you! AI-assisted.
R0Y00 commented 2026-12-02 12:18:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T12:18:38Z.

Review: APPROVED


The earlier POPF/POPFQ finding is addressed by the may-be-set analysis for TF and AC and the input-derived flag-image refusal controls. Pigalot's independent current-head review and its source-built differential and mutation evidence cover this revision. I checked the current trial merge and required Windows CI, both clean.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6150573516 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1473#pullrequestreview-6150573516). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T12:18:38Z. **Review:** APPROVED --- The earlier POPF/POPFQ finding is addressed by the may-be-set analysis for TF and AC and the input-derived flag-image refusal controls. Pigalot's independent current-head review and its source-built differential and mutation evidence cover this revision. I checked the current trial merge and required Windows CI, both clean.
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!1466
No description provided.