32 #ifndef MCKL_MATH_VMF_HPP 33 #define MCKL_MATH_VMF_HPP 50 #define MCKL_DEFINE_MATH_VMF_VML_1R(func, name) \ 51 inline void name(std::size_t n, const float *a, float *y) \ 53 internal::size_check<MKL_INT>(n, #name); \ 54 ::vs##func(static_cast<MKL_INT>(n), a, y); \ 57 inline void name(std::size_t n, const double *a, double *y) \ 59 internal::size_check<MKL_INT>(n, #name); \ 60 ::vd##func(static_cast<MKL_INT>(n), a, y); \ 63 #define MCKL_DEFINE_MATH_VMF_VML_1C(func, name) \ 65 std::size_t n, const std::complex<float> *a, std::complex<float> *y) \ 67 internal::size_check<MKL_INT>(n, #name); \ 68 ::vc##func(static_cast<MKL_INT>(n), \ 69 reinterpret_cast<const ::MKL_Complex8 *>(a), \ 70 reinterpret_cast<::MKL_Complex8 *>(y)); \ 73 inline void name(std::size_t n, const std::complex<double> *a, \ 74 std::complex<double> *y) \ 76 internal::size_check<MKL_INT>(n, #name); \ 77 ::vz##func(static_cast<MKL_INT>(n), \ 78 reinterpret_cast<const ::MKL_Complex16 *>(a), \ 79 reinterpret_cast<::MKL_Complex16 *>(y)); \ 82 #define MCKL_DEFINE_MATH_VMF_VML_2R(func, name) \ 83 inline void name(std::size_t n, const float *a, const float *b, float *y) \ 85 internal::size_check<MKL_INT>(n, #name); \ 86 ::vs##func(static_cast<MKL_INT>(n), a, b, y); \ 90 std::size_t n, const double *a, const double *b, double *y) \ 92 internal::size_check<MKL_INT>(n, #name); \ 93 ::vd##func(static_cast<MKL_INT>(n), a, b, y); \ 96 #define MCKL_DEFINE_MATH_VMF_VML_2C(func, name) \ 97 inline void name(std::size_t n, const std::complex<float> *a, \ 98 const std::complex<float> *b, std::complex<float> *y) \ 100 internal::size_check<MKL_INT>(n, #name); \ 101 ::vc##func(static_cast<MKL_INT>(n), \ 102 reinterpret_cast<const ::MKL_Complex8 *>(a), \ 103 reinterpret_cast<const ::MKL_Complex8 *>(b), \ 104 reinterpret_cast<::MKL_Complex8 *>(y)); \ 107 inline void name(std::size_t n, const std::complex<double> *a, \ 108 const std::complex<double> *b, std::complex<double> *y) \ 110 internal::size_check<MKL_INT>(n, #name); \ 111 ::vz##func(static_cast<MKL_INT>(n), \ 112 reinterpret_cast<const ::MKL_Complex16 *>(a), \ 113 reinterpret_cast<const ::MKL_Complex16 *>(b), \ 114 reinterpret_cast<::MKL_Complex16 *>(y)); \ 130 inline
void abs(
std::
size_t n, const
std::complex<
float> *a,
float *y)
132 internal::size_check<MKL_INT>(n,
"abs");
133 ::vcAbs(static_cast<MKL_INT>(n),
134 reinterpret_cast<const ::MKL_Complex8 *>(a), y);
137 inline void abs(std::size_t n,
const std::complex<double> *a,
double *y)
139 internal::size_check<MKL_INT>(n,
"abs");
140 ::vzAbs(static_cast<MKL_INT>(n),
141 reinterpret_cast<const ::MKL_Complex16 *>(a), y);
144 inline void arg(std::size_t n,
const std::complex<float> *a,
float *y)
146 internal::size_check<MKL_INT>(n,
"arg");
147 ::vcArg(static_cast<MKL_INT>(n),
148 reinterpret_cast<const ::MKL_Complex8 *>(a), y);
151 inline void arg(std::size_t n,
const std::complex<double> *a,
double *y)
153 internal::size_check<MKL_INT>(n,
"arg");
154 ::vzArg(static_cast<MKL_INT>(n),
155 reinterpret_cast<const ::MKL_Complex16 *>(a), y);
158 inline void linear_frac(std::size_t n,
const float *a,
const float *b,
159 float beta_a,
float beta_b,
float mu_a,
float mu_b,
float *y)
161 internal::size_check<MKL_INT>(n,
"linear_frac");
163 static_cast<MKL_INT>(n), a, b, beta_a, beta_b, mu_a, mu_b, y);
166 inline void linear_frac(std::size_t n,
const double *a,
const double *b,
167 double beta_a,
double beta_b,
double mu_a,
double mu_b,
double *y)
169 internal::size_check<MKL_INT>(n,
"linear_frac");
171 static_cast<MKL_INT>(n), a, b, beta_a, beta_b, mu_a, mu_b, y);
187 inline
void pow(
std::
size_t n, const
float *a,
float b,
float *y)
189 internal::size_check<MKL_INT>(n,
"pow");
190 ::vsPowx(static_cast<MKL_INT>(n), a, b, y);
193 inline void pow(std::size_t n,
const double *a,
double b,
double *y)
195 internal::size_check<MKL_INT>(n,
"pow");
196 ::vdPowx(static_cast<MKL_INT>(n), a, b, y);
199 inline void pow(std::size_t n,
const std::complex<float> *a,
200 std::complex<float> b, std::complex<float> *y)
202 internal::size_check<MKL_INT>(n,
"pow");
203 ::MKL_Complex8 c = {b.real(), b.imag()};
204 ::vcPowx(static_cast<MKL_INT>(n),
205 reinterpret_cast<const ::MKL_Complex8 *>(a), c,
206 reinterpret_cast<::MKL_Complex8 *>(y));
209 inline void pow(std::size_t n,
const std::complex<double> *a,
210 std::complex<double> b, std::complex<double> *y)
212 internal::size_check<MKL_INT>(n,
"pow");
213 ::MKL_Complex16 c = {b.real(), b.imag()};
214 ::vzPowx(static_cast<MKL_INT>(n),
215 reinterpret_cast<const ::MKL_Complex16 *>(a), c,
216 reinterpret_cast<::MKL_Complex16 *>(y));
241 inline
void sincos(
std::
size_t n, const
float *a,
float *y,
float *z)
243 internal::size_check<MKL_INT>(n,
"sincos");
244 ::vsSinCos(static_cast<MKL_INT>(n), a, y, z);
247 inline void sincos(std::size_t n,
const double *a,
double *y,
double *z)
249 internal::size_check<MKL_INT>(n,
"sincos");
250 ::vdSinCos(static_cast<MKL_INT>(n), a, y, z);
253 inline void cis(std::size_t n,
const float *a, std::complex<float> *y)
255 internal::size_check<MKL_INT>(n,
"cis");
256 ::vcCIS(static_cast<MKL_INT>(n), a, reinterpret_cast<::MKL_Complex8 *>(y));
259 inline void cis(std::size_t n,
const double *a, std::complex<double> *y)
261 internal::size_check<MKL_INT>(n,
"cis");
263 static_cast<MKL_INT>(n), a, reinterpret_cast<::MKL_Complex16 *>(y));
314 inline
void modf(
std::
size_t n, const
float *a,
float *y,
float *z)
316 internal::size_check<MKL_INT>(n,
"modf");
317 ::vsModf(static_cast<MKL_INT>(n), a, y, z);
320 inline void modf(std::size_t n,
const double *a,
double *y,
double *z)
322 internal::size_check<MKL_INT>(n,
"modf");
323 ::vdModf(static_cast<MKL_INT>(n), a, y, z);
328 #endif // MCKL_USE_MKL_VML 330 #if MCKL_USE_ASM_LIBRARY && MCKL_USE_ASM_VMF && MCKL_USE_FMA 332 #define MCKL_DEFINE_MATH_VMF_ASM_1S(func) \ 333 inline void func(std::size_t n, const float *a, float *y) \ 335 ::mckl_vs_##func(n, a, y); \ 338 #define MCKL_DEFINE_MATH_VMF_ASM_1D(func) \ 339 inline void func(std::size_t n, const double *a, double *y) \ 341 ::mckl_vd_##func(n, a, y); \ 344 #define MCKL_DEFINE_MATH_VMF_ASM_2S(func) \ 345 inline void func(std::size_t n, const float *a, const float *b, float *y) \ 347 ::mckl_vs_##func(n, a, b, y); \ 350 #define MCKL_DEFINE_MATH_VMF_ASM_2D(func) \ 352 std::size_t n, const double *a, const double *b, double *y) \ 354 ::mckl_vd_##func(n, a, b, y); \ 359 #if !MCKL_USE_MKL_VML 361 MCKL_DEFINE_MATH_VMF_ASM_1S(
sqrt)
362 MCKL_DEFINE_MATH_VMF_ASM_1D(
sqrt)
364 MCKL_DEFINE_MATH_VMF_ASM_1S(
exp)
365 MCKL_DEFINE_MATH_VMF_ASM_1D(
exp)
367 MCKL_DEFINE_MATH_VMF_ASM_1S(
expm1)
368 MCKL_DEFINE_MATH_VMF_ASM_1D(
expm1)
370 MCKL_DEFINE_MATH_VMF_ASM_1S(
log)
371 MCKL_DEFINE_MATH_VMF_ASM_1D(
log)
373 MCKL_DEFINE_MATH_VMF_ASM_1S(
log10)
374 MCKL_DEFINE_MATH_VMF_ASM_1D(
log10)
375 MCKL_DEFINE_MATH_VMF_ASM_1S(
log1p)
376 MCKL_DEFINE_MATH_VMF_ASM_1D(
log1p)
378 MCKL_DEFINE_MATH_VMF_ASM_1D(
cos)
379 MCKL_DEFINE_MATH_VMF_ASM_1D(
sin)
381 inline void sincos(std::size_t n,
const double *a,
double *y,
double *z)
386 MCKL_DEFINE_MATH_VMF_ASM_1D(
tan)
388 MCKL_DEFINE_MATH_VMF_ASM_1S(
exp2)
389 MCKL_DEFINE_MATH_VMF_ASM_1D(
exp2)
391 MCKL_DEFINE_MATH_VMF_ASM_1S(
log2)
392 MCKL_DEFINE_MATH_VMF_ASM_1D(
log2)
394 #endif // MCKL_USE_MKL_VML 398 #endif // MCKL_USE_ASM_LIBRARY && MCKL_USE_ASM_VMF && MCKL_USE_FMA 400 #if MCKL_USE_ASM_LIBRARY && MCKL_USE_ASM_FMA 402 #define MCKL_DEFINE_MATH_FMA_FMA(op, name) \ 403 inline void name(std::size_t n, const float *a, const float *b, \ 404 const float *c, float *y) \ 406 ::mckl_##op##_vvv_ps(n, a, b, c, y); \ 410 std::size_t n, const float *a, const float *b, float c, float *y) \ 412 ::mckl_##op##_vvs_ps(n, a, b, c, y); \ 416 std::size_t n, const float *a, float b, const float *c, float *y) \ 418 ::mckl_##op##_vsv_ps(n, a, b, c, y); \ 422 std::size_t n, float a, const float *b, const float *c, float *y) \ 424 ::mckl_##op##_svv_ps(n, a, b, c, y); \ 428 std::size_t n, float a, float b, const float *c, float *y) \ 430 ::mckl_##op##_ssv_ps(n, a, b, c, y); \ 434 std::size_t n, float a, const float *b, float c, float *y) \ 436 ::mckl_##op##_svs_ps(n, a, b, c, y); \ 440 std::size_t n, const float *a, float b, float c, float *y) \ 442 ::mckl_##op##_vss_ps(n, a, b, c, y); \ 445 inline void name(std::size_t n, const double *a, const double *b, \ 446 const double *c, double *y) \ 448 ::mckl_##op##_vvv_pd(n, a, b, c, y); \ 452 std::size_t n, const double *a, const double *b, double c, double *y) \ 454 ::mckl_##op##_vvs_pd(n, a, b, c, y); \ 458 std::size_t n, const double *a, double b, const double *c, double *y) \ 460 ::mckl_##op##_vsv_pd(n, a, b, c, y); \ 464 std::size_t n, double a, const double *b, const double *c, double *y) \ 466 ::mckl_##op##_svv_pd(n, a, b, c, y); \ 470 std::size_t n, double a, double b, const double *c, double *y) \ 472 ::mckl_##op##_ssv_pd(n, a, b, c, y); \ 476 std::size_t n, double a, const double *b, double c, double *y) \ 478 ::mckl_##op##_svs_pd(n, a, b, c, y); \ 482 std::size_t n, const double *a, double b, double c, double *y) \ 484 ::mckl_##op##_vss_pd(n, a, b, c, y); \ 491 MCKL_DEFINE_MATH_FMA_FMA(fmadd512,
muladd)
492 MCKL_DEFINE_MATH_FMA_FMA(fmsub512,
mulsub)
493 MCKL_DEFINE_MATH_FMA_FMA(fnmadd512,
nmuladd)
494 MCKL_DEFINE_MATH_FMA_FMA(fnmsub512,
nmulsub)
496 MCKL_DEFINE_MATH_FMA_FMA(fmadd512,
fmadd)
497 MCKL_DEFINE_MATH_FMA_FMA(fmsub512,
fmsub)
498 MCKL_DEFINE_MATH_FMA_FMA(fnmadd512,
fnmadd)
499 MCKL_DEFINE_MATH_FMA_FMA(fnmsub512,
fnmsub)
501 #else // MCKL_USE_AVX512 513 #endif // MCKL_USE_AVX512 517 #endif // MCKL_USE_ASM_LIBRARY && MCKL_USE_ASM_FMA 519 #define MCKL_DEFINE_MATH_VMF_1(func, name) \ 520 template <typename T> \ 521 inline void name(std::size_t n, const T *a, T *y) \ 523 for (std::size_t i = 0; i != n; ++i) \ 527 #define MCKL_DEFINE_MATH_VMF_2(func, name) \ 528 template <typename T> \ 529 inline void name(std::size_t n, const T *a, const T *b, T *y) \ 531 for (std::size_t i = 0; i != n; ++i) \ 532 y[i] = func(a[i], b[i]); \ 535 #define MCKL_DEFINE_MATH_VMF_2VS(func, name) \ 536 template <typename T> \ 537 inline void name(std::size_t n, const T *a, T b, T *y) \ 539 for (std::size_t i = 0; i != n; ++i) \ 540 y[i] = func(a[i], b); \ 543 #define MCKL_DEFINE_MATH_VMF_2SV(func, name) \ 544 template <typename T> \ 545 inline void name(std::size_t n, T a, const T *b, T *y) \ 547 for (std::size_t i = 0; i != n; ++i) \ 548 y[i] = func(a, b[i]); \ 551 #define MCKL_DEFINE_MATH_VMF_B(op, name) \ 552 template <typename T> \ 553 inline void name(std::size_t n, const T *a, const T *b, T *y) \ 555 for (std::size_t i = 0; i != n; ++i) \ 556 y[i] = a[i] op b[i]; \ 559 template <typename T> \ 560 inline T name(T a, T b) \ 565 #define MCKL_DEFINE_MATH_VMF_BVS(op, name) \ 566 template <typename T> \ 567 inline void name(std::size_t n, const T *a, T b, T *y) \ 569 for (std::size_t i = 0; i != n; ++i) \ 573 #define MCKL_DEFINE_MATH_VMF_BSV(op, name) \ 574 template <typename T> \ 575 inline void name(std::size_t n, T a, const T *b, T *y) \ 577 for (std::size_t i = 0; i != n; ++i) \ 581 #define MCKL_DEFINE_MATH_VMF_FMA(op, name, attr) \ 582 template <typename T> \ 583 attr inline void name( \ 584 std::size_t n, const T *a, const T *b, const T *c, T *y) \ 586 for (std::size_t i = 0; i != n; ++i) \ 587 y[i] = op(a[i], b[i], c[i]); \ 590 template <typename T> \ 591 attr inline void name(std::size_t n, const T *a, const T *b, T c, T *y) \ 593 for (std::size_t i = 0; i != n; ++i) \ 594 y[i] = op(a[i], b[i], c); \ 597 template <typename T> \ 598 attr inline void name(std::size_t n, const T *a, T b, const T *c, T *y) \ 600 for (std::size_t i = 0; i != n; ++i) \ 601 y[i] = op(a[i], b, c[i]); \ 604 template <typename T> \ 605 attr inline void name(std::size_t n, T a, const T *b, const T *c, T *y) \ 607 for (std::size_t i = 0; i != n; ++i) \ 608 y[i] = op(a, b[i], c[i]); \ 611 template <typename T> \ 612 attr inline void name(std::size_t n, T a, T b, const T *c, T *y) \ 614 for (std::size_t i = 0; i != n; ++i) \ 615 y[i] = op(a, b, c[i]); \ 618 template <typename T> \ 619 attr inline void name(std::size_t n, T a, const T *b, T c, T *y) \ 621 for (std::size_t i = 0; i != n; ++i) \ 622 y[i] = op(a, b[i], c); \ 625 template <typename T> \ 626 attr inline void name(std::size_t n, const T *a, T b, T c, T *y) \ 628 for (std::size_t i = 0; i != n; ++i) \ 629 y[i] = op(a[i], b, c); \ 634 template <
typename T>
640 template <
typename T>
643 return const_one<T>() / a;
646 template <
typename T>
652 template <
typename T>
658 template <
typename T>
664 template <
typename T>
672 template <
typename T>
675 return fmadd(a, b, c);
678 template <
typename T>
681 return fmsub(a, b, c);
684 template <
typename T>
690 template <
typename T>
696 #else // MCKL_USE_FMA 698 template <
typename T>
699 inline T
muladd(T a, T b, T c)
704 template <
typename T>
705 inline T
mulsub(T a, T b, T c)
710 template <
typename T>
711 inline T
nmuladd(T a, T b, T c)
716 template <
typename T>
717 inline T
nmulsub(T a, T b, T c)
722 #endif // MCKL_USE_FMA 724 template <
typename T>
730 template <
typename T>
736 template <
typename T>
744 template <
typename T>
752 template <
typename T>
755 T y = const_sqrt_1by2<T>() * a;
758 return y *
static_cast<T
>(0.5) +
static_cast<T
>(0.5);
761 template <
typename T>
764 T y = a *
static_cast<T
>(-2) + static_cast<T>(2);
767 return y * const_sqrt_2<T>();
792 template <
typename T>
794 inline void sqr(std::size_t n,
const T *a, T *y)
796 for (std::size_t i = 0; i != n; ++i) {
825 template <
typename T>
827 inline void abs(std::size_t n,
const std::complex<T> *a, T *y)
829 for (std::size_t i = 0; i != n; ++i) {
835 template <
typename T>
836 inline void arg(std::size_t n,
const std::complex<T> *a, T *y)
838 for (std::size_t i = 0; i != n; ++i) {
845 template <
typename T>
846 inline void linear_frac(std::size_t n,
const T *a,
const T *b, T beta_a,
847 T beta_b, T mu_a, T mu_b, T *y)
849 const std::size_t k = 1024;
850 const std::size_t m = n / k;
851 const std::size_t l = n % k;
852 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
853 for (std::size_t j = 0; j != k; ++j) {
854 y[j] =
muladd(beta_a, a[j], mu_a);
856 for (std::size_t j = 0; j != k; ++j) {
857 y[j] /=
muladd(beta_b, b[j], mu_b);
860 for (std::size_t i = 0; i != l; ++i) {
861 y[i] =
muladd(beta_a, a[i], mu_a);
863 for (std::size_t i = 0; i != l; ++i) {
864 y[i] /=
muladd(beta_b, b[i], mu_b);
917 template <typename T>
920 const std::size_t k = 1024;
921 const std::size_t m = n / k;
922 const std::size_t l = n % k;
923 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
934 template <
typename T>
936 inline void invcbrt(std::size_t n,
const T *a, T *y)
938 const std::size_t k = 1024;
939 const std::size_t m = n / k;
940 const std::size_t l = n % k;
941 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
950 template <
typename T>
951 inline void pow2o3(std::size_t n,
const T *a, T *y)
953 const std::size_t k = 1024;
954 const std::size_t m = n / k;
955 const std::size_t l = n % k;
956 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
965 template <
typename T>
966 inline void pow3o2(std::size_t n,
const T *a, T *y)
968 const std::size_t k = 1024;
969 const std::size_t m = n / k;
970 const std::size_t l = n % k;
971 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
973 for (std::size_t j = 0; j != k; ++j) {
974 y[j] = y[j] * y[j] * y[j];
978 for (std::size_t i = 0; i != l; ++i) {
979 y[i] = y[i] * y[i] * y[i];
1014 template <typename T>
1017 pow<T>(n,
static_cast<T
>(10), a, y);
1052 template <typename T>
1055 const std::size_t k = 1024;
1056 const std::size_t m = n / k;
1057 const std::size_t l = n % k;
1061 for (std::size_t i = 0; i != m; ++i, a += k, y += k, z += k) {
1062 sin<T>(k, a, s.data());
1064 std::copy_n(s.data(), k, y);
1066 sin<T>(l, a, s.data());
1068 std::copy_n(s.data(), l, y);
1070 for (std::size_t i = 0; i != m; ++i, a += k, y += k, z += k) {
1080 template <
typename T>
1081 inline void cis(std::size_t n,
const T *a, std::complex<T> *y)
1083 const std::size_t k = 1024;
1084 const std::size_t m = n / k;
1085 const std::size_t l = n % k;
1088 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1089 sincos<T>(k, a, s, c);
1090 for (std::size_t j = 0; j != k; ++j) {
1095 sincos<T>(l, a, s, c);
1096 for (std::size_t j = 0; j != l; ++j) {
1105 template <
typename T>
1107 inline void cospi(std::size_t n,
const T *a, T *y)
1109 const std::size_t k = 1024;
1110 const std::size_t m = n / k;
1111 const std::size_t l = n % k;
1112 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1113 mul<T>(k, a, const_pi<T>(), y);
1116 mul<T>(l, a, const_pi<T>(), y);
1121 template <
typename T>
1122 inline void sinpi(std::size_t n,
const T *a, T *y)
1124 const std::size_t k = 1024;
1125 const std::size_t m = n / k;
1126 const std::size_t l = n % k;
1127 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1128 mul<T>(k, a, const_pi<T>(), y);
1131 mul<T>(l, a, const_pi<T>(), y);
1136 template <
typename T>
1137 inline void tanpi(std::size_t n,
const T *a, T *y)
1139 const std::size_t k = 1024;
1140 const std::size_t m = n / k;
1141 const std::size_t l = n % k;
1142 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1143 mul<T>(k, a, const_pi<T>(), y);
1146 mul<T>(l, a, const_pi<T>(), y);
1151 template <
typename T>
1152 inline void cosd(std::size_t n,
const T *a, T *y)
1154 const std::size_t k = 1024;
1155 const std::size_t m = n / k;
1156 const std::size_t l = n % k;
1157 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1158 mul<T>(k, a, const_pi<T>() / 180, y);
1161 mul<T>(l, a, const_pi<T>() / 180, y);
1166 template <
typename T>
1167 inline void sind(std::size_t n,
const T *a, T *y)
1169 const std::size_t k = 1024;
1170 const std::size_t m = n / k;
1171 const std::size_t l = n % k;
1172 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1173 mul<T>(k, a, const_pi<T>() / 180, y);
1176 mul<T>(l, a, const_pi<T>() / 180, y);
1181 template <
typename T>
1182 inline void tand(std::size_t n,
const T *a, T *y)
1184 const std::size_t k = 1024;
1185 const std::size_t m = n / k;
1186 const std::size_t l = n % k;
1187 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1188 mul<T>(k, a, const_pi<T>() / 180, y);
1191 mul<T>(l, a, const_pi<T>() / 180, y);
1216 template <
typename T>
1218 inline void acospi(std::size_t n,
const T *a, T *y)
1220 const std::size_t k = 1024;
1221 const std::size_t m = n / k;
1222 const std::size_t l = n % k;
1223 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1225 mul<T>(k, y, 1 / const_pi<T>(), y);
1228 mul<T>(l, y, 1 / const_pi<T>(), y);
1232 template <
typename T>
1233 inline void asinpi(std::size_t n,
const T *a, T *y)
1235 const std::size_t k = 1024;
1236 const std::size_t m = n / k;
1237 const std::size_t l = n % k;
1238 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1240 mul<T>(k, y, 1 / const_pi<T>(), y);
1243 mul<T>(l, y, 1 / const_pi<T>(), y);
1247 template <
typename T>
1248 inline void atanpi(std::size_t n,
const T *a, T *y)
1250 const std::size_t k = 1024;
1251 const std::size_t m = n / k;
1252 const std::size_t l = n % k;
1253 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1255 mul<T>(k, y, 1 / const_pi<T>(), y);
1258 mul<T>(l, y, 1 / const_pi<T>(), y);
1263 template <
typename T>
1264 inline void atan2pi(std::size_t n,
const T *a,
const T *b, T *y)
1266 const std::size_t k = 1024;
1267 const std::size_t m = n / k;
1268 const std::size_t l = n % k;
1269 for (std::size_t i = 0; i != m; ++i, a += k, b += k, y += k) {
1270 atan2<T>(k, a, b, y);
1271 mul<T>(k, y, 1 / const_pi<T>(), y);
1273 atan2<T>(l, a, b, y);
1274 mul<T>(l, y, 1 / const_pi<T>(), y);
1279 template <
typename T>
1280 inline void atan2pi(std::size_t n,
const T *a, T b, T *y)
1282 const std::size_t k = 1024;
1283 const std::size_t m = n / k;
1284 const std::size_t l = n % k;
1285 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1286 atan2<T>(k, a, b, y);
1287 mul<T>(k, y, 1 / const_pi<T>(), y);
1289 atan2<T>(l, a, b, y);
1290 mul<T>(l, y, 1 / const_pi<T>(), y);
1295 template <
typename T>
1296 inline void atan2pi(std::size_t n, T a,
const T *b, T *y)
1298 const std::size_t k = 1024;
1299 const std::size_t m = n / k;
1300 const std::size_t l = n % k;
1301 for (std::size_t i = 0; i != m; ++i, b += k, y += k) {
1302 atan2<T>(k, a, b, y);
1303 mul<T>(k, y, 1 / const_pi<T>(), y);
1305 atan2<T>(l, a, b, y);
1306 mul<T>(l, y, 1 / const_pi<T>(), y);
1355 template <typename T>
1358 const std::size_t k = 1024;
1359 const std::size_t m = n / k;
1360 const std::size_t l = n % k;
1361 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1362 mul<T>(k, const_sqrt_1by2<T>(), a, y);
1364 muladd<T>(k, y,
static_cast<T
>(0.5),
static_cast<T
>(0.5), y);
1366 mul<T>(l, const_sqrt_1by2<T>(), a, y);
1368 muladd<T>(l, y,
static_cast<T
>(0.5),
static_cast<T
>(0.5), y);
1373 template <
typename T>
1376 const std::size_t k = 1024;
1377 const std::size_t m = n / k;
1378 const std::size_t l = n % k;
1379 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
1380 muladd<T>(k, a,
static_cast<T
>(-2), static_cast<T>(2), y);
1381 erfcinv<T>(k, y, y);
1382 mul<T>(k, const_sqrt_2<T>(), y, y);
1384 muladd<T>(l, a,
static_cast<T
>(-2), static_cast<T>(2), y);
1385 erfcinv<T>(l, y, y);
1386 mul<T>(l, const_sqrt_2<T>(), y, y);
1424 template <typename T>
1425 inline
void modf(
std::
size_t n, const T *a, T *y, T *z)
1427 for (std::size_t i = 0; i != n; ++i, ++a, ++y, ++z) {
1438 #if MCKL_USE_ASM_LIBRARY && MCKL_USE_AVX2 1440 #define MCKL_DEFINE_MATH_VMF_ASM_FPCLASSIFY(func) \ 1441 inline std::size_t func(std::size_t n, const float *a) \ 1443 return ::mckl_vs_##func(n, a); \ 1446 inline std::size_t func(std::size_t n, const double *a) \ 1448 return ::mckl_vd_##func(n, a); \ 1453 MCKL_DEFINE_MATH_VMF_ASM_FPCLASSIFY(
find_zero)
1454 MCKL_DEFINE_MATH_VMF_ASM_FPCLASSIFY(
find_inf)
1455 MCKL_DEFINE_MATH_VMF_ASM_FPCLASSIFY(
find_nan)
1460 MCKL_DEFINE_MATH_VMF_ASM_FPCLASSIFY(
count_zero)
1461 MCKL_DEFINE_MATH_VMF_ASM_FPCLASSIFY(
count_inf)
1462 MCKL_DEFINE_MATH_VMF_ASM_FPCLASSIFY(
count_nan)
1479 #endif // MCKL_USE_ASM_LIBRARY && MCKL_USE_AVX2 1481 #define MCKL_DEFINE_MATH_VMF_FPCLASSIFY_FIND(func, test) \ 1482 template <typename T> \ 1483 inline std::size_t find_##func(std::size_t n, const T *a) \ 1485 for (std::size_t i = 0; i != n; ++i, ++a) \ 1491 template <typename T> \ 1492 inline std::size_t find_##func(std::size_t n, const std::complex<T> *a) \ 1494 return find_##func(n * 2, reinterpret_cast<const T *>(a)) / 2; \ 1497 #define MCKL_DEFINE_MATH_VMF_FPCLASSIFY_COUNT(func, test) \ 1498 template <typename T> \ 1499 inline std::size_t count_##func(std::size_t n, const T *a) \ 1501 std::size_t c = 0; \ 1502 for (std::size_t i = 0; i != n; ++i, ++a) \ 1508 template <typename T> \ 1509 inline std::size_t count_##func(std::size_t n, const std::complex<T> *a) \ 1511 return count_##func(n * 2, reinterpret_cast<const T *>(a)) / 2; \ 1514 namespace internal {
1516 template <
typename T>
1519 static_assert(std::is_floating_point<T>::value,
1520 "checking for subnormal used with a type other than floating point");
1524 return b > 0 && b < std::numeric_limits<T>::min();
1527 template <
typename T>
1615 #endif // MCKL_MATH_VMF_HPP void sinpi(std::size_t n, const float *a, float *y)
std::size_t count_subnormal(std::size_t n, const T *a)
Return the number of elements that are subnormal.
void atan(std::size_t n, const T *a, T *y)
For , compute .
void lgamma(std::size_t n, const T *a, T *y)
For , compute .
std::size_t count_not_subnormal(std::size_t n, const T *a)
Return the number of elements that are not subnormal.
void cbrt(std::size_t n, const T *a, T *y)
For , compute .
void hypot(std::size_t n, const float *a, const float *b, float *y)
void expm1(std::size_t n, const float *a, float *y)
std::size_t count_not_zero(std::size_t n, const T *a)
Return the number of elements that are not zero.
std::size_t count_inf(std::size_t n, const T *a)
Return the number of elements that are infinity.
void asinh(std::size_t n, const float *a, float *y)
std::size_t find_not_normal(std::size_t n, const T *a)
Return the index of the first element that is not normal.
void pow(std::size_t n, const float *a, const float *b, float *y)
void arg(std::size_t n, const std::complex< float > *a, float *y)
void mul(std::size_t n, const float *a, const float *b, float *y)
void fma(std::size_t n, const T *a, const T *b, const T *c, T *y)
For , compute .
T erfcinv(T y)
Inverse complement error function.
void invcbrt(std::size_t n, const float *a, float *y)
void hypot(std::size_t n, T a, const T *b, T *y)
For , compute .
#define MCKL_DEFINE_MATH_VMF_FPCLASSIFY_FIND(func, test)
void cosh(std::size_t n, const float *a, float *y)
void arg(std::size_t n, const std::complex< T > *a, T *y)
For , compute .
void ceil(std::size_t n, const float *a, float *y)
void tan(std::size_t n, const float *a, float *y)
#define MCKL_DEFINE_MATH_VMF_1(func, name)
void logb(std::size_t n, const T *a, T *y)
For , compute .
void erf(std::size_t n, const float *a, float *y)
#define MCKL_PUSH_CLANG_WARNING(warning)
void round(std::size_t n, const float *a, float *y)
void acos(std::size_t n, const float *a, float *y)
void sinh(std::size_t n, const float *a, float *y)
std::size_t count_zero(std::size_t n, const T *a)
Return the number of elements that are zero.
void acosh(std::size_t n, const T *a, T *y)
For , compute .
void tan(std::size_t n, const T *a, T *y)
For , compute .
std::size_t count_not_finite(std::size_t n, const T *a)
Return the number of elements that are not finite.
void lgamma(std::size_t n, const float *a, float *y)
void fma(std::size_t n, const T *a, T b, T c, T *y)
void pow2o3(std::size_t n, const float *a, float *y)
void atan2(std::size_t n, T a, const T *b, T *y)
For , compute with signs to determine the quadrant.
std::size_t find_subnormal(std::size_t n, const T *a)
Return the index of the first element that is subnormal.
std::size_t find_inf(std::size_t n, const T *a)
Return the index of the first element that is infinity.
void mulbyconj(std::size_t n, const std::complex< float > *a, const std::complex< float > *b, std::complex< float > *y)
#define MCKL_DEFINE_MATH_VMF_2SV(func, name)
void sin(std::size_t n, const float *a, float *y)
void tand(std::size_t n, const float *a, float *y)
void atanpi(std::size_t n, const float *a, float *y)
void inv(std::size_t n, const float *a, float *y)
void linear_frac(std::size_t n, const float *a, const float *b, float beta_a, float beta_b, float mu_a, float mu_b, float *y)
std::size_t count_not_inf(std::size_t n, const T *a)
Return the number of elements that are not infinity.
std::size_t find_finite(std::size_t n, const T *a)
Return the index of the first element that is finite.
void log(std::size_t n, const float *a, float *y)
void tanpi(std::size_t n, const float *a, float *y)
#define MCKL_DEFINE_MATH_VMF_2(func, name)
void log1p(std::size_t n, const T *a, T *y)
For , compute .
std::size_t count_finite(std::size_t n, const T *a)
Return the number of elements that are finite.
std::size_t find_nan(std::size_t n, const T *a)
Return the index of the first element that is nan.
void cdfnorm(std::size_t n, const float *a, float *y)
#define MCKL_DEFINE_MATH_VMF_VML_1R(func, name)
void cdfnorminv(std::size_t n, const float *a, float *y)
void log2(std::size_t n, const T *a, T *y)
For , compute .
#define MCKL_DEFINE_MATH_VMF_BSV(op, name)
void sqrt(std::size_t n, const T *a, T *y)
For , compute .
#define MCKL_DEFINE_MATH_VMF_B(op, name)
void sinh(std::size_t n, const T *a, T *y)
For , compute .
void log(std::size_t n, const T *a, T *y)
For , compute .
std::size_t find_not_finite(std::size_t n, const T *a)
Return the index of the first element that is not finite.
void sincos(std::size_t n, const float *a, float *y, float *z)
#define MCKL_DEFINE_MATH_VMF_FMA(op, name, attr)
void abs(std::size_t n, const float *a, float *y)
void conj(std::size_t n, const T *a, T *y)
For , compute .
void log1p(std::size_t n, const float *a, float *y)
void exp2(std::size_t n, const float *a, float *y)
void exp10(std::size_t n, const float *a, float *y)
void erf(std::size_t n, const T *a, T *y)
For , compute .
void cbrt(std::size_t n, const float *a, float *y)
void mckl_vd_sincos(size_t, const double *, double *, double *)
void sub(std::size_t n, const float *a, const float *b, float *y)
#define MCKL_DEFINE_MATH_VMF_FPCLASSIFY_COUNT(func, test)
void acos(std::size_t n, const T *a, T *y)
For , compute .
void atanh(std::size_t n, const T *a, T *y)
For , compute .
void tanh(std::size_t n, const T *a, T *y)
For , compute .
void acosh(std::size_t n, const float *a, float *y)
void cospi(std::size_t n, const float *a, float *y)
void floor(std::size_t n, const float *a, float *y)
std::size_t find_normal(std::size_t n, const T *a)
Return the index of the first element that is normal.
void acospi(std::size_t n, const float *a, float *y)
void cis(std::size_t n, const float *a, std::complex< float > *y)
void modf(std::size_t n, const float *a, float *y, float *z)
void sqr(std::size_t n, const float *a, float *y)
#define MCKL_PUSH_INTEL_WARNING(wid)
std::size_t find_zero(std::size_t n, const T *a)
Return the index of the first element that is zero.
void atan2(std::size_t n, const float *a, const float *b, float *y)
std::size_t find_not_subnormal(std::size_t n, const T *a)
Return the index of the first element that is not subnormal.
void modf(std::size_t n, const T *a, T *y, T *z)
For , compute the integeral and fraction parts.
std::size_t find_not_nan(std::size_t n, const T *a)
Return the index of the first element that is not nan.
void logb(std::size_t n, const float *a, float *y)
void cosd(std::size_t n, const float *a, float *y)
std::size_t count_not_nan(std::size_t n, const T *a)
Return the number of elements that are not nan.
void expint1(std::size_t n, const float *a, float *y)
#define MCKL_DEFINE_MATH_VMF_2VS(func, name)
void invsqrt(std::size_t n, const float *a, float *y)
void sqrt(std::size_t n, const float *a, float *y)
void cos(std::size_t n, const float *a, float *y)
std::size_t count_not_normal(std::size_t n, const T *a)
Return the number of elements that are not normal.
void sind(std::size_t n, const float *a, float *y)
void tgamma(std::size_t n, const T *a, T *y)
For , compute .
void asin(std::size_t n, const float *a, float *y)
void atan(std::size_t n, const float *a, float *y)
void exp(std::size_t n, const float *a, float *y)
void atan2pi(std::size_t n, const float *a, const float *b, float *y)
#define MCKL_POP_CLANG_WARNING
void conj(std::size_t n, const std::complex< float > *a, std::complex< float > *y)
#define MCKL_ALIGNMENT
The default alignment for scalar type.
void tanh(std::size_t n, const float *a, float *y)
#define MCKL_DEFINE_MATH_VMF_VML_1C(func, name)
#define MCKL_DEFINE_MATH_VMF_VML_2C(func, name)
T erfinv(T y)
Inverse error function.
#define MCKL_DEFINE_MATH_VMF_VML_2R(func, name)
void log10(std::size_t n, const T *a, T *y)
For , compute .
void erfc(std::size_t n, const float *a, float *y)
void asinpi(std::size_t n, const float *a, float *y)
std::size_t find_not_inf(std::size_t n, const T *a)
Return the index of the first element that is not infinity.
std::size_t count_nan(std::size_t n, const T *a)
Return the number of elements that are nan.
void asinh(std::size_t n, const T *a, T *y)
For , compute .
void cosh(std::size_t n, const T *a, T *y)
For , compute .
void tgamma(std::size_t n, const float *a, float *y)
void pow(std::size_t n, T a, const T *b, T *y)
For , compute .
void log2(std::size_t n, const float *a, float *y)
void abs(std::size_t n, const std::complex< T > *a, T *y)
For , compute .
void nearbyint(std::size_t n, const float *a, float *y)
void log10(std::size_t n, const float *a, float *y)
void pow3o2(std::size_t n, const float *a, float *y)
void div(std::size_t n, const float *a, const float *b, float *y)
void expm1(std::size_t n, const T *a, T *y)
For , compute .
std::size_t count_normal(std::size_t n, const T *a)
Return the number of elements that are normal.
void trunc(std::size_t n, const float *a, float *y)
#define MCKL_POP_INTEL_WARNING
std::size_t find_not_zero(std::size_t n, const T *a)
Return the index of the first element that is not zero.
void asin(std::size_t n, const T *a, T *y)
For , compute .
void atanh(std::size_t n, const float *a, float *y)
void rint(std::size_t n, const float *a, float *y)
void add(std::size_t n, const float *a, const float *b, float *y)
#define MCKL_DEFINE_MATH_VMF_BVS(op, name)