From 3794d2417db51ba1e50fa9f3e0d7df973328e6b0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 28 Oct 2021 15:01:13 +0100 Subject: Write a `log(n)` fallback for `llvm_vector_reduce_add` This may be what LLVM does at any rate --- src/common.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/common.cpp') 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; -- cgit v1.2.3