开发者

Conditional Move on the PowerPC

Is there a conditional-move-equivalent on the Po开发者_JAVA百科werPC (32 or 64) instruction set? It can obviously be emulated using a conditional branch, but I want something that outperforms that.


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)


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.


Using fsel by itself can often result in incorrect results for exceptional values like NaN and Inf. You'll have to consider the results for each comparison carefully.

Integer select has been implemented in at least two variants of PowerPC.

IBM has the selii,selir,selri,selrr instructions in their AS/400 systems. These can select between a register or a signed 5-bit immediate for each source. The decision is based on an AS/400-specific register.

Motorola/Freescale has the "isel APU" found in the e200 and e500 series (and possibly others). These use a regular condition register bit, but can only select from register sources.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