Skip to content

Commit

Permalink
Cleanup saturated operators testing
Browse files Browse the repository at this point in the history
Also always use the generic implementation for floating point version.
  • Loading branch information
serge-sans-paille committed Nov 4, 2022
1 parent 31fd404 commit 4d18c0f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 64 deletions.
24 changes: 24 additions & 0 deletions include/xsimd/arch/generic/xsimd_generic_arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@ namespace xsimd
self, other);
}

// sadd
template <class A>
inline batch<float, A> sadd(batch<float, A> const& self, batch<float, A> const& other, requires_arch<generic>) noexcept
{
return add(self, other); // no saturated arithmetic on floating point numbers
}
template <class A>
inline batch<double, A> sadd(batch<double, A> const& self, batch<double, A> const& other, requires_arch<generic>) noexcept
{
return add(self, other); // no saturated arithmetic on floating point numbers
}

// ssub
template <class A>
inline batch<float, A> ssub(batch<float, A> const& self, batch<float, A> const& other, requires_arch<generic>) noexcept
{
return sub(self, other); // no saturated arithmetic on floating point numbers
}
template <class A>
inline batch<double, A> ssub(batch<double, A> const& self, batch<double, A> const& other, requires_arch<generic>) noexcept
{
return sub(self, other); // no saturated arithmetic on floating point numbers
}

}

}
Expand Down
20 changes: 0 additions & 20 deletions include/xsimd/arch/xsimd_avx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,16 +1132,6 @@ namespace xsimd
}

// sadd
template <class A>
inline batch<float, A> sadd(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx>) noexcept
{
return add(self, other); // no saturated arithmetic on floating point numbers
}
template <class A>
inline batch<double, A> sadd(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx>) noexcept
{
return add(self, other); // no saturated arithmetic on floating point numbers
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> sadd(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx>) noexcept
{
Expand Down Expand Up @@ -1357,16 +1347,6 @@ namespace xsimd
}

// ssub
template <class A>
inline batch<float, A> ssub(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx>) noexcept
{
return _mm256_sub_ps(self, other); // no saturated arithmetic on floating point numbers
}
template <class A>
inline batch<double, A> ssub(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx>) noexcept
{
return _mm256_sub_pd(self, other); // no saturated arithmetic on floating point numbers
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> ssub(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx>) noexcept
{
Expand Down
20 changes: 0 additions & 20 deletions include/xsimd/arch/xsimd_avx512f.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,16 +1350,6 @@ namespace xsimd
}

// sadd
template <class A>
inline batch<float, A> sadd(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx512f>) noexcept
{
return add(self, other); // no saturated arithmetic on floating point numbers
}
template <class A>
inline batch<double, A> sadd(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx512f>) noexcept
{
return add(self, other); // no saturated arithmetic on floating point numbers
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> sadd(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512f>) noexcept
{
Expand Down Expand Up @@ -1642,16 +1632,6 @@ namespace xsimd
}

// ssub
template <class A>
inline batch<float, A> ssub(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx512f>) noexcept
{
return _mm512_sub_ps(self, other); // no saturated arithmetic on floating point numbers
}
template <class A>
inline batch<double, A> ssub(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx512f>) noexcept
{
return _mm512_sub_pd(self, other); // no saturated arithmetic on floating point numbers
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> ssub(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512f>) noexcept
{
Expand Down
22 changes: 1 addition & 21 deletions include/xsimd/arch/xsimd_sse2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,11 +1325,7 @@ namespace xsimd
}

// sadd
template <class A>
inline batch<float, A> sadd(batch<float, A> const& self, batch<float, A> const& other, requires_arch<sse2>) noexcept
{
return _mm_add_ps(self, other); // no saturated arithmetic on floating point numbers
}

// TODO: move this in xsimd_generic
namespace detail
{
Expand Down Expand Up @@ -1386,11 +1382,6 @@ namespace xsimd
}
}
}
template <class A>
inline batch<double, A> sadd(batch<double, A> const& self, batch<double, A> const& other, requires_arch<sse2>) noexcept
{
return _mm_add_pd(self, other); // no saturated arithmetic on floating point numbers
}

// set
template <class A, class... Values>
Expand Down Expand Up @@ -1449,11 +1440,6 @@ namespace xsimd
}

// ssub
template <class A>
inline batch<float, A> ssub(batch<float, A> const& self, batch<float, A> const& other, requires_arch<sse2>) noexcept
{
return _mm_sub_ps(self, other); // no saturated arithmetic on floating point numbers
}
// TODO: move this in xsimd_generic
namespace detail
{
Expand Down Expand Up @@ -1507,12 +1493,6 @@ namespace xsimd
}
}

template <class A>
inline batch<double, A> ssub(batch<double, A> const& self, batch<double, A> const& other, requires_arch<sse2>) noexcept
{
return _mm_sub_pd(self, other); // no saturated arithmetic on floating point numbers
}

// store_aligned
template <class A>
inline void store_aligned(float* mem, batch<float, A> const& self, requires_arch<sse2>) noexcept
Expand Down
4 changes: 2 additions & 2 deletions include/xsimd/types/xsimd_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ namespace xsimd
* @return the result of the saturated addition.
*/
template <class T, class A>
inline auto sadd(batch<T, A> const& x, batch<T, A> const& y) noexcept -> decltype(x + y)
inline batch<T, A> sadd(batch<T, A> const& x, batch<T, A> const& y) noexcept
{
detail::static_check_supported_config<T, A>();
return kernel::sadd<A>(x, y, A {});
Expand Down Expand Up @@ -1884,7 +1884,7 @@ namespace xsimd
* @return the result of the saturated difference.
*/
template <class T, class A>
inline auto ssub(batch<T, A> const& x, batch<T, A> const& y) noexcept -> decltype(x - y)
inline batch<T, A> ssub(batch<T, A> const& x, batch<T, A> const& y) noexcept
{
detail::static_check_supported_config<T, A>();
return kernel::ssub<A>(x, y, A {});
Expand Down
4 changes: 3 additions & 1 deletion test/test_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ struct batch_test

void test_saturated_arithmetic() const
{
#ifdef T
// batch + batch
{
array_type expected;
Expand All @@ -259,6 +258,7 @@ struct batch_test
INFO("sadd(batch, batch)");
CHECK_BATCH_EQ(res, expected);
}
#if 0
// batch + scalar
{
array_type expected;
Expand All @@ -271,6 +271,7 @@ struct batch_test
INFO("sadd(scalar, batch)");
CHECK_BATCH_EQ(rres, expected);
}
#endif
// batch - batch
{
array_type expected;
Expand All @@ -280,6 +281,7 @@ struct batch_test
INFO("ssub(batch, batch)");
CHECK_BATCH_EQ(res, expected);
}
#if 0
// batch - scalar
{
array_type expected;
Expand Down

0 comments on commit 4d18c0f

Please sign in to comment.