diff --git a/src/backend/pagemap.h b/src/backend/pagemap.h index 7a794c1..c3e5667 100644 --- a/src/backend/pagemap.h +++ b/src/backend/pagemap.h @@ -83,7 +83,7 @@ namespace snmalloc { static_assert( has_bounds_ == has_bounds, "Don't set SFINAE template parameter!"); - constexpr size_t COVERED_BITS = bits::ADDRESS_BITS - GRANULARITY_BITS; + constexpr size_t COVERED_BITS = PAL::address_bits - GRANULARITY_BITS; constexpr size_t ENTRIES = bits::one_at_bit(COVERED_BITS); return ENTRIES * sizeof(T); } @@ -204,7 +204,7 @@ namespace snmalloc } else { - return bits::one_at_bit(bits::ADDRESS_BITS - GRANULARITY_BITS); + return bits::one_at_bit(PAL::address_bits - GRANULARITY_BITS); } } diff --git a/src/ds/bits.h b/src/ds/bits.h index 20e1b4f..455ec4a 100644 --- a/src/ds/bits.h +++ b/src/ds/bits.h @@ -30,12 +30,7 @@ namespace snmalloc namespace bits { - static constexpr size_t BITS = sizeof(size_t) * 8; - - static constexpr bool is64() - { - return BITS == 64; - } + static constexpr size_t BITS = Aal::bits; /** * Returns a value of type T that has a single bit set, @@ -52,8 +47,6 @@ namespace snmalloc return (static_cast(1)) << shift; } - static constexpr size_t ADDRESS_BITS = is64() ? 48 : 32; - inline SNMALLOC_FAST_PATH size_t clz(size_t x) { SNMALLOC_ASSERT(x != 0); // Calling with 0 is UB on some implementations diff --git a/src/mem/sizeclasstable.h b/src/mem/sizeclasstable.h index 3e08c44..c406ac1 100644 --- a/src/mem/sizeclasstable.h +++ b/src/mem/sizeclasstable.h @@ -41,7 +41,7 @@ namespace snmalloc // Large classes range from [SUPERSLAB, ADDRESS_SPACE).// TODO static constexpr size_t NUM_LARGE_CLASSES = - bits::ADDRESS_BITS - MAX_SIZECLASS_BITS; + Pal::address_bits - MAX_SIZECLASS_BITS; inline SNMALLOC_FAST_PATH static size_t aligned_size(size_t alignment, size_t size) @@ -179,7 +179,7 @@ namespace snmalloc auto rsize = sizeclass_to_size(sc); - if constexpr (bits::is64()) + if constexpr (sizeof(offset) >= 8) { // Only works for 64 bit multiplication, as the following will overflow in // 32bit. @@ -192,6 +192,10 @@ namespace snmalloc // SUPERSLAB_BITS <= 24, "The following code assumes max of 24 bits"); // TODO 24 hack + static_assert(bits::BITS >= 24, "About to attempt a negative shift"); + static_assert( + (8 * sizeof(offset)) >= (bits::BITS - 24), + "About to shift further than the type"); return (((offset >> MIN_ALLOC_BITS) * sizeclass_metadata.fast[sc].div_mult) >> (bits::BITS - 24)) * @@ -209,7 +213,7 @@ namespace snmalloc // SUPERSLAB_SIZE. // SNMALLOC_ASSERT(offset <= SUPERSLAB_SIZE); - if constexpr (bits::is64()) + if constexpr (sizeof(offset) >= 8) { // Only works for 64 bit multiplication, as the following will overflow in // 32bit. @@ -219,6 +223,7 @@ namespace snmalloc // square of the offset to be representable. // TODO 24 hack. Redo the maths given the multiple // slab sizes + static_assert(bits::BITS >= 25); static constexpr size_t MASK = ~(bits::one_at_bit(bits::BITS - 1 - 24) - 1); diff --git a/src/mem/slaballocator.h b/src/mem/slaballocator.h index f714c07..5c91b44 100644 --- a/src/mem/slaballocator.h +++ b/src/mem/slaballocator.h @@ -24,7 +24,7 @@ namespace snmalloc /** * How many slab sizes that can be provided. */ - constexpr size_t NUM_SLAB_SIZES = bits::ADDRESS_BITS - MIN_CHUNK_BITS; + constexpr size_t NUM_SLAB_SIZES = Pal::address_bits - MIN_CHUNK_BITS; /** * Used to ensure the per slab meta data is large enough for both use cases. diff --git a/src/test/func/memory/memory.cc b/src/test/func/memory/memory.cc index cf65096..a0daef7 100644 --- a/src/test/func/memory/memory.cc +++ b/src/test/func/memory/memory.cc @@ -292,7 +292,7 @@ void test_external_pointer_large() auto& alloc = ThreadAlloc::get(); - constexpr size_t count_log = snmalloc::bits::is64() ? 5 : 3; + constexpr size_t count_log = Pal::address_bits > 32 ? 5 : 3; constexpr size_t count = 1 << count_log; // Pre allocate all the objects size_t* objects[count]; diff --git a/src/test/perf/external_pointer/externalpointer.cc b/src/test/perf/external_pointer/externalpointer.cc index 6a8616d..e2fdb06 100644 --- a/src/test/perf/external_pointer/externalpointer.cc +++ b/src/test/perf/external_pointer/externalpointer.cc @@ -19,7 +19,7 @@ namespace test { size_t rand = (size_t)r.next(); size_t offset = bits::clz(rand); - if constexpr (bits::is64()) + if constexpr (Pal::address_bits > 32) { if (offset > 30) offset = 30;