From de030821914cd97e5bfe2e0c0afd9f47820cb6f4 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 29 Jul 2019 14:58:28 -0700 Subject: [PATCH] util: Generate multiple versions of spdk_u32log2 Generate multiple versions for various architectures automatically. Fixes issue #713 Change-Id: I757a1d05e54c938b66dd5b2ec255ad960bb89945 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463550 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- include/spdk/util.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/spdk/util.h b/include/spdk/util.h index 8655112bf..fb37caabd 100644 --- a/include/spdk/util.h +++ b/include/spdk/util.h @@ -57,6 +57,12 @@ extern "C" { /* Ceiling division of unsigned integers */ #define SPDK_CEIL_DIV(x,y) (((x)+(y)-1)/(y)) +/* The following will automatically generate several version of + * this function, targeted at different architectures. This + * is only supported by GCC 6 or newer. */ +#if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__clang__) +__attribute__((target_clones("bmi", "arch=core2", "arch=atom", "default"))) +#endif static inline uint32_t spdk_u32log2(uint32_t x) { @@ -73,6 +79,12 @@ spdk_align32pow2(uint32_t x) return 1u << (1 + spdk_u32log2(x - 1)); } +/* The following will automatically generate several version of + * this function, targeted at different architectures. This + * is only supported by GCC 6 or newer. */ +#if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__clang__) +__attribute__((target_clones("bmi", "arch=core2", "arch=atom", "default"))) +#endif static inline uint64_t spdk_u64log2(uint64_t x) {