diff options
Diffstat (limited to 'include/lib/utils_def.h')
-rw-r--r-- | include/lib/utils_def.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/lib/utils_def.h b/include/lib/utils_def.h index b397e302..185a1c12 100644 --- a/include/lib/utils_def.h +++ b/include/lib/utils_def.h @@ -18,6 +18,12 @@ #define BIT(nr) (1ULL << (nr)) +/* + * This variant of div_round_up can be used in macro definition but should not + * be used in C code as the `div` parameter is evaluated twice. + */ +#define DIV_ROUND_UP_2EVAL(n, d) (((n) + (d) - 1) / (d)) + #define MIN(x, y) __extension__ ({ \ __typeof__(x) _x = (x); \ __typeof__(y) _y = (y); \ @@ -49,6 +55,11 @@ #define round_down(value, boundary) \ ((value) & ~round_boundary(value, boundary)) +#define div_round_up(val, div) __extension__ ({ \ + __typeof__(div) _div = (div); \ + round_up((val), _div)/_div; \ +}) + /* * Evaluates to 1 if (ptr + inc) overflows, 0 otherwise. * Both arguments must be unsigned pointer values (i.e. uintptr_t). |