ctz
Count trailing zero bits
This instruction is defined by:
Synopsis
This instruction 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 (i.e., XLEN-1). Accordingly, if the input is 0, the output is XLEN, and if the least-significant bit of the input is a 1, the output is 0.
Execution
-
Pruned, XLEN == 64
-
Original
if ((%%LINK%csr_field;misa.B;CSR[misa].B%% == 1'b0)) {
%%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
X[rd] = %%LINK%func;lowest_set_bit;lowest_set_bit%%(X[rs1]);
if (%%LINK%func;implemented?;implemented?%%(ExtensionName::B) && (%%LINK%csr_field;misa.B;CSR[misa].B%% == 1'b0)) {
%%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
if (%%LINK%func;xlen;xlen%%() == 32) {
X[rd] = %%LINK%func;lowest_set_bit;lowest_set_bit%%(X[rs1][31:0]);
} else {
X[rd] = %%LINK%func;lowest_set_bit;lowest_set_bit%%(X[rs1]);
}