Skip to content

Commit

Permalink
Fix horizontal max/min for uchar
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Sep 29, 2023
1 parent ea663e2 commit 743bfe9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Vc/sse/detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,9 @@ Vc_INTRINSIC schar min(__m128i a, schar) {
return std::min(schar(_mm_cvtsi128_si32(a) >> 8), schar(_mm_cvtsi128_si32(a)));
}
Vc_INTRINSIC uchar min(__m128i a, uchar) {
a = min(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(1, 0, 3, 2)), schar());
a = min(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 0, 3, 2)), schar());
a = min(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 1, 1, 1)), schar());
a = min(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(1, 0, 3, 2)), uchar());
a = min(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 0, 3, 2)), uchar());
a = min(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 1, 1, 1)), uchar());
return std::min((_mm_cvtsi128_si32(a) >> 8) & 0xff, _mm_cvtsi128_si32(a) & 0xff);
}

Expand Down Expand Up @@ -764,9 +764,9 @@ Vc_INTRINSIC schar max(__m128i a, schar) {
return std::max(schar(_mm_cvtsi128_si32(a) >> 8), schar(_mm_cvtsi128_si32(a)));
}
Vc_INTRINSIC uchar max(__m128i a, uchar) {
a = max(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(1, 0, 3, 2)), schar());
a = max(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 0, 3, 2)), schar());
a = max(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 1, 1, 1)), schar());
a = max(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(1, 0, 3, 2)), uchar());
a = max(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 0, 3, 2)), uchar());
a = max(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 1, 1, 1)), uchar());
return std::max((_mm_cvtsi128_si32(a) >> 8) & 0xff, _mm_cvtsi128_si32(a) & 0xff);
}

Expand Down
17 changes: 17 additions & 0 deletions tests/arithmetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,23 @@ TEST_TYPES(Vec, testMax, AllVectors)
}
}

#if defined(Vc_IMPL_AVX2) && !defined(Vc_MSVC)
TEST(minChar)
{
uint8_t a[64]{0, 10, 250};
COMPARE(Vc::schar_v(reinterpret_cast<Vc::schar*>(a)).min(), Vc::schar{-6});
COMPARE(Vc::uchar_v(a).min(), Vc::uchar{0});
}

// Tests issue: https://github.com/VcDevel/Vc/issues/349
TEST(maxChar)
{
uint8_t a[64]{0, 10, 250};
COMPARE(Vc::schar_v(reinterpret_cast<Vc::schar*>(a)).max(), Vc::schar{10});
COMPARE(Vc::uchar_v(a).max(), Vc::uchar{250});
}
#endif

// testProduct{{{1
TEST_TYPES(Vec, testProduct, AllVectors)
{
Expand Down

0 comments on commit 743bfe9

Please sign in to comment.