You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[General]: FCOMI/FUCOMI preserves C1 for nonempty operands #73
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.
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.
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.
Activity
tremalrik commentedon Oct 8, 2026
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.
OsamaAlkhodairy commentedon Oct 8, 2026
Thanks for checking. I have run more tests and agree with your assessment.
brandonhalesintel commentedon Oct 13, 2026
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.