clz

Count Leading Zeros (Thumb)

CLZ <Rd>, <Rm>

Counts consecutive zeros.

Pseudocode Operation

Rd ← CountLeadingZeros(Rm[31:0])

Example

CLZ r0, r2

Encoding

Binary Layout
111110101
31:23
011
22:20
Rn
19:16
1111
15:12
Rd
11:8
10
7:6
00
5:4
Rm
3:0
 
Format Thumb Misc
Opcode 0xFAB0F080
Extension A32 (Base)

Operands

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

Related

Other forms of clz

  • clz Count Leading Zeros
  • clz Count Leading Zeros (A32)
  • clz Vector Count Leading Zeros

Across architectures

Count Leading Zeros : how x86, ARM, RISC-V, and PowerISA each do this.

More in A32 (Base)

Reference

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>;