From bded797f771daf80c03dd0eaf93c5cb463cf9256 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Thu, 19 Dec 2019 01:00:55 -0500 Subject: [PATCH] util: add SPDK_ALIGN_FLOOR/CEIL macro definition Change-Id: Ideb3a037a91b13432b8c0bd1271166067caf69c4 Signed-off-by: Changpeng Liu Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478409 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- include/spdk/util.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/spdk/util.h b/include/spdk/util.h index 993d10ac1..41734e46e 100644 --- a/include/spdk/util.h +++ b/include/spdk/util.h @@ -59,6 +59,23 @@ extern "C" { /* Ceiling division of unsigned integers */ #define SPDK_CEIL_DIV(x,y) (((x)+(y)-1)/(y)) +/** + * Macro to align a value to a given power-of-two. The resultant value + * will be of the same type as the first parameter, and will be no + * bigger than the first parameter. Second parameter must be a + * power-of-two value. + */ +#define SPDK_ALIGN_FLOOR(val, align) \ + (typeof(val))((val) & (~((typeof(val))((align) - 1)))) +/** + * Macro to align a value to a given power-of-two. The resultant value + * will be of the same type as the first parameter, and will be no lower + * than the first parameter. Second parameter must be a power-of-two + * value. + */ +#define SPDK_ALIGN_CEIL(val, align) \ + SPDK_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) + uint32_t spdk_u32log2(uint32_t x); static inline uint32_t