clz

Count Leading Zeros (A32)

CLZ<c> <Rd>, <Rm>

Counts the number of consecutive zeros from MSB.

Details

Counts the number of consecutive zero bits from the most significant bit (MSB) of Rm and stores the count in Rd; if Rm is 0, the result is 32. Condition flags are not affected by this instruction. Executes in A32 only.

Pseudocode Operation

if Rm == 0 then
  Rd ← 32
else
  count ← 0
  for i from 31 down to 0
    if Rm[i] == 1 then
      break
    count ← count + 1
  Rd ← count
condition_flags unchanged

Example

CLZ r0, r2

Encoding

Binary Layout
cond
00010110
1
1
1
1
Rd
1
1
1
1
0001
Rm
 
Format Data Proc
Opcode 0x016F0F10
Extension A32 (Base)

Operands

  • Rd
    Destination general-purpose register
  • Rm
    Second source / offset general-purpose register

Reference (Arm AArch32 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x016F0F10 CLZ{<c>}{<q>} <Rd>, <Rm> A32 cond | 00010110 | 1 | 1 | 1 | 1 | Rd | 1 | 1 | 1 | 1 | 0001 | Rm
0xFAB0F080 CLZ{<c>}{<q>} <Rd>, <Rm> T32 111110101 | 011 | Rn | 1111 | Rd | 10 | 00 | Rm

Description

Count Leading Zeros returns the number of binary zero bits before the first binary one bit in a value.

Operation

if ConditionPassed() then
    EncodingSpecificOperations();
    result = CountLeadingZeroBits(R[m]);
    R[d] = result<31:0>;