aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-07-10 19:57:54 +0100
committergingerBill <bill@gingerbill.org>2021-07-10 19:57:54 +0100
commit0a61d4bf2b2d6e8c8d0c92410f6dcfd2b6046f86 (patch)
tree35fb694e1128eb3afd4838f5dbee8b9f790cef37 /src
parent332461c0d2703ae6dad4e0fb6812b57ffa92815e (diff)
Use `next_pow2_isize`
Diffstat (limited to 'src')
-rw-r--r--src/common.cpp19
-rw-r--r--src/ptr_set.cpp17
-rw-r--r--src/queue.cpp2
3 files changed, 20 insertions, 18 deletions
diff --git a/src/common.cpp b/src/common.cpp
index 44e0158b3..2591ca068 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -37,6 +37,7 @@ gb_inline void zero_size(void *ptr, isize len) {
i32 next_pow2(i32 n);
i64 next_pow2(i64 n);
+isize next_pow2_isize(isize n);
template <typename U, typename V>
@@ -680,6 +681,24 @@ i64 next_pow2(i64 n) {
n++;
return n;
}
+isize next_pow2_isize(isize n) {
+ if (n <= 0) {
+ return 0;
+ }
+ n--;
+ n |= n >> 1;
+ n |= n >> 2;
+ n |= n >> 4;
+ n |= n >> 8;
+ n |= n >> 16;
+ if (gb_size_of(isize) == 8) {
+ n |= n >> 32;
+ }
+ n++;
+ return n;
+}
+
+
i32 bit_set_count(u32 x) {
x -= ((x >> 1) & 0x55555555);
diff --git a/src/ptr_set.cpp b/src/ptr_set.cpp
index 5432fa094..f12deede8 100644
--- a/src/ptr_set.cpp
+++ b/src/ptr_set.cpp
@@ -32,23 +32,6 @@ template <typename T> void ptr_set_grow (PtrSet<T> *s);
template <typename T> void ptr_set_rehash (PtrSet<T> *s, isize new_count);
-isize next_pow2_isize(isize n) {
- if (n <= 0) {
- return 0;
- }
- n--;
- n |= n >> 1;
- n |= n >> 2;
- n |= n >> 4;
- n |= n >> 8;
- n |= n >> 16;
- if (gb_size_of(isize) == 8) {
- n |= n >> 32;
- }
- n++;
- return n;
-}
-
template <typename T>
void ptr_set_init(PtrSet<T> *s, gbAllocator a, isize capacity) {
capacity = next_pow2_isize(gb_max(16, capacity));
diff --git a/src/queue.cpp b/src/queue.cpp
index 296a21ba3..7087af03e 100644
--- a/src/queue.cpp
+++ b/src/queue.cpp
@@ -28,7 +28,7 @@ struct MPMCQueue {
template <typename T>
void mpmc_init(MPMCQueue<T> *q, gbAllocator a, isize size) {
- size = next_pow2(size);
+ size = next_pow2_isize(size);
GB_ASSERT(gb_is_power_of_two(size));
gb_mutex_init(&q->mutex);