build: switch release build to -O3
[vpp.git] / src / vppinfra / cpu.h
index 6a81218..40857fb 100644 (file)
 #include <sys/syscall.h>
 #include <vppinfra/format.h>
 
-/*
- * multiarchitecture support. Adding new entry will produce
- * new graph node function variant optimized for specific cpu
- * microarchitecture.
- * Order is important for runtime selection, as 1st match wins...
- */
-
-#if __x86_64__ && CLIB_DEBUG == 0
-#define foreach_march_variant(macro, x) \
-  macro(avx2,  x, "arch=core-avx2")
-#else
-#define foreach_march_variant(macro, x)
-#endif
-
-
-#if __GNUC__ > 4  && !__clang__ && CLIB_DEBUG == 0
-#define CLIB_CPU_OPTIMIZED __attribute__ ((optimize ("O3")))
+#if defined(__x86_64__)
+#define foreach_march_variant                                                 \
+  _ (hsw, "Intel Haswell")                                                    \
+  _ (trm, "Intel Tremont")                                                    \
+  _ (skx, "Intel Skylake (server) / Cascade Lake")                            \
+  _ (icl, "Intel Ice Lake")
+#elif defined(__aarch64__)
+#define foreach_march_variant                                                 \
+  _ (octeontx2, "Marvell Octeon TX2")                                         \
+  _ (thunderx2t99, "Marvell ThunderX2 T99")                                   \
+  _ (qdf24xx, "Qualcomm CentriqTM 2400")                                      \
+  _ (cortexa72, "ARM Cortex-A72")                                             \
+  _ (neoversen1, "ARM Neoverse N1")
 #else
-#define CLIB_CPU_OPTIMIZED
+#define foreach_march_variant
 #endif
 
-
-#define CLIB_MULTIARCH_ARCH_CHECK(arch, fn, tgt)                       \
-  if (clib_cpu_supports_ ## arch())                                    \
-    return & fn ## _ ##arch;
-
-/* FIXME to be removed */
-#define CLIB_MULTIARCH_SELECT_FN(fn,...)
+typedef enum
+{
+  CLIB_MARCH_VARIANT_TYPE = 0,
+#define _(s, n) CLIB_MARCH_VARIANT_TYPE_##s,
+  foreach_march_variant
+#undef _
+    CLIB_MARCH_TYPE_N_VARIANTS
+} clib_march_variant_type_t;
 
 #ifdef CLIB_MARCH_VARIANT
 #define __CLIB_MULTIARCH_FN(a,b) a##_##b
@@ -164,21 +161,8 @@ _ (asimddp,    20) \
 _ (sha512,     21) \
 _ (sve,        22)
 
-static inline u32
-clib_get_current_cpu_id ()
-{
-  unsigned cpu, node;
-  syscall (__NR_getcpu, &cpu, &node, 0);
-  return cpu;
-}
-
-static inline u32
-clib_get_current_numa_node ()
-{
-  unsigned cpu, node;
-  syscall (__NR_getcpu, &cpu, &node, 0);
-  return node;
-}
+u32 clib_get_current_cpu_id ();
+u32 clib_get_current_numa_node ();
 
 #if defined(__x86_64__)
 #include "cpuid.h"
@@ -195,6 +179,7 @@ clib_get_cpuid (const u32 lev, u32 * eax, u32 * ebx, u32 * ecx, u32 * edx)
   return 1;
 }
 
+typedef int (*clib_cpu_supports_func_t) ();
 
 #define _(flag, func, reg, bit) \
 static inline int                                                      \
@@ -412,19 +397,18 @@ CLIB_MARCH_SFX(fn ## _march_constructor) (void)                           \
 }                                                                      \
 
 #ifndef CLIB_MARCH_VARIANT
-#define CLIB_MARCH_FN(fn, rtype, _args...)                             \
-  static rtype CLIB_CPU_OPTIMIZED CLIB_MARCH_SFX (fn ## _ma)(_args);   \
-  rtype (*fn ## _selected) (_args) = & CLIB_MARCH_SFX (fn ## _ma);     \
-  int fn ## _selected_priority = 0;                                    \
-  static inline rtype CLIB_CPU_OPTIMIZED                               \
-  CLIB_MARCH_SFX (fn ## _ma)(_args)
+#define CLIB_MARCH_FN(fn, rtype, _args...)                                    \
+  static rtype CLIB_MARCH_SFX (fn##_ma) (_args);                              \
+  rtype (*fn##_selected) (_args) = &CLIB_MARCH_SFX (fn##_ma);                 \
+  int fn##_selected_priority = 0;                                             \
+  static inline rtype CLIB_MARCH_SFX (fn##_ma) (_args)
 #else
-#define CLIB_MARCH_FN(fn, rtype, _args...)                             \
-  static rtype CLIB_CPU_OPTIMIZED CLIB_MARCH_SFX (fn ## _ma)(_args);   \
-  extern rtype (*fn ## _selected) (_args);                             \
-  extern int fn ## _selected_priority;                                 \
-  CLIB_MARCH_FN_CONSTRUCTOR (fn)                                       \
-  static rtype CLIB_CPU_OPTIMIZED CLIB_MARCH_SFX (fn ## _ma)(_args)
+#define CLIB_MARCH_FN(fn, rtype, _args...)                                    \
+  static rtype CLIB_MARCH_SFX (fn##_ma) (_args);                              \
+  extern rtype (*fn##_selected) (_args);                                      \
+  extern int fn##_selected_priority;                                          \
+  CLIB_MARCH_FN_CONSTRUCTOR (fn)                                              \
+  static rtype CLIB_MARCH_SFX (fn##_ma) (_args)
 #endif
 
 #define CLIB_MARCH_FN_SELECT(fn) (* fn ## _selected)