Volume 1 Application Programming (794095), страница 69
Текст из файла (страница 69)
In the zerooperand form, the instruction compares ST(1) with ST(0) and writes the x87 status-word conditioncodes accordingly. In the one-operand form, the instruction reads a 32-bit or 64-bit value frommemory, 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 thecondition 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 tworegisters of preloaded data from the stack.The FCOMI instruction compares the contents of ST(0) with the contents of another stack register andwrites the ZF, PF, and CF flags in the rFLAGS register as shown in Table 6-14.
If no source isspecified, ST(0) is compared to ST(1). If ST(0) or the source operand is a NaN or in an unsupportedformat, the flags are set to indicate an unordered condition.The FCOMIP instruction performs the same comparison as FCOMI but also pops ST(0) after writingthe rFLAGS bits.Table 6-14. rFLAGS Values for FCOMI InstructionFlagST(0) > ST(i) ST(0) < ST(i) ST(0) = ST(i)UnorderedZF0011PF0001CF0101For comparison-based branches, the combination of FCOMI and FCMOVcc is faster than the classicalmethod 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 thedescription of ordered vs. unordered compares immediately below.Floating-Point Unordered Compare••••FUCOM—Floating-Point Unordered CompareFUCOMP—Floating-Point Unordered Compare and PopFUCOMPP—Floating-Point Unordered Compare and Pop TwiceFUCOMI—Floating-Point Unordered Compare and Set Flags272x87 Floating-Point Programming24592—Rev.
3.13—July 2007•AMD64 TechnologyFUCOMIP—Floating-Point Unordered Compare and Set Flags and PopThe FUCOMx instructions perform the same operations as the FCOMx instructions, except that theFUCOMx instructions generate an invalid-operation exception (IE) only if any operand is anunsupported data type or a signaling NaN (SNaN), whereas the ordered-compare FCOMx instructionsgenerate an invalid-operation exception if any operand is an unsupported data type or any type of NaN.For a description of NaNs, see “Number Representation” on page 254.Integer Compare• FICOM—Floating-Point Integer Compare• FICOMP—Floating-Point Integer Compare and PopThe FICOM instruction reads a 16-bit or 32-bit integer value from memory, compares it with ST(0),and writes the condition codes in the same way as the FCOM instruction.The FICOMP instruction performs the same operations as FICOM but also pops ST(0).Test• FTST—Floating-Point Test with ZeroThe FTST instruction compares ST(0) with zero and writes the condition codes in the same way as theFCOM instruction.Classify• FXAM—Floating-Point ExamineThe FXAM instruction determines the type of value in ST(0) and sets the condition codes accordingly,as shown in Table 6-15.Table 6-15.
Condition-Code Settings for FXAMC3C2C0C11Meaning0000+unsupported0001-unsupported0010+NAN0011-NAN0100+normal0101-normal0110+infinity0111-infinity1000+01001-0Note:1. C1 is the sign of ST(0).x87 Floating-Point Programming273AMD64 Technology24592—Rev. 3.13—July 2007Table 6-15. Condition-Code Settings for FXAM (continued)C3C2C0C11Meaning1010+empty1011-empty1100+denormal1101-denormalNote:1.
C1 is the sign of ST(0).6.4.7 Stack ManagementThe stack management instructions move the x87 top-of-stack pointer (TOP) and clear the contents ofstack registers.Stack Control••FDECSTP—Floating-Point Decrement Stack-Top PointerFINCSTP—Floating-Point Increment Stack-Top PointerThe FINCSTP and FDECSTP instructions increment and decrement, respectively, the TOP, modulo-8.Neither the x87 tag word nor the contents of the floating-point stack itself is updated.Clear State• FFREE—Free Floating-Point RegisterThe FFREE instruction frees a specified stack register by setting the x87 tag-word bits for the registerto all 1s, indicating empty. Neither the stack-register contents nor the stack pointer is modified by thisinstruction.6.4.8 No OperationThis instruction uses processor cycles but generates no result.•FNOP—Floating-Point No OperationThe FNOP instruction has no operands and writes no result.
Its purpose is simply to delay execution ofa sequence of instructions.6.4.9 ControlThe control instructions are used to initialize, save, and restore x87 processor state and to manage x87exceptions.Initialize• FINIT—Floating-Point Initialize• FNINIT—Floating-Point No-Wait Initialize274x87 Floating-Point Programming24592—Rev. 3.13—July 2007AMD64 TechnologyThe FINIT and FNINIT instructions set all bits in the x87 control-word, status-word, and tag wordregisters to their default values. Assemblers issue FINIT as an FWAIT instruction followed by anFNINIT instruction. Thus, FINIT (but not FNINIT) reports pending unmasked x87 floating-pointexceptions before performing the initialization.Both FINIT and FNINIT write the control word with its initialization value, 037Fh, which specifiesround-to-nearest, all exceptions masked, and double-extended-precision.
The tag word indicates thatthe floating-point registers are empty. The status word and the four condition-code bits are cleared to 0.The x87 pointers and opcode state (“Pointers and Opcode State” on page 247) are all cleared to 0.The FINIT instruction should be used when pending x87 floating-point exceptions are being reported(unmasked).
The no-wait instruction, FNINIT, should be used when pending x87 floating-pointexceptions are not being reported (masked).Wait for Exceptions• FWAIT or WAIT—Wait for Unmasked x87 Floating-Point ExceptionsThe FWAIT and WAIT instructions are synonyms. The instruction forces the processor to test for andhandle any pending, unmasked x87 floating-point exceptions.Clear Exceptions• FCLEX—Floating-Point Clear Flags• FNCLEX—Floating-Point No-Wait Clear FlagsThese instructions clear the status-word exception flags, stack-fault flag, and busy flag. They leave thefour condition-code bits undefined.Assemblers issue FCLEX as an FWAIT instruction followed by an FNCLEX instruction. Thus,FCLEX (but not FNCLEX) reports pending unmasked x87 floating-point exceptions before clearingthe exception flags.The FCLEX instruction should be used when pending x87 floating-point exceptions are being reported(unmasked).
The no-wait instruction, FNCLEX, should be used when pending x87 floating-pointexceptions are not being reported (masked).Save and Restore x87 Control Word• FLDCW—Floating-Point Load x87 Control Word• FSTCW—Floating-Point Store Control Word• FNSTCW—Floating-Point No-Wait Store Control WordThese instructions load or store the x87 control-word register as a 2-byte value from or to a memorylocation.The FLDCW instruction loads a control word. If the loaded control word unmasks any pending x87floating-point exceptions, these exceptions are reported when the next non-control x87 or 64-bit mediainstruction is executed.x87 Floating-Point Programming275AMD64 Technology24592—Rev.
3.13—July 2007Assemblers issue FSTCW as an FWAIT instruction followed by an FNSTCW instruction. Thus,FSTCW (but not FNSTCW) reports pending unmasked x87 floating-point exceptions before storingthe control word.The FSTCW instruction should be used when pending x87 floating-point exceptions are beingreported (unmasked). The no-wait instruction, FNSTCW, should be used when pending x87 floatingpoint exceptions are not being reported (masked).Save x87 Status Word• FSTSW—Floating-Point Store Status Word• FNSTSW—Floating-Point No-Wait Store Status WordThese instructions store the x87 status word either at a specified 2-byte memory location or in the AXregister. The second form, FxSTSW AX, is used in older code to copy condition codes through the AXregister to the rFLAGS register, where they can be used for conditional branching using generalpurpose instructions.
However, the combination of FCOMI and FCMOVcc provides a faster method ofconditional branching.Assemblers issue FSTSW as an FWAIT instruction followed by an FNSTSW instruction. Thus,FSTSW (but not FNSTSW) reports pending unmasked x87 floating-point exceptions before storingthe status word.The FSTSW instruction should be used when pending x87 floating-point exceptions are beingreported (unmasked).
The no-wait instruction, FNSTSW, should be used when pending x87 floatingpoint exceptions are not being reported (masked).Save and Restore x87 Environment• FLDENV—Floating-Point Load x87 Environment• FNSTENV—Floating-Point No-Wait Store Environment• FSTENV—Floating-Point Store EnvironmentThese instructions load or store the entire x87 environment (non-data processor state) as a 14-byte or28-byte block, depending on effective operand size, from or to memory.When executing FLDENV, any exception flags are set in the new status word, and these exceptions areunmasked in the control word, a floating-point exception occurs when the next non-control x87 or 64bit media instruction is executed.Assemblers issue FSTENV as an FWAIT instruction followed by an FNSTENV instruction.