Skip to content

Commit e3dbecf

Browse files
Test and fix min/max implementation on uint32_t for AVX2
1 parent b40bc5c commit e3dbecf

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

include/xsimd/types/xsimd_avx_int32.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,18 +441,18 @@ namespace xsimd
441441
static batch_type min(const batch_type& lhs, const batch_type& rhs)
442442
{
443443
#if XSIMD_X86_INSTR_SET >= XSIMD_X86_AVX2_VERSION
444-
return _mm256_min_epi32(lhs, rhs);
444+
return _mm256_min_epu32(lhs, rhs);
445445
#else
446-
XSIMD_APPLY_SSE_FUNCTION(_mm_min_epi32, lhs, rhs);
446+
XSIMD_APPLY_SSE_FUNCTION(_mm_min_epu32, lhs, rhs);
447447
#endif
448448
}
449449

450450
static batch_type max(const batch_type& lhs, const batch_type& rhs)
451451
{
452452
#if XSIMD_X86_INSTR_SET >= XSIMD_X86_AVX2_VERSION
453-
return _mm256_max_epi32(lhs, rhs);
453+
return _mm256_max_epu32(lhs, rhs);
454454
#else
455-
XSIMD_APPLY_SSE_FUNCTION(_mm_max_epi32, lhs, rhs);
455+
XSIMD_APPLY_SSE_FUNCTION(_mm_max_epu32, lhs, rhs);
456456
#endif
457457
}
458458

test/test_batch.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,14 @@ class batch_test : public testing::Test
356356
batch_type res = min(batch_lhs(), batch_rhs());
357357
EXPECT_BATCH_EQ(res, expected) << print_function_name("min");
358358
}
359+
// min limit case
360+
{
361+
array_type expected;
362+
std::transform(lhs.cbegin(), lhs.cend(), rhs.cbegin(), expected.begin(),
363+
[](const value_type& , const value_type& r) { return std::min(std::numeric_limits<value_type>::min(), r); });
364+
batch_type res = xsimd::min(batch_type(std::numeric_limits<value_type>::min()), batch_rhs());
365+
EXPECT_BATCH_EQ(res, expected) << print_function_name("min limit");
366+
}
359367
// fmin
360368
{
361369
array_type expected;
@@ -372,6 +380,14 @@ class batch_test : public testing::Test
372380
batch_type res = max(batch_lhs(), batch_rhs());
373381
EXPECT_BATCH_EQ(res, expected) << print_function_name("max");
374382
}
383+
// max limit case
384+
{
385+
array_type expected;
386+
std::transform(lhs.cbegin(), lhs.cend(), rhs.cbegin(), expected.begin(),
387+
[](const value_type& , const value_type& r) { return std::max(std::numeric_limits<value_type>::max(), r); });
388+
batch_type res = xsimd::max(batch_type(std::numeric_limits<value_type>::max()), batch_rhs());
389+
EXPECT_BATCH_EQ(res, expected) << print_function_name("max limit");
390+
}
375391
// fmax
376392
{
377393
array_type expected;

0 commit comments

Comments
 (0)