Commit bded797f authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

util: add SPDK_ALIGN_FLOOR/CEIL macro definition



Change-Id: Ideb3a037a91b13432b8c0bd1271166067caf69c4
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478409


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 10b84535
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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