mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 05:08:14 +00:00
Use next_pow2_isize
This commit is contained in:
@@ -37,6 +37,7 @@ gb_inline void zero_size(void *ptr, isize len) {
|
|||||||
|
|
||||||
i32 next_pow2(i32 n);
|
i32 next_pow2(i32 n);
|
||||||
i64 next_pow2(i64 n);
|
i64 next_pow2(i64 n);
|
||||||
|
isize next_pow2_isize(isize n);
|
||||||
|
|
||||||
|
|
||||||
template <typename U, typename V>
|
template <typename U, typename V>
|
||||||
@@ -680,6 +681,24 @@ i64 next_pow2(i64 n) {
|
|||||||
n++;
|
n++;
|
||||||
return 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) {
|
i32 bit_set_count(u32 x) {
|
||||||
x -= ((x >> 1) & 0x55555555);
|
x -= ((x >> 1) & 0x55555555);
|
||||||
|
|||||||
@@ -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);
|
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>
|
template <typename T>
|
||||||
void ptr_set_init(PtrSet<T> *s, gbAllocator a, isize capacity) {
|
void ptr_set_init(PtrSet<T> *s, gbAllocator a, isize capacity) {
|
||||||
capacity = next_pow2_isize(gb_max(16, capacity));
|
capacity = next_pow2_isize(gb_max(16, capacity));
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ struct MPMCQueue {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void mpmc_init(MPMCQueue<T> *q, gbAllocator a, isize size) {
|
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_ASSERT(gb_is_power_of_two(size));
|
||||||
|
|
||||||
gb_mutex_init(&q->mutex);
|
gb_mutex_init(&q->mutex);
|
||||||
|
|||||||
Reference in New Issue
Block a user