cmpli
Compare Logical Immediate - 28 00 00 00
cmpli

Instruction Syntax

Mnemonic Format Flags
cmpli crfD,L,rA,UIMM -
cmplwi crfD,rA,UIMM L = 0 (extended mnemonic)

Instruction Encoding

0
0
1
0
1
0
c
c
c
0
L
A
A
A
A
A
U
I
M
M
U
I
M
M
U
I
M
M
U
I
M
M

Field Bits Description
Primary Opcode 0-5 001010 (0x0A)
crfD 6-8 Condition register field
Reserved 9 Should be zero
L 10 64-bit comparison (0 = 32-bit)
rA 11-15 Source register A
UIMM 16-31 16-bit unsigned immediate value

Operation

a ← (rA)
if a u (0x0000 || UIMM) then c ← 0b010
else c ← 0b001
CR[4×crfD+32:4×crfD+35] ← c || XER[SO]

The contents of rA are compared with the zero-extended immediate value treating the operands as unsigned integers. The result of the comparison is placed into condition register field crfD.

Note: In 32-bit implementations, if L=1 the instruction form is invalid.

Affected Registers

Condition Register (crfD field)

(always)

For more information on condition codes see Section 2.1.3, "Condition Register," in the PowerPC Microprocessor Family: The Programming Environments manual.

Examples

Basic Unsigned Immediate Comparison

cmpli cr0, 0, r3, 100    # Compare r3 with 100 unsigned, set CR0
cmplwi cr1, r5, 0xFFFF   # Compare r5 with 65535 unsigned (32-bit), set CR1

Array Bounds Checking

# Check if index is within array bounds
cmplwi cr0, r3, 100      # Compare index with array size (100)
bge bounds_error         # Branch if index >= size
# Index is valid (0 <= index < 100)

Testing for NULL Pointer

cmplwi cr0, r3, 0        # Test if pointer is NULL
beq null_pointer         # Branch if r3 == 0 (NULL)
# Pointer is valid

Bit Field Validation

# Check if value fits in 8 bits (0-255)
cmplwi cr0, r3, 255      # Compare with maximum 8-bit value
ble fits_in_byte         # Branch if value <= 255
# Value requires more than 8 bits

Power of Two Testing

# Check if value is less than a power of 2
cmplwi cr0, r3, 1024     # Compare with 2^10
blt less_than_1k         # Branch if < 1024
cmplwi cr0, r3, 4096     # Compare with 2^12  
blt less_than_4k         # Branch if < 4096

Memory Size Checking

# Check memory allocation size
cmplwi cr0, r4, 0x10000  # Compare with 64KB
bge large_allocation     # Branch if >= 64KB
cmplwi cr0, r4, 0x1000   # Compare with 4KB
bge medium_allocation    # Branch if >= 4KB
# Small allocation (< 4KB)

Related Instructions

cmp, cmpi, cmpl