Skip to content

[General]: FCOMI/FUCOMI preserves C1 for nonempty operands #73

Open

Description

@OsamaAlkhodairy

Problem

The PDF specifies C1=0 for the FCOMI family. The executable operation clears C1 only in its empty-stack branch; ordinary finite comparisons leave the incoming C1 unchanged.

Concrete case

Set C1=1, use two nonempty stack entries each holding 1, mask exceptions and execute FCOMI ST(0),ST(1). The source updates the comparison flags but retains C1=1. The PDF's FPU Flags Affected entry implies C1=0. The same shared operation is used by FUCOMI and the popping forms.

Expected behavior and references

References use Intel SDM 325462-093, checked on 2026-10-01. PDF page numbers below refer to the combined manual.

Source

Source checked at Intel SDM repository commit b5218b0f1cf512304d4b3cb364433a08fcee47cb.

Suggested correction

Follow the SDM's C1 rule by moving the C1=0 assignment before the empty-stack check, so both the empty-stack and ordinary comparison paths clear it.

Evidence

On AMD EPYC-Milan under KVM, finite comparisons with incoming C1=1 leave C1=1.

AI disclosure

Assisted by Codex

Activity

  1. tremalrik commented on Oct 8, 2026

    @tremalrik

    I ran a few tests on both an Intel Core-i7 13800H and an AMD Zen3: both of them show behavior that agrees with the executable operation and disagrees with the SDM - the C1 flag is set to 0 if either of the input registers is Empty and left unmodified otherwise. The executable operation is correct, and the "FPU Flags Affected" section of the SDM should be fixed.

  2. OsamaAlkhodairy commented on Oct 8, 2026

    @OsamaAlkhodairy
    Author

    Thanks for checking. I have run more tests and agree with your assessment.

  3. brandonhalesintel commented on Oct 13, 2026

    @brandonhalesintel

    Thanks for the detailed report. We also agree with this assessment.

    The executable operation is validated against recorded silicon traces, and those traces show that the FCOMI family does not clear C1 on the ordinary (non-stack-fault) comparison path. On a finite FUCOMI ST(0), ST(i) executed with C1 already set, the hardware-recorded x87 status word after the instruction is 0x5F61 - C1 (bit 9) still set. With the suggested change applied (hoisting C1 := 0 above the empty-stack check) the spec produces 0x5D61, differing from hardware in bit 9 and nothing else. That same single-bit divergence appears on every trace containing an FCOMI-family instruction executed with C1 already set.

    Your own Evidence section reports the same result ("finite comparisons with incoming C1 = 1 leave C1 = 1").

    So the current structure is deliberate: C1 is cleared only on the stack-fault path, where it carries its architectural "stack underflow rather than overflow" meaning for the #IS condition. It is worth noting that this really is different from FCOM/FUCOM/FTST, which do clear C1 unconditionally - the C-flag-writing comparisons and the EFLAGS-writing comparisons diverge here, which is very likely how the discrepancy arose in the first place.

    The documentation appears to be inaccurate. The "FPU Flags Affected" entry for FCOMI/FCOMIP/FUCOMI/FUCOMIP reads "C1 - Set to 0", which is accurate only for the stack-fault case. Something closer to "C1 - Set to 0 if stack underflow occurred; otherwise not affected" would match the hardware, and follows a wording pattern the SDM already uses for other x87 instructions. The correction belongs there rather than in the executable operation, so we are re-scoping this as a documentation fix.

    The executable operation is unchanged.

  4. added
    SDM PDF issueThis problem is present in the SDM PDF and is/may be present in the website as a consequence
    and removed on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SDM PDF issueThis problem is present in the SDM PDF and is/may be present in the website as a consequence

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions