Skip to content

Commit

Permalink
Fix horizontal max/min for uchar
Browse files Browse the repository at this point in the history
Fixes: #349
  • Loading branch information
bernhardmgruber committed Sep 29, 2023
1 parent ea663e2 commit dec4980
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Vc/sse/detail.h
Original file line number Diff line number Diff line change
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)
}
}

#ifdef Vc_IMPL_AVX2
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 dec4980

Please sign in to comment.