Take Advantage Of The Fsincos Instruction - AMD Athlon Processor x86 Optimization Manual

X86 code optimization
Table of Contents

Advertisement

22007E/0—November 1999

Take Advantage of the FSINCOS Instruction

Take Advantage of the FSINCOS Instruction
Since out-of-range arguments are extremely uncommon, the
conditional branch will be perfectly predicted, and the other
instructions used to guard the trigonometric instruction can
execute in parallel to it.
Frequently, a piece of code that needs to compute the sine of an
argument also needs to compute the cosine of that same
argument. In such cases, the FSINCOS instruction should be
used to compute both trigonometric functions concurrently,
which is faster than using separate FSIN and FCOS instructions
to accomplish the same task.
Example 1 (Avoid):
FLD
QWORD PTR [x]
FLD
DWORD PTR [two_to_the_63]
FCOMIP ST,ST(1)
JBE
$in_range
CALL
$reduce_range
$in_range:
FLD
ST(0)
FCOS
FSTP
QWORD PTR [cosine_x]
FSIN
FSTP
QWORD PTR [sine_x]
Example 2 (Preferred):
FLD
QWORD PTR [x]
FLD
DWORD PTR [two_to_the_63]
FCOMIP ST,ST(1)
JBE
$in_range
CALL
$reduce_range
$in_range:
FSINCOS
FSTP
QWORD PTR [cosine_x]
FSTP
QWORD PTR [sine_x]
AMD Athlon™ Processor x86 Code Optimization
105

Advertisement

Table of Contents
loading

Table of Contents