Fix fallback lg_floor() implementations.

This commit is contained in:
Jason Evans 2014-06-01 22:05:08 -07:00
parent 6f6704c35b
commit 0b5c92213f

View File

@ -152,9 +152,9 @@ lg_floor(size_t x)
{ {
#if (LG_SIZEOF_PTR == LG_SIZEOF_INT) #if (LG_SIZEOF_PTR == LG_SIZEOF_INT)
return ((8 << LG_SIZEOF_PTR - 1) - __builtin_clz(x)); return (((8 << LG_SIZEOF_PTR) - 1) - __builtin_clz(x));
#elif (LG_SIZEOF_PTR == LG_SIZEOF_LONG) #elif (LG_SIZEOF_PTR == LG_SIZEOF_LONG)
return ((8 << LG_SIZEOF_PTR - 1) - __builtin_clzl(x)); return (((8 << LG_SIZEOF_PTR) - 1) - __builtin_clzl(x));
#else #else
# error "Unsupported type sizes for lg_floor()" # error "Unsupported type sizes for lg_floor()"
#endif #endif
@ -164,16 +164,22 @@ JEMALLOC_INLINE size_t
lg_floor(size_t x) lg_floor(size_t x)
{ {
x |= (x >> 1); x |= (x >> 1);
x |= (x >> 2); x |= (x >> 2);
x |= (x >> 4); x |= (x >> 4);
x |= (x >> 8); x |= (x >> 8);
x |= (x >> 16); x |= (x >> 16);
#if (LG_SIZEOF_PTR == 3 && LG_SIZEOF_PTR == LG_SIZEOF_LONG) #if (LG_SIZEOF_PTR == 3 && LG_SIZEOF_PTR == LG_SIZEOF_LONG)
x |= (x >> 32); x |= (x >> 32);
return (65 - ffsl(~x)); if (x == KZU(0xffffffffffffffff))
return (63);
x++;
return (ffsl(x) - 2);
#elif (LG_SIZEOF_PTR == 2) #elif (LG_SIZEOF_PTR == 2)
return (33 - ffs(~x)); if (x == KZU(0xffffffff))
return (31);
x++;
return (ffs(x) - 2);
#else #else
# error "Unsupported type sizes for lg_floor()" # error "Unsupported type sizes for lg_floor()"
#endif #endif