aboutsummaryrefslogtreecommitdiff
path: root/src/common.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-10-28 15:01:13 +0100
committergingerBill <bill@gingerbill.org>2021-10-28 15:01:13 +0100
commit3794d2417db51ba1e50fa9f3e0d7df973328e6b0 (patch)
tree50e9b1ce0626bcabb240a551aa6ab5568feec679 /src/common.cpp
parent70793236abc278dd51ca577b35ca1757851380d3 (diff)
Write a `log(n)` fallback for `llvm_vector_reduce_add`
This may be what LLVM does at any rate
Diffstat (limited to 'src/common.cpp')
-rw-r--r--src/common.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/common.cpp b/src/common.cpp
index bebae6ab3..7af7026b9 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -443,7 +443,17 @@ u64 ceil_log2(u64 x) {
return cast(u64)(bit_set_count(x) - 1 - y);
}
-
+u32 prev_pow2(u32 n) {
+ if (n == 0) {
+ return 0;
+ }
+ n |= n >> 1;
+ n |= n >> 2;
+ n |= n >> 4;
+ n |= n >> 8;
+ n |= n >> 16;
+ return n - (n >> 1);
+}
i32 prev_pow2(i32 n) {
if (n <= 0) {
return 0;