16 #ifndef included_clib_cpu_h 17 #define included_clib_cpu_h 28 #if __x86_64__ && CLIB_DEBUG == 0 29 #define foreach_march_variant(macro, x) \ 30 macro(avx2, x, "arch=core-avx2") 32 #define foreach_march_variant(macro, x) 36 #if __GNUC__ > 4 && !__clang__ 37 #define CLIB_CPU_OPTIMIZED __attribute__ ((optimize ("O3"))) 39 #define CLIB_CPU_OPTIMIZED 43 #define CLIB_MULTIARCH_ARCH_CHECK(arch, fn, tgt) \ 44 if (clib_cpu_supports_ ## arch()) \ 45 return & fn ## _ ##arch; 47 #define CLIB_MULTIARCH_SELECT_FN(fn,...) \ 48 __VA_ARGS__ void * fn ## _multiarch_select(void) \ 50 foreach_march_variant(CLIB_MULTIARCH_ARCH_CHECK, fn) \ 54 #ifdef CLIB_MARCH_VARIANT 55 #define __CLIB_MULTIARCH_FN(a,b) a##_##b 56 #define _CLIB_MULTIARCH_FN(a,b) __CLIB_MULTIARCH_FN(a,b) 57 #define CLIB_MULTIARCH_FN(fn) _CLIB_MULTIARCH_FN(fn,CLIB_MARCH_VARIANT) 59 #define CLIB_MULTIARCH_FN(fn) fn 62 #define CLIB_MARCH_SFX CLIB_MULTIARCH_FN 64 #define foreach_x86_64_flags \ 66 _ (ssse3, 1, ecx, 9) \ 67 _ (sse41, 1, ecx, 19) \ 68 _ (sse42, 1, ecx, 20) \ 71 _ (avx512f, 7, ebx, 16) \ 72 _ (x86_aes, 1, ecx, 25) \ 74 _ (invariant_tsc, 0x80000007, edx, 8) 77 #define foreach_aarch64_flags \ 102 #if defined(__x86_64__) 108 if ((
u32) __get_cpuid_max (0x80000000 & lev, 0) < lev)
111 __cpuid_count (lev, 0, *eax, *ebx, *ecx, *edx);
113 __cpuid (lev, *eax, *ebx, *ecx, *edx);
118 #define _(flag, func, reg, bit) \ 120 clib_cpu_supports_ ## flag() \ 122 u32 __attribute__((unused)) eax, ebx = 0, ecx = 0, edx = 0; \ 123 clib_get_cpuid (func, &eax, &ebx, &ecx, &edx); \ 125 return ((reg & (1 << bit)) != 0); \ 131 #define _(flag, func, reg, bit) \ 132 static inline int clib_cpu_supports_ ## flag() { return 0; } 136 #if defined(__aarch64__) 137 #include <sys/auxv.h> 138 #define _(flag, bit) \ 140 clib_cpu_supports_ ## flag() \ 142 unsigned long hwcap = getauxval(AT_HWCAP); \ 143 return (hwcap & (1 << bit)); \ 148 #define _(flag, bit) \ 149 static inline int clib_cpu_supports_ ## flag() { return 0; } 161 #if defined (__aarch64__) 162 return clib_cpu_supports_x86_aes ();
163 #elif defined (__aarch64__) 164 return clib_cpu_supports_aarch64_aes ();
173 if (clib_cpu_supports_avx512f ())
181 if (clib_cpu_supports_avx2 ())
186 #ifdef CLIB_MARCH_VARIANT 187 #define CLIB_MARCH_FN_PRIORITY() CLIB_MARCH_SFX(clib_cpu_march_priority)() 189 #define CLIB_MARCH_FN_PRIORITY() 0 format_function_t format_cpu_flags
#define foreach_aarch64_flags
static int clib_cpu_march_priority_avx512()
static int clib_get_cpuid(const u32 lev, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
static int clib_cpu_march_priority_avx2()
#define foreach_x86_64_flags
static foreach_aarch64_flags int clib_cpu_supports_aes()
format_function_t format_cpu_uarch
format_function_t format_cpu_model_name