mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 23:39:31 +03:00
slightly better bsf
This commit is contained in:
parent
3f6d286a08
commit
570b6b5a7a
1 changed files with 2 additions and 3 deletions
|
@ -205,9 +205,8 @@ static inline size_t mi_ctz(size_t x) {
|
||||||
#elif mi_has_builtinz(ctz)
|
#elif mi_has_builtinz(ctz)
|
||||||
return (x!=0 ? (size_t)mi_builtinz(ctz)(x) : MI_SIZE_BITS);
|
return (x!=0 ? (size_t)mi_builtinz(ctz)(x) : MI_SIZE_BITS);
|
||||||
#elif defined(__GNUC__) && (MI_ARCH_X64 || MI_ARCH_X86)
|
#elif defined(__GNUC__) && (MI_ARCH_X64 || MI_ARCH_X86)
|
||||||
if (x==0) return MI_SIZE_BITS;
|
size_t r = MI_SIZE_BITS; // bsf leaves destination unmodified if the argument is 0 (see <https://github.com/llvm/llvm-project/pull/102885>)
|
||||||
size_t r;
|
__asm ("bsf\t%1, %0" : "+r"(r) : "r"(x) : "cc");
|
||||||
__asm ("bsf\t%1, %0" : "=r"(r) : "r"(x) : "cc");
|
|
||||||
return r;
|
return r;
|
||||||
#elif MI_HAS_FAST_POPCOUNT
|
#elif MI_HAS_FAST_POPCOUNT
|
||||||
return (x!=0 ? (mi_popcount(x^(x-1))-1) : MI_SIZE_BITS);
|
return (x!=0 ? (mi_popcount(x^(x-1))-1) : MI_SIZE_BITS);
|
||||||
|
|
Loading…
Add table
Reference in a new issue