aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-06-27 13:03:26 +0200
committerDamjan Marion <dmarion@me.com>2018-06-27 12:59:11 +0000
commitbf129f458f6f36d57a4378c72ce134ba44858472 (patch)
tree9d61613b33f6c8380e967e45e083d6102819ec3c
parent2d11e9f4b9e22f6da17fbe83b99e4ca9a5c0e507 (diff)
vppinfra: add vector horizontal add and byte swap (SSE4.2 & AVX2)
Change-Id: I4e0fd487970796f0153a5b16333827d23b57deac Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--src/vppinfra/vector_avx2.h16
-rw-r--r--src/vppinfra/vector_sse42.h15
2 files changed, 31 insertions, 0 deletions
diff --git a/src/vppinfra/vector_avx2.h b/src/vppinfra/vector_avx2.h
index 6dd110c52e3..6b298be8bfd 100644
--- a/src/vppinfra/vector_avx2.h
+++ b/src/vppinfra/vector_avx2.h
@@ -121,6 +121,22 @@ _(i8x16, i64x4, epi8_epi64)
#undef _
/* *INDENT-ON* */
+static_always_inline u16x16
+u16x16_byte_swap (u16x16 v)
+{
+ u8x32 swap = {
+ 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14,
+ 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
+ };
+ return (u16x16) _mm256_shuffle_epi8 ((__m256i) v, (__m256i) swap);
+}
+
+static_always_inline u32x8
+u32x8_hadd (u32x8 v1, u32x8 v2)
+{
+ return (u32x8) _mm256_hadd_epi32 ((__m256i) v1, (__m256i) v2);
+}
+
#endif /* included_vector_avx2_h */
/*
diff --git a/src/vppinfra/vector_sse42.h b/src/vppinfra/vector_sse42.h
index fa377cc983b..deb98776f7f 100644
--- a/src/vppinfra/vector_sse42.h
+++ b/src/vppinfra/vector_sse42.h
@@ -592,6 +592,21 @@ u8x16_msb_mask (u8x16 v)
#undef _signed_binop
+static_always_inline u16x8
+u16x8_byte_swap (u16x8 v)
+{
+ u8x16 swap = {
+ 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14,
+ };
+ return (u16x8) _mm_shuffle_epi8 ((__m128i) v, (__m128i) swap);
+}
+
+static_always_inline u32x4
+u32x4_hadd (u32x4 v1, u32x4 v2)
+{
+ return (u32x4) _mm_hadd_epi32 ((__m128i) v1, (__m128i) v2);
+}
+
#endif /* included_vector_sse2_h */
/*