aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2020-12-29 06:37:37 -0800
committerAndrew Waterman <andrew@sifive.com>2020-12-29 06:37:37 -0800
commit9671dc573cbca478c6570771f16ba6741e815fa1 (patch)
tree80dec3dc828514d7e2a44b82799232f570413607
parent29829bb3266866ba2ec742c34857b02a04b5405e (diff)
downloadriscv-isa-sim-9671dc573cbca478c6570771f16ba6741e815fa1.zip
riscv-isa-sim-9671dc573cbca478c6570771f16ba6741e815fa1.tar.gz
riscv-isa-sim-9671dc573cbca478c6570771f16ba6741e815fa1.tar.bz2
Add log2 helper function
-rw-r--r--riscv/arith.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/riscv/arith.h b/riscv/arith.h
index 72bb515..b900e27 100644
--- a/riscv/arith.h
+++ b/riscv/arith.h
@@ -166,4 +166,12 @@ static inline int clz(uint64_t val)
return res;
}
+static inline int log2(uint64_t val)
+{
+ if (!val)
+ return 0;
+
+ return 63 - clz(val);
+}
+
#endif