MathFunctions.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Rohit Garg <rpg.314@gmail.com>
5 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_MOREVECTORIZATION_MATHFUNCTIONS_H
12 #define EIGEN_MOREVECTORIZATION_MATHFUNCTIONS_H
13 
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
21 template<typename Packet> inline static Packet pasin(Packet a) { return std::asin(a); }
22 
23 #ifdef EIGEN_VECTORIZE_SSE
24 
26 {
28  EIGEN_DECLARE_CONST_Packet4f(minus_half, -0.5);
30 
31  EIGEN_DECLARE_CONST_Packet4f_FROM_INT(sign_mask, 0x80000000);
32 
33  EIGEN_DECLARE_CONST_Packet4f(pi, 3.141592654);
34  EIGEN_DECLARE_CONST_Packet4f(pi_over_2, 3.141592654*0.5);
35 
36  EIGEN_DECLARE_CONST_Packet4f(asin1, 4.2163199048E-2);
37  EIGEN_DECLARE_CONST_Packet4f(asin2, 2.4181311049E-2);
38  EIGEN_DECLARE_CONST_Packet4f(asin3, 4.5470025998E-2);
39  EIGEN_DECLARE_CONST_Packet4f(asin4, 7.4953002686E-2);
40  EIGEN_DECLARE_CONST_Packet4f(asin5, 1.6666752422E-1);
41 
42  Packet4f a = pabs(x);//got the absolute value
43 
44  Packet4f sign_bit= _mm_and_ps(x, p4f_sign_mask);//extracted the sign bit
45 
46  Packet4f z1,z2;//will need them during computation
47 
48 
49 //will compute the two branches for asin
50 //so first compare with half
51 
52  Packet4f branch_mask= _mm_cmpgt_ps(a, p4f_half);//this is to select which branch to take
53 //both will be taken, and finally results will be merged
54 //the branch for values >0.5
55 
56  {
57 //the core series expansion
58  z1=pmadd(p4f_minus_half,a,p4f_half);
59  Packet4f x1=psqrt(z1);
60  Packet4f s1=pmadd(p4f_asin1, z1, p4f_asin2);
61  Packet4f s2=pmadd(s1, z1, p4f_asin3);
62  Packet4f s3=pmadd(s2,z1, p4f_asin4);
63  Packet4f s4=pmadd(s3,z1, p4f_asin5);
64  Packet4f temp=pmul(s4,z1);//not really a madd but a mul by z so that the next term can be a madd
65  z1=pmadd(temp,x1,x1);
66  z1=padd(z1,z1);
67  z1=psub(p4f_pi_over_2,z1);
68  }
69 
70  {
71 //the core series expansion
72  Packet4f x2=a;
73  z2=pmul(x2,x2);
74  Packet4f s1=pmadd(p4f_asin1, z2, p4f_asin2);
75  Packet4f s2=pmadd(s1, z2, p4f_asin3);
76  Packet4f s3=pmadd(s2,z2, p4f_asin4);
77  Packet4f s4=pmadd(s3,z2, p4f_asin5);
78  Packet4f temp=pmul(s4,z2);//not really a madd but a mul by z so that the next term can be a madd
79  z2=pmadd(temp,x2,x2);
80  }
81 
82 /* select the correct result from the two branch evaluations */
83  z1 = _mm_and_ps(branch_mask, z1);
84  z2 = _mm_andnot_ps(branch_mask, z2);
85  Packet4f z = _mm_or_ps(z1,z2);
86 
87 /* update the sign */
88  return _mm_xor_ps(z, sign_bit);
89 }
90 
91 #endif // EIGEN_VECTORIZE_SSE
92 
93 } // end namespace internal
94 
95 } // end namespace Eigen
96 
97 #endif // EIGEN_MOREVECTORIZATION_MATHFUNCTIONS_H
ArrayXXi a
#define EIGEN_DONT_INLINE
bool pmul(const bool &a, const bool &b)
static EIGEN_DECLARE_CONST_Packet4f(1, 1.0f)
static EIGEN_DECLARE_CONST_Packet4f_FROM_INT(inv_mant_mask, ~0x7f800000)
Packet pabs(const Packet &a)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psqrt(const Packet &a)
Packet psub(const Packet &a, const Packet &b)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasin(const Packet &a)
__vector float Packet4f
Packet pmadd(const Packet &a, const Packet &b, const Packet &c)
bool padd(const bool &a, const bool &b)
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
Eigen::AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Eigen::internal::remove_all_t< DerType >, typename Eigen::internal::traits< Eigen::internal::remove_all_t< DerType >>::Scalar, product) > asin(const Eigen::AutoDiffScalar< DerType > &x)