summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2016-12-21 20:33:17 (GMT)
committerJason Evans <jasone@canonware.com>2016-12-23 18:34:34 (GMT)
commitbacb6afc6c5a83c5bf2e5e04a6db99600046e971 (patch)
treedde5a362f85131fe4cfb440c9d565d2c9b0ec5ab /test/unit
parent194d6f9de8ff92841b67f38a2a6a06818e3240dd (diff)
downloadjemalloc-bacb6afc6c5a83c5bf2e5e04a6db99600046e971.zip
jemalloc-bacb6afc6c5a83c5bf2e5e04a6db99600046e971.tar.gz
jemalloc-bacb6afc6c5a83c5bf2e5e04a6db99600046e971.tar.bz2
Simplify arena_slab_regind().
Rewrite arena_slab_regind() to provide sufficient constant data for the compiler to perform division strength reduction. This replaces more general manual strength reduction that was implemented before arena_bin_info was compile-time-constant. It would be possible to slightly improve on the compiler-generated division code by taking advantage of range limits that the compiler doesn't know about.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/slab.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/unit/slab.c b/test/unit/slab.c
new file mode 100644
index 0000000..42e82a8
--- /dev/null
+++ b/test/unit/slab.c
@@ -0,0 +1,35 @@
+#include "test/jemalloc_test.h"
+
+TEST_BEGIN(test_arena_slab_regind)
+{
+ szind_t binind;
+
+ for (binind = 0; binind < NBINS; binind++) {
+ size_t regind;
+ extent_t slab;
+ const arena_bin_info_t *bin_info = &arena_bin_info[binind];
+ extent_init(&slab, NULL, mallocx(bin_info->slab_size,
+ MALLOCX_LG_ALIGN(LG_PAGE)), bin_info->slab_size, 0, 0, true,
+ false, true, true);
+ assert_ptr_not_null(extent_addr_get(&slab),
+ "Unexpected malloc() failure");
+ for (regind = 0; regind < bin_info->nregs; regind++) {
+ void *reg = (void *)((uintptr_t)extent_addr_get(&slab) +
+ (bin_info->reg_size * regind));
+ assert_zu_eq(arena_slab_regind(&slab, binind, reg),
+ regind,
+ "Incorrect region index computed for size %zu",
+ bin_info->reg_size);
+ }
+ free(extent_addr_get(&slab));
+ }
+}
+TEST_END
+
+int
+main(void)
+{
+
+ return (test(
+ test_arena_slab_regind));
+}