views:

79

answers:

2

Is there a conditional-move-equivalent on the PowerPC (32 or 64) instruction set? It can obviously be emulated using a conditional branch, but I want something that outperforms that.

+1  A: 

Remember that PowerPC is RISC, so the instruction set is intentionally simple. You can find useful tips in the IBM "PowerPC Compiler Writer’s Guide" (ISBN 0-9649654-0-2) though - there are a number of examples of branchless implementations of conditional sequences (e.g. max/min) which might give you some ideas.

Also, if you have AltiVec, and your code can be vectorised, then conditional moves are very easy using e.g. compares and vec_sel.

Paul R
tc.
A: 

PowerPC has at least a floating-point conditional move operation, fsel, which works like follows:

fsel f0, f1, f2, f3 // f0 = ( f1 >= 0 ? f2 : f3 )

For Integer values, you could use bit masks to "select" which value to use.

Here's a discussion on this topic (integer at the bottom)

Chris Waters
Optional instruction, so you should check whether it exists on your target processor ;)
tc.