cpu: PF after the VEX scalar compares in the shared lowering (SETP/SETNP/CMOVP/CMOVNP/JP/JNP) #1146

Closed
opened 2026-11-24 01:51:24 +00:00 by legacy-code-archaeologist · 2 comments
legacy-code-archaeologist commented 2026-11-24 01:51:24 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T01:51:24Z.


Claim and design question: PF after the VEX scalar compares in the shared lowering

setnp, cmovp and cmovnp (Integer group of docs/coverage/x64_zen2.tsv) have no passing fixture. In tools/ffx_version_query.py:

  • VCOMISS, VUCOMISS, VCOMISD and VUCOMISD already compute unordered and assign parity = unordered, but only when the function declares PF. Today that is only a checked x87 function that reads PF (the parity = x87_depth is not None and … rule).
  • SETP, SETNP, CMOVP and CMOVNP are not lowered at all. JP and JNP are lowered only under that x87 rule.

Compilers emit exactly this pattern for float equality and NaN tests, for example vucomiss xmm0, xmm1; setnp al; sete cl; and al, cl for a == b, or jp to a NaN path. So AVX code with float comparisons stops there. I found no open issue or PR about it and would like to take a first increment.

Proposed rule

  • Declare parity in any function whose body contains a PF consumer: JP, JNP, SETP, SETNP, CMOVP or CMOVNP, in addition to today's x87 rule.
  • Accept a consumer only when its flag producer, found with the existing straight-line producer search, is one that defines PF in the lowering:
    • the four VEX compares (parity = unordered);
    • the x87 producers already modeled by x87_lower.check_flags;
    • the producers that already clear PF (parity = false).
  • Refuse any other producer, for example ADD or CMP, where PF is the parity of the result's low byte and is not modeled, with a named diagnostic. That keeps a wrong PF from being read.
  • Lower SETP/SETNP as write(parity) / write(!parity), and CMOVP/CMOVNP like the other CMOVcc, including the 32-bit zero extension when the condition is false.
  • Functions without a PF consumer keep exactly today's generated code.

Proposed fixture (source-built MASM, differential, ; coverage: source cpu_aot_parity)

Exports:

  • VUCOMISS and VUCOMISD followed by SETNP, SETP, CMOVP and CMOVNP (register and memory sources), and by JP and JNP;
  • the setnp / sete / and equality idiom.

Inputs, chosen at run time: ordered pairs, equal values, ±0, ±infinity, quiet and signaling NaNs in either operand. Native and translated results must match, flags included.

Refusals (named diagnostics):

  • SETNP after ADD;
  • a PF consumer across a join;
  • CMOVP after an instruction that leaves PF undefined.

Controls (mutated C++): noparity (PF always false) and swap (P and NP exchanged) must fail. Also an /O2 build and both presets.

