summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2019-04-02 19:06:50 +0200
committerDamjan Marion <damarion@cisco.com>2019-04-02 19:07:02 +0200
commitf6adf1f8dbbdfb2822c391d7d1b132d2846bf004 (patch)
treec697e421db9762550b9d940119878d8cdc8514f6 /src
parentf65074e4df47d05238e051615dbaf5d2bcbaddf2 (diff)
vppinfra: add u32x4 min / max sse4.2 inlines
Change-Id: I38e0be777199654ece286fdd1a42931ed99bbe8a Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/vector_sse42.h73
1 files changed, 49 insertions, 24 deletions
diff --git a/src/vppinfra/vector_sse42.h b/src/vppinfra/vector_sse42.h
index ee5b4dcc7df..a2d737a4892 100644
--- a/src/vppinfra/vector_sse42.h
+++ b/src/vppinfra/vector_sse42.h
@@ -78,6 +78,20 @@ t##s##x##c##_is_all_equal (t##s##x##c v, t##s x) \
foreach_sse42_vec128i foreach_sse42_vec128u
#undef _
+
+/* min, max */
+#define _(t, s, c, i) \
+static_always_inline t##s##x##c \
+t##s##x##c##_min (t##s##x##c a, t##s##x##c b) \
+{ return (t##s##x##c) _mm_min_##i ((__m128i) a, (__m128i) b); } \
+\
+static_always_inline t##s##x##c \
+t##s##x##c##_max (t##s##x##c a, t##s##x##c b) \
+{ return (t##s##x##c) _mm_max_##i ((__m128i) a, (__m128i) b); } \
+
+_(i,8,16,epi8) _(i,16,8,epi16) _(i,32,4,epi32) _(i,64,2,epi64)
+_(u,8,16,epu8) _(u,16,8,epu16) _(u,32,4,epu32) _(u,64,2,epu64)
+#undef _
/* *INDENT-ON* */
#define CLIB_VEC128_SPLAT_DEFINED
@@ -520,12 +534,6 @@ u32x4_zero_byte_mask (u32x4 x)
return u8x16_compare_byte_mask ((u8x16) (x == zero));
}
-always_inline u8x16
-u8x16_max (u8x16 x, u8x16 y)
-{
- return (u8x16) _mm_max_epu8 ((__m128i) x, (__m128i) y);
-}
-
always_inline u32
u8x16_max_scalar (u8x16 x)
{
@@ -536,12 +544,6 @@ u8x16_max_scalar (u8x16 x)
return _mm_extract_epi16 ((__m128i) x, 0) & 0xff;
}
-always_inline u8x16
-u8x16_min (u8x16 x, u8x16 y)
-{
- return (u8x16) _mm_min_epu8 ((__m128i) x, (__m128i) y);
-}
-
always_inline u8
u8x16_min_scalar (u8x16 x)
{
@@ -552,12 +554,6 @@ u8x16_min_scalar (u8x16 x)
return _mm_extract_epi16 ((__m128i) x, 0) & 0xff;
}
-always_inline i16x8
-i16x8_max (i16x8 x, i16x8 y)
-{
- return (i16x8) _mm_max_epi16 ((__m128i) x, (__m128i) y);
-}
-
always_inline i16
i16x8_max_scalar (i16x8 x)
{
@@ -567,12 +563,6 @@ i16x8_max_scalar (i16x8 x)
return _mm_extract_epi16 ((__m128i) x, 0);
}
-always_inline i16x8
-i16x8_min (i16x8 x, i16x8 y)
-{
- return (i16x8) _mm_min_epi16 ((__m128i) x, (__m128i) y);
-}
-
always_inline i16
i16x8_min_scalar (i16x8 x)
{
@@ -582,6 +572,41 @@ i16x8_min_scalar (i16x8 x)
return _mm_extract_epi16 ((__m128i) x, 0);
}
+#define u8x16_align_right(a, b, imm) \
+ (u8x16) _mm_alignr_epi8 ((__m128i) a, (__m128i) b, imm)
+
+static_always_inline u32
+u32x4_min_scalar (u32x4 v)
+{
+ v = u32x4_min (v, (u32x4) u8x16_align_right ((u8x16) v, (u8x16) v, 8));
+ v = u32x4_min (v, (u32x4) u8x16_align_right ((u8x16) v, (u8x16) v, 4));
+ return v[0];
+}
+
+static_always_inline u32
+u32x4_max_scalar (u32x4 v)
+{
+ v = u32x4_max (v, (u32x4) u8x16_align_right ((u8x16) v, (u8x16) v, 8));
+ v = u32x4_max (v, (u32x4) u8x16_align_right ((u8x16) v, (u8x16) v, 4));
+ return v[0];
+}
+
+static_always_inline u32
+i32x4_min_scalar (i32x4 v)
+{
+ v = i32x4_min (v, (i32x4) u8x16_align_right ((u8x16) v, (u8x16) v, 8));
+ v = i32x4_min (v, (i32x4) u8x16_align_right ((u8x16) v, (u8x16) v, 4));
+ return v[0];
+}
+
+static_always_inline u32
+i32x4_max_scalar (i32x4 v)
+{
+ v = i32x4_max (v, (i32x4) u8x16_align_right ((u8x16) v, (u8x16) v, 8));
+ v = i32x4_max (v, (i32x4) u8x16_align_right ((u8x16) v, (u8x16) v, 4));
+ return v[0];
+}
+
static_always_inline u16
u8x16_msb_mask (u8x16 v)
{