← Home

ctzw

Count trailing zero bits in word

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

Assembly format

ctzw xd, xs1

Encoding

313029282726252423222120191817161514131211109876543210
011000000001xs1001xd0011011

Decode variables

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

Execution

# lowest_set_bit() reports xlen() (64 here) for a zero input, but ctzw must report 32
if (X[xs1][31:0] == 0) {
  X[xd] = 32;
} else {
  X[xd] = lowest_set_bit(X[xs1][31:0]);
}

Defined by

RV64 and 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.