cmpi
Compare Immediate
cmpi BF, L, RA, SI
Compares the contents of register RA with a sign-extended immediate value.
Encoding
Binary Layout
11
BF
/
L
RA
SI
Operands
-
BF
Condition Register Field -
L
Size (0=32-bit, 1=64-bit) -
RA
Source Register -
SI
Signed 16-bit Immediate
Example
cmpi cr0, 1, r3, -5
// Compare r3 vs -5 (64-bit signed).
Registers Altered
CR, XERRelated
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 contents of register RA ((RA)32:63 sign-extended to 64 bits if L=0) are compared with the sign-extended value of the SI field, treating the operands as signed integers. The result of the comparison is placed into CR field BF.
Operation
if L = 0 then a ←EXTS((RA)32:63)
else a ←(RA)
if a < EXTS(SI) then c ←0b100
else if a > EXTS(SI) then c ←0b010
else c ←0b001
CR4×BF+32:4×BF+35 ←c || XERSO
Extended Mnemonics
| Extended Mnemonic | Equivalent Instruction |
|---|---|
| cmpdi | |
| cmpwi |
Programming Note
The cmpi instruction is commonly used for signed integer comparisons where one operand is an immediate value. Be cautious with the alignment of the register RA, as incorrect alignment can lead to unexpected results. This instruction operates at user privilege level and does not generate exceptions under normal circumstances.