FCMOV explained

FCMOV is a floating point conditional move opcode of the Intel x86 architecture, first introduced in Pentium Pro processors. It copies the contents of one of the floating point stack register, depending on the contents of EFLAGS integer flag register, to the ST(0) (top of stack) register. There are 8 variants of the instruction selected by the condition codes that need be set for the instruction to perform the move.

Similar to the CMOV instruction, FCMOV allows some conditional operations to be performed without the usual branching overhead.[1] However, it has a higher latency than conditional branch instructions.[2] Therefore, it is most useful for simple yet unpredictable comparison or conditional operations, where it can provide substantial performance gains.

The instruction is usually used with the FCOMI instruction or the FCOM-FSTSW-SAHF idiom to set the relevant condition codes based on the result of a floating point comparison.

Variants

This table shows the variants of the FCMOV instructions.[1] The first operand is always the ST(0) register (equivalently, the top of the floating point stack). The Opcode column indicates a two-byte sequence where the second byte is a base value indicating the number of the floating point stack register to use for the second operand. Add the desired number to complete the corresponding opcode value.

OpcodeMnemonicMeaningCondition
DA C0+iFCMOVBMove if belowCarry flag set
DA C8+iFCMOVEMove if equalZero flag set
DA D0+iFCMOVBEMove if below or equalCarry flag or Zero flag set
DA D8+iFCMOVUMove if unorderedParity flag set
DB C0+iFCMOVNBMove if not belowCarry flag cleared
DB C8+iFCMOVNEMove if not equalZero flag cleared
DB D0+iFCMOVNBEMove if not below or equalCarry flag and Zero flag cleared
DB D8+iFCMOVNUMove if not unorderedParity flag cleared

External links

Notes and References

  1. Intel Architecture Software Developer Manual, Volume 2: Instruction Set Reference. Available for download at http://www.intel.com/design/intarch/manuals/243191.htm
  2. Fog, A: Optimizing subroutines in assembly language. An optimization guide for x86 platforms. Available for download at http://www.agner.org/optimize/