api: API trace improvements
[vpp.git] / src / vppinfra / vector.h
index fcff5e7..6a6635b 100644 (file)
 
 /* Vector types. */
 
-#if defined (__MMX__) || defined (__IWMMXT__) || defined (__aarch64__)
-#define CLIB_HAVE_VEC64
-#endif
-
-#if defined (__aarch64__) && defined(__ARM_NEON)
+#if defined (__aarch64__) && defined(__ARM_NEON) || defined (__i686__)
 #define CLIB_HAVE_VEC128
 #endif
 
 #endif
 #endif
 
-#if defined (__AVX512F__)
+#if defined (__AVX512BITALG__)
 #define CLIB_HAVE_VEC512
 #endif
 
-/* 128 implies 64 */
-#ifdef CLIB_HAVE_VEC128
-#define CLIB_HAVE_VEC64
-#endif
-
 #define _vector_size(n) __attribute__ ((vector_size (n)))
+#define _vector_size_unaligned(n) __attribute__ ((vector_size (n),  __aligned__ (1)))
 
 #define foreach_vec64i  _(i,8,8)  _(i,16,4)  _(i,32,2)
 #define foreach_vec64u  _(u,8,8)  _(u,16,4)  _(u,32,2)
 /* Type Definitions */
 #define _(t,s,c) \
 typedef t##s t##s##x##c _vector_size (s/8*c);  \
+typedef t##s t##s##x##c##u _vector_size_unaligned (s/8*c);     \
 typedef union {          \
   t##s##x##c as_##t##s##x##c;  \
   t##s as_##t##s[c];     \
@@ -121,83 +114,20 @@ typedef union {     \
   foreach_vec512i foreach_vec512u foreach_vec512f
 #undef _
 
-/* Vector word sized types. */
-#ifndef CLIB_VECTOR_WORD_BITS
-#ifdef CLIB_HAVE_VEC128
-#define CLIB_VECTOR_WORD_BITS 128
-#else
-#define CLIB_VECTOR_WORD_BITS 64
-#endif
-#endif /* CLIB_VECTOR_WORD_BITS */
-
-/* Vector word sized types. */
-#if CLIB_VECTOR_WORD_BITS == 128
-typedef i8 i8x _vector_size (16);
-typedef i16 i16x _vector_size (16);
-typedef i32 i32x _vector_size (16);
-typedef i64 i64x _vector_size (16);
-typedef u8 u8x _vector_size (16);
-typedef u16 u16x _vector_size (16);
-typedef u32 u32x _vector_size (16);
-typedef u64 u64x _vector_size (16);
-#endif
-#if CLIB_VECTOR_WORD_BITS == 64
-typedef i8 i8x _vector_size (8);
-typedef i16 i16x _vector_size (8);
-typedef i32 i32x _vector_size (8);
-typedef i64 i64x _vector_size (8);
-typedef u8 u8x _vector_size (8);
-typedef u16 u16x _vector_size (8);
-typedef u32 u32x _vector_size (8);
-typedef u64 u64x _vector_size (8);
-#endif
+/* universal inlines */
+#define _(t, s, c) \
+static_always_inline t##s##x##c                                         \
+t##s##x##c##_zero ()                                                    \
+{ return (t##s##x##c) {}; }                                             \
+
+foreach_vec
+#undef _
 
 #undef _vector_size
 
 #define VECTOR_WORD_TYPE(t) t##x
 #define VECTOR_WORD_TYPE_LEN(t) (sizeof (VECTOR_WORD_TYPE(t)) / sizeof (t))
 
-/* this series of macros generate _is_equal, _is_greater, _is_zero, _add
-   and _sub inline funcitons for each vector type */
-#define _(t, s, c) \
-  static_always_inline t##s##x##c                      \
-t##s##x##c##_is_equal (t##s##x##c v1, t##s##x##c v2)   \
-{ return (v1 == v2); }                                 \
-                                                       \
-static_always_inline t##s##x##c                                \
-t##s##x##c##_is_greater (t##s##x##c v1, t##s##x##c v2) \
-{ return (v1 > v2); }                                  \
-                                                       \
-static_always_inline t##s##x##c                                \
-t##s##x##c##_is_zero (t##s##x##c v1)                   \
-{ t##s##x##c z = {0}; return (v1 == z); }              \
-                                                       \
-static_always_inline t##s##x##c                                \
-t##s##x##c##_add (t##s##x##c v1, t##s##x##c v2)                \
-{ return (v1 + v2); }                                  \
-                                                       \
-static_always_inline t##s##x##c                                \
-t##s##x##c##_sub (t##s##x##c v1, t##s##x##c v2)                \
-{ return (v1 - v2); }
-  foreach_vec
-#undef _
-
-/* this macro generate _splat inline functions for each scalar vector type */
-#define _(t, s, c) \
-  static_always_inline t##s##x##c                      \
-t##s##x##c##_splat (t##s x)                            \
-{                                                      \
-    t##s##x##c r;                                      \
-    int i;                                             \
-                                                       \
-    for (i = 0; i < c; i++)                            \
-      r[i] = x;                                                \
-                                                       \
-    return r;                                          \
-}
-  foreach_vec128i foreach_vec128u
-#undef _
-
 #if defined (__SSE4_2__) && __GNUC__ >= 4
 #include <vppinfra/vector_sse42.h>
 #endif
@@ -206,7 +136,7 @@ t##s##x##c##_splat (t##s x)                         \
 #include <vppinfra/vector_avx2.h>
 #endif
 
-#if defined (__AVX512F__)
+#if defined(__AVX512F__)
 #include <vppinfra/vector_avx512.h>
 #endif
 
@@ -218,8 +148,22 @@ t##s##x##c##_splat (t##s x)                                \
 #include <vppinfra/vector_neon.h>
 #endif
 
-#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
-#include <vppinfra/vector_funcs.h>
+/* this macro generate _splat inline functions for each scalar vector type */
+#ifndef CLIB_VEC128_SPLAT_DEFINED
+#define _(t, s, c) \
+  static_always_inline t##s##x##c                      \
+t##s##x##c##_splat (t##s x)                            \
+{                                                      \
+    t##s##x##c r;                                      \
+    int i;                                             \
+                                                       \
+    for (i = 0; i < c; i++)                            \
+      r[i] = x;                                                \
+                                                       \
+    return r;                                          \
+}
+  foreach_vec128i foreach_vec128u
+#undef _
 #endif
 
 /* *INDENT-ON* */