cmp
Compare
cmp BF, L, RA, RB
Compares two registers as signed integers and records the result in the specified Condition Register Field.
Encoding
Binary Layout
31
0:5
BF
6:8
/
9
L
10
RA
11:15
RB
16:20
0000000000
21:30
1
31
Operands
-
BF
Condition Register Field (0-7) -
L
Operand Size (0=32-bit, 1=64-bit) -
RA
Source Register 1 -
RB
Source Register 2
Example
cmp cr7, 0, r3, r4
// Compare r3 vs r4 (32-bit signed), result in cr7.
Registers Altered
CRRelated
Across architectures
Compare and Branch : how x86, ARM, RISC-V, and PowerISA each do this.
More in Base
Reference
View in PowerISA v3.1C Specification ↗
OPF Power ISA v3.1C
Description
The fixed-point Compare instructions compare the contents of register RA with either the sign-extended value of the SI field, the zero-extended value of the UI field, or the contents of register RB. The comparison is signed for cmpi and cmp, and unsigned for cmpli and cmpl. The L field determines whether the operands are treated as 32-bit or 64-bit quantities.
Operation
if (RA) < (RB) then CR[BF] <- 0b1000 (LT)...
Programming Note
The cmp instruction is commonly used for signed comparisons between two registers. Ensure that the operands are correctly aligned and consider the L field to specify whether the comparison should be performed on 32-bit or 64-bit values. The result of the comparison updates the Condition Register (CR), so always check CR[BF] after executing cmp to determine the outcome.