0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::buffer: Add pointer alignment check tool to suite.

This commit is contained in:
Jason Volk 2020-07-09 17:06:26 -07:00
parent dd8a4b812f
commit 60d2f04c14

View file

@ -61,6 +61,7 @@ namespace ircd::buffer
// Misc utils
constexpr size_t padding(const size_t &size, const size_t &alignment);
constexpr size_t pad_to(const size_t &size, const size_t &alignment);
bool aligned(const void *const &, const size_t &alignment);
// Single buffer iteration of contents
template<class it> const it &begin(const buffer<it> &buffer);
@ -329,7 +330,7 @@ ircd::buffer::aligned(const buffer<it> &buffer,
const size_t &a)
{
return likely(a)?
uintptr_t(data(buffer)) % a == 0 && padded(buffer, a):
aligned(data(buffer), a) && padded(buffer, a):
true;
}
@ -442,6 +443,13 @@ ircd::buffer::begin(const buffer<it> &buffer)
return get<0>(buffer);
}
inline bool
ircd::buffer::aligned(const void *const &ptr,
const size_t &alignment)
{
return uintptr_t(ptr) % alignment == 0;
}
constexpr size_t
ircd::buffer::pad_to(const size_t &size,
const size_t &alignment)