2-8. Three-Valued Compare Function

The three-valued compare function, a slight generalization of the sign function, is defined by

There are both signed and unsigned versions, and unless otherwise specified, this section applies to both.

Comparison predicate instructions permit a three-instruction solution, an obvious generalization of Equations (3):

A solution for unsigned integers on PowerPC is shown below [CWG]. On this machine, “carry” is “not borrow.”

 subf R5,Ry,Rx # R5 <-- Rx - Ry. subfc R6,Rx,Ry # R6 <-- Ry - Rx, set carry. subfe R7,Ry,Rx ...

Get Hacker's Delight now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.