17#include <xvec/detail/config.hpp>
20#if defined(__cpp_lib_is_scoped_enum) && (__cpp_lib_is_scoped_enum >= 202011L)
22namespace _XVEC_NAMESPACE::simd::detail {
24 concept is_scoped_enum = std::is_scoped_enum_v<E>;
27namespace _XVEC_NAMESPACE::simd::detail {
31 (!std::is_convertible_v<E, std::underlying_type_t<E>>);
35namespace _XVEC_NAMESPACE::simd::detail {
40 !std::same_as<std::remove_cv_t<T>,
bool> &&
41 !std::same_as<std::remove_cv_t<T>,
char> &&
42 !std::same_as<std::remove_cv_t<T>,
wchar_t> &&
43 !std::same_as<std::remove_cv_t<T>,
char8_t> &&
44 !std::same_as<std::remove_cv_t<T>,
char16_t> &&
45 !std::same_as<std::remove_cv_t<T>,
char32_t>;
49template<saturation_
integer To, saturation_
integer From>
52 if (std::in_range<To>(value))
53 return static_cast<To
>(value);
57 if constexpr (std::signed_integral<From>) {
59 return std::numeric_limits<To>::min();
63 return std::numeric_limits<To>::max();
67template<saturation_
integer T>
72 if (!__builtin_add_overflow(lhs, rhs, &result))
75 constexpr T lowest = std::numeric_limits<T>::min();
76 constexpr T highest = std::numeric_limits<T>::max();
78 if constexpr (std::unsigned_integral<T>) {
84 return rhs < 0 ? lowest : highest;
89template<saturation_
integer T>
94 if (!__builtin_sub_overflow(lhs, rhs, &result))
97 constexpr T lowest = std::numeric_limits<T>::min();
98 constexpr T highest = std::numeric_limits<T>::max();
100 if constexpr (std::unsigned_integral<T>) {
108 return rhs < 0 ? highest : lowest;
113template<saturation_
integer T>
118 if (!__builtin_mul_overflow(lhs, rhs, &result))
121 constexpr T lowest = std::numeric_limits<T>::min();
122 constexpr T highest = std::numeric_limits<T>::max();
124 if constexpr (std::unsigned_integral<T>) {
132 return (lhs < 0) == (rhs < 0) ? highest : lowest;
137template<saturation_
integer T>
140 if constexpr (std::signed_integral<T>) {
143 if (lhs == std::numeric_limits<T>::min() && rhs == T{-1})
144 return std::numeric_limits<T>::max();
152template<
typename T =
void>
154 constexpr T operator()(
const T& lhs,
const T& rhs)
const {
159template<
typename T =
void>
161 constexpr T operator()(
const T& lhs,
const T& rhs)
const {
169 template<
typename T,
typename U>
170 constexpr auto operator()(T&& lhs, U&& rhs)
const
171 ->
decltype(std::forward<T>(lhs) << std::forward<U>(rhs)) {
172 return std::forward<T>(lhs) << std::forward<U>(rhs);
175 using is_transparent = void;
180 template<
typename T,
typename U>
181 constexpr auto operator()(T&& lhs, U&& rhs)
const
182 ->
decltype(std::forward<T>(lhs) >> std::forward<U>(rhs)) {
183 return std::forward<T>(lhs) >> std::forward<U>(rhs);
186 using is_transparent = void;
189template<
typename _Tp>
191 std::same_as<std::remove_cvref_t<_Tp>,
unsigned char> ||
192 std::same_as<std::remove_cvref_t<_Tp>,
unsigned short> ||
193 std::same_as<std::remove_cvref_t<_Tp>,
unsigned int> ||
194 std::same_as<std::remove_cvref_t<_Tp>,
unsigned long> ||
195 std::same_as<std::remove_cvref_t<_Tp>,
unsigned long long>;
202template <funnel_shift_source T, std::
integral S>
204 constexpr auto N = std::numeric_limits<T>::digits;
205 assert(s >= 0 &&
static_cast<unsigned>(s) <
static_cast<unsigned>(N));
206 const auto r =
static_cast<unsigned>(s);
207 if (r == 0)
return low;
208 return static_cast<T
>((low >> r) | (high << (N - r)));
216template <funnel_shift_source T, std::
integral S>
218 constexpr auto N = std::numeric_limits<T>::digits;
219 assert(s >= 0 &&
static_cast<unsigned>(s) <
static_cast<unsigned>(N));
220 const auto r =
static_cast<unsigned>(s);
221 if (r == 0)
return high;
222 return static_cast<T
>((high << r) | (low >> (N - r)));
227#if defined(__FLT16_MIN__) && !defined(__STDCPP_FLOAT16_T__)
233struct numeric_limits<_Float16> {
234 static constexpr bool is_specialized =
true;
236 static constexpr int digits = 11;
237 static constexpr int digits10 = 3;
238 static constexpr int max_digits10 = 5;
239 static constexpr bool is_signed =
true;
240 static constexpr bool is_integer =
false;
241 static constexpr bool is_exact =
false;
242 static constexpr int radix = 2;
243 static constexpr int min_exponent = -13;
244 static constexpr int min_exponent10 = -4;
245 static constexpr int max_exponent = 16;
246 static constexpr int max_exponent10 = 4;
248 static constexpr bool has_infinity =
true;
249 static constexpr bool has_quiet_NaN =
true;
250 static constexpr bool has_signaling_NaN =
true;
252 static constexpr bool is_iec559 =
true;
253 static constexpr bool is_bounded =
true;
254 static constexpr bool is_modulo =
false;
256 static constexpr bool traps =
false;
257 static constexpr bool tinyness_before =
false;
258 static constexpr float_round_style round_style = round_to_nearest;
260 static constexpr _Float16 min() noexcept {
return static_cast<_Float16
>(__FLT16_MIN__); }
261 static constexpr _Float16 max() noexcept {
return static_cast<_Float16
>(__FLT16_MAX__); }
262 static constexpr _Float16 lowest() noexcept {
return static_cast<_Float16
>(-__FLT16_MAX__); }
263 static constexpr _Float16 epsilon() noexcept {
return static_cast<_Float16
>(__FLT16_EPSILON__); }
264 static constexpr _Float16 round_error() noexcept {
return static_cast<_Float16
>(0.5f); }
265 static constexpr _Float16 infinity() noexcept {
return static_cast<_Float16
>(__builtin_huge_valf()); }
266 static constexpr _Float16 quiet_NaN() noexcept {
return static_cast<_Float16
>(__builtin_nanf(
"")); }
267 static constexpr _Float16 signaling_NaN() noexcept {
return static_cast<_Float16
>(__builtin_nansf(
"")); }
268 static constexpr _Float16 denorm_min() noexcept {
return static_cast<_Float16
>(__FLT16_DENORM_MIN__); }
Definition compat.hpp:190
constexpr T funnel_shift_right(T high, T low, S s) noexcept
Definition compat.hpp:203
constexpr T saturating_sub(T lhs, T rhs) noexcept
Subtract two integers, clamping an unrepresentable mathematical result.
Definition compat.hpp:90
constexpr T saturating_div(T lhs, T rhs) noexcept
Divide two integers, clamping an unrepresentable mathematical result.
Definition compat.hpp:138
constexpr T saturating_add(T lhs, T rhs) noexcept
Add two integers, clamping an unrepresentable mathematical result.
Definition compat.hpp:68
constexpr T funnel_shift_left(T high, T low, S s) noexcept
Definition compat.hpp:217
constexpr To saturating_cast(From value) noexcept
Definition compat.hpp:50
constexpr T saturating_mul(T lhs, T rhs) noexcept
Multiply two integers, clamping an unrepresentable mathematical result.
Definition compat.hpp:114
Definition compat.hpp:153
Definition compat.hpp:160