fcomi
Compare Real and Set EFLAGS
FCOMI ST(0), ST(i)
Compares ST(0) with ST(i) and sets CPU EFLAGS directly.
Details
Compares ST(0) with ST(i) and directly sets the CPU EFLAGS (ZF, PF, CF) to reflect the comparison result, enabling use of standard conditional jumps without FSTSW. Available on P6 and later processors. The comparison does not pop the stack and affects CPU flags rather than FPU condition codes.
Pseudocode Operation
if (ST(0) > ST(i)) { ZF←0; PF←0; CF←0; }
else if (ST(0) < ST(i)) { ZF←0; PF←0; CF←1; }
else if (ST(0) == ST(i)) { ZF←1; PF←0; CF←0; }
else { ZF←1; PF←1; CF←1; }
Example
FCOMI st(0), st(1)
Encoding
Binary Layout
DB
+0
Operands
-
dest
x87 FPU top-of-stack register ST(0) -
src
x87 FPU stack register ST(i)
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| DB F0+i | FCOMI ST, ST(i) | Valid Valid | Compare ST(0) with ST(i) and set status flags accordingly. | ||
| DF F0+i | FCOMIP ST, ST(i) | Valid Valid | Compare ST(0) with ST(i), set status flags accordingly, and pop register stack. | ||
| DB E8+i | FUCOMI ST, ST(i) | Valid Valid | Compare ST(0) with ST(i), check for ordered values, and set status flags accordingly. | ||
| DF E8+i | FUCOMIP ST, ST(i) | Valid Valid | Compare ST(0) with ST(i), check for ordered values, set status flags accordingly, and pop register stack. |
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.
Table 3-24. FCOMI/FCOMIP/ FUCOMI/FUCOMIP Results
Comparison Results* ZF PF CF
ST0 > ST(i) 0 0 0
ST0 < ST(i) 0 0 1
ST0 = ST(i) 1 0 0
Unordered** 1 1 1
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;
Exceptions
Protected Mode Exceptions
#NM CR0.EM[bit 2] or CR0.TS[bit 3] = 1.
#MF If there is a pending x87 FPU exception.
#UD If the LOCK prefix is used.
Real-Address Mode Exceptions
Same exceptions as in protected mode.
Virtual-8086 Mode Exceptions
Same exceptions as in protected mode.
Compatibility Mode Exceptions
Same exceptions as in protected mode.
64-Bit Mode Exceptions
Same exceptions as in protected mode.
FCOMI/FCOMIP/ FUCOMI/FUCOMIP—Compare Floating-Point Values and Set EFLAGS Vol. 2A 3-329