Skip to content

Commit cff139f

Browse files
committed
Use the SSE saturating subtract for 8 and 16 bit types on AVX
1 parent 6337721 commit cff139f

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

include/xsimd/arch/xsimd_avx.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,15 @@ namespace xsimd
17181718
template <class A, class T, class = std::enable_if_t<std::is_integral_v<T>>>
17191719
XSIMD_INLINE batch<T, A> ssub(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx>) noexcept
17201720
{
1721-
if (std::is_signed_v<T>)
1721+
// 8 and 16 bit saturating subtraction has dedicated SSE2 instructions,
1722+
// wider types have none, so only those take the generic sequence below.
1723+
if constexpr (sizeof(T) <= 2)
1724+
{
1725+
return detail::fwd_to_sse([](__m128i s, __m128i o) noexcept
1726+
{ return ssub(batch<T, sse4_2>(s), batch<T, sse4_2>(o)); },
1727+
self, other);
1728+
}
1729+
else if (std::is_signed_v<T>)
17221730
{
17231731
auto mask = (other >> (8 * sizeof(T) - 1));
17241732
auto self_overflow_branch = min(std::numeric_limits<T>::max() + other, self);

0 commit comments

Comments
 (0)