diff options
author | YenHaoChen <howard25336284@gmail.com> | 2022-10-20 16:02:12 +0800 |
---|---|---|
committer | Andrew Waterman <aswaterman@gmail.com> | 2022-10-20 01:27:41 -0700 |
commit | e8340aedc84cc9daee1f66e718a4b4a887cb8749 (patch) | |
tree | 6d021fbd8aeecbd2d4ba7b470258f025537c3b67 /riscv/arith.h | |
parent | 2e12d7251e00778c50552d53dd0d61edb990ab3b (diff) | |
download | riscv-isa-sim-e8340aedc84cc9daee1f66e718a4b4a887cb8749.zip riscv-isa-sim-e8340aedc84cc9daee1f66e718a4b4a887cb8749.tar.gz riscv-isa-sim-e8340aedc84cc9daee1f66e718a4b4a887cb8749.tar.bz2 |
move fucntion cto() from processor.h to arith.h
Only triggers.cc uses the arithmetic function cto(). Instead of putting
the cto() in processor.h, putting it in arith.h with other arithmetic
functions, e.g., ctz() and clz(), makes more sense.
Diffstat (limited to 'riscv/arith.h')
-rw-r--r-- | riscv/arith.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/riscv/arith.h b/riscv/arith.h index 9e0c2f7..13c525a 100644 --- a/riscv/arith.h +++ b/riscv/arith.h @@ -188,6 +188,15 @@ static inline int clz(uint64_t val) return res; } +// Count number of contiguous 1 bits starting from the LSB. +static inline int cto(uint64_t val) +{ + int res = 0; + while ((val & 1) == 1) + val >>= 1, res++; + return res; +} + static inline int log2(uint64_t val) { if (!val) |