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