7-38
FLOATING-POINT UNIT
7.5.6.1.BRANCHING ON THE FPU CONDITION CODES
The processor does not offer any control-flow instructions that branch on the setting of the
condition code flags (C0, C2, and C3) in the FPU status word. To branch on the state of these
flags, the FPU status word must first be moved to the AX register in the integer unit. The
FSTSW AX (store status word) instruction can be used for this purpose. When these flags are
in the AX register, the TEST instruction can be used to control conditional branching as follows:
1.Check for an unordered result. Use the TEST instruction to compare the contents of the
AX register with the constant 0400H (refer to Table 7-17). This operation will clear the ZF
flag in the EFLAGS register if the condition code flags indicate an unordered result;
otherwise, the ZF flag will be set. The JNZ instruction can then be used to transfer control
(if necessary) to a procedure for handling unordered operands.
2.Check ordered comparison result. Use the constants given in Table 7-17 in the TEST
instruction to test for a less than, equal to, or greater than result, then use the corresponding
conditional branch instruction to transfer program control to the appropriate procedure or
section of code.
If a program or procedure has been thoroughly tested and it incorporates periodic checks for
QNaN results, then it is not necessary to check for the unordered result every time a comparison
is made.
Refer to Section 7.3.3., “Branching and Conditional Moves on FPU Condition Codes”, for
another technique for branching on FPU condition codes.
Some non-comparison FPU instructions update the condition code flags in the FPU status word.
To ensure that the status word is not altered inadvertently, store it immediately following a
comparison operation.
7.5.7.Trigonometric Instructions
The following instructions perform four common trigonometric functions:
FSIN
Sine
FCOS
Cosine
FSINCOS
Sine and cosine
FPTAN
Tangent
FPATAN
Arctangent
Table 7-17. TEST Instruction Constants for Conditional Branching
Order
Constant
Branch
ST(0) > Source Operand
4500H
JZ
ST(0) < Source Operand
0100H
JNZ
ST(0) = Source Operand
4000H
JNZ
Unordered
0400H
JNZ