mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd::util: Add alignment gauge to suite.
This commit is contained in:
parent
736c8014dd
commit
6827994a62
1 changed files with 15 additions and 0 deletions
|
@ -21,6 +21,7 @@ inline namespace util
|
|||
constexpr size_t pad_to(const size_t size, const size_t alignment);
|
||||
constexpr uintptr_t align(uintptr_t, size_t alignment);
|
||||
constexpr uintptr_t align_up(uintptr_t, size_t alignment);
|
||||
constexpr ulong alignment(const uintptr_t);
|
||||
|
||||
// Alignment inline tools
|
||||
bool aligned(const void *const &, const size_t &alignment);
|
||||
|
@ -29,8 +30,16 @@ inline namespace util
|
|||
template<class T = char> T *align(void *const &, const size_t &alignment);
|
||||
template<class T = char> const T *align_up(const void *const &, const size_t &alignment);
|
||||
template<class T = char> T *align_up(void *const &, const size_t &alignment);
|
||||
ulong alignment(const void *const &);
|
||||
}}
|
||||
|
||||
[[gnu::always_inline]]
|
||||
inline ulong
|
||||
ircd::util::alignment(const void *const &ptr)
|
||||
{
|
||||
return alignment(uintptr_t(ptr));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
[[gnu::always_inline]]
|
||||
inline T *
|
||||
|
@ -95,6 +104,12 @@ ircd::util::aligned(const volatile void *const &ptr,
|
|||
return aligned(uintptr_t(ptr), alignment);
|
||||
}
|
||||
|
||||
constexpr ulong
|
||||
ircd::util::alignment(const uintptr_t ptr)
|
||||
{
|
||||
return 1UL << __builtin_ctzl(ptr);
|
||||
}
|
||||
|
||||
constexpr uintptr_t
|
||||
ircd::util::align_up(uintptr_t ptr,
|
||||
size_t alignment)
|
||||
|
|
Loading…
Reference in a new issue