diff --git a/include/xsimd/arch/xsimd_avx.hpp b/include/xsimd/arch/xsimd_avx.hpp index 20bbf600f..9d93be071 100644 --- a/include/xsimd/arch/xsimd_avx.hpp +++ b/include/xsimd/arch/xsimd_avx.hpp @@ -925,12 +925,12 @@ namespace xsimd template XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept { - return _mm256_max_ps(self, other); + return _mm256_max_ps(other, self); } template XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept { - return _mm256_max_pd(self, other); + return _mm256_max_pd(other, self); } template ::value, void>::type> XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept @@ -942,12 +942,12 @@ namespace xsimd template XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept { - return _mm256_min_ps(self, other); + return _mm256_min_ps(other, self); } template XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept { - return _mm256_min_pd(self, other); + return _mm256_min_pd(other, self); } template ::value, void>::type> XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept diff --git a/include/xsimd/arch/xsimd_avx512f.hpp b/include/xsimd/arch/xsimd_avx512f.hpp index 7073d9d4f..7d980a538 100644 --- a/include/xsimd/arch/xsimd_avx512f.hpp +++ b/include/xsimd/arch/xsimd_avx512f.hpp @@ -1326,12 +1326,12 @@ namespace xsimd template XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept { - return _mm512_max_ps(self, other); + return _mm512_max_ps(other, self); } template XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept { - return _mm512_max_pd(self, other); + return _mm512_max_pd(other, self); } template ::value, void>::type> XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept @@ -1376,12 +1376,12 @@ namespace xsimd template XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept { - return _mm512_min_ps(self, other); + return _mm512_min_ps(other, self); } template XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept { - return _mm512_min_pd(self, other); + return _mm512_min_pd(other, self); } template ::value, void>::type> XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept diff --git a/include/xsimd/arch/xsimd_sse2.hpp b/include/xsimd/arch/xsimd_sse2.hpp index e8ad82875..2e892de3a 100644 --- a/include/xsimd/arch/xsimd_sse2.hpp +++ b/include/xsimd/arch/xsimd_sse2.hpp @@ -1137,7 +1137,7 @@ namespace xsimd template XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept { - return _mm_max_ps(self, other); + return _mm_max_ps(other, self); } template ::value, void>::type> XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept @@ -1147,14 +1147,14 @@ namespace xsimd template XSIMD_INLINE batch max(batch const& self, batch const& other, requires_arch) noexcept { - return _mm_max_pd(self, other); + return _mm_max_pd(other, self); } // min template XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept { - return _mm_min_ps(self, other); + return _mm_min_ps(other, self); } template ::value, void>::type> XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept @@ -1164,7 +1164,7 @@ namespace xsimd template XSIMD_INLINE batch min(batch const& self, batch const& other, requires_arch) noexcept { - return _mm_min_pd(self, other); + return _mm_min_pd(other, self); } // mul diff --git a/test/test_xsimd_api.cpp b/test/test_xsimd_api.cpp index bea9f1b86..26b7618ad 100644 --- a/test/test_xsimd_api.cpp +++ b/test/test_xsimd_api.cpp @@ -658,6 +658,29 @@ struct xsimd_api_float_types_functions value_type val(0); CHECK_EQ(extract(xsimd::log1p(T(val))), std::log1p(val)); } + + void test_max_nan() + { + value_type val0(2.7818); + value_type valN(NAN); +#if XSIMD_WITH_AVX || XSIMD_WITH_SSE2 + using isnan = doctest::IsNaN; + CHECK_EQ(isnan(extract(xsimd::max(T(val0), T(valN)))), isnan(std::max(val0, valN))); + CHECK_EQ(isnan(extract(xsimd::max(T(valN), T(val0)))), isnan(std::max(valN, val0))); +#endif + } + + void test_min_nan() + { + value_type val0(2.7818); + value_type valN(NAN); +#if XSIMD_WITH_AVX || XSIMD_WITH_SSE2 + using isnan = doctest::IsNaN; + CHECK_EQ(isnan(extract(xsimd::min(T(val0), T(valN)))), isnan(std::min(val0, valN))); + CHECK_EQ(isnan(extract(xsimd::min(T(valN), T(val0)))), isnan(std::min(valN, val0))); +#endif + } + void test_nearbyint() { value_type val(3.1); @@ -929,6 +952,16 @@ TEST_CASE_TEMPLATE("[xsimd api | float types functions]", B, FLOAT_TYPES) Test.test_log1p(); } + SUBCASE("max_nan") + { + Test.test_max_nan(); + } + + SUBCASE("min_nan") + { + Test.test_min_nan(); + } + SUBCASE("nearbyint") { Test.test_nearbyint();