← Home

clz

Count leading zero bits

Counts the number of 0's before the first 1, starting at the most-significant bit (i.e., XLEN-1) and progressing to bit 0. Accordingly, if the input is 0, the output is XLEN, and if the most-significant bit of the input is a 1, the output is 0.

Assembly format

clz xd, xs1

Encoding

313029282726252423222120191817161514131211109876543210
011000000000xs1001xd0010011

Decode variables

VariableBitsWidth
xs1[19:15]5
xd[11:7]5

Execution

X[xd] = (xlen() - 1) - $signed(highest_set_bit(X[xs1]));

Defined by

Zbb

Access

SUVSVU
AlwaysAlwaysAlwaysAlways

Version af3eaf9+cheriot.f635218

Data from the RISC-V Unified Database, copyright RISC-V International and contributors.

CHERIoT extensions from the CHERIoT specification and Sail model, copyright Microsoft and the CHERIoT Platform contributors.

This site is provided as a community resource and is NOT affiliated with nor endorsed by RISC-V International.