25#ifndef _GLIBCXX_EXPERIMENTAL_SIMD_MATH_H_
26#define _GLIBCXX_EXPERIMENTAL_SIMD_MATH_H_
28#if __cplusplus >= 201703L
33_GLIBCXX_SIMD_BEGIN_NAMESPACE
34template <
typename _Tp,
typename _V>
35 using _Samesize = fixed_size_simd<_Tp, _V::size()>;
38template <
typename _DoubleR,
typename _Tp,
typename _Abi>
39 struct _Math_return_type;
41template <
typename _DoubleR,
typename _Tp,
typename _Abi>
42 using _Math_return_type_t =
43 typename _Math_return_type<_DoubleR, _Tp, _Abi>::type;
45template <
typename _Tp,
typename _Abi>
46 struct _Math_return_type<double, _Tp, _Abi>
47 {
using type = simd<_Tp, _Abi>; };
49template <
typename _Tp,
typename _Abi>
50 struct _Math_return_type<bool, _Tp, _Abi>
51 {
using type = simd_mask<_Tp, _Abi>; };
53template <
typename _DoubleR,
typename _Tp,
typename _Abi>
54 struct _Math_return_type
55 {
using type = fixed_size_simd<_DoubleR, simd_size_v<_Tp, _Abi>>; };
59#define _GLIBCXX_SIMD_MATH_CALL_(__name) \
60template <typename _Tp, typename _Abi, typename..., \
61 typename _R = _Math_return_type_t< \
62 decltype(std::__name(declval<double>())), _Tp, _Abi>> \
63 _GLIBCXX_SIMD_ALWAYS_INLINE \
64 enable_if_t<is_floating_point_v<_Tp>, _R> \
65 __name(simd<_Tp, _Abi> __x) \
66 { return {__private_init, _Abi::_SimdImpl::_S_##__name(__data(__x))}; }
70template <
typename _Up,
typename _Tp,
typename _Abi>
71 struct _Extra_argument_type;
73template <
typename _Tp,
typename _Abi>
74 struct _Extra_argument_type<_Tp*, _Tp, _Abi>
76 using type = simd<_Tp, _Abi>*;
77 static constexpr double*
declval();
78 static constexpr bool __needs_temporary_scalar =
true;
80 _GLIBCXX_SIMD_INTRINSIC
static constexpr auto _S_data(type __x)
81 {
return &__data(*__x); }
84template <
typename _Up,
typename _Tp,
typename _Abi>
85 struct _Extra_argument_type<_Up*, _Tp, _Abi>
87 static_assert(is_integral_v<_Up>);
88 using type = fixed_size_simd<_Up, simd_size_v<_Tp, _Abi>>*;
89 static constexpr _Up*
declval();
90 static constexpr bool __needs_temporary_scalar =
true;
92 _GLIBCXX_SIMD_INTRINSIC
static constexpr auto _S_data(type __x)
93 {
return &__data(*__x); }
96template <
typename _Tp,
typename _Abi>
97 struct _Extra_argument_type<_Tp, _Tp, _Abi>
99 using type = simd<_Tp, _Abi>;
100 static constexpr double declval();
101 static constexpr bool __needs_temporary_scalar =
false;
103 _GLIBCXX_SIMD_INTRINSIC
static constexpr decltype(
auto)
104 _S_data(
const type& __x)
105 {
return __data(__x); }
108template <
typename _Up,
typename _Tp,
typename _Abi>
109 struct _Extra_argument_type
111 static_assert(is_integral_v<_Up>);
112 using type = fixed_size_simd<_Up, simd_size_v<_Tp, _Abi>>;
113 static constexpr _Up
declval();
114 static constexpr bool __needs_temporary_scalar =
false;
116 _GLIBCXX_SIMD_INTRINSIC
static constexpr decltype(
auto)
117 _S_data(
const type& __x)
118 {
return __data(__x); }
123#define _GLIBCXX_SIMD_MATH_CALL2_(__name, __arg2) \
125 typename _Tp, typename _Abi, typename..., \
126 typename _Arg2 = _Extra_argument_type<__arg2, _Tp, _Abi>, \
127 typename _R = _Math_return_type_t< \
128 decltype(std::__name(declval<double>(), _Arg2::declval())), _Tp, _Abi>> \
129 _GLIBCXX_SIMD_ALWAYS_INLINE \
130 enable_if_t<is_floating_point_v<_Tp>, _R> \
131 __name(const simd<_Tp, _Abi>& __x, const typename _Arg2::type& __y) \
133 return {__private_init, \
134 _Abi::_SimdImpl::_S_##__name(__data(__x), _Arg2::_S_data(__y))}; \
136template <typename _Up, typename _Tp, typename _Abi> \
137 _GLIBCXX_SIMD_INTRINSIC _Math_return_type_t< \
138 decltype(std::__name( \
140 declval<enable_if_t< \
142 is_same<__arg2, _Tp>, \
143 negation<is_same<__remove_cvref_t<_Up>, simd<_Tp, _Abi>>>, \
144 is_convertible<_Up, simd<_Tp, _Abi>>, is_floating_point<_Tp>>, \
147 __name(_Up&& __xx, const simd<_Tp, _Abi>& __yy) \
148 { return __name(simd<_Tp, _Abi>(static_cast<_Up&&>(__xx)), __yy); }
152#define _GLIBCXX_SIMD_MATH_CALL3_(__name, __arg2, __arg3) \
153template <typename _Tp, typename _Abi, typename..., \
154 typename _Arg2 = _Extra_argument_type<__arg2, _Tp, _Abi>, \
155 typename _Arg3 = _Extra_argument_type<__arg3, _Tp, _Abi>, \
156 typename _R = _Math_return_type_t< \
157 decltype(std::__name(declval<double>(), _Arg2::declval(), \
158 _Arg3::declval())), \
160 _GLIBCXX_SIMD_ALWAYS_INLINE \
161 enable_if_t<is_floating_point_v<_Tp>, _R> \
162 __name(const simd<_Tp, _Abi>& __x, const typename _Arg2::type& __y, \
163 const typename _Arg3::type& __z) \
165 return {__private_init, \
166 _Abi::_SimdImpl::_S_##__name(__data(__x), _Arg2::_S_data(__y), \
167 _Arg3::_S_data(__z))}; \
170 typename _T0, typename _T1, typename _T2, typename..., \
171 typename _U0 = __remove_cvref_t<_T0>, \
172 typename _U1 = __remove_cvref_t<_T1>, \
173 typename _U2 = __remove_cvref_t<_T2>, \
174 typename _Simd = conditional_t<is_simd_v<_U1>, _U1, _U2>, \
175 typename = enable_if_t<conjunction_v< \
176 is_simd<_Simd>, is_convertible<_T0&&, _Simd>, \
177 is_convertible<_T1&&, _Simd>, is_convertible<_T2&&, _Simd>, \
178 negation<conjunction< \
179 is_simd<_U0>, is_floating_point<__value_type_or_identity_t<_U0>>>>>>> \
180 _GLIBCXX_SIMD_INTRINSIC decltype(__name(declval<const _Simd&>(), \
181 declval<const _Simd&>(), \
182 declval<const _Simd&>())) \
183 __name(_T0&& __xx, _T1&& __yy, _T2&& __zz) \
185 return __name(_Simd(static_cast<_T0&&>(__xx)), \
186 _Simd(static_cast<_T1&&>(__yy)), \
187 _Simd(static_cast<_T2&&>(__zz))); \
192template <
typename _Abi>
193 _GLIBCXX_SIMD_ALWAYS_INLINE
static simd<float, _Abi>
194 __cosSeries(
const simd<float, _Abi>& __x)
196 const simd<float, _Abi> __x2 = __x * __x;
197 simd<float, _Abi> __y;
199 __y = __y * __x2 - 0x1.6c1p-10f;
200 __y = __y * __x2 + 0x1.555556p-5f;
201 return __y * (__x2 * __x2) - .5f * __x2 + 1.f;
204template <
typename _Abi>
205 _GLIBCXX_SIMD_ALWAYS_INLINE
static simd<double, _Abi>
206 __cosSeries(
const simd<double, _Abi>& __x)
208 const simd<double, _Abi> __x2 = __x * __x;
209 simd<double, _Abi> __y;
210 __y = 0x1.AC00000000000p-45;
211 __y = __y * __x2 - 0x1.9394000000000p-37;
212 __y = __y * __x2 + 0x1.1EED8C0000000p-29;
213 __y = __y * __x2 - 0x1.27E4FB7400000p-22;
214 __y = __y * __x2 + 0x1.A01A01A018000p-16;
215 __y = __y * __x2 - 0x1.6C16C16C16C00p-10;
216 __y = __y * __x2 + 0x1.5555555555554p-5;
217 return (__y * __x2 - .5f) * __x2 + 1.f;
222template <
typename _Abi>
223 _GLIBCXX_SIMD_ALWAYS_INLINE
static simd<float, _Abi>
224 __sinSeries(
const simd<float, _Abi>& __x)
226 const simd<float, _Abi> __x2 = __x * __x;
227 simd<float, _Abi> __y;
228 __y = -0x1.9CC000p-13f;
229 __y = __y * __x2 + 0x1.111100p-7f;
230 __y = __y * __x2 - 0x1.555556p-3f;
231 return __y * (__x2 * __x) + __x;
234template <
typename _Abi>
235 _GLIBCXX_SIMD_ALWAYS_INLINE
static simd<double, _Abi>
236 __sinSeries(
const simd<double, _Abi>& __x)
240 const simd<double, _Abi> __x2 = __x * __x;
241 simd<double, _Abi> __y;
242 __y = -0x1.ACF0000000000p-41;
243 __y = __y * __x2 + 0x1.6124400000000p-33;
244 __y = __y * __x2 - 0x1.AE64567000000p-26;
245 __y = __y * __x2 + 0x1.71DE3A5540000p-19;
246 __y = __y * __x2 - 0x1.A01A01A01A000p-13;
247 __y = __y * __x2 + 0x1.1111111111110p-7;
248 __y = __y * __x2 - 0x1.5555555555555p-3;
249 return __y * (__x2 * __x) + __x;
254template <
int _Bits,
typename _Tp,
typename _Abi>
255 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi>
256 __zero_low_bits(simd<_Tp, _Abi> __x)
258 const simd<_Tp, _Abi> __bitmask
259 = __bit_cast<_Tp>(~make_unsigned_t<__int_for_sizeof_t<_Tp>>() << _Bits);
260 return {__private_init,
261 _Abi::_SimdImpl::_S_bit_and(__data(__x), __data(__bitmask))};
285template <
typename _Tp,
typename _Abi>
288 simd<_Tp, _Abi> _M_x;
289 rebind_simd_t<int, simd<_Tp, _Abi>> _M_quadrant;
292namespace __math_float {
293inline constexpr float __pi_over_4 = 0x1.921FB6p-1f;
294inline constexpr float __2_over_pi = 0x1.45F306p-1f;
295inline constexpr float __pi_2_5bits0
297inline constexpr float __pi_2_5bits0_rem
300namespace __math_double {
301inline constexpr double __pi_over_4 = 0x1.921fb54442d18p-1;
302inline constexpr double __2_over_pi = 0x1.45F306DC9C883p-1;
303inline constexpr double __pi_2 = 0x1.921fb54442d18p0;
306template <
typename _Abi>
307 _GLIBCXX_SIMD_ALWAYS_INLINE _Folded<float, _Abi>
308 __fold_input(
const simd<float, _Abi>& __x)
310 using _V = simd<float, _Abi>;
311 using _IV = rebind_simd_t<int, _V>;
312 using namespace __math_float;
313 _Folded<float, _Abi> __r;
317 constexpr float __1_over_pi = 0x1.45F306p-2f;
318 const auto __y = (__r._M_x * __1_over_pi + 0x1.8p23f) - 0x1.8p23f;
321 constexpr float __pi0 = 0x1.920000p1f;
322 constexpr float __pi1 = 0x1.fb4000p-11f;
323 constexpr float __pi2 = 0x1.444000p-23f;
324 constexpr float __pi3 = 0x1.68c234p-38f;
325 __r._M_x - __y*__pi0 - __y*__pi1 - __y*__pi2 - __y*__pi3
327 if (_GLIBCXX_SIMD_IS_UNLIKELY(all_of(__r._M_x < __pi_over_4)))
329 else if (_GLIBCXX_SIMD_IS_LIKELY(all_of(__r._M_x < 6 * __pi_over_4)))
331 const _V __y = nearbyint(__r._M_x * __2_over_pi);
332 __r._M_quadrant = static_simd_cast<_IV>(__y) & 3;
333 __r._M_x -= __y * __pi_2_5bits0;
334 __r._M_x -= __y * __pi_2_5bits0_rem;
338 using __math_double::__2_over_pi;
339 using __math_double::__pi_2;
340 using _VD = rebind_simd_t<double, _V>;
341 _VD __xd = static_simd_cast<_VD>(__r._M_x);
342 _VD __y = nearbyint(__xd * __2_over_pi);
343 __r._M_quadrant = static_simd_cast<_IV>(__y) & 3;
344 __r._M_x = static_simd_cast<_V>(__xd - __y * __pi_2);
350template <
typename _Abi>
351 _GLIBCXX_SIMD_ALWAYS_INLINE _Folded<double, _Abi>
352 __fold_input(
const simd<double, _Abi>& __x)
354 using _V = simd<double, _Abi>;
355 using _IV = rebind_simd_t<int, _V>;
356 using namespace __math_double;
358 _Folded<double, _Abi> __r;
360 if (_GLIBCXX_SIMD_IS_UNLIKELY(all_of(__r._M_x < __pi_over_4)))
365 const _V __y = nearbyint(__r._M_x / (2 * __pi_over_4));
366 __r._M_quadrant = static_simd_cast<_IV>(__y) & 3;
368 if (_GLIBCXX_SIMD_IS_LIKELY(all_of(__r._M_x < 1025 * __pi_over_4)))
371 __r._M_x -= __y * 0x1.921FB54443000p0;
372 __r._M_x -= __y * -0x1.73DCB3B39A000p-43;
373 __r._M_x -= __y * 0x1.45C06E0E68948p-86;
375 else if (_GLIBCXX_SIMD_IS_LIKELY(all_of(__y <= 0x1.0p30)))
378 __r._M_x -= __y * 0x1.921FB40000000p0;
379 __r._M_x -= __y * 0x1.4442D00000000p-24;
380 __r._M_x -= __y * 0x1.8469898CC5170p-48;
385 const _V __y_hi = __zero_low_bits<26>(__y);
386 const _V __y_lo = __y - __y_hi;
387 const auto __pi_2_1 = 0x1.921FB50000000p0;
388 const auto __pi_2_2 = 0x1.110B460000000p-26;
389 const auto __pi_2_3 = 0x1.1A62630000000p-54;
390 const auto __pi_2_4 = 0x1.8A2E03707344Ap-81;
391 __r._M_x = __r._M_x - __y_hi * __pi_2_1
392 - max(__y_hi * __pi_2_2, __y_lo * __pi_2_1)
393 - min(__y_hi * __pi_2_2, __y_lo * __pi_2_1)
394 - max(__y_hi * __pi_2_3, __y_lo * __pi_2_2)
395 - min(__y_hi * __pi_2_3, __y_lo * __pi_2_2)
396 - max(__y * __pi_2_4, __y_lo * __pi_2_3)
397 - min(__y * __pi_2_4, __y_lo * __pi_2_3);
404template <
typename _Tp,
typename _Abi>
405 _GLIBCXX_SIMD_INTRINSIC
406 rebind_simd_t<int, simd<_Tp, _Abi>>
407 __extract_exponent_as_int(
const simd<_Tp, _Abi>& __v)
409 using _Vp = simd<_Tp, _Abi>;
410 using _Up = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
411 using namespace std::experimental::__float_bitwise_operators;
412 using namespace std::experimental::__proposed;
413 const _Vp __exponent_mask
415 return static_simd_cast<rebind_simd_t<int, _Vp>>(
416 simd_bit_cast<rebind_simd_t<_Up, _Vp>>(__v & __exponent_mask)
417 >> (__digits_v<_Tp> - 1));
422template <
typename ImplFun,
typename FallbackFun,
typename... _Args>
423 _GLIBCXX_SIMD_INTRINSIC
auto
424 __impl_or_fallback_dispatch(
int, ImplFun&& __impl_fun, FallbackFun&&,
426 ->
decltype(__impl_fun(
static_cast<_Args&&
>(__args)...))
427 {
return __impl_fun(
static_cast<_Args&&
>(__args)...); }
429template <
typename ImplFun,
typename FallbackFun,
typename... _Args,
430 typename = __detail::__odr_helper>
432 __impl_or_fallback_dispatch(
float, ImplFun&&, FallbackFun&& __fallback_fun,
434 ->
decltype(__fallback_fun(
static_cast<_Args&&
>(__args)...))
435 {
return __fallback_fun(
static_cast<_Args&&
>(__args)...); }
437template <
typename... _Args>
438 _GLIBCXX_SIMD_INTRINSIC
auto
439 __impl_or_fallback(_Args&&... __args)
441 return __impl_or_fallback_dispatch(
int(),
static_cast<_Args&&
>(__args)...);
446_GLIBCXX_SIMD_MATH_CALL_(acos)
447_GLIBCXX_SIMD_MATH_CALL_(asin)
448_GLIBCXX_SIMD_MATH_CALL_(atan)
449_GLIBCXX_SIMD_MATH_CALL2_(atan2, _Tp)
466template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
467 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
468 cos(
const simd<_Tp, _Abi>& __x)
470 using _V = simd<_Tp, _Abi>;
471 if constexpr (__is_scalar_abi<_Abi>() || __is_fixed_size_abi_v<_Abi>)
472 return {__private_init, _Abi::_SimdImpl::_S_cos(__data(__x))};
475 if constexpr (is_same_v<_Tp, float>)
476 if (_GLIBCXX_SIMD_IS_UNLIKELY(any_of(
abs(__x) >= 393382)))
477 return static_simd_cast<_V>(
478 cos(static_simd_cast<rebind_simd_t<double, _V>>(__x)));
480 const auto __f = __fold_input(__x);
486 using namespace std::experimental::__float_bitwise_operators;
488 = _V(-0.f) & static_simd_cast<_V>((1 + __f._M_quadrant) << 30);
490 const auto __need_cos = (__f._M_quadrant & 1) == 0;
491 if (_GLIBCXX_SIMD_IS_UNLIKELY(all_of(__need_cos)))
492 return __sign_flip ^ __cosSeries(__f._M_x);
493 else if (_GLIBCXX_SIMD_IS_UNLIKELY(none_of(__need_cos)))
494 return __sign_flip ^ __sinSeries(__f._M_x);
497 _V __r = __sinSeries(__f._M_x);
498 where(__need_cos.__cvt(), __r) = __cosSeries(__f._M_x);
499 return __r ^ __sign_flip;
504template <
typename _Tp>
505 _GLIBCXX_SIMD_ALWAYS_INLINE
506 enable_if_t<is_floating_point<_Tp>::value, simd<_Tp, simd_abi::scalar>>
507 cos(simd<_Tp, simd_abi::scalar> __x)
512template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
513 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
514 sin(
const simd<_Tp, _Abi>& __x)
516 using _V = simd<_Tp, _Abi>;
517 if constexpr (__is_scalar_abi<_Abi>() || __is_fixed_size_abi_v<_Abi>)
518 return {__private_init, _Abi::_SimdImpl::_S_sin(__data(__x))};
521 if constexpr (is_same_v<_Tp, float>)
522 if (_GLIBCXX_SIMD_IS_UNLIKELY(any_of(
abs(__x) >= 527449)))
523 return static_simd_cast<_V>(
524 sin(static_simd_cast<rebind_simd_t<double, _V>>(__x)));
526 const auto __f = __fold_input(__x);
532 using namespace std::experimental::__float_bitwise_operators;
533 const auto __sign_flip
534 = (__x ^ static_simd_cast<_V>(1 - __f._M_quadrant)) & _V(_Tp(-0.));
536 const auto __need_sin = (__f._M_quadrant & 1) == 0;
537 if (_GLIBCXX_SIMD_IS_UNLIKELY(all_of(__need_sin)))
538 return __sign_flip ^ __sinSeries(__f._M_x);
539 else if (_GLIBCXX_SIMD_IS_UNLIKELY(none_of(__need_sin)))
540 return __sign_flip ^ __cosSeries(__f._M_x);
543 _V __r = __cosSeries(__f._M_x);
544 where(__need_sin.__cvt(), __r) = __sinSeries(__f._M_x);
545 return __sign_flip ^ __r;
550template <
typename _Tp>
551 _GLIBCXX_SIMD_ALWAYS_INLINE
552 enable_if_t<is_floating_point<_Tp>::value, simd<_Tp, simd_abi::scalar>>
553 sin(simd<_Tp, simd_abi::scalar> __x)
557_GLIBCXX_SIMD_MATH_CALL_(tan)
558_GLIBCXX_SIMD_MATH_CALL_(acosh)
559_GLIBCXX_SIMD_MATH_CALL_(asinh)
560_GLIBCXX_SIMD_MATH_CALL_(atanh)
561_GLIBCXX_SIMD_MATH_CALL_(cosh)
562_GLIBCXX_SIMD_MATH_CALL_(sinh)
563_GLIBCXX_SIMD_MATH_CALL_(tanh)
566_GLIBCXX_SIMD_MATH_CALL_(exp)
567_GLIBCXX_SIMD_MATH_CALL_(exp2)
568_GLIBCXX_SIMD_MATH_CALL_(expm1)
572#if _GLIBCXX_SIMD_X86INTRIN
573template <
typename _Tp,
size_t _Np>
574 _GLIBCXX_SIMD_INTRINSIC
575 _SimdWrapper<_Tp, _Np>
576 __getexp(_SimdWrapper<_Tp, _Np> __x)
578 if constexpr (__have_avx512vl && __is_sse_ps<_Tp, _Np>())
579 return __auto_bitcast(_mm_getexp_ps(__to_intrin(__x)));
580 else if constexpr (__have_avx512f && __is_sse_ps<_Tp, _Np>())
581 return __auto_bitcast(_mm512_getexp_ps(__auto_bitcast(__to_intrin(__x))));
582 else if constexpr (__have_avx512vl && __is_sse_pd<_Tp, _Np>())
583 return _mm_getexp_pd(__x);
584 else if constexpr (__have_avx512f && __is_sse_pd<_Tp, _Np>())
585 return __lo128(_mm512_getexp_pd(__auto_bitcast(__x)));
586 else if constexpr (__have_avx512vl && __is_avx_ps<_Tp, _Np>())
587 return _mm256_getexp_ps(__x);
588 else if constexpr (__have_avx512f && __is_avx_ps<_Tp, _Np>())
589 return __lo256(_mm512_getexp_ps(__auto_bitcast(__x)));
590 else if constexpr (__have_avx512vl && __is_avx_pd<_Tp, _Np>())
591 return _mm256_getexp_pd(__x);
592 else if constexpr (__have_avx512f && __is_avx_pd<_Tp, _Np>())
593 return __lo256(_mm512_getexp_pd(__auto_bitcast(__x)));
594 else if constexpr (__is_avx512_ps<_Tp, _Np>())
595 return _mm512_getexp_ps(__x);
596 else if constexpr (__is_avx512_pd<_Tp, _Np>())
597 return _mm512_getexp_pd(__x);
599 __assert_unreachable<_Tp>();
602template <
typename _Tp,
size_t _Np>
603 _GLIBCXX_SIMD_INTRINSIC
604 _SimdWrapper<_Tp, _Np>
605 __getmant_avx512(_SimdWrapper<_Tp, _Np> __x)
607 if constexpr (__have_avx512vl && __is_sse_ps<_Tp, _Np>())
608 return __auto_bitcast(_mm_getmant_ps(__to_intrin(__x), _MM_MANT_NORM_p5_1,
610 else if constexpr (__have_avx512f && __is_sse_ps<_Tp, _Np>())
611 return __auto_bitcast(_mm512_getmant_ps(__auto_bitcast(__to_intrin(__x)),
614 else if constexpr (__have_avx512vl && __is_sse_pd<_Tp, _Np>())
615 return _mm_getmant_pd(__x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src);
616 else if constexpr (__have_avx512f && __is_sse_pd<_Tp, _Np>())
617 return __lo128(_mm512_getmant_pd(__auto_bitcast(__x), _MM_MANT_NORM_p5_1,
619 else if constexpr (__have_avx512vl && __is_avx_ps<_Tp, _Np>())
620 return _mm256_getmant_ps(__x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src);
621 else if constexpr (__have_avx512f && __is_avx_ps<_Tp, _Np>())
622 return __lo256(_mm512_getmant_ps(__auto_bitcast(__x), _MM_MANT_NORM_p5_1,
624 else if constexpr (__have_avx512vl && __is_avx_pd<_Tp, _Np>())
625 return _mm256_getmant_pd(__x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src);
626 else if constexpr (__have_avx512f && __is_avx_pd<_Tp, _Np>())
627 return __lo256(_mm512_getmant_pd(__auto_bitcast(__x), _MM_MANT_NORM_p5_1,
629 else if constexpr (__is_avx512_ps<_Tp, _Np>())
630 return _mm512_getmant_ps(__x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src);
631 else if constexpr (__is_avx512_pd<_Tp, _Np>())
632 return _mm512_getmant_pd(__x, _MM_MANT_NORM_p5_1, _MM_MANT_SIGN_src);
634 __assert_unreachable<_Tp>();
644template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
645 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
646 frexp(
const simd<_Tp, _Abi>& __x, _Samesize<
int, simd<_Tp, _Abi>>* __exp)
648 if constexpr (simd_size_v<_Tp, _Abi> == 1)
651 const auto __r = std::frexp(__x[0], &__tmp);
655 else if constexpr (__is_fixed_size_abi_v<_Abi>)
656 return {__private_init, _Abi::_SimdImpl::_S_frexp(__data(__x), __data(*__exp))};
657#if _GLIBCXX_SIMD_X86INTRIN
658 else if constexpr (__have_avx512f)
660 constexpr size_t _Np = simd_size_v<_Tp, _Abi>;
661 constexpr size_t _NI = _Np < 4 ? 4 : _Np;
662 const auto __v = __data(__x);
663 const auto __isnonzero
664 = _Abi::_SimdImpl::_S_isnonzerovalue_mask(__v._M_data);
665 const _SimdWrapper<int, _NI> __exp_plus1
666 = 1 + __convert<_SimdWrapper<int, _NI>>(__getexp(__v))._M_data;
667 const _SimdWrapper<int, _Np> __e = __wrapper_bitcast<int, _Np>(
668 _Abi::_CommonImpl::_S_blend(_SimdWrapper<bool, _NI>(__isnonzero),
669 _SimdWrapper<int, _NI>(), __exp_plus1));
670 simd_abi::deduce_t<int, _Np>::_CommonImpl::_S_store(__e, __exp);
671 return {__private_init,
672 _Abi::_CommonImpl::_S_blend(_SimdWrapper<bool, _Np>(
674 __v, __getmant_avx512(__v))};
680 static_assert(
sizeof(_Tp) == 4 ||
sizeof(_Tp) == 8);
681 using _V = simd<_Tp, _Abi>;
682 using _IV = rebind_simd_t<int, _V>;
683 using namespace std::experimental::__proposed;
684 using namespace std::experimental::__float_bitwise_operators;
686 constexpr int __exp_adjust =
sizeof(_Tp) == 4 ? 0x7e : 0x3fe;
687 constexpr int __exp_offset =
sizeof(_Tp) == 4 ? 0x70 : 0x200;
688 constexpr _Tp __subnorm_scale =
sizeof(_Tp) == 4 ? 0x1p112 : 0x1p512;
689 _GLIBCXX_SIMD_USE_CONSTEXPR_API _V __exponent_mask
691 _GLIBCXX_SIMD_USE_CONSTEXPR_API _V __p5_1_exponent
692 = -(2 - __epsilon_v<_Tp>) / 2;
694 _V __mant = __p5_1_exponent & (__exponent_mask | __x);
695 const _IV __exponent_bits = __extract_exponent_as_int(__x);
696 if (_GLIBCXX_SIMD_IS_LIKELY(all_of(isnormal(__x))))
699 = simd_cast<_Samesize<int, _V>>(__exponent_bits - __exp_adjust);
703#if __FINITE_MATH_ONLY__
706 const auto __iszero_inf_nan = __x == 0;
708 using _Ip = __int_for_sizeof_t<_Tp>;
709 const auto __as_int = simd_bit_cast<rebind_simd_t<_Ip, _V>>(
abs(__x));
710 const auto __inf = simd_bit_cast<rebind_simd_t<_Ip, _V>>(_V(__infinity_v<_Tp>));
711 const auto __iszero_inf_nan = static_simd_cast<typename _V::mask_type>(
712 __as_int == 0 || __as_int >= __inf);
715 const _V __scaled_subnormal = __x * __subnorm_scale;
716 const _V __mant_subnormal
717 = __p5_1_exponent & (__exponent_mask | __scaled_subnormal);
718 where(!isnormal(__x), __mant) = __mant_subnormal;
719 where(__iszero_inf_nan, __mant) = __x;
720 _IV __e = __extract_exponent_as_int(__scaled_subnormal);
722 typename conditional_t<
sizeof(
typename _V::value_type) ==
sizeof(
int),
724 const _MaskType __value_isnormal = isnormal(__x).__cvt();
725 where(__value_isnormal.__cvt(), __e) = __exponent_bits;
726 static_assert(
sizeof(_IV) ==
sizeof(__value_isnormal));
728 = (simd_bit_cast<_IV>(__value_isnormal) & _IV(__exp_adjust))
729 | (simd_bit_cast<_IV>(static_simd_cast<_MaskType>(__exponent_bits == 0)
730 & static_simd_cast<_MaskType>(__x != 0))
731 & _IV(__exp_adjust + __exp_offset));
732 *__exp = simd_cast<_Samesize<int, _V>>(__e - __offset);
738_GLIBCXX_SIMD_MATH_CALL2_(ldexp,
int)
739_GLIBCXX_SIMD_MATH_CALL_(ilogb)
742_GLIBCXX_SIMD_MATH_CALL_(log)
743_GLIBCXX_SIMD_MATH_CALL_(log10)
744_GLIBCXX_SIMD_MATH_CALL_(log1p)
745_GLIBCXX_SIMD_MATH_CALL_(log2)
749template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
750 enable_if_t<is_floating_point<_Tp>::value, simd<_Tp, _Abi>>
751 logb(
const simd<_Tp, _Abi>& __x)
753 constexpr size_t _Np = simd_size_v<_Tp, _Abi>;
754 if constexpr (_Np == 1)
755 return std::logb(__x[0]);
756 else if constexpr (__is_fixed_size_abi_v<_Abi>)
757 return {__private_init, _Abi::_SimdImpl::_S_logb(__data(__x))};
758#if _GLIBCXX_SIMD_X86INTRIN
759 else if constexpr (__have_avx512vl && __is_sse_ps<_Tp, _Np>())
760 return {__private_init,
761 __auto_bitcast(_mm_getexp_ps(__to_intrin(__as_vector(__x))))};
762 else if constexpr (__have_avx512vl && __is_sse_pd<_Tp, _Np>())
763 return {__private_init, _mm_getexp_pd(__data(__x))};
764 else if constexpr (__have_avx512vl && __is_avx_ps<_Tp, _Np>())
765 return {__private_init, _mm256_getexp_ps(__data(__x))};
766 else if constexpr (__have_avx512vl && __is_avx_pd<_Tp, _Np>())
767 return {__private_init, _mm256_getexp_pd(__data(__x))};
768 else if constexpr (__have_avx512f && __is_avx_ps<_Tp, _Np>())
769 return {__private_init,
770 __lo256(_mm512_getexp_ps(__auto_bitcast(__data(__x))))};
771 else if constexpr (__have_avx512f && __is_avx_pd<_Tp, _Np>())
772 return {__private_init,
773 __lo256(_mm512_getexp_pd(__auto_bitcast(__data(__x))))};
774 else if constexpr (__is_avx512_ps<_Tp, _Np>())
775 return {__private_init, _mm512_getexp_ps(__data(__x))};
776 else if constexpr (__is_avx512_pd<_Tp, _Np>())
777 return {__private_init, _mm512_getexp_pd(__data(__x))};
781 using _V = simd<_Tp, _Abi>;
782 using namespace std::experimental::__proposed;
783 auto __is_normal = isnormal(__x);
787 const _V abs_x =
abs(__x);
791 auto&& __exponent = [](
const _V& __v) {
792 using namespace std::experimental::__proposed;
793 using _IV = rebind_simd_t<
794 conditional_t<
sizeof(_Tp) ==
sizeof(_LLong), _LLong,
int>, _V>;
795 return (simd_bit_cast<_IV>(__v) >> (__digits_v<_Tp> - 1))
796 - (__max_exponent_v<_Tp> - 1);
798 _V __r = static_simd_cast<_V>(__exponent(abs_x));
799 if (_GLIBCXX_SIMD_IS_LIKELY(all_of(__is_normal)))
803 const auto __is_zero = __x == 0;
804 const auto __is_nan = isnan(__x);
805 const auto __is_inf = isinf(__x);
806 where(__is_zero, __r) = -__infinity_v<_Tp>;
807 where(__is_nan, __r) = __x;
808 where(__is_inf, __r) = __infinity_v<_Tp>;
809 __is_normal |= __is_zero || __is_nan || __is_inf;
810 if (all_of(__is_normal))
816 const _V __scaled = abs_x * _Tp(0x1p112);
817 _V __scaled_exp = static_simd_cast<_V>(__exponent(__scaled) - 112);
818 where(__is_normal, __scaled_exp) = __r;
824template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
825 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
826 modf(
const simd<_Tp, _Abi>& __x, simd<_Tp, _Abi>* __iptr)
828 if constexpr (simd_size_v<_Tp, _Abi> == 1)
831 _Tp __r = std::modf(__x[0], &__tmp);
837 const auto __integral = trunc(__x);
838 *__iptr = __integral;
839 auto __r = __x - __integral;
840#if !__FINITE_MATH_ONLY__
841 where(isinf(__x), __r) = _Tp();
843 return copysign(__r, __x);
847_GLIBCXX_SIMD_MATH_CALL2_(scalbn,
int)
848_GLIBCXX_SIMD_MATH_CALL2_(scalbln,
long)
850_GLIBCXX_SIMD_MATH_CALL_(cbrt)
852_GLIBCXX_SIMD_MATH_CALL_(abs)
853_GLIBCXX_SIMD_MATH_CALL_(fabs)
857template <
typename _Tp,
typename _Abi>
858 _GLIBCXX_SIMD_ALWAYS_INLINE
859 enable_if_t<!is_floating_point_v<_Tp> && is_signed_v<_Tp>, simd<_Tp, _Abi>>
860 abs(
const simd<_Tp, _Abi>& __x)
861 {
return {__private_init, _Abi::_SimdImpl::_S_abs(__data(__x))}; }
863#define _GLIBCXX_SIMD_CVTING2(_NAME) \
864template <typename _Tp, typename _Abi> \
865 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi> _NAME( \
866 const simd<_Tp, _Abi>& __x, const __type_identity_t<simd<_Tp, _Abi>>& __y) \
868 return _NAME(__x, __y); \
871template <typename _Tp, typename _Abi> \
872 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi> _NAME( \
873 const __type_identity_t<simd<_Tp, _Abi>>& __x, const simd<_Tp, _Abi>& __y) \
875 return _NAME(__x, __y); \
878#define _GLIBCXX_SIMD_CVTING3(_NAME) \
879template <typename _Tp, typename _Abi> \
880 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi> _NAME( \
881 const __type_identity_t<simd<_Tp, _Abi>>& __x, const simd<_Tp, _Abi>& __y, \
882 const simd<_Tp, _Abi>& __z) \
884 return _NAME(__x, __y, __z); \
887template <typename _Tp, typename _Abi> \
888 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi> _NAME( \
889 const simd<_Tp, _Abi>& __x, const __type_identity_t<simd<_Tp, _Abi>>& __y, \
890 const simd<_Tp, _Abi>& __z) \
892 return _NAME(__x, __y, __z); \
895template <typename _Tp, typename _Abi> \
896 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi> _NAME( \
897 const simd<_Tp, _Abi>& __x, const simd<_Tp, _Abi>& __y, \
898 const __type_identity_t<simd<_Tp, _Abi>>& __z) \
900 return _NAME(__x, __y, __z); \
903template <typename _Tp, typename _Abi> \
904 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi> _NAME( \
905 const simd<_Tp, _Abi>& __x, const __type_identity_t<simd<_Tp, _Abi>>& __y, \
906 const __type_identity_t<simd<_Tp, _Abi>>& __z) \
908 return _NAME(__x, __y, __z); \
911template <typename _Tp, typename _Abi> \
912 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi> _NAME( \
913 const __type_identity_t<simd<_Tp, _Abi>>& __x, const simd<_Tp, _Abi>& __y, \
914 const __type_identity_t<simd<_Tp, _Abi>>& __z) \
916 return _NAME(__x, __y, __z); \
919template <typename _Tp, typename _Abi> \
920 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi> _NAME( \
921 const __type_identity_t<simd<_Tp, _Abi>>& __x, \
922 const __type_identity_t<simd<_Tp, _Abi>>& __y, const simd<_Tp, _Abi>& __z) \
924 return _NAME(__x, __y, __z); \
927template <
typename _R,
typename _ToApply,
typename _Tp,
typename... _Tps>
928 _GLIBCXX_SIMD_INTRINSIC _R
929 __fixed_size_apply(_ToApply&& __apply,
const _Tp& __arg0,
930 const _Tps&... __args)
932 return {__private_init,
933 __data(__arg0)._M_apply_per_chunk(
934 [&](
auto __impl,
const auto&... __inner) {
935 using _V =
typename decltype(__impl)::simd_type;
936 return __data(__apply(_V(__private_init, __inner)...));
941template <
typename _VV,
typename = __detail::__odr_helper>
942 __remove_cvref_t<_VV>
943 __hypot(_VV __x, _VV __y)
945 using _V = __remove_cvref_t<_VV>;
946 using _Tp =
typename _V::value_type;
947 if constexpr (_V::size() == 1)
948 return std::hypot(_Tp(__x[0]), _Tp(__y[0]));
949 else if constexpr (__is_fixed_size_abi_v<typename _V::abi_type>)
951 return __fixed_size_apply<_V>([](
auto __a,
952 auto __b) {
return hypot(__a, __b); },
962 using namespace __float_bitwise_operators;
963 using namespace __proposed;
964 _V __absx =
abs(__x);
965 _V __absy =
abs(__y);
966 _V __hi = max(__absx, __absy);
967 _V __lo = min(__absy, __absx);
970 _GLIBCXX_SIMD_USE_CONSTEXPR_API _V __inf(__infinity_v<_Tp>);
973 if constexpr (__have_neon && !__have_neon_a32)
976 const _V __hi_exp = __hi & __inf;
977 _V __scale_back = __hi_exp;
980 where(__hi_exp > 1, __scale_back) = __hi_exp * _Tp(0.125);
982 const _V __scale = (__scale_back ^ __inf) * _Tp(.5);
983 const _V __h1 = __hi * __scale;
984 const _V __l1 = __lo * __scale;
985 _V __r = __scale_back *
sqrt(__h1 * __h1 + __l1 * __l1);
987 where(__hi == 0, __r) = 0;
998 if (_GLIBCXX_SIMD_IS_LIKELY(all_of(isnormal(__x))
999 && all_of(isnormal(__y))))
1002 const _V __hi_exp = __hi & __inf;
1009 using _Ip = __int_for_sizeof_t<_Tp>;
1010 using _IV = rebind_simd_t<_Ip, _V>;
1011 const auto __as_int = simd_bit_cast<_IV>(__hi_exp);
1013 = simd_bit_cast<_V>(2 * __bit_cast<_Ip>(_Tp(1)) - __as_int);
1015 const _V __scale = (__hi_exp ^ __inf) * _Tp(.5);
1017 _GLIBCXX_SIMD_USE_CONSTEXPR_API _V __mant_mask
1018 = __norm_min_v<_Tp> - __denorm_min_v<_Tp>;
1019 const _V __h1 = (__hi & __mant_mask) | _V(1);
1020 const _V __l1 = __lo * __scale;
1021 return __hi_exp *
sqrt(__h1 * __h1 + __l1 * __l1);
1028 _V __scale = _V(1 / __norm_min_v<_Tp>);
1032 where(__hi >= __norm_min_v<_Tp>, __scale)
1033 = ((__hi & __inf) ^ __inf) * _Tp(.5);
1035 _V __hi_exp = __norm_min_v<_Tp>;
1036 where(__hi >= __norm_min_v<_Tp>, __hi_exp)
1038 _V __h1 = __hi * __scale;
1039 _V __l1 = __lo * __scale;
1043 _V __r = __hi_exp *
sqrt(__h1 * __h1 + __l1 * __l1);
1044#ifdef __STDC_IEC_559__
1056 where(isunordered(__x, __y), __fixup) = __quiet_NaN_v<_Tp>;
1057 where(isinf(__absx) || isinf(__absy), __fixup) = __inf;
1058 where(!(__lo == 0 || isunordered(__x, __y)
1059 || (isinf(__absx) || isinf(__absy))),
1069template <
typename _Tp,
typename _Abi>
1070 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi>
1071 hypot(
const simd<_Tp, _Abi>& __x,
const simd<_Tp, _Abi>& __y)
1073 return __hypot<conditional_t<__is_fixed_size_abi_v<_Abi>,
1074 const simd<_Tp, _Abi>&, simd<_Tp, _Abi>>>(__x,
1078_GLIBCXX_SIMD_CVTING2(hypot)
1080 template <
typename _VV,
typename = __detail::__odr_helper>
1081 __remove_cvref_t<_VV>
1082 __hypot(_VV __x, _VV __y, _VV __z)
1084 using _V = __remove_cvref_t<_VV>;
1085 using _Abi =
typename _V::abi_type;
1086 using _Tp =
typename _V::value_type;
1092 if constexpr (__is_fixed_size_abi_v<_Abi> && _V::size() > 1)
1094 return __fixed_size_apply<simd<_Tp, _Abi>>(
1095 [](
auto __a,
auto __b,
auto __c) {
return hypot(__a, __b, __c); },
1100 using namespace __float_bitwise_operators;
1101 using namespace __proposed;
1102 const _V __absx =
abs(__x);
1103 const _V __absy =
abs(__y);
1104 const _V __absz =
abs(__z);
1105 _V __hi = max(max(__absx, __absy), __absz);
1106 _V __l0 = min(__absz, max(__absx, __absy));
1107 _V __l1 = min(__absy, __absx);
1108 if constexpr (__digits_v<_Tp> == 64 && __max_exponent_v<_Tp> == 0x4000
1109 && __min_exponent_v<_Tp> == -0x3FFD && _V::size() == 1)
1113#ifdef __STDC_IEC_559__
1115 if (isinf(__absx[0]) || isinf(__absy[0]) || isinf(__absz[0]))
1116 return __infinity_v<_Tp>;
1117 else if (isunordered(__absx[0], __absy[0] + __absz[0]))
1118 return __quiet_NaN_v<_Tp>;
1119 else if (__l0[0] == 0 && __l1[0] == 0)
1123 const _ULLong __tmp = 0x8000'0000'0000'0000ull;
1124 __builtin_memcpy(&__data(__hi_exp), &__tmp, 8);
1125 const _V __scale = 1 / __hi_exp;
1129 return __hi_exp *
sqrt((__l0 * __l0 + __l1 * __l1) + __hi * __hi);
1134 _GLIBCXX_SIMD_USE_CONSTEXPR_API _V __inf(__infinity_v<_Tp>);
1136#ifndef __FAST_MATH__
1137 if constexpr (_V::size() > 1 && __have_neon && !__have_neon_a32)
1140 const _V __hi_exp = __hi & __inf;
1141 _V __scale_back = __hi_exp;
1144 where(__hi_exp > 1, __scale_back) = __hi_exp * _Tp(0.125);
1147 const _V __scale = (__scale_back ^ __inf) * _Tp(.5);
1148 const _V __h1 = __hi * __scale;
1151 _V __lo = __l0 * __l0
1153 asm(
"" :
"+m"(__lo));
1154 _V __r = __scale_back *
sqrt(__h1 * __h1 + __lo);
1156 where(__hi == 0, __r) = 0;
1167 if (_GLIBCXX_SIMD_IS_LIKELY(all_of(isnormal(__x))
1168 && all_of(isnormal(__y))
1169 && all_of(isnormal(__z))))
1172 const _V __hi_exp = __hi & __inf;
1179 using _Ip = __int_for_sizeof_t<_Tp>;
1180 using _IV = rebind_simd_t<_Ip, _V>;
1181 const auto __as_int = simd_bit_cast<_IV>(__hi_exp);
1183 = simd_bit_cast<_V>(2 * __bit_cast<_Ip>(_Tp(1)) - __as_int);
1185 const _V __scale = (__hi_exp ^ __inf) * _Tp(.5);
1187 constexpr _Tp __mant_mask
1188 = __norm_min_v<_Tp> - __denorm_min_v<_Tp>;
1189 const _V __h1 = (__hi & _V(__mant_mask)) | _V(1);
1195 return __hi_exp *
sqrt(__lo + __h1 * __h1);
1202 _V __scale = _V(1 / __norm_min_v<_Tp>);
1206 where(__hi >= __norm_min_v<_Tp>, __scale)
1207 = ((__hi & __inf) ^ __inf) * _Tp(.5);
1209 _V __hi_exp = __norm_min_v<_Tp>;
1210 where(__hi >= __norm_min_v<_Tp>, __hi_exp)
1212 _V __h1 = __hi * __scale;
1215 _V __lo = __l0 * __l0
1217 _V __r = __hi_exp *
sqrt(__lo + __h1 * __h1);
1218#ifdef __STDC_IEC_559__
1222 where(isunordered(__x, __y + __z), __fixup)
1223 = __quiet_NaN_v<_Tp>;
1224 where(isinf(__absx) || isinf(__absy) || isinf(__absz), __fixup)
1233 where(!(__lo == 0 || isunordered(__x, __y + __z)
1234 || isinf(__absx) || isinf(__absy) || isinf(__absz)),
1245 template <
typename _Tp,
typename _Abi>
1246 _GLIBCXX_SIMD_INTRINSIC simd<_Tp, _Abi>
1247 hypot(
const simd<_Tp, _Abi>& __x,
const simd<_Tp, _Abi>& __y,
1248 const simd<_Tp, _Abi>& __z)
1250 return __hypot<conditional_t<__is_fixed_size_abi_v<_Abi>,
1251 const simd<_Tp, _Abi>&, simd<_Tp, _Abi>>>(__x,
1256_GLIBCXX_SIMD_CVTING3(hypot)
1258_GLIBCXX_SIMD_MATH_CALL2_(pow, _Tp)
1260_GLIBCXX_SIMD_MATH_CALL_(sqrt)
1261_GLIBCXX_SIMD_MATH_CALL_(erf)
1262_GLIBCXX_SIMD_MATH_CALL_(erfc)
1263_GLIBCXX_SIMD_MATH_CALL_(lgamma)
1264_GLIBCXX_SIMD_MATH_CALL_(tgamma)
1265_GLIBCXX_SIMD_MATH_CALL_(ceil)
1266_GLIBCXX_SIMD_MATH_CALL_(floor)
1267_GLIBCXX_SIMD_MATH_CALL_(nearbyint)
1268_GLIBCXX_SIMD_MATH_CALL_(rint)
1269_GLIBCXX_SIMD_MATH_CALL_(lrint)
1270_GLIBCXX_SIMD_MATH_CALL_(llrint)
1272_GLIBCXX_SIMD_MATH_CALL_(round)
1273_GLIBCXX_SIMD_MATH_CALL_(lround)
1274_GLIBCXX_SIMD_MATH_CALL_(llround)
1276_GLIBCXX_SIMD_MATH_CALL_(trunc)
1278_GLIBCXX_SIMD_MATH_CALL2_(fmod, _Tp)
1279_GLIBCXX_SIMD_MATH_CALL2_(remainder, _Tp)
1280_GLIBCXX_SIMD_MATH_CALL3_(remquo, _Tp,
int*)
1282template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1283 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1284 copysign(
const simd<_Tp, _Abi>& __x,
const simd<_Tp, _Abi>& __y)
1286 if constexpr (simd_size_v<_Tp, _Abi> == 1)
1287 return std::copysign(__x[0], __y[0]);
1288 else if constexpr (__is_fixed_size_abi_v<_Abi>)
1289 return {__private_init, _Abi::_SimdImpl::_S_copysign(__data(__x), __data(__y))};
1292 using _V = simd<_Tp, _Abi>;
1293 using namespace std::experimental::__float_bitwise_operators;
1294 _GLIBCXX_SIMD_USE_CONSTEXPR_API
auto __signmask = _V(1) ^ _V(-1);
1295 return (__x & ~__signmask) | (__y & __signmask);
1299_GLIBCXX_SIMD_MATH_CALL2_(nextafter, _Tp)
1302_GLIBCXX_SIMD_MATH_CALL2_(fdim, _Tp)
1303_GLIBCXX_SIMD_MATH_CALL2_(fmax, _Tp)
1304_GLIBCXX_SIMD_MATH_CALL2_(fmin, _Tp)
1306_GLIBCXX_SIMD_MATH_CALL3_(fma, _Tp, _Tp)
1307_GLIBCXX_SIMD_MATH_CALL_(fpclassify)
1308_GLIBCXX_SIMD_MATH_CALL_(isfinite)
1312template <
typename _Tp,
typename _Abi,
typename...,
1313 typename _R = _Math_return_type_t<bool, _Tp, _Abi>>
1314 _GLIBCXX_SIMD_ALWAYS_INLINE
1315 enable_if_t<is_floating_point_v<_Tp>, _R>
1316 isinf(simd<_Tp, _Abi> __x)
1317 {
return {__private_init, _Abi::_SimdImpl::_S_isinf(__data(__x))}; }
1319template <
typename _Tp,
typename _Abi,
typename...,
1320 typename _R = _Math_return_type_t<bool, _Tp, _Abi>>
1321 _GLIBCXX_SIMD_ALWAYS_INLINE
1322 enable_if_t<is_floating_point_v<_Tp>, _R>
1323 isnan(simd<_Tp, _Abi> __x)
1324 {
return {__private_init, _Abi::_SimdImpl::_S_isnan(__data(__x))}; }
1326_GLIBCXX_SIMD_MATH_CALL_(isnormal)
1328template <
typename...,
typename _Tp,
typename _Abi>
1329 _GLIBCXX_SIMD_ALWAYS_INLINE
1330 simd_mask<_Tp, _Abi>
1331 signbit(simd<_Tp, _Abi> __x)
1333 if constexpr (is_integral_v<_Tp>)
1335 if constexpr (is_unsigned_v<_Tp>)
1336 return simd_mask<_Tp, _Abi>{};
1341 return {__private_init, _Abi::_SimdImpl::_S_signbit(__data(__x))};
1344_GLIBCXX_SIMD_MATH_CALL2_(isgreater, _Tp)
1345_GLIBCXX_SIMD_MATH_CALL2_(isgreaterequal, _Tp)
1346_GLIBCXX_SIMD_MATH_CALL2_(isless, _Tp)
1347_GLIBCXX_SIMD_MATH_CALL2_(islessequal, _Tp)
1348_GLIBCXX_SIMD_MATH_CALL2_(islessgreater, _Tp)
1349_GLIBCXX_SIMD_MATH_CALL2_(isunordered, _Tp)
1377template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1378 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1379 assoc_laguerre(
const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __n,
1380 const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __m,
1381 const simd<_Tp, _Abi>& __x)
1383 return simd<_Tp, _Abi>([&](
auto __i) {
1388template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1389 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1390 assoc_legendre(
const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __n,
1391 const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __m,
1392 const simd<_Tp, _Abi>& __x)
1394 return simd<_Tp, _Abi>([&](
auto __i) {
1399_GLIBCXX_SIMD_MATH_CALL2_(beta, _Tp)
1400_GLIBCXX_SIMD_MATH_CALL_(comp_ellint_1)
1401_GLIBCXX_SIMD_MATH_CALL_(comp_ellint_2)
1402_GLIBCXX_SIMD_MATH_CALL2_(comp_ellint_3, _Tp)
1403_GLIBCXX_SIMD_MATH_CALL2_(cyl_bessel_i, _Tp)
1404_GLIBCXX_SIMD_MATH_CALL2_(cyl_bessel_j, _Tp)
1405_GLIBCXX_SIMD_MATH_CALL2_(cyl_bessel_k, _Tp)
1406_GLIBCXX_SIMD_MATH_CALL2_(cyl_neumann, _Tp)
1407_GLIBCXX_SIMD_MATH_CALL2_(ellint_1, _Tp)
1408_GLIBCXX_SIMD_MATH_CALL2_(ellint_2, _Tp)
1409_GLIBCXX_SIMD_MATH_CALL3_(ellint_3, _Tp, _Tp)
1410_GLIBCXX_SIMD_MATH_CALL_(expint)
1412template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1413 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1414 hermite(
const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __n,
1415 const simd<_Tp, _Abi>& __x)
1417 return simd<_Tp, _Abi>(
1418 [&](
auto __i) {
return std::hermite(__n[__i], __x[__i]); });
1421template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1422 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1423 laguerre(
const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __n,
1424 const simd<_Tp, _Abi>& __x)
1426 return simd<_Tp, _Abi>(
1427 [&](
auto __i) {
return std::laguerre(__n[__i], __x[__i]); });
1430template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1431 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1432 legendre(
const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __n,
1433 const simd<_Tp, _Abi>& __x)
1435 return simd<_Tp, _Abi>(
1436 [&](
auto __i) {
return std::legendre(__n[__i], __x[__i]); });
1439_GLIBCXX_SIMD_MATH_CALL_(riemann_zeta)
1441template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1442 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1443 sph_bessel(
const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __n,
1444 const simd<_Tp, _Abi>& __x)
1446 return simd<_Tp, _Abi>(
1450template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1451 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1452 sph_legendre(
const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __l,
1453 const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __m,
1454 const simd<_Tp, _Abi>& theta)
1456 return simd<_Tp, _Abi>([&](
auto __i) {
1461template <
typename _Tp,
typename _Abi,
typename = __detail::__odr_helper>
1462 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Abi>>
1463 sph_neumann(
const fixed_size_simd<
unsigned, simd_size_v<_Tp, _Abi>>& __n,
1464 const simd<_Tp, _Abi>& __x)
1466 return simd<_Tp, _Abi>(
1471#undef _GLIBCXX_SIMD_CVTING2
1472#undef _GLIBCXX_SIMD_CVTING3
1473#undef _GLIBCXX_SIMD_MATH_CALL_
1474#undef _GLIBCXX_SIMD_MATH_CALL2_
1475#undef _GLIBCXX_SIMD_MATH_CALL3_
1477_GLIBCXX_SIMD_END_NAMESPACE
complex< _Tp > sin(const complex< _Tp > &)
Return complex sine of z.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
complex< _Tp > cos(const complex< _Tp > &)
Return complex cosine of z.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
typename conditional< _Cond, _Iftrue, _Iffalse >::type conditional_t
Alias template for conditional.
auto declval() noexcept -> decltype(__declval< _Tp >(0))
__gnu_cxx::__promote< _Tp >::__type sph_bessel(unsigned int __n, _Tp __x)
__gnu_cxx::__promote< _Tp >::__type legendre(unsigned int __l, _Tp __x)
__gnu_cxx::__promote< _Tp >::__type sph_neumann(unsigned int __n, _Tp __x)
__gnu_cxx::__promote< _Tp >::__type assoc_laguerre(unsigned int __n, unsigned int __m, _Tp __x)
__gnu_cxx::__promote< _Tp >::__type sph_legendre(unsigned int __l, unsigned int __m, _Tp __theta)
__gnu_cxx::__promote< _Tp >::__type hermite(unsigned int __n, _Tp __x)
__gnu_cxx::__promote< _Tp >::__type laguerre(unsigned int __n, _Tp __x)
__gnu_cxx::__promote< _Tp >::__type assoc_legendre(unsigned int __l, unsigned int __m, _Tp __x)