From 0a61d4bf2b2d6e8c8d0c92410f6dcfd2b6046f86 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 10 Jul 2021 19:57:54 +0100 Subject: [PATCH] Use `next_pow2_isize` --- src/common.cpp | 19 +++++++++++++++++++ src/ptr_set.cpp | 17 ----------------- src/queue.cpp | 2 +- 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 @@ -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 void ptr_set_grow (PtrSet *s); template void ptr_set_rehash (PtrSet *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 void ptr_set_init(PtrSet *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 void mpmc_init(MPMCQueue *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);