2009-03-07 13:52:44 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2009-03-07 13:52:44 +00:00
|
|
|
//
|
|
|
|
|
// Copyright (C) 2009 Rohit Garg <rpg.314@gmail.com>
|
2010-07-22 17:23:11 +02:00
|
|
|
// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-03-07 13:52:44 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2009-03-07 13:52:44 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_GEOMETRY_SSE_H
|
|
|
|
|
#define EIGEN_GEOMETRY_SSE_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
|
|
|
|
|
2009-12-14 17:26:24 -05:00
|
|
|
template<class Derived, class OtherDerived>
|
2017-06-07 10:10:30 +02:00
|
|
|
struct quat_product<Architecture::SSE, Derived, OtherDerived, float>
|
2009-10-27 13:19:16 +00:00
|
|
|
{
|
2017-06-07 10:10:30 +02:00
|
|
|
enum {
|
|
|
|
|
AAlignment = traits<Derived>::Alignment,
|
|
|
|
|
BAlignment = traits<OtherDerived>::Alignment,
|
|
|
|
|
ResAlignment = traits<Quaternion<float> >::Alignment
|
|
|
|
|
};
|
2012-01-31 12:58:52 +01:00
|
|
|
static inline Quaternion<float> run(const QuaternionBase<Derived>& _a, const QuaternionBase<OtherDerived>& _b)
|
2009-10-27 13:19:16 +00:00
|
|
|
{
|
2009-10-27 15:45:24 -04:00
|
|
|
Quaternion<float> res;
|
2015-03-02 20:09:33 +01:00
|
|
|
const __m128 mask = _mm_setr_ps(0.f,0.f,0.f,-0.f);
|
2017-06-07 10:10:30 +02:00
|
|
|
__m128 a = _a.coeffs().template packet<AAlignment>(0);
|
|
|
|
|
__m128 b = _b.coeffs().template packet<BAlignment>(0);
|
2015-03-02 20:09:33 +01:00
|
|
|
__m128 s1 = _mm_mul_ps(vec4f_swizzle1(a,1,2,0,2),vec4f_swizzle1(b,2,0,1,2));
|
|
|
|
|
__m128 s2 = _mm_mul_ps(vec4f_swizzle1(a,3,3,3,1),vec4f_swizzle1(b,0,1,2,1));
|
2017-06-07 10:10:30 +02:00
|
|
|
pstoret<float,Packet4f,ResAlignment>(
|
|
|
|
|
&res.x(),
|
2010-10-25 10:15:22 -04:00
|
|
|
_mm_add_ps(_mm_sub_ps(_mm_mul_ps(a,vec4f_swizzle1(b,3,3,3,3)),
|
|
|
|
|
_mm_mul_ps(vec4f_swizzle1(a,2,0,1,0),
|
|
|
|
|
vec4f_swizzle1(b,1,2,0,0))),
|
2015-03-02 20:09:33 +01:00
|
|
|
_mm_xor_ps(mask,_mm_add_ps(s1,s2))));
|
|
|
|
|
|
2009-10-27 13:19:16 +00:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-07 10:10:30 +02:00
|
|
|
template<class Derived>
|
|
|
|
|
struct quat_conj<Architecture::SSE, Derived, float>
|
2015-03-02 20:09:33 +01:00
|
|
|
{
|
2017-06-07 10:10:30 +02:00
|
|
|
enum {
|
|
|
|
|
ResAlignment = traits<Quaternion<float> >::Alignment
|
|
|
|
|
};
|
2015-03-02 20:09:33 +01:00
|
|
|
static inline Quaternion<float> run(const QuaternionBase<Derived>& q)
|
|
|
|
|
{
|
|
|
|
|
Quaternion<float> res;
|
|
|
|
|
const __m128 mask = _mm_setr_ps(-0.f,-0.f,-0.f,0.f);
|
2017-06-07 10:10:30 +02:00
|
|
|
pstoret<float,Packet4f,ResAlignment>(&res.x(), _mm_xor_ps(mask, q.coeffs().template packet<traits<Derived>::Alignment>(0)));
|
2015-03-02 20:09:33 +01:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2009-03-11 14:20:36 +00:00
|
|
|
template<typename VectorLhs,typename VectorRhs>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct cross3_impl<Architecture::SSE,VectorLhs,VectorRhs,float,true>
|
2009-12-14 17:26:24 -05:00
|
|
|
{
|
2017-06-07 10:10:30 +02:00
|
|
|
enum {
|
|
|
|
|
ResAlignment = traits<typename plain_matrix_type<VectorLhs>::type>::Alignment
|
|
|
|
|
};
|
2012-01-31 12:58:52 +01:00
|
|
|
static inline typename plain_matrix_type<VectorLhs>::type
|
2009-03-11 14:20:36 +00:00
|
|
|
run(const VectorLhs& lhs, const VectorRhs& rhs)
|
|
|
|
|
{
|
First part of a big refactoring of alignment control to enable the handling of arbitrarily aligned buffers. It includes:
- AlignedBit flag is deprecated. Alignment is now specified by the evaluator through the 'Alignment' enum, e.g., evaluator<Xpr>::Alignment. Its value is in Bytes.
- Add several enums to specify alignment: Aligned8, Aligned16, Aligned32, Aligned64, Aligned128. AlignedMax corresponds to EIGEN_MAX_ALIGN_BYTES. Such enums are used to define the above Alignment value, and as the 'Options' template parameter of Map<> and Ref<>.
- The Aligned enum is now deprecated. It is now an alias for Aligned16.
- Currently, traits<Matrix<>>, traits<Array<>>, traits<Ref<>>, traits<Map<>>, and traits<Block<>> also expose the Alignment enum.
2015-08-06 15:31:07 +02:00
|
|
|
__m128 a = lhs.template packet<traits<VectorLhs>::Alignment>(0);
|
|
|
|
|
__m128 b = rhs.template packet<traits<VectorRhs>::Alignment>(0);
|
2010-10-25 10:15:22 -04:00
|
|
|
__m128 mul1=_mm_mul_ps(vec4f_swizzle1(a,1,2,0,3),vec4f_swizzle1(b,2,0,1,3));
|
|
|
|
|
__m128 mul2=_mm_mul_ps(vec4f_swizzle1(a,2,0,1,3),vec4f_swizzle1(b,1,2,0,3));
|
|
|
|
|
typename plain_matrix_type<VectorLhs>::type res;
|
2017-06-07 10:10:30 +02:00
|
|
|
pstoret<float,Packet4f,ResAlignment>(&res.x(),_mm_sub_ps(mul1,mul2));
|
2009-03-11 14:20:36 +00:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-12 23:30:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-07 10:10:30 +02:00
|
|
|
template<class Derived, class OtherDerived>
|
|
|
|
|
struct quat_product<Architecture::SSE, Derived, OtherDerived, double>
|
2010-07-12 23:30:47 +02:00
|
|
|
{
|
2017-06-07 10:10:30 +02:00
|
|
|
enum {
|
|
|
|
|
BAlignment = traits<OtherDerived>::Alignment,
|
|
|
|
|
ResAlignment = traits<Quaternion<double> >::Alignment
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-31 12:58:52 +01:00
|
|
|
static inline Quaternion<double> run(const QuaternionBase<Derived>& _a, const QuaternionBase<OtherDerived>& _b)
|
2010-07-12 23:30:47 +02:00
|
|
|
{
|
|
|
|
|
const Packet2d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0));
|
|
|
|
|
|
|
|
|
|
Quaternion<double> res;
|
|
|
|
|
|
|
|
|
|
const double* a = _a.coeffs().data();
|
2017-06-07 10:10:30 +02:00
|
|
|
Packet2d b_xy = _b.coeffs().template packet<BAlignment>(0);
|
|
|
|
|
Packet2d b_zw = _b.coeffs().template packet<BAlignment>(2);
|
2010-10-25 10:15:22 -04:00
|
|
|
Packet2d a_xx = pset1<Packet2d>(a[0]);
|
|
|
|
|
Packet2d a_yy = pset1<Packet2d>(a[1]);
|
|
|
|
|
Packet2d a_zz = pset1<Packet2d>(a[2]);
|
|
|
|
|
Packet2d a_ww = pset1<Packet2d>(a[3]);
|
2010-07-12 23:30:47 +02:00
|
|
|
|
|
|
|
|
// two temporaries:
|
|
|
|
|
Packet2d t1, t2;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* t1 = ww*xy + yy*zw
|
|
|
|
|
* t2 = zz*xy - xx*zw
|
|
|
|
|
* res.xy = t1 +/- swap(t2)
|
|
|
|
|
*/
|
2010-10-25 10:15:22 -04:00
|
|
|
t1 = padd(pmul(a_ww, b_xy), pmul(a_yy, b_zw));
|
|
|
|
|
t2 = psub(pmul(a_zz, b_xy), pmul(a_xx, b_zw));
|
2012-03-21 23:50:43 +01:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2010-08-16 11:11:43 -04:00
|
|
|
EIGEN_UNUSED_VARIABLE(mask)
|
2017-06-07 10:10:30 +02:00
|
|
|
pstoret<double,Packet2d,ResAlignment>(&res.x(), _mm_addsub_pd(t1, preverse(t2)));
|
2010-07-12 23:30:47 +02:00
|
|
|
#else
|
2017-06-07 10:10:30 +02:00
|
|
|
pstoret<double,Packet2d,ResAlignment>(&res.x(), padd(t1, pxor(mask,preverse(t2))));
|
2010-07-12 23:30:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* t1 = ww*zw - yy*xy
|
|
|
|
|
* t2 = zz*zw + xx*xy
|
|
|
|
|
* res.zw = t1 -/+ swap(t2) = swap( swap(t1) +/- t2)
|
|
|
|
|
*/
|
2010-10-25 10:15:22 -04:00
|
|
|
t1 = psub(pmul(a_ww, b_zw), pmul(a_yy, b_xy));
|
|
|
|
|
t2 = padd(pmul(a_zz, b_zw), pmul(a_xx, b_xy));
|
2012-03-21 23:50:43 +01:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2010-08-16 11:11:43 -04:00
|
|
|
EIGEN_UNUSED_VARIABLE(mask)
|
2017-06-07 10:10:30 +02:00
|
|
|
pstoret<double,Packet2d,ResAlignment>(&res.z(), preverse(_mm_addsub_pd(preverse(t1), t2)));
|
2010-07-12 23:30:47 +02:00
|
|
|
#else
|
2017-06-07 10:10:30 +02:00
|
|
|
pstoret<double,Packet2d,ResAlignment>(&res.z(), psub(t1, pxor(mask,preverse(t2))));
|
2010-07-12 23:30:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-07 10:10:30 +02:00
|
|
|
template<class Derived>
|
|
|
|
|
struct quat_conj<Architecture::SSE, Derived, double>
|
2015-03-02 20:09:33 +01:00
|
|
|
{
|
2017-06-07 10:10:30 +02:00
|
|
|
enum {
|
|
|
|
|
ResAlignment = traits<Quaternion<double> >::Alignment
|
|
|
|
|
};
|
2015-03-02 20:09:33 +01:00
|
|
|
static inline Quaternion<double> run(const QuaternionBase<Derived>& q)
|
|
|
|
|
{
|
|
|
|
|
Quaternion<double> res;
|
|
|
|
|
const __m128d mask0 = _mm_setr_pd(-0.,-0.);
|
|
|
|
|
const __m128d mask2 = _mm_setr_pd(-0.,0.);
|
2017-06-07 10:10:30 +02:00
|
|
|
pstoret<double,Packet2d,ResAlignment>(&res.x(), _mm_xor_pd(mask0, q.coeffs().template packet<traits<Derived>::Alignment>(0)));
|
|
|
|
|
pstoret<double,Packet2d,ResAlignment>(&res.z(), _mm_xor_pd(mask2, q.coeffs().template packet<traits<Derived>::Alignment>(2)));
|
2015-03-02 20:09:33 +01:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
} // end namespace internal
|
2010-07-12 23:30:47 +02:00
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2009-03-07 13:52:44 +00:00
|
|
|
#endif // EIGEN_GEOMETRY_SSE_H
|