@@ -30,6 +30,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3030
3131template <__signed_or_unsigned_integer _Tp>
3232_LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat (_Tp __x, _Tp __y) noexcept {
33+ # if __has_builtin(__builtin_elementwise_add_sat)
34+ return __builtin_elementwise_add_sat (__x, __y);
35+ # else
3336 if (_Tp __sum; !__builtin_add_overflow (__x, __y, std::addressof (__sum)))
3437 return __sum;
3538 // Handle overflow
@@ -44,10 +47,14 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept {
4447 // Overflows if (x < 0 && y < 0)
4548 return std::numeric_limits<_Tp>::min ();
4649 }
50+ # endif
4751}
4852
4953template <__signed_or_unsigned_integer _Tp>
5054_LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat (_Tp __x, _Tp __y) noexcept {
55+ # if __has_builtin(__builtin_elementwise_sub_sat)
56+ return __builtin_elementwise_sub_sat (__x, __y);
57+ # else
5158 if (_Tp __sub; !__builtin_sub_overflow (__x, __y, std::addressof (__sub)))
5259 return __sub;
5360 // Handle overflow
@@ -63,6 +70,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept {
6370 // Overflows if (x < 0 && y > 0)
6471 return std::numeric_limits<_Tp>::min ();
6572 }
73+ # endif
6674}
6775
6876template <__signed_or_unsigned_integer _Tp>
0 commit comments