svm: march svm_fifo take 2
[vpp.git] / src / vppinfra / cpu.h
index 110815c..c636cf8 100644 (file)
@@ -190,6 +190,35 @@ clib_cpu_march_priority_avx2 ()
 #endif
 #endif /* included_clib_cpu_h */
 
+#define CLIB_MARCH_FN_CONSTRUCTOR(fn)                                  \
+static void __clib_constructor                                                 \
+CLIB_MARCH_SFX(fn ## _march_constructor) (void)                                \
+{                                                                      \
+  if (CLIB_MARCH_FN_PRIORITY() > fn ## _selected_priority)             \
+    {                                                                  \
+      fn ## _selected = & CLIB_MARCH_SFX (fn ## _ma);                  \
+      fn ## _selected_priority = CLIB_MARCH_FN_PRIORITY();             \
+    }                                                                  \
+}                                                                      \
+
+#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)
+#else
+#define CLIB_MARCH_FN(fn, rtype, _args...)                             \
+  static rtype CLIB_CPU_OPTIMIZED CLIB_MARCH_SFX (fn ## _ma)(_args);   \
+  extern int (*fn ## _selected) (_args);                               \
+  extern int fn ## _selected_priority;                                 \
+  CLIB_MARCH_FN_CONSTRUCTOR (fn)                                       \
+  static rtype CLIB_CPU_OPTIMIZED CLIB_MARCH_SFX (fn ## _ma)(_args)
+#endif
+
+#define CLIB_MARCH_FN_SELECT(fn) (* fn ## _selected)
+
 format_function_t format_cpu_uarch;
 format_function_t format_cpu_model_name;
 format_function_t format_cpu_flags;