util: add SPDK_ALIGN_FLOOR/CEIL macro definition

Change-Id: Ideb3a037a91b13432b8c0bd1271166067caf69c4
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478409
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Changpeng Liu 2019-12-19 01:00:55 -05:00 committed by Tomasz Zawadzki
parent 10b84535f8
commit bded797f77

View File

@ -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