Skip to content

Commit 2e6c1b1

Browse files
Fix horizontal max for uchar
Fixes: VcDevel#349
1 parent d4b8109 commit 2e6c1b1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Vc/sse/detail.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,9 @@ Vc_INTRINSIC schar max(__m128i a, schar) {
764764
return std::max(schar(_mm_cvtsi128_si32(a) >> 8), schar(_mm_cvtsi128_si32(a)));
765765
}
766766
Vc_INTRINSIC uchar max(__m128i a, uchar) {
767-
a = max(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(1, 0, 3, 2)), schar());
768-
a = max(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 0, 3, 2)), schar());
769-
a = max(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 1, 1, 1)), schar());
767+
a = max(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(1, 0, 3, 2)), uchar());
768+
a = max(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 0, 3, 2)), uchar());
769+
a = max(a, _mm_shufflelo_epi16(a, _MM_SHUFFLE(1, 1, 1, 1)), uchar());
770770
return std::max((_mm_cvtsi128_si32(a) >> 8) & 0xff, _mm_cvtsi128_si32(a) & 0xff);
771771
}
772772

tests/arithmetics.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,13 @@ TEST_TYPES(Vec, testMax, AllVectors)
472472
}
473473
}
474474

475+
// Tests issue: https://github.com/VcDevel/Vc/issues/349
476+
TEST(Vec, maxChar) {
477+
uint8_t a[64]{0, 10, 250};
478+
COMPARE(Vc::schar_v((signed char*)a).max() == 10);
479+
COMPARE(Vc::char_v(a).max() == 250);
480+
}
481+
475482
// testProduct{{{1
476483
TEST_TYPES(Vec, testProduct, AllVectors)
477484
{

0 commit comments

Comments
 (0)