hw: provide 'bool aligned' function in util.h

ref #474
This commit is contained in:
Martin Stein 2014-08-05 21:19:59 +02:00 committed by Norman Feske
parent d48d0e7b43
commit e686aee5f9
1 changed files with 16 additions and 3 deletions

View File

@ -67,10 +67,23 @@ namespace Genode
/**
* Round down to a specific alignment
* Return an address rounded down to a specific alignment
*
* \param addr original address
* \param alignm_log2 log2 of the required alignment
*/
inline addr_t trunc(addr_t const addr, unsigned const alignm_log2)
{ return addr & ~((1 << alignm_log2) - 1); }
inline addr_t trunc(addr_t const addr, addr_t const alignm_log2) {
return (addr >> alignm_log2) << alignm_log2; }
/**
* Return wether a pointer fullfills an alignment
*
* \param p pointer
* \param alignm_log2 log2 of the required alignment
*/
inline bool aligned(void * const p, addr_t const alignm_log2) {
return (addr_t)p == trunc((addr_t)p, alignm_log2); }
/**