Count Leading Zeros
Count zero bits above the most significant set bit.
Bit Manipulation
Semantics
rd = clz(rs1). Note the semantic split: true CLZ counts leading zeros, while x86's older BSR returns the INDEX of the highest set bit and leaves the destination undefined for a zero input.
| Architecture | Instructions | Expressed as | How this architecture does it |
|---|---|---|---|
| x86 | one instruction | Two different operations that are easy to confuse: LZCNT (BMI1/ABM) counts leading zeros and is defined for a zero input, while the older BSR returns the bit INDEX of the highest set bit and leaves the destination undefined when the source is zero. | |
| ARM | one instruction | Base instruction, defined to return the register width for a zero input. | |
| RISC-V | one instruction | Zbb extension, defined to return XLEN for a zero input like ARM's, so no special case is needed. CLZW gives the 32-bit count on RV64. | |
| PowerISA | one instruction | Base instruction in both 64-bit and 32-bit forms. |
Other operations
Add With Carry Atomic Compare and Swap Atomic Fetch and Add Breakpoint Trap Byte Swap (Endianness Reversal) Cache Line Flush Cache Prefetch Hint Compare and Branch Conditional Select (Branchless Move) Count Trailing Zeros Floating-Point Square Root Fused Multiply-Add Integer Addition Integer Divide Integer Multiply Load-Acquire Memory Barrier / Fence No Operation Population Count Rotate Left Sign Extend Byte System Call