FCOMI, FCOMIP, FUCOMI, FUCOMIP

Compare Floating-Point Values and Set EFLAGS

stableVMJITAOTinstruction

Encodings

OpcodeInstructionOp/En64-bitCompat/LegacyDescription
DB F0+iFCOMI ST, ST(i)ValidValidCompare ST(0) with ST(i) and set status flags accordingly.
DF F0+iFCOMIP ST, ST(i)ValidValidCompare ST(0) with ST(i), set status flags accordingly, and pop register stack.
DB E8+iFUCOMI ST, ST(i)ValidValidCompare ST(0) with ST(i), check for ordered values, and set status flags accordingly.
DF E8+iFUCOMIP ST, ST(i)ValidValidCompare ST(0) with ST(i), check for ordered values, set status flags accordingly, and pop register stack.

Measured cost

Loading measurements from arch-data...

Description

Performs an unordered comparison of the contents of registers ST(0) and ST(i) and sets the status flags ZF, PF, and CF in the EFLAGS register according to the results (see the table below). The sign of zero is ignored for comparisons, so that 0.0 is equal to +0.0.

FCOMI/FCOMIP/ FUCOMI/FUCOMIP Results

Comparison Results*ZFPFCF
ST0 > ST(i)000
ST0 < ST(i)001
ST0 = ST(i)100
Unordered**111

IA-32 architecture compatibility

The FCOMI/FCOMIP/FUCOMI/FUCOMIP instructions were introduced to the IA-32 Architecture in the P6 family processors and are not available in earlier IA-32 processors.

FCOMI/FCOMIP/ FUCOMI/FUCOMIP--Compare Floating-Point Values and Set EFLAGS

Operation

CASE (relation of operands) OF

    ST(0) > ST(i):  ZF, PF, CF := 000;

    ST(0) < ST(i):  ZF, PF, CF := 001;

    ST(0) = ST(i):  ZF, PF, CF := 100;

ESAC;

IF Instruction is FCOMI or FCOMIP
    THEN

        IF ST(0) or ST(i) = NaN or unsupported format

                THEN
                      #IA

                  IF FPUControlWord.IM = 1

                            THEN
                                  ZF, PF, CF := 111;

                      FI;
          FI;
FI;

IF Instruction is FUCOMI or FUCOMIP
    THEN

        IF ST(0) or ST(i) = QNaN, but not SNaN or unsupported format

                THEN
                      ZF, PF, CF := 111;

                ELSE (* ST(0) or ST(i) is SNaN or unsupported format *)
                       #IA;

                  IF FPUControlWord.IM = 1

                            THEN
                                  ZF, PF, CF := 111;

                      FI;
          FI;
FI;

IF Instruction is FCOMIP or FUCOMIP
    THEN
          PopRegisterStack;

FI;

FPU Flags Affected

C1                  Set to 0.

C0, C2, C3          Not affected.

Floating-Point Exceptions

#IS                 Stack underflow occurred.
#IA                 (FCOMI or FCOMIP instruction) One or both operands are NaN values or have unsupported

formats.

(FUCOMI or FUCOMIP instruction) One or both operands are SNaN values (but not QNaNs) or have undefined formats. Detection of a QNaN value does not raise an invalid-operand exception.

FCOMI/FCOMIP/ FUCOMI/FUCOMIP--Compare Floating-Point Values and Set EFLAGS

Exceptions

Protected mode
#NMCR0.EM[bit 2] or CR0.TS[bit 3] = 1.
#MFIf there is a pending x87 FPU exception.
#UDIf the LOCK prefix is used.
Real address mode
Same exceptions as in protected mode.
Virtual-8086 mode
Same exceptions as in protected mode.
Compatibility mode
Same exceptions as in protected mode.
64-bit mode
Same exceptions as in protected mode.

Sources