Move to AAL/PAL bits and address_bits
This commit is contained in:
committed by
Nathaniel Wesley Filardo
parent
e212ddd0e0
commit
15e3052087
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T>(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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user