diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-07-10 09:12:02 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-07-17 07:45:55 +0200 |
commit | 77bd64d1fd37704bbd9e78b10b3847381299889a (patch) | |
tree | e571abe5c7b58001d575df8609c0776aebc7f7f2 /include | |
parent | 36d837d791c52f28565325d30494118de65986ce (diff) | |
download | barebox-77bd64d1fd37704bbd9e78b10b3847381299889a.tar.gz barebox-77bd64d1fd37704bbd9e78b10b3847381299889a.tar.xz |
include: Add round_up/round_down macros from kernel
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@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/kernel.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 4322f01580..b90d8f7e04 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. |