X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Futil.h;h=962bad2f31376a23b799a818e2f6acdcce38554e;hb=87c8489148d5e6d44b1d55f1325658222852232c;hp=a945eb2757baafef582ddb259b71c42b73554cbb;hpb=34e63086edddcae06d7c1a4fa84fec0861e50758;p=openvswitch diff --git a/lib/util.h b/lib/util.h index a945eb27..962bad2f 100644 --- a/lib/util.h +++ b/lib/util.h @@ -52,9 +52,19 @@ extern const char *program_name; +/* Returns the number of elements in ARRAY. */ #define ARRAY_SIZE(ARRAY) (sizeof ARRAY / sizeof *ARRAY) -#define ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y) * (Y)) + +/* Returns X / Y, rounding up. X must be nonnegative to round correctly. */ +#define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y)) + +/* Returns X rounded up to the nearest multiple of Y. */ +#define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y)) + +/* Returns X rounded down to the nearest multiple of Y. */ #define ROUND_DOWN(X, Y) ((X) / (Y) * (Y)) + +/* Returns true if X is a power of 2, otherwise false. */ #define IS_POW2(X) ((X) && !((X) & ((X) - 1))) #ifndef MIN