ISARef Multi-ISA & Silicon Reference
45,419 ISA items · 105,907 timings · 1,823 microarchs · 16,083 chips · 105 sources
Arch:
Tier:

ctz

T1 riscv bitmanip insn
Count trailing zero bits
SourceRISC-V Official Unified Database (riscv-unified-db) (riscv_unified_db)
Reliability TierT1 — Official Specification
ISA / Silicon ScopeRV32/RV64 Zbb
RV32 / RV64 (Ratified & Standard Extensions)
License & VersionApache-2.0 / CC-BY-4.0
main
Upstreamhttps://github.com/riscv/riscv-unified-db
Privilegeuser
ExtensionsZbb

Summary

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.

Syntax / Encoding

ctz xd, xs1 | 011000000001xxxxx001xxxxx0010011 (mask=0xfff0707f match=0x60101013)

Cross-Chip Latency & Throughput (11 cores)

MicroarchitectureLatency (cycles)Recip. TPuopsPortsSource
SiFive P670 / P60010.251SiFiveP600IntArithllvm_sched_models
SiFive P870 / P80010.251SiFiveP800IntArithllvm_sched_models
SpacemiT X10010.251SMTX100_IQllvm_sched_models
SpacemiT X60 (K1)10.51SMX60_IEUllvm_sched_models
Syntacore SCR7111BMUllvm_sched_models
Tenstorrent Ascalon-X111AscalonFXllvm_sched_models
MIPS P8700 (RISC-V)211p8700IssueAL2llvm_sched_models
Andes 45-Series30.51Andes45ALUllvm_sched_models
SiFive 7-Series (U74)311PipeBllvm_sched_models
XiangShan KunMingHu30.51XSPipeGroupBKUllvm_sched_models
XiangShan NanHu30.51XS2MDUllvm_sched_models

Binary Encodings (1)

WidthFormatBit PatternMask / Match
32RV011000000001xxxxx001xxxxx00100110xfff0707f / 0x60101013

Operands

NameDescription
xs1bits [19:15]
xdbits [11:7]

Reference Notes

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.