CTZ
Count Trailing Zeros
CTZ rd, rs1
Counts the number of 0 bits at the LSB end of the register.
Encoding
Binary Layout
011000000001
31:20
rs1
19:15
001
14:12
rd
11:7
0010011
6:0
Operands
-
rd
Destination register (integer) -
rs1
Source
Example
CTZ x10, x11
// Find lowest set bit index.
Related
Across architectures
Count Trailing Zeros : how x86, ARM, RISC-V, and PowerISA each do this.
More in Zbb
Reference
View in RISC-V Unprivileged ISA Specification ↗
RISC-V ISA Manual
Description
CTZ counts the number of trailing (least-significant) zero bits in rs1, writing the count to rd. Returns XLEN if rs1 is zero.
Operation
int count = 0; while(rs1[count] == 0) count++; R[rd] = count;