vppinfra: put each vector function into own file

Type: refactor
Change-Id: I2dd9a18497992ac7e2686c14f5d17eccccda0cda
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt
index 64420b9..8f9d074 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -188,7 +188,8 @@
   vector_altivec.h
   vector_avx2.h
   vector_avx512.h
-  vector_funcs.h
+  vector/mask_compare.h
+  vector/compress.h
   vector.h
   vector_neon.h
   vector_sse42.h
@@ -264,13 +265,13 @@
   endforeach()
 
 set(test_files
-  test_vector_funcs_compress.c
-  test_vector_funcs_mask_compare.c
+  vector/test/compress.c
+  vector/test/mask_compare.c
 )
 
 add_vpp_executable(test_vector_funcs
   SOURCES
-  test_vector_funcs.c
+  vector/test/test.c
   ${test_files}
   LINK_LIBRARIES vppinfra
 )
diff --git a/src/vppinfra/vector/compress.h b/src/vppinfra/vector/compress.h
new file mode 100644
index 0000000..1d5d84e
--- /dev/null
+++ b/src/vppinfra/vector/compress.h
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: Apache-2.0
+ * Copyright(c) 2021 Cisco Systems, Inc.
+ */
+
+#ifndef included_vector_compress_h
+#define included_vector_compress_h
+#include <vppinfra/clib.h>
+#include <vppinfra/memcpy.h>
+
+static_always_inline u32 *
+clib_compress_u32_x64 (u32 *dst, u32 *src, u64 mask)
+{
+#if defined(CLIB_HAVE_VEC512_COMPRESS)
+  u32x16u *sv = (u32x16u *) src;
+  for (int i = 0; i < 4; i++)
+    {
+      int cnt = _popcnt32 ((u16) mask);
+      u32x16_compress_store (sv[i], mask, dst);
+      dst += cnt;
+      mask >>= 16;
+    }
+
+#elif defined(CLIB_HAVE_VEC256_COMPRESS)
+  u32x8u *sv = (u32x8u *) src;
+  for (int i = 0; i < 8; i++)
+    {
+      int cnt = _popcnt32 ((u8) mask);
+      u32x8_compress_store (sv[i], mask, dst);
+      dst += cnt;
+      mask >>= 8;
+    }
+#else
+  while (mask)
+    {
+      u16 bit = count_trailing_zeros (mask);
+      mask = clear_lowest_set_bit (mask);
+      dst++[0] = src[bit];
+    }
+#endif
+  return dst;
+}
+
+/** \brief Compress array of 32-bit elemments into destination array based on
+ * mask
+
+    @param dst destination array of u32 elements
+    @param src source array of u32 elements
+    @param mask array of u64 values representing compress mask
+    @param n_elts number of elements in the source array
+    @return number of elements stored in destionation array
+*/
+
+static_always_inline u32
+clib_compress_u32 (u32 *dst, u32 *src, u64 *mask, u32 n_elts)
+{
+  u32 *dst0 = dst;
+  while (n_elts >= 64)
+    {
+      if (mask[0] == ~0ULL)
+	{
+	  clib_memcpy_u32 (dst, src, 64);
+	  dst += 64;
+	}
+      else
+	dst = clib_compress_u32_x64 (dst, src, mask[0]);
+
+      mask++;
+      src += 64;
+      n_elts -= 64;
+    }
+
+  if (PREDICT_TRUE (n_elts == 0))
+    return dst - dst0;
+
+  return clib_compress_u32_x64 (dst, src, mask[0] & pow2_mask (n_elts)) - dst0;
+}
+
+#endif
diff --git a/src/vppinfra/vector_funcs.h b/src/vppinfra/vector/mask_compare.h
similarity index 75%
rename from src/vppinfra/vector_funcs.h
rename to src/vppinfra/vector/mask_compare.h
index fed1b5c..cac48a3 100644
--- a/src/vppinfra/vector_funcs.h
+++ b/src/vppinfra/vector/mask_compare.h
@@ -2,8 +2,8 @@
  * Copyright(c) 2021 Cisco Systems, Inc.
  */
 
-#ifndef included_vector_funcs_h
-#define included_vector_funcs_h
+#ifndef included_vector_mask_compare_h
+#define included_vector_mask_compare_h
 #include <vppinfra/clib.h>
 #include <vppinfra/memcpy.h>
 
@@ -163,72 +163,4 @@
   bitmap[0] = clib_mask_compare_u32_x64 (v, a, n_elts) & pow2_mask (n_elts);
 }
 
