
Software Optimization Guide for AMD64 Processors | 25112 Rev. 3.06 September 2005 |
2.27Speeding Up Branches Based on Comparisons Between Floats
Optimization
Store operands of type float into a memory location and use integer comparison with the memory location to perform fast branches in cases where compilers do not support fast
Application
This optimization applies to
Rationale
Branches based on
AMD Opteron processors support the FCOMI, FUCOMI, FCOMIP, and FUCOMIP instructions that allow implementation of fast branches based on comparisons between operands of type double or type float. However, many compilers do not support generating these instructions. Likewise,
Many compilers only implement branches based on
Branches Dependent on Integer Comparisons Are Fast
One alternative for branches dependent upon the outcome of the comparison of operands of type float is to store the operand(s) into a memory location and then perform an integer comparison with that memory location. Branches dependent on integer comparisons are very fast. It should be noted that the replacement code uses a load dependent on an immediately prior store. If the store is not
The replacement code works well for comparisons against zero, including correct behavior when encountering a negative zero as allowed by the
54 | C and C++ | Chapter 2 |