Software Optimization Guide for AMD64 Processors | 25112 Rev. 3.06 September 2005 |
6.7Replacing Branches with Computation
Optimization
Use computation to simulate predicted execution or conditional moves.
Application
This optimization applies to:
•
•
Rationale
Branches can negatively impact the performance of code. If the body of the branch is small, you can achieve higher performance by replacing the branch with computation. The computation simulates predicated execution or conditional moves. There are many SSE and SSE2 instructions that can be useful for accomplishing this. The principal instructions are as follows: ANDPS, ANDPD, ANDNPS, ANDNPD, CMPPS, CMPSS, CMPPD, CMPSD, MINPS, MINSS, MINPD, MINSD, MAXPS, MAXSS, MAXPD, MAXSD, ORPS, ORPD, PAND, PANDN, PCMPEQB, PCMPEQD, PCMPEQW, PCMPGTB, PCMPGTD, PCMPGTW, PMAXSW, PMAXUB, PMINSW, PMINUB, POR, PXOR, XORPS, and XORPD.
For
Muxing Constructs
The most important construct to use in avoiding branches in SIMD code is a
136 | Branch Optimizations | Chapter 6 |