base: add 'aligned' function to util/misc_math.h

This function simplifies the sanity checking of values that are expected
to be aligned, e.g., data offsets within packet streams.
This commit is contained in:
Norman Feske
2019-04-05 09:05:35 +02:00
committed by Christian Helmuth
parent 6ea1179145
commit 10c567daee
2 changed files with 8 additions and 13 deletions

View File

@ -26,7 +26,7 @@ namespace Genode {
static constexpr T abs(T value) { return value >= 0 ? value : -value; }
/**
/*
* Alignment to the power of two
*/
template <typename T>
@ -41,6 +41,10 @@ namespace Genode {
static constexpr T align_addr(T addr, int align) {
return (addr + _align_offset((T)align)) & _align_mask((T)align); }
template <typename T>
static constexpr bool aligned(T value, unsigned align_log2) {
return (_align_offset(align_log2) & value) == 0; }
/**
* LOG2