Geometry_SSE.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-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
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_GEOMETRY_SSE_H
12 #define EIGEN_GEOMETRY_SSE_H
13 
14 namespace Eigen {
15 
16 namespace internal {
17 
18 template<class Derived, class OtherDerived>
19 struct quat_product<Architecture::SSE, Derived, OtherDerived, float, Aligned16>
20 {
22  {
24  const __m128 mask = _mm_setr_ps(0.f,0.f,0.f,-0.f);
25  __m128 a = _a.coeffs().template packet<Aligned16>(0);
26  __m128 b = _b.coeffs().template packet<Aligned16>(0);
27  __m128 s1 = _mm_mul_ps(vec4f_swizzle1(a,1,2,0,2),vec4f_swizzle1(b,2,0,1,2));
28  __m128 s2 = _mm_mul_ps(vec4f_swizzle1(a,3,3,3,1),vec4f_swizzle1(b,0,1,2,1));
29  pstore(&res.x(),
30  _mm_add_ps(_mm_sub_ps(_mm_mul_ps(a,vec4f_swizzle1(b,3,3,3,3)),
31  _mm_mul_ps(vec4f_swizzle1(a,2,0,1,0),
32  vec4f_swizzle1(b,1,2,0,0))),
33  _mm_xor_ps(mask,_mm_add_ps(s1,s2))));
34 
35  return res;
36  }
37 };
38 
39 template<class Derived, int Alignment>
40 struct quat_conj<Architecture::SSE, Derived, float, Alignment>
41 {
43  {
45  const __m128 mask = _mm_setr_ps(-0.f,-0.f,-0.f,0.f);
46  pstore(&res.x(), _mm_xor_ps(mask, q.coeffs().template packet<Alignment>(0)));
47  return res;
48  }
49 };
50 
51 
52 template<typename VectorLhs,typename VectorRhs>
53 struct cross3_impl<Architecture::SSE,VectorLhs,VectorRhs,float,true>
54 {
55  static inline typename plain_matrix_type<VectorLhs>::type
56  run(const VectorLhs& lhs, const VectorRhs& rhs)
57  {
58  __m128 a = lhs.template packet<traits<VectorLhs>::Alignment>(0);
59  __m128 b = rhs.template packet<traits<VectorRhs>::Alignment>(0);
60  __m128 mul1=_mm_mul_ps(vec4f_swizzle1(a,1,2,0,3),vec4f_swizzle1(b,2,0,1,3));
61  __m128 mul2=_mm_mul_ps(vec4f_swizzle1(a,2,0,1,3),vec4f_swizzle1(b,1,2,0,3));
63  pstore(&res.x(),_mm_sub_ps(mul1,mul2));
64  return res;
65  }
66 };
67 
68 
69 
70 
71 template<class Derived, class OtherDerived, int Alignment>
72 struct quat_product<Architecture::SSE, Derived, OtherDerived, double, Alignment>
73 {
75  {
76  const Packet2d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0));
77 
79 
80  const double* a = _a.coeffs().data();
81  Packet2d b_xy = _b.coeffs().template packet<Alignment>(0);
82  Packet2d b_zw = _b.coeffs().template packet<Alignment>(2);
83  Packet2d a_xx = pset1<Packet2d>(a[0]);
84  Packet2d a_yy = pset1<Packet2d>(a[1]);
85  Packet2d a_zz = pset1<Packet2d>(a[2]);
86  Packet2d a_ww = pset1<Packet2d>(a[3]);
87 
88  // two temporaries:
89  Packet2d t1, t2;
90 
91  /*
92  * t1 = ww*xy + yy*zw
93  * t2 = zz*xy - xx*zw
94  * res.xy = t1 +/- swap(t2)
95  */
96  t1 = padd(pmul(a_ww, b_xy), pmul(a_yy, b_zw));
97  t2 = psub(pmul(a_zz, b_xy), pmul(a_xx, b_zw));
98 #ifdef EIGEN_VECTORIZE_SSE3
100  pstore(&res.x(), _mm_addsub_pd(t1, preverse(t2)));
101 #else
102  pstore(&res.x(), padd(t1, pxor(mask,preverse(t2))));
103 #endif
104 
105  /*
106  * t1 = ww*zw - yy*xy
107  * t2 = zz*zw + xx*xy
108  * res.zw = t1 -/+ swap(t2) = swap( swap(t1) +/- t2)
109  */
110  t1 = psub(pmul(a_ww, b_zw), pmul(a_yy, b_xy));
111  t2 = padd(pmul(a_zz, b_zw), pmul(a_xx, b_xy));
112 #ifdef EIGEN_VECTORIZE_SSE3
114  pstore(&res.z(), preverse(_mm_addsub_pd(preverse(t1), t2)));
115 #else
116  pstore(&res.z(), psub(t1, pxor(mask,preverse(t2))));
117 #endif
118 
119  return res;
120 }
121 };
122 
123 template<class Derived, int Alignment>
124 struct quat_conj<Architecture::SSE, Derived, double, Alignment>
125 {
127  {
128  Quaternion<double> res;
129  const __m128d mask0 = _mm_setr_pd(-0.,-0.);
130  const __m128d mask2 = _mm_setr_pd(-0.,0.);
131  pstore(&res.x(), _mm_xor_pd(mask0, q.coeffs().template packet<Alignment>(0)));
132  pstore(&res.z(), _mm_xor_pd(mask2, q.coeffs().template packet<Alignment>(2)));
133  return res;
134  }
135 };
136 
137 } // end namespace internal
138 
139 } // end namespace Eigen
140 
141 #endif // EIGEN_GEOMETRY_SSE_H
static plain_matrix_type< VectorLhs >::type run(const VectorLhs &lhs, const VectorRhs &rhs)
Definition: Geometry_SSE.h:56
static Quaternion< float > run(const QuaternionBase< Derived > &_a, const QuaternionBase< OtherDerived > &_b)
Definition: Geometry_SSE.h:21
f
Definition: LDLT.h:16
EIGEN_DEVICE_FUNC Packet padd(const Packet &a, const Packet &b)
static Quaternion< double > run(const QuaternionBase< Derived > &q)
Definition: Geometry_SSE.h:126
#define vec4f_swizzle1(v, p, q, r, s)
EIGEN_DEVICE_FUNC const internal::traits< Derived >::Coefficients & coeffs() const
Definition: Quaternion.h:85
Base class for quaternion expressions.
EIGEN_DEVICE_FUNC void pstore(Scalar *to, const Packet &from)
The quaternion class used to represent 3D orientations and rotations.
EIGEN_DEVICE_FUNC Packet psub(const Packet &a, const Packet &b)
EIGEN_STRONG_INLINE Packet2d pset1< Packet2d >(const double &from)
EIGEN_DEVICE_FUNC Packet pxor(const Packet &a, const Packet &b)
static Quaternion< float > run(const QuaternionBase< Derived > &q)
Definition: Geometry_SSE.h:42
EIGEN_DEVICE_FUNC Packet pmul(const Packet &a, const Packet &b)
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:615
static Quaternion< double > run(const QuaternionBase< Derived > &_a, const QuaternionBase< OtherDerived > &_b)
Definition: Geometry_SSE.h:74
EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf &a)


co_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:00:41