SSE/TypeCasting.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) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_TYPE_CASTING_SSE_H
11 #define EIGEN_TYPE_CASTING_SSE_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 #ifndef EIGEN_VECTORIZE_AVX
18 template <>
19 struct type_casting_traits<float, int> {
20  enum {
21  VectorizedCast = 1,
22  SrcCoeffRatio = 1,
23  TgtCoeffRatio = 1
24  };
25 };
26 
27 template <>
28 struct type_casting_traits<int, float> {
29  enum {
30  VectorizedCast = 1,
31  SrcCoeffRatio = 1,
32  TgtCoeffRatio = 1
33  };
34 };
35 
36 template <>
37 struct type_casting_traits<double, float> {
38  enum {
42  };
43 };
44 
45 template <>
46 struct type_casting_traits<float, double> {
47  enum {
51  };
52 };
53 #endif
54 
56  return _mm_cvttps_epi32(a);
57 }
58 
60  return _mm_cvtepi32_ps(a);
61 }
62 
64  return _mm_shuffle_ps(_mm_cvtpd_ps(a), _mm_cvtpd_ps(b), (1 << 2) | (1 << 6));
65 }
66 
68  // Simply discard the second half of the input
69  return _mm_cvtps_pd(a);
70 }
71 
73  return _mm_castps_si128(a);
74 }
75 
77  return _mm_castsi128_ps(a);
78 }
79 
81  return _mm_castsi128_pd(a);
82 }
83 
85  return _mm_castpd_si128(a);
86 }
87 
88 // Disable the following code since it's broken on too many platforms / compilers.
89 //#elif defined(EIGEN_VECTORIZE_SSE) && (!EIGEN_ARCH_x86_64) && (!EIGEN_COMP_MSVC)
90 #if 0
91 
92 template <>
93 struct type_casting_traits<Eigen::half, float> {
94  enum {
95  VectorizedCast = 1,
96  SrcCoeffRatio = 1,
97  TgtCoeffRatio = 1
98  };
99 };
100 
101 template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4h, Packet4f>(const Packet4h& a) {
102  __int64_t a64 = _mm_cvtm64_si64(a.x);
103  Eigen::half h = raw_uint16_to_half(static_cast<unsigned short>(a64));
104  float f1 = static_cast<float>(h);
105  h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16));
106  float f2 = static_cast<float>(h);
107  h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32));
108  float f3 = static_cast<float>(h);
109  h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48));
110  float f4 = static_cast<float>(h);
111  return _mm_set_ps(f4, f3, f2, f1);
112 }
113 
114 template <>
115 struct type_casting_traits<float, Eigen::half> {
116  enum {
117  VectorizedCast = 1,
118  SrcCoeffRatio = 1,
119  TgtCoeffRatio = 1
120  };
121 };
122 
123 template<> EIGEN_STRONG_INLINE Packet4h pcast<Packet4f, Packet4h>(const Packet4f& a) {
124  EIGEN_ALIGN16 float aux[4];
125  pstore(aux, a);
126  Eigen::half h0(aux[0]);
127  Eigen::half h1(aux[1]);
128  Eigen::half h2(aux[2]);
129  Eigen::half h3(aux[3]);
130 
131  Packet4h result;
132  result.x = _mm_set_pi16(h3.x, h2.x, h1.x, h0.x);
133  return result;
134 }
135 
136 #endif
137 
138 } // end namespace internal
139 
140 } // end namespace Eigen
141 
142 #endif // EIGEN_TYPE_CASTING_SSE_H
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
Eigen::internal::Packet4i
__vector int Packet4i
Definition: AltiVec/PacketMath.h:31
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
test_constructor::f1
auto f1
Definition: testHybridNonlinearFactor.cpp:56
Eigen::internal::Packet4f
__vector float Packet4f
Definition: AltiVec/PacketMath.h:30
example::h0
const double h0
Definition: testGPSFactor.cpp:41
b
Scalar * b
Definition: benchVecAdd.cpp:17
Eigen::internal::pcast< Packet4i, Packet4f >
EIGEN_STRONG_INLINE Packet4f pcast< Packet4i, Packet4f >(const Packet4i &a)
Definition: AltiVec/PacketMath.h:2198
f2
double f2(const Vector2 &x)
Definition: testNumericalDerivative.cpp:56
Eigen::internal::preinterpret< Packet4f, Packet4i >
EIGEN_STRONG_INLINE Packet4f preinterpret< Packet4f, Packet4i >(const Packet4i &a)
Definition: AltiVec/PacketMath.h:2248
h
const double h
Definition: testSimpleHelicopter.cpp:19
result
Values result
Definition: OdometryOptimize.cpp:8
Eigen::internal::pcast< Packet4f, Packet4i >
EIGEN_STRONG_INLINE Packet4i pcast< Packet4f, Packet4i >(const Packet4f &a)
Definition: AltiVec/PacketMath.h:2190
Eigen::internal::preinterpret< Packet4i, Packet2d >
EIGEN_STRONG_INLINE Packet4i preinterpret< Packet4i, Packet2d >(const Packet2d &a)
Definition: SSE/TypeCasting.h:84
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::internal::preinterpret< Packet2d, Packet4i >
EIGEN_STRONG_INLINE Packet2d preinterpret< Packet2d, Packet4i >(const Packet4i &a)
Definition: SSE/TypeCasting.h:80
Eigen::internal::pstore
EIGEN_DEVICE_FUNC void pstore(Scalar *to, const Packet &from)
Definition: GenericPacketMath.h:696
Eigen::internal::pcast< Packet4f, Packet2d >
EIGEN_STRONG_INLINE Packet2d pcast< Packet4f, Packet2d >(const Packet4f &a)
Definition: SSE/TypeCasting.h:67
Eigen::internal::type_casting_traits::SrcCoeffRatio
@ SrcCoeffRatio
Definition: GenericPacketMath.h:151
Eigen::internal::preinterpret< Packet4i, Packet4f >
EIGEN_STRONG_INLINE Packet4i preinterpret< Packet4i, Packet4f >(const Packet4f &a)
Definition: AltiVec/PacketMath.h:2244
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
Eigen::internal::Packet2d
v2f64 Packet2d
Definition: MSA/PacketMath.h:820
f3
double f3(double x1, double x2)
Definition: testNumericalDerivative.cpp:76
Eigen::internal::type_casting_traits
Definition: GenericPacketMath.h:148
Eigen::internal::type_casting_traits::TgtCoeffRatio
@ TgtCoeffRatio
Definition: GenericPacketMath.h:152
Eigen::half_impl::raw_uint16_to_half
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw raw_uint16_to_half(numext::uint16_t x)
Definition: Half.h:495
f4
double f4(double x, double y, double z)
Definition: testNumericalDerivative.cpp:105
gtsam.examples.DogLegOptimizerExample.float
float
Definition: DogLegOptimizerExample.py:113
Eigen::internal::pcast< Packet2d, Packet4f >
EIGEN_STRONG_INLINE Packet4f pcast< Packet2d, Packet4f >(const Packet2d &a, const Packet2d &b)
Definition: SSE/TypeCasting.h:63
EIGEN_ALIGN16
#define EIGEN_ALIGN16
Definition: ConfigureVectorization.h:153
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::type_casting_traits::VectorizedCast
@ VectorizedCast
Definition: GenericPacketMath.h:150
Eigen::half
Definition: Half.h:142


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:09:37