Question: is extending PF to these consumers after the VEX compares the scope you want for a first PR? I'd leave PF from ordinary ALU results out, as a separate step, because it touches every integer flag producer.

Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6572783143 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1153). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T01:51:24Z. --- ### Claim and design question: PF after the VEX scalar compares in the shared lowering `setnp`, `cmovp` and `cmovnp` (Integer group of `docs/coverage/x64_zen2.tsv`) have no passing fixture. In `tools/ffx_version_query.py`: - VCOMISS, VUCOMISS, VCOMISD and VUCOMISD already compute `unordered` and assign `parity = unordered`, but only when the function declares PF. Today that is only a checked x87 function that reads PF (the `parity = x87_depth is not None and …` rule). - SETP, SETNP, CMOVP and CMOVNP are not lowered at all. JP and JNP are lowered only under that x87 rule. Compilers emit exactly this pattern for float equality and NaN tests, for example `vucomiss xmm0, xmm1; setnp al; sete cl; and al, cl` for `a == b`, or `jp` to a NaN path. So AVX code with float comparisons stops there. I found no open issue or PR about it and would like to take a first increment. **Proposed rule** - Declare `parity` in any function whose body contains a PF consumer: JP, JNP, SETP, SETNP, CMOVP or CMOVNP, in addition to today's x87 rule. - Accept a consumer only when its flag producer, found with the existing straight-line producer search, is one that defines PF in the lowering: - the four VEX compares (`parity = unordered`); - the x87 producers already modeled by `x87_lower.check_flags`; - the producers that already clear PF (`parity = false`). - Refuse any other producer, for example ADD or CMP, where PF is the parity of the result's low byte and is not modeled, with a named diagnostic. That keeps a wrong PF from being read. - Lower SETP/SETNP as `write(parity)` / `write(!parity)`, and CMOVP/CMOVNP like the other CMOVcc, including the 32-bit zero extension when the condition is false. - Functions without a PF consumer keep exactly today's generated code. **Proposed fixture (source-built MASM, differential, `; coverage: source cpu_aot_parity`)** Exports: - VUCOMISS and VUCOMISD followed by SETNP, SETP, CMOVP and CMOVNP (register and memory sources), and by JP and JNP; - the `setnp` / `sete` / `and` equality idiom. Inputs, chosen at run time: ordered pairs, equal values, ±0, ±infinity, quiet and signaling NaNs in either operand. Native and translated results must match, flags included. Refusals (named diagnostics): - SETNP after ADD; - a PF consumer across a join; - CMOVP after an instruction that leaves PF undefined. Controls (mutated C++): `noparity` (PF always false) and `swap` (P and NP exchanged) must fail. Also an `/O2` build and both presets. **Question:** is extending PF to these consumers after the VEX compares the scope you want for a first PR? I'd leave PF from ordinary ALU results out, as a separate step, because it touches every integer flag producer. Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100. AI-assisted (Claude Code).
R0Y00 commented 2026-11-24 06:50:06 +00:00 (Migrated from github.com)
Author
Contributor

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


Please take the PF consumer slice. Accept each consumer where the existing control-flow and flag analysis proves the reaching PF definition, including the four VEX compares and the already modeled x87 producers. Preserve the current refusal when the producer is unmodeled, undefined or ambiguous at a join.

Test the ordered/equal/unordered flags under a documented masked MXCSR setup, with both quiet and signaling NaNs in each operand. Keep existing floating-point exception behavior outside that fixture scope. Check both outcomes of CMOVP/CMOVNP, including upper 32-bit clearing for a 32-bit destination and the existing memory-read/fault behavior. The proposed stale-PF and reversed-condition controls should both fail. Include the independent Windows native versus translated and /O2 runs.

Intel instruction set reference

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119697652 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1153#issuecomment-7119697652). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T02:02:35Z. --- Please take the PF consumer slice. Accept each consumer where the existing control-flow and flag analysis proves the reaching PF definition, including the four VEX compares and the already modeled x87 producers. Preserve the current refusal when the producer is unmodeled, undefined or ambiguous at a join. Test the ordered/equal/unordered flags under a documented masked MXCSR setup, with both quiet and signaling NaNs in each operand. Keep existing floating-point exception behavior outside that fixture scope. Check both outcomes of CMOVP/CMOVNP, including upper 32-bit clearing for a 32-bit destination and the existing memory-read/fault behavior. The proposed stale-PF and reversed-condition controls should both fail. Include the independent Windows native versus translated and /O2 runs. [Intel instruction set reference](https://cdrdv2-public.intel.com/774492/325383-sdm-vol-2abcd.pdf)
R0Y00 commented 2026-11-24 06:50:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T03:42:46Z.


Implemented in #1193. The source-built Release test matched native flags and memory-source behavior on the tested VEX and x87 paths, including ordered and unordered inputs. The /O2 result also matched. The stale and reversed parity controls produced the expected mismatches, and paths without a modeled reaching PF definition were refused.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121349727 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1153#issuecomment-7121349727). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T03:42:46Z. --- Implemented in #1193. The source-built Release test matched native flags and memory-source behavior on the tested VEX and x87 paths, including ordered and unordered inputs. The /O2 result also matched. The stale and reversed parity controls produced the expected mismatches, and paths without a modeled reaching PF definition were refused.
Sign in to join this conversation.
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#1146
No description provided.