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.
ctzw xd, xs1
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 11 | 00000000 | 1 | xs1 | 00 | 1 | xd | 00 | 11 | 0 | 11 | ||||||||||||||||||||
| Variable | Bits | Width |
|---|---|---|
xs1 | [19:15] | 5 |
xd | [11:7] | 5 |
# 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]);
}
RV64 and Zbb
| S | U | VS | VU |
|---|---|---|---|
| Always | Always | Always | Always |
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.