cntlzw
Count Leading Zeros Word
cntlzw RA, RS
Counts the number of consecutive 0 bits starting from bit 32 (MSB of the low word).
Encoding
Binary Layout
31
0:5
RS
6:10
RA
11:15
00000
16:20
000011010
21:30
Rc
31
Operands
-
RA
Target Register -
RS
Source Register
Example
cntlzw r3, r4
// r3 = Leading Zeros in lower 32-bits of r4.
Registers Altered
CR0Related
Across architectures
Count Leading Zeros : 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
Counts the number of consecutive zero bits from the MSB (bit 0) of the 32-bit word in RS and stores the result in RA. The count ranges from 0 to 32. If Rc=1, CR0 is updated based on the result.
Operation
n ← 0
while n < 32 and RS[n] = 0 do n ← n + 1
RA ← n
if Rc = 1 then CR0 ← (RA = 0, RA < 0, RA > 0, SO)
Programming Note
When Rc=1 (dot form), CR0 is updated with the signed comparison of the result against zero (LT, GT, EQ) and the current SO bit from XER.