From: arighi Date: Thu, 30 Sep 2010 14:15:13 +0000 (+0000) Subject: Introduce ALIGN_UP() macro X-Git-Tag: 2.6.0~15 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=2045959d176e3584849c9bd67728317922604265;p=bertos.git Introduce ALIGN_UP() macro Add a generic macro to align a value to the next alignment boundary. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4386 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/macros.h b/bertos/cfg/macros.h index d0ccf433..3ec6b277 100644 --- a/bertos/cfg/macros.h +++ b/bertos/cfg/macros.h @@ -94,6 +94,11 @@ #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* !(COMPILER_STATEMENT_EXPRESSIONS && COMPILER_TYPEOF) */ +/** Align \p value to the next \p align boundary */ +#define ALIGN_UP(value, align) (((value) & ((align) - 1)) ? \ + (((value) + ((align) - 1)) & ~((align) - 1)) : \ + (value)) + /** Bound \a x between \a min and \a max. */ #define MINMAX(min,x,max) (MIN(MAX(min, x), max))