-static_always_inline u32 *
-clib_compress_u32_x64 (u32 *dst, u32 *src, u64 mask)
-{
-#if defined(CLIB_HAVE_VEC512_COMPRESS)
-  u32x16u *sv = (u32x16u *) src;
-  for (int i = 0; i < 4; i++)
-    {
-      int cnt = _popcnt32 ((u16) mask);
-      u32x16_compress_store (sv[i], mask, dst);
-      dst += cnt;
-      mask >>= 16;
-    }
-
-#elif defined(CLIB_HAVE_VEC256_COMPRESS)
-  u32x8u *sv = (u32x8u *) src;
-  for (int i = 0; i < 8; i++)
-    {
-      int cnt = _popcnt32 ((u8) mask);
-      u32x8_compress_store (sv[i], mask, dst);
-      dst += cnt;
-      mask >>= 8;
-    }
-#else
-  while (mask)
-    {
-      u16 bit = count_trailing_zeros (mask);
-      mask = clear_lowest_set_bit (mask);
-      dst++[0] = src[bit];
-    }
-#endif
-  return dst;
-}
-
-/** \brief Compare array of 32-bit elemments into destination array based on
- * mask
-
-    @param dst destination array of u32 elements
-    @param src source array of u32 elements
-    @param mask array of u64 values representing compress mask
-    @param n_elts number of elements in the source array
-    @return number of elements stored in destionation array
-*/
-
-static_always_inline u32
-clib_compress_u32 (u32 *dst, u32 *src, u64 *mask, u32 n_elts)
-{
-  u32 *dst0 = dst;
-  while (n_elts >= 64)
-    {
-      if (mask[0] == ~0ULL)
-	{
-	  clib_memcpy_u32 (dst, src, 64);
-	  dst += 64;
-	}
-      else
-	dst = clib_compress_u32_x64 (dst, src, mask[0]);
-
-      mask++;
-      src += 64;
-      n_elts -= 64;
-    }
-
-  if (PREDICT_TRUE (n_elts == 0))
-    return dst - dst0;
-
-  return clib_compress_u32_x64 (dst, src, mask[0] & pow2_mask (n_elts)) - dst0;
-}
-
 #endif
diff --git a/src/vppinfra/test_vector_funcs_compress.c b/src/vppinfra/vector/test/compress.c
similarity index 95%
rename from src/vppinfra/test_vector_funcs_compress.c
rename to src/vppinfra/vector/test/compress.c
index c081560..7e3eba9 100644
--- a/src/vppinfra/test_vector_funcs_compress.c
+++ b/src/vppinfra/vector/test/compress.c
@@ -3,8 +3,8 @@
  */
 
 #include <vppinfra/format.h>
-#include <vppinfra/vector_funcs.h>
-#include <vppinfra/test_vector_funcs.h>
+#include <vppinfra/vector/test/test.h>
+#include <vppinfra/vector/compress.h>
 
 __clib_test_fn u32
 clib_compress_u32_wrapper (u32 *dst, u32 *src, u64 *mask, u32 n_elts)
diff --git a/src/vppinfra/test_vector_funcs_mask_compare.c b/src/vppinfra/vector/test/mask_compare.c
similarity index 95%
rename from src/vppinfra/test_vector_funcs_mask_compare.c
rename to src/vppinfra/vector/test/mask_compare.c
index 009f877..64df0ee 100644
--- a/src/vppinfra/test_vector_funcs_mask_compare.c
+++ b/src/vppinfra/vector/test/mask_compare.c
@@ -3,8 +3,8 @@
  */
 
 #include <vppinfra/format.h>
-#include <vppinfra/vector_funcs.h>
-#include <vppinfra/test_vector_funcs.h>
+#include <vppinfra/vector/test/test.h>
+#include <vppinfra/vector/mask_compare.h>
 
 __clib_test_fn void
 clib_mask_compare_u16_wrapper (u16 v, u16 *a, u64 *mask, u32 n_elts)
diff --git a/src/vppinfra/test_vector_funcs.c b/src/vppinfra/vector/test/test.c
similarity index 94%
rename from src/vppinfra/test_vector_funcs.c
rename to src/vppinfra/vector/test/test.c
index 85f159a..0e90bac 100644
--- a/src/vppinfra/test_vector_funcs.c
+++ b/src/vppinfra/vector/test/test.c
@@ -3,7 +3,7 @@
  */
 
 #include <vppinfra/format.h>
-#include <vppinfra/test_vector_funcs.h>
+#include <vppinfra/vector/test/test.h>
 
 test_registration_t *test_registrations[CLIB_MARCH_TYPE_N_VARIANTS] = {};
 
diff --git a/src/vppinfra/test_vector_funcs.h b/src/vppinfra/vector/test/test.h
similarity index 100%
rename from src/vppinfra/test_vector_funcs.h
rename to src/vppinfra/vector/test/test.h