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 updates comparison flags on unmasked invalid operation #72
The shared executable operation writes ZF/PF/CF before testing whether invalid operation is unmasked. The PDF says those three flags are updated only when the invalid-operation exception is masked. The source and PDF therefore specify different comparison flags for the same inputs.
Concrete case
With x87 enabled and no pending exception, compare signaling NaN 0x7fff8000000000000001 in ST(0) with 1 in ST(1), using FCOMI, control word 0x037e and incoming ZF=PF=CF=0. The source writes all three flags to 1, then suppresses result/pop effects. The PDF implies that the incoming comparison flags remain zero. The shared empty-stack branch also writes the flags before considering the mask.
Expected behavior and references
References use Intel SDM 325462-093, checked on 2026-10-01. PDF page numbers below refer to the combined manual.
Follow the SDM's comparison-flag rule by preserving ZF/PF/CF when invalid operation is unmasked. In the empty-stack branch, write these flags only when IM=1; after Compare, write them only when IE=0 or IM=1. Retain the clearing of OF/SF/AF and the existing pop suppression.
Evidence
On AMD EPYC-Milan under KVM, the unmasked-invalid comparison sets ZF/PF/CF to 1, matching the executable operation.
For the FCOMI instruction, citing the behavior of an AMD EPYC as evidence is a bit iffy, especially given that AMD and Intel document different flags behavior for this instruction (AMD documents that OF/SF/AF are left unmodified, while Intel documents them as set 0).
However, in any case, I checked the behavior on both an Intel Core I7-13800H and an AMD Zen3, and: in the case of an unordered compare that causes IE=1, both of them set ZF=PF=CF=1 even when IM=0. The executable specification is correct, and the SDM needs to be fixed.
(Also, the AMD processor sets OF=SF=AF=0, which is the same as Intel's documented behavior but runs contrary to AMD's documentation)
Thanks for the detailed report. We investigated this and also agree with this assessment.
The executable operation is validated against recorded silicon traces. Those traces contradict the suggested correction. On an FUCOMI ST(0), ST(i) that raises an unmasked invalid-operation exception, the hardware-recorded EFLAGS after the instruction is 0x00000047 - ZF = PF = CF = 1. With the suggested change applied (withholding ZF/PF/CF when IM = 0) the spec produces 0x00000002, and it diverges from hardware on every trace in which an FCOMI-family instruction takes that path.
This is consistent with the deferred nature of x87 numeric exceptions. An unmasked x87 exception does not abort the instruction that caused it: the instruction completes, records the exception in the x87 status word, sets FPUStatusWord.ES, and the #MF fault is reported later, on the next waiting x87 or WAIT/FWAIT instruction. What is suppressed is the x87-side effect - the register writeback, and the stack pop for the popping forms - which the operation already models via write_result. EFLAGS is not x87 state, so it is written unconditionally.
There is a genuine discrepancy here. The Table 1-18 note stating that ZF, PF and CF are not updated when the invalid-operation exception is unmasked does not describe the hardware, and is not consistent with the deferred-exception model described in Vol. 1 section 8.7. The correction belongs in that note rather than in the executable operation, so we are re-scoping this as a documentation fix.
Activity
tremalrik commentedon Oct 8, 2026
For the
FCOMIinstruction, citing the behavior of an AMD EPYC as evidence is a bit iffy, especially given that AMD and Intel document different flags behavior for this instruction (AMD documents that OF/SF/AF are left unmodified, while Intel documents them as set 0).However, in any case, I checked the behavior on both an Intel Core I7-13800H and an AMD Zen3, and: in the case of an unordered compare that causes IE=1, both of them set ZF=PF=CF=1 even when IM=0. The executable specification is correct, and the SDM needs to be fixed.
(Also, the AMD processor sets OF=SF=AF=0, which is the same as Intel's documented behavior but runs contrary to AMD's documentation)
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 investigated this and also agree with this assessment.
The executable operation is validated against recorded silicon traces. Those traces contradict the suggested correction. On an FUCOMI ST(0), ST(i) that raises an unmasked invalid-operation exception, the hardware-recorded EFLAGS after the instruction is 0x00000047 - ZF = PF = CF = 1. With the suggested change applied (withholding ZF/PF/CF when IM = 0) the spec produces 0x00000002, and it diverges from hardware on every trace in which an FCOMI-family instruction takes that path.
This is consistent with the deferred nature of x87 numeric exceptions. An unmasked x87 exception does not abort the instruction that caused it: the instruction completes, records the exception in the x87 status word, sets FPUStatusWord.ES, and the #MF fault is reported later, on the next waiting x87 or WAIT/FWAIT instruction. What is suppressed is the x87-side effect - the register writeback, and the stack pop for the popping forms - which the operation already models via write_result. EFLAGS is not x87 state, so it is written unconditionally.
There is a genuine discrepancy here. The Table 1-18 note stating that ZF, PF and CF are not updated when the invalid-operation exception is unmasked does not describe the hardware, and is not consistent with the deferred-exception model described in Vol. 1 section 8.7. The correction belongs in that note rather than in the executable operation, so we are re-scoping this as a documentation fix.
The executable operation is unchanged.