Move bits::is_aligned_block to address.h

And chase consequences
This commit is contained in:
Nathaniel Filardo
2019-11-12 15:12:48 +00:00
parent 261249d9cb
commit 20e804728b
9 changed files with 34 additions and 28 deletions

View File

@@ -1,4 +1,7 @@
#pragma once
#include "bits.h"
#include <cassert>
#include <cstdint>
namespace snmalloc
@@ -39,4 +42,18 @@ namespace snmalloc
{
return reinterpret_cast<T*>(address);
}
/**
* Test if a pointer is aligned to a given size, which must be a power of
* two.
*/
template<size_t alignment>
static inline bool is_aligned_block(void* p, size_t size)
{
static_assert(bits::next_pow2_const(alignment) == alignment);
return ((static_cast<size_t>(address_cast(p)) | size) & (alignment - 1)) ==
0;
}
} // namespace snmalloc

View File

@@ -6,7 +6,6 @@
// #define USE_LZCNT
#include "../aal/aal.h"
#include "address.h"
#include "defines.h"
#include <atomic>
@@ -240,15 +239,6 @@ namespace snmalloc
return value;
}
template<size_t alignment>
static inline bool is_aligned_block(void* p, size_t size)
{
assert(next_pow2(alignment) == alignment);
return ((static_cast<size_t>(address_cast(p)) | size) &
(alignment - 1)) == 0;
}
/************************************************
*
* Map large range of strictly positive integers