Skip to content

Commit 1a83817

Browse files
authored
Fix incorrect use of clz (#8)
* fix incorrect use of clz when input is 0 * don't force use of native arch when building
1 parent dcecae9 commit 1a83817

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

simple_pool/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ add_compile_options(
1919
-Wimplicit-fallthrough
2020
-Wundef
2121
-Wfloat-equal
22-
-march=native
2322
-fPIE
2423
-fno-omit-frame-pointer
2524
)

simple_pool/dyn_mem_pool.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ void multipool_free(struct MultiPool* multipool) {
313313
uint32_t find_multipool_index_for_size(uint32_t size) {
314314
static const uint32_t int32bitcount = sizeof(uint32_t) * CHAR_BIT;
315315
uint32_t size_value = (size - 1) >>DynPoolMinMultiPoolMemNodeSizeBits;
316+
if( __builtin_expect(size_value == 0, 0)) {
317+
return 0;
318+
}
316319
return (int32bitcount - (uint32_t)__builtin_clz(size_value));
317320
}
318321

0 commit comments

Comments
 (0)