summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2016-02-24 18:32:45 (GMT)
committerJason Evans <je@fb.com>2016-02-24 21:03:48 (GMT)
commit9f4ee6034c3ac6a8c8b5f9a0d76822fb2fd90c41 (patch)
tree9c54e3e9e3d7048498aea9cde2e0839c8409a27f
parentb41a07c31a53cb91729f69b4a23e3a8801ee9846 (diff)
downloadjemalloc-9f4ee6034c3ac6a8c8b5f9a0d76822fb2fd90c41.zip
jemalloc-9f4ee6034c3ac6a8c8b5f9a0d76822fb2fd90c41.tar.gz
jemalloc-9f4ee6034c3ac6a8c8b5f9a0d76822fb2fd90c41.tar.bz2
Refactor jemalloc_ffs*() into ffs_*().
Use appropriate versions to resolve 64-to-32-bit data loss warnings.
-rw-r--r--include/jemalloc/internal/arena.h2
-rw-r--r--include/jemalloc/internal/bitmap.h4
-rw-r--r--include/jemalloc/internal/jemalloc_internal_defs.h.in2
-rw-r--r--include/jemalloc/internal/private_symbols.txt9
-rw-r--r--include/jemalloc/internal/prng.h2
-rw-r--r--include/jemalloc/internal/util.h86
-rw-r--r--src/arena.c3
-rw-r--r--src/chunk.c2
8 files changed, 70 insertions, 40 deletions
diff --git a/include/jemalloc/internal/arena.h b/include/jemalloc/internal/arena.h
index 05800e4..165fb52 100644
--- a/include/jemalloc/internal/arena.h
+++ b/include/jemalloc/internal/arena.h
@@ -1099,7 +1099,7 @@ arena_run_regind(arena_run_t *run, arena_bin_info_t *bin_info, const void *ptr)
/* Rescale (factor powers of 2 out of the numerator and denominator). */
interval = bin_info->reg_interval;
- shift = jemalloc_ffs(interval) - 1;
+ shift = ffs_zu(interval) - 1;
diff >>= shift;
interval >>= shift;
diff --git a/include/jemalloc/internal/bitmap.h b/include/jemalloc/internal/bitmap.h
index fcc6005..c14e716 100644
--- a/include/jemalloc/internal/bitmap.h
+++ b/include/jemalloc/internal/bitmap.h
@@ -176,11 +176,11 @@ bitmap_sfu(bitmap_t *bitmap, const bitmap_info_t *binfo)
i = binfo->nlevels - 1;
g = bitmap[binfo->levels[i].group_offset];
- bit = jemalloc_ffsl(g) - 1;
+ bit = ffs_lu(g) - 1;
while (i > 0) {
i--;
g = bitmap[binfo->levels[i].group_offset + bit];
- bit = (bit << LG_BITMAP_GROUP_NBITS) + (jemalloc_ffsl(g) - 1);
+ bit = (bit << LG_BITMAP_GROUP_NBITS) + (ffs_lu(g) - 1);
}
bitmap_set(bitmap, binfo, bit);
diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in
index 4bcda71..2c75371 100644
--- a/include/jemalloc/internal/jemalloc_internal_defs.h.in
+++ b/include/jemalloc/internal/jemalloc_internal_defs.h.in
@@ -190,7 +190,7 @@
/*
* ffs*() functions to use for bitmapping. Don't use these directly; instead,
- * use jemalloc_ffs*() from util.h.
+ * use ffs_*() from util.h.
*/
#undef JEMALLOC_INTERNAL_FFSLL
#undef JEMALLOC_INTERNAL_FFSL
diff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt
index 761aa75..adab8a5 100644
--- a/include/jemalloc/internal/private_symbols.txt
+++ b/include/jemalloc/internal/private_symbols.txt
@@ -243,6 +243,12 @@ extent_tree_szad_reverse_iter
extent_tree_szad_reverse_iter_recurse
extent_tree_szad_reverse_iter_start
extent_tree_szad_search
+ffs_llu
+ffs_lu
+ffs_u
+ffs_u32
+ffs_u64
+ffs_zu
get_errno
hash
hash_fmix_32
@@ -292,9 +298,6 @@ isqalloc
isthreaded
ivsalloc
ixalloc
-jemalloc_ffs
-jemalloc_ffs64
-jemalloc_ffsl
jemalloc_postfork_child
jemalloc_postfork_parent
jemalloc_prefork
diff --git a/include/jemalloc/internal/prng.h b/include/jemalloc/internal/prng.h
index 44d67c9..5830f8b 100644
--- a/include/jemalloc/internal/prng.h
+++ b/include/jemalloc/internal/prng.h
@@ -64,7 +64,7 @@ prng_range(uint64_t *state, uint64_t range)
assert(range > 1);
/* Compute the ceiling of lg(range). */
- lg_range = jemalloc_ffs64(pow2_ceil_u64(range)) - 1;
+ lg_range = ffs_u64(pow2_ceil_u64(range)) - 1;
/* Generate a result in [0..range) via repeated trial. */
do {
diff --git a/include/jemalloc/internal/util.h b/include/jemalloc/internal/util.h
index 39f7087..46d47df 100644
--- a/include/jemalloc/internal/util.h
+++ b/include/jemalloc/internal/util.h
@@ -121,9 +121,12 @@ void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
#ifdef JEMALLOC_H_INLINES
#ifndef JEMALLOC_ENABLE_INLINE
-int jemalloc_ffs64(uint64_t bitmap);
-int jemalloc_ffsl(long bitmap);
-int jemalloc_ffs(int bitmap);
+unsigned ffs_llu(unsigned long long bitmap);
+unsigned ffs_lu(unsigned long bitmap);
+unsigned ffs_u(unsigned bitmap);
+unsigned ffs_zu(size_t bitmap);
+unsigned ffs_u64(uint64_t bitmap);
+unsigned ffs_u32(uint32_t bitmap);
uint64_t pow2_ceil_u64(uint64_t x);
uint32_t pow2_ceil_u32(uint32_t x);
size_t pow2_ceil_zu(size_t x);
@@ -140,33 +143,65 @@ int get_errno(void);
# error JEMALLOC_INTERNAL_FFS{,L,LL} should have been defined by configure
#endif
-JEMALLOC_ALWAYS_INLINE int
-jemalloc_ffs64(uint64_t bitmap)
+JEMALLOC_ALWAYS_INLINE unsigned
+ffs_llu(unsigned long long bitmap)
{
-#if LG_SIZEOF_LONG == 3
- return (JEMALLOC_INTERNAL_FFSL(bitmap));
-#elif LG_SIZEOF_LONG_LONG == 3
return (JEMALLOC_INTERNAL_FFSLL(bitmap));
-#else
-#error No implementation for 64-bit ffs()
-#endif
}
-JEMALLOC_ALWAYS_INLINE int
-jemalloc_ffsl(long bitmap)
+JEMALLOC_ALWAYS_INLINE unsigned
+ffs_lu(unsigned long bitmap)
{
return (JEMALLOC_INTERNAL_FFSL(bitmap));
}
-JEMALLOC_ALWAYS_INLINE int
-jemalloc_ffs(int bitmap)
+JEMALLOC_ALWAYS_INLINE unsigned
+ffs_u(unsigned bitmap)
{
return (JEMALLOC_INTERNAL_FFS(bitmap));
}
+JEMALLOC_ALWAYS_INLINE unsigned
+ffs_zu(size_t bitmap)
+{
+
+#if LG_SIZEOF_PTR == LG_SIZEOF_LONG
+ return (ffs_lu(bitmap));
+#elif LG_SIZEOF_PTR == LG_SIZEOF_INT
+ return (ffs_u(bitmap));
+#else
+#error No implementation for size_t ffs()
+#endif
+}
+
+JEMALLOC_ALWAYS_INLINE unsigned
+ffs_u64(uint64_t bitmap)
+{
+
+#if LG_SIZEOF_LONG == 3
+ return (ffs_lu(bitmap));
+#elif LG_SIZEOF_LONG_LONG == 3
+ return (ffs_llu(bitmap));
+#else
+#error No implementation for 64-bit ffs()
+#endif
+}
+
+JEMALLOC_ALWAYS_INLINE unsigned
+ffs_u32(uint32_t bitmap)
+{
+
+#if LG_SIZEOF_INT == 2
+ return (ffs_u(bitmap));
+#else
+#error No implementation for 32-bit ffs()
+#endif
+ return (ffs_u(bitmap));
+}
+
JEMALLOC_INLINE uint64_t
pow2_ceil_u64(uint64_t x)
{
@@ -235,7 +270,7 @@ lg_floor(size_t x)
#elif (LG_SIZEOF_PTR == 2)
_BitScanReverse(&ret, x);
#else
-# error "Unsupported type sizes for lg_floor()"
+# error "Unsupported type size for lg_floor()"
#endif
return (ret);
}
@@ -251,7 +286,7 @@ lg_floor(size_t x)
#elif (LG_SIZEOF_PTR == LG_SIZEOF_LONG)
return (((8 << LG_SIZEOF_PTR) - 1) - __builtin_clzl(x));
#else
-# error "Unsupported type sizes for lg_floor()"
+# error "Unsupported type size for lg_floor()"
#endif
}
#else
@@ -266,20 +301,13 @@ lg_floor(size_t x)
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
-#if (LG_SIZEOF_PTR == 3 && LG_SIZEOF_PTR == LG_SIZEOF_LONG)
+#if (LG_SIZEOF_PTR == 3)
x |= (x >> 32);
- if (x == KZU(0xffffffffffffffff))
- return (63);
- x++;
- return (jemalloc_ffsl(x) - 2);
-#elif (LG_SIZEOF_PTR == 2)
- if (x == KZU(0xffffffff))
- return (31);
- x++;
- return (jemalloc_ffs(x) - 2);
-#else
-# error "Unsupported type sizes for lg_floor()"
#endif
+ if (x == SIZE_T_MAX)
+ return ((8 << LG_SIZEOF_PTR) - 1);
+ x++;
+ return (ffs_zu(x) - 2);
}
#endif
diff --git a/src/arena.c b/src/arena.c
index ec81336..7b065d6 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -3391,8 +3391,7 @@ bin_info_run_size_calc(arena_bin_info_t *bin_info)
* be twice as large in order to maintain alignment.
*/
if (config_fill && unlikely(opt_redzone)) {
- size_t align_min = ZU(1) << (jemalloc_ffs(bin_info->reg_size) -
- 1);
+ size_t align_min = ZU(1) << (ffs_zu(bin_info->reg_size) - 1);
if (align_min <= REDZONE_MINSIZE) {
bin_info->redzone_size = REDZONE_MINSIZE;
pad_size = 0;
diff --git a/src/chunk.c b/src/chunk.c
index 6ba1ca7..3d32a40 100644
--- a/src/chunk.c
+++ b/src/chunk.c
@@ -716,7 +716,7 @@ chunk_boot(void)
* so pages_map will always take fast path.
*/
if (!opt_lg_chunk) {
- opt_lg_chunk = jemalloc_ffs((int)info.dwAllocationGranularity)
+ opt_lg_chunk = ffs_u((unsigned)info.dwAllocationGranularity)
- 1;
}
#else