X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;h=6a5742824479165f846e2df2f32c69d935998d9d;hb=da054c3782f25b3b18243f6c76dcfcf90ba70274;hp=9f5e4552b49ed16b2ae86723ad3f3bfdd7115f69;hpb=fed1e721fd0c81e60c77120539f34e16c2585634;p=elogind.git diff --git a/src/shared/macro.h b/src/shared/macro.h index 9f5e4552b..6a5742824 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -95,15 +95,15 @@ #error "Wut? Pointers are neither 4 nor 8 bytes long?" #endif -#define ALIGN_PTR(p) ((void*) ALIGN((unsigned long) p)) -#define ALIGN4_PTR(p) ((void*) ALIGN4((unsigned long) p)) -#define ALIGN8_PTR(p) ((void*) ALIGN8((unsigned long) p)) +#define ALIGN_PTR(p) ((void*) ALIGN((unsigned long) (p))) +#define ALIGN4_PTR(p) ((void*) ALIGN4((unsigned long) (p))) +#define ALIGN8_PTR(p) ((void*) ALIGN8((unsigned long) (p))) static inline size_t ALIGN_TO(size_t l, size_t ali) { return ((l + ali - 1) & ~(ali - 1)); } -#define ALIGN_TO_PTR(p, ali) ((void*) ALIGN_TO((unsigned long) p, ali)) +#define ALIGN_TO_PTR(p, ali) ((void*) ALIGN_TO((unsigned long) (p), (ali))) /* align to next higher power-of-2 (except for: 0 => 0, overflow => 0) */ static inline unsigned long ALIGN_POWER2(unsigned long u) { @@ -197,6 +197,17 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { UNIQ_T(X,xq); \ }) +/* [(x + y - 1) / y] suffers from an integer overflow, even though the + * computation should be possible in the given type. Therefore, we use + * [x / y + !!(x % y)]. Note that on "Real CPUs" a division returns both the + * quotient and the remainder, so both should be equally fast. */ +#define DIV_ROUND_UP(_x, _y) \ + __extension__ ({ \ + const typeof(_x) __x = (_x); \ + const typeof(_y) __y = (_y); \ + (__x / __y + !!(__x % __y)); \ + }) + #define assert_se(expr) \ do { \ if (_unlikely_(!(expr))) \