CLZ

Count Leading Zeros

CLZ rd, rs1

Counts the number of 0 bits at the MSB end of the register.

Details

CLZ counts the number of leading (most-significant) zero bits in rs1, writing the count to rd. Returns XLEN if rs1 is zero.

Pseudocode Operation

int count = 0; while(rs1[XLEN-1-count] == 0) count++; R[rd] = count;

Example

CLZ x10, x11

Encoding

Binary Layout
0110000
31:25
00000
24:20
rs1
19:15
001
14:12
rd
11:7
0010011
6:0
 
Format I-Type
Opcode 0x13
Extension Zbb

Operands

  • rd
    Destination register (integer)
  • rs1
    Source