X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;fp=src%2Fshared%2Fmacro.h;h=6a5742824479165f846e2df2f32c69d935998d9d;hp=548294e47b65f5cc4636dbc0776bfece60245ea2;hb=180a60bc879ab0554297bc08a7a0b9274b119b55;hpb=5ef378c1c5ba1a29a461e77685765da81163c853 diff --git a/src/shared/macro.h b/src/shared/macro.h index 548294e47..6a5742824 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -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))) \