clz
Count Leading Zeros (Thumb)
CLZ <Rd>, <Rm>
Counts consecutive zeros.
Details
Count the number of leading zero bits in the 32-bit value in Rm and place the result in Rd. The result ranges from 0 (all bits set) to 32 (all bits clear). No condition flags are affected. This instruction is available in T32 (Thumb) and executes in all privilege levels.
Pseudocode Operation
Rd ← CountLeadingZeros(Rm[31:0])
Example
CLZ r0, r2
Encoding
Binary Layout
111110101
011
Rn
1111
Rd
10
00
Rm
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>;