Skip to content

Commit

Permalink
Fix horizontal max for uchar
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Dec 9, 2022
1 parent d4b8109 commit 28e1190
Show file tree
Hide file tree
Showing 2 changed files with 10 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
7 changes: 7 additions & 0 deletions tests/arithmetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,13 @@ TEST_TYPES(Vec, testMax, AllVectors)
}
}

// Tests issue: https://github.com/VcDevel/Vc/issues/349
TEST(Vec, testMaxChar) {
uint8_t a[64]{0, 10, 250};
COMPARE(Vc::schar_v((signed char*)a).max() == 10);
COMPARE(Vc::char_v(a).max() == 250);
}

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

0 comments on commit 28e1190

Please sign in to comment.