Update to use a more efficient power of 2 check. (#274)

This commit is contained in:
Matthew Parkinson
2021-01-27 11:58:41 +00:00
committed by GitHub
parent db3580a9d8
commit a3660c4069
10 changed files with 21 additions and 18 deletions

View File

@@ -76,8 +76,7 @@ namespace snmalloc
static constexpr size_t OS_PAGE_SIZE = Pal::page_size;
static_assert(
bits::next_pow2_const(OS_PAGE_SIZE) == OS_PAGE_SIZE,
"OS_PAGE_SIZE must be a power of two");
bits::is_pow2(OS_PAGE_SIZE), "OS_PAGE_SIZE must be a power of two");
static_assert(
OS_PAGE_SIZE % Aal::smallest_page_size == 0,
"The smallest architectural page size must divide OS_PAGE_SIZE");

View File

@@ -32,7 +32,7 @@ namespace snmalloc
static void* reserve_aligned(size_t size) noexcept
{
// Alignment must be a power of 2.
SNMALLOC_ASSERT(size == bits::next_pow2(size));
SNMALLOC_ASSERT(bits::is_pow2(size));
SNMALLOC_ASSERT(size >= minimum_alloc_size);
size_t log2align = bits::next_pow2_bits(size);

View File

@@ -62,7 +62,7 @@ namespace snmalloc
template<bool committed>
static void* reserve_aligned(size_t size) noexcept
{
SNMALLOC_ASSERT(size == bits::next_pow2(size));
SNMALLOC_ASSERT(bits::is_pow2(size));
SNMALLOC_ASSERT(size >= minimum_alloc_size);
size_t align = size;

View File

@@ -212,7 +212,7 @@ namespace snmalloc
*/
static std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
{
SNMALLOC_ASSERT(size == bits::next_pow2(size));
SNMALLOC_ASSERT(bits::is_pow2(size));
// Magic number for over-allocating chosen by the Pal
// These should be further refined based on experiments.

View File

@@ -185,7 +185,7 @@ namespace snmalloc
template<bool committed>
static void* reserve_aligned(size_t size) noexcept
{
SNMALLOC_ASSERT(size == bits::next_pow2(size));
SNMALLOC_ASSERT(bits::is_pow2(size));
SNMALLOC_ASSERT(size >= minimum_alloc_size);
DWORD flags = MEM_RESERVE;
@@ -215,7 +215,7 @@ namespace snmalloc
# else
static std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
{
SNMALLOC_ASSERT(size == bits::next_pow2(size));
SNMALLOC_ASSERT(bits::is_pow2(size));
// Magic number for over-allocating chosen by the Pal
// These should be further refined based on experiments.