Yes, we already have roundup/rounddown. Unlike these macros round_up/round_down are optimized to (and only work with) power-of-2 arguments. It's a poor name, but kernel code needs it, so add it to barebox aswell. Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- include/linux/kernel.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 4322f01..b90d8f7 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -5,6 +5,19 @@ #include <linux/barebox-wrapper.h> /* + * This looks more complex than it should be. But we need to + * get the type for the ~ right in round_down (it needs to be + * as wide as the result!), and we want to evaluate the macro + * arguments just once each. + * + * NOTE these functions only round to power-of-2 arguments. Use + * roundup/rounddown for non power-of-2-arguments. + */ +#define __round_mask(x, y) ((__typeof__(x))((y)-1)) +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) +#define round_down(x, y) ((x) & ~__round_mask(x, y)) + +/* * min()/max()/clamp() macros that also do * strict type-checking.. See the * "unnecessary" pointer comparison. -- 2.0.1 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox