mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-17 14:48:20 +00:00
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:
committed by
Christian Helmuth
parent
6ea1179145
commit
10c567daee
@ -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
|
||||
|
Reference in New Issue
Block a user