diff options
author | Albert ARIBAUD <albert.u.boot@aribaud.net> | 2014-02-19 10:55:58 +0100 |
---|---|---|
committer | Albert ARIBAUD <albert.u.boot@aribaud.net> | 2014-02-19 10:55:58 +0100 |
commit | 1feb6e3c9216a34885f24f0df4a02a30dfb35f19 (patch) | |
tree | a971d9d2fe6528910cf7acaf7632b747731c6caa /include/common.h | |
parent | 529a8d05ff848e7bfd6049c99210557aa5e31d39 (diff) | |
parent | e158665c1e4c4665302f0d95e26b7c7e6b70a83c (diff) | |
download | u-boot-imx-1feb6e3c9216a34885f24f0df4a02a30dfb35f19.zip u-boot-imx-1feb6e3c9216a34885f24f0df4a02a30dfb35f19.tar.gz u-boot-imx-1feb6e3c9216a34885f24f0df4a02a30dfb35f19.tar.bz2 |
Merge branch 'u-boot-microblaze/zynq' into 'u-boot-arm/master'
Diffstat (limited to 'include/common.h')
-rw-r--r-- | include/common.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h index 221b776..ea3e5ed 100644 --- a/include/common.h +++ b/include/common.h @@ -964,6 +964,22 @@ static inline phys_addr_t map_to_sysmem(const void *ptr) #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) +/* + * Divide positive or negative dividend by positive divisor and round + * to closest integer. Result is undefined for negative divisors and + * for negative dividends if the divisor variable type is unsigned. + */ +#define DIV_ROUND_CLOSEST(x, divisor)( \ +{ \ + typeof(x) __x = x; \ + typeof(divisor) __d = divisor; \ + (((typeof(x))-1) > 0 || \ + ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ + (((__x) + ((__d) / 2)) / (__d)) : \ + (((__x) - ((__d) / 2)) / (__d)); \ +} \ +) + #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |