User Guide

x87 Floating-Point Programming 271
24592—Rev. 3.15—November 2009 AMD64 Technology
FCOMP—Floating-Point Compare and Pop
FCOMPP—Floating-Point Compare and Pop Twice
FCOMI—Floating-Point Compare and Set Flags
FCOMIP—Floating-Point Compare and Set Flags and Pop
The FCOM instruction syntax has forms that include zero or one explicit source operands. In the zero-
operand form, the instruction compares ST(1) with ST(0) and writes the x87 status-word condition
codes accordingly. In the one-operand form, the instruction reads a 32-bit or 64-bit value from
memory, compares it with ST(0), and writes the x87 condition codes accordingly.
The FCOMP instruction performs the same operation as FCOM but also pops ST(0) after writing the
condition codes.
The FCOMPP instruction performs the same operation as FCOM but also pops both ST(0) and ST(1).
FCOMPP can be used to initialize the x87 stack at the end of an x87 procedure by removing two
registers of preloaded data from the stack.
The FCOMI instruction compares the contents of ST(0) with the contents of another stack register and
writes the ZF, PF, and CF flags in the rFLAGS register as shown in Table 6-14. If no source is
specified, ST(0) is compared to ST(1). If ST(0) or the source operand is a NaN or in an unsupported
format, the flags are set to indicate an unordered condition.
The FCOMIP instruction performs the same comparison as FCOMI but also pops ST(0) after writing
the rFLAGS bits.
For comparison-based branches, the combination of FCOMI and FCMOVcc is faster than the classical
method of using FxSTSW AX to copy condition codes through the AX register to the rFLAGS register,
where they can provide branch direction for conditional operations.
The FCOMx instructions perform ordered compares, as opposed to the FUCOMx instructions. See the
description of ordered vs. unordered compares immediately below.
Floating-Point Unordered Compare
FUCOM—Floating-Point Unordered Compare
FUCOMP—Floating-Point Unordered Compare and Pop
FUCOMPP—Floating-Point Unordered Compare and Pop Twice
FUCOMI—Floating-Point Unordered Compare and Set Flags
Table 6-14. rFLAGS Values for FCOMI Instruction
Flag ST(0) > ST(i) ST(0) < ST(i) ST(0) = ST(i) Unordered
ZF0011
PF0001
CF0101