From 570b6b5a7a4509cf659b38ff032eeedb58923db2 Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 21 Jan 2025 20:53:16 -0800 Subject: [PATCH 1/2] slightly better bsf --- include/mimalloc/bits.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/mimalloc/bits.h b/include/mimalloc/bits.h index 5b847f4b..64875e9d 100644 --- a/include/mimalloc/bits.h +++ b/include/mimalloc/bits.h @@ -205,9 +205,8 @@ static inline size_t mi_ctz(size_t x) { #elif mi_has_builtinz(ctz) return (x!=0 ? (size_t)mi_builtinz(ctz)(x) : MI_SIZE_BITS); #elif defined(__GNUC__) && (MI_ARCH_X64 || MI_ARCH_X86) - if (x==0) return MI_SIZE_BITS; - size_t r; - __asm ("bsf\t%1, %0" : "=r"(r) : "r"(x) : "cc"); + size_t r = MI_SIZE_BITS; // bsf leaves destination unmodified if the argument is 0 (see ) + __asm ("bsf\t%1, %0" : "+r"(r) : "r"(x) : "cc"); return r; #elif MI_HAS_FAST_POPCOUNT return (x!=0 ? (mi_popcount(x^(x-1))-1) : MI_SIZE_BITS); From 5946e9cebf8e713fc17d23417cc6c34acf6cd76f Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 21 Jan 2025 20:58:45 -0800 Subject: [PATCH 2/2] fix assert --- include/mimalloc/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index d96cfa4c..01373025 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -789,7 +789,7 @@ static inline void mi_page_set_has_aligned(mi_page_t* page, bool has_aligned) { } static inline void mi_page_set_heap(mi_page_t* page, mi_heap_t* heap) { - mi_assert_internal(!mi_page_is_in_full(page)); + // mi_assert_internal(!mi_page_is_in_full(page)); // can happen when destroying pages on heap_destroy // only the aligned flag is retained (and in particular clear the abandoned-mapped flag). const mi_page_flags_t flags = (mi_page_has_aligned(page) ? MI_PAGE_HAS_ALIGNED : 0); const mi_threadid_t tid = (heap == NULL ? 0 : heap->tld->thread_id) | flags;