cntlzw or cntlz (Count Leading Zeros Word) instruction

Purpose

Counts the number of leading zeros of the 32-bit value in a source general-purpose register (GPR) and stores the result in a GPR.

Syntax

Bits Value
0 - 5 31
6-10 RS
11-15 RA
16-20 ///
21-30 26
31 Rc
PowerPC® 
cntlzw RA, RS
cntlzw. RA, RS
POWER® family 
cntlz RA, RS
cntlz. RA, RS

Description

The cntlzw and cntlz instructions count the number (0 - 32) of consecutive zero bits of the 32 low-order bits of GPR RS and store the result in the target GPR RA.

Item Description
Syntax Form Overflow Exception (OE) Fixed-Point Exception Register Record Bit (Rc) Condition Register Field 0
cntlzw None None 0 None
cntlzw. None None 1 LT,GT,EQ,SO
cntlz None None 0 None
cntlz. None None 1 LT,GT,EQ,SO

The two syntax forms of the cntlzw instruction and the two syntax forms of the cntlz instruction never affect the fixed-point exception register. If the syntax form sets the Record (Rc) bit to 1, the instruction affects the Less Than (LT) zero, Greater Than (GT) zero, Equal To (EQ) zero, and Summary Overflow (SO) bits in Condition Register Field 0.

Parameters

Item Description
RA Specifies the target general-purpose register where the result of the operation is stored.
RS Specifies the source general-purpose register for the operation.

Examples

The following code counts the number of leading zeros in the 32-bit value contained in GPR 3 and places the result back in GPR 3:


# Assume GPR 3 contains 0x0FFF FFFF 0061 9920.
cntlzw 3,3
# GPR 3 now holds 0x0000 0000 0000 0009. Note that the high-order 32 bits
 are ignored when computing the result.