unsupported/Eigen/src/MoreVectorization/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 namespace Eigen {
15 
16 namespace internal {
17 
19 template<typename Packet> inline static Packet pasin(Packet a) { return std::asin(a); }
20 
21 #ifdef EIGEN_VECTORIZE_SSE
22 
24 {
26  _EIGEN_DECLARE_CONST_Packet4f(minus_half, -0.5);
28 
29  _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(sign_mask, 0x80000000);
30 
31  _EIGEN_DECLARE_CONST_Packet4f(pi, 3.141592654);
32  _EIGEN_DECLARE_CONST_Packet4f(pi_over_2, 3.141592654*0.5);
33 
34  _EIGEN_DECLARE_CONST_Packet4f(asin1, 4.2163199048E-2);
35  _EIGEN_DECLARE_CONST_Packet4f(asin2, 2.4181311049E-2);
36  _EIGEN_DECLARE_CONST_Packet4f(asin3, 4.5470025998E-2);
37  _EIGEN_DECLARE_CONST_Packet4f(asin4, 7.4953002686E-2);
38  _EIGEN_DECLARE_CONST_Packet4f(asin5, 1.6666752422E-1);
39 
40  Packet4f a = pabs(x);//got the absolute value
41 
42  Packet4f sign_bit= _mm_and_ps(x, p4f_sign_mask);//extracted the sign bit
43 
44  Packet4f z1,z2;//will need them during computation
45 
46 
47 //will compute the two branches for asin
48 //so first compare with half
49 
50  Packet4f branch_mask= _mm_cmpgt_ps(a, p4f_half);//this is to select which branch to take
51 //both will be taken, and finally results will be merged
52 //the branch for values >0.5
53 
54  {
55 //the core series expansion
56  z1=pmadd(p4f_minus_half,a,p4f_half);
58  Packet4f s1=pmadd(p4f_asin1, z1, p4f_asin2);
59  Packet4f s2=pmadd(s1, z1, p4f_asin3);
60  Packet4f s3=pmadd(s2,z1, p4f_asin4);
61  Packet4f s4=pmadd(s3,z1, p4f_asin5);
62  Packet4f temp=pmul(s4,z1);//not really a madd but a mul by z so that the next term can be a madd
63  z1=pmadd(temp,x1,x1);
64  z1=padd(z1,z1);
65  z1=psub(p4f_pi_over_2,z1);
66  }
67 
68  {
69 //the core series expansion
70  Packet4f x2=a;
71  z2=pmul(x2,x2);
72  Packet4f s1=pmadd(p4f_asin1, z2, p4f_asin2);
73  Packet4f s2=pmadd(s1, z2, p4f_asin3);
74  Packet4f s3=pmadd(s2,z2, p4f_asin4);
75  Packet4f s4=pmadd(s3,z2, p4f_asin5);
76  Packet4f temp=pmul(s4,z2);//not really a madd but a mul by z so that the next term can be a madd
77  z2=pmadd(temp,x2,x2);
78  }
79 
80 /* select the correct result from the two branch evaluations */
81  z1 = _mm_and_ps(branch_mask, z1);
82  z2 = _mm_andnot_ps(branch_mask, z2);
83  Packet4f z = _mm_or_ps(z1,z2);
84 
85 /* update the sign */
86  return _mm_xor_ps(z, sign_bit);
87 }
88 
89 #endif // EIGEN_VECTORIZE_SSE
90 
91 } // end namespace internal
92 
93 } // end namespace Eigen
94 
95 #endif // EIGEN_MOREVECTORIZATION_MATHFUNCTIONS_H
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::psqrt
EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f &a)
Definition: MSA/PacketMath.h:723
Eigen::internal::pasin
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasin(const Packet &a)
Definition: GenericPacketMath.h:764
Eigen::internal::Packet4f
__vector float Packet4f
Definition: AltiVec/PacketMath.h:30
z1
Point2 z1
Definition: testTriangulationFactor.cpp:45
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
Eigen::internal::_EIGEN_DECLARE_CONST_Packet4f_FROM_INT
static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(inv_mant_mask, ~0x7f800000)
asin
const EIGEN_DEVICE_FUNC AsinReturnType asin() const
Definition: ArrayCwiseUnaryOps.h:311
Eigen::internal::_EIGEN_DECLARE_CONST_Packet4f
static _EIGEN_DECLARE_CONST_Packet4f(1, 1.0f)
x1
Pose3 x1
Definition: testPose3.cpp:663
Eigen::internal::Packet
Definition: ZVector/PacketMath.h:47
Eigen::internal::psub
EIGEN_DEVICE_FUNC Packet psub(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:222
pybind_wrapper_test_script.z
z
Definition: pybind_wrapper_test_script.py:61
E
DiscreteKey E(5, 2)
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
Eigen::internal::pmul
EIGEN_DEVICE_FUNC Packet pmul(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:237
Eigen::internal::pmadd
EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
Definition: AltiVec/PacketMath.h:827
Eigen::internal::pabs
EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f &a)
Definition: AltiVec/PacketMath.h:1176
Eigen::internal::padd
EIGEN_DEVICE_FUNC Packet padd(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:215
internal
Definition: BandTriangularSolver.h:13
Eigen::half
Definition: Half.h:142
x2
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
z2
static const Unit3 z2
Definition: testRotateFactor.cpp:43
EIGEN_DONT_INLINE
#define EIGEN_DONT_INLINE
Definition: Macros.h:940


gtsam
Author(s):
autogenerated on Thu Nov 28 2024 04:03:41