Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
Eigen  3.4.0
 
Loading...
Searching...
No Matches
AVX/TypeCasting.h
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_AVX_H
11#define EIGEN_TYPE_CASTING_AVX_H
12
13namespace Eigen {
14
15namespace internal {
16
17// For now we use SSE to handle integers, so we can't use AVX instructions to cast
18// from int to float
19template <>
20struct type_casting_traits<float, int> {
21 enum {
22 VectorizedCast = 0,
23 SrcCoeffRatio = 1,
24 TgtCoeffRatio = 1
25 };
26};
27
28template <>
29struct type_casting_traits<int, float> {
30 enum {
31 VectorizedCast = 0,
32 SrcCoeffRatio = 1,
33 TgtCoeffRatio = 1
34 };
35};
36
37
38#ifndef EIGEN_VECTORIZE_AVX512
39
40template <>
41struct type_casting_traits<Eigen::half, float> {
42 enum {
43 VectorizedCast = 1,
44 SrcCoeffRatio = 1,
45 TgtCoeffRatio = 1
46 };
47};
48
49
50template <>
51struct type_casting_traits<float, Eigen::half> {
52 enum {
53 VectorizedCast = 1,
54 SrcCoeffRatio = 1,
55 TgtCoeffRatio = 1
56 };
57};
58
59template <>
60struct type_casting_traits<bfloat16, float> {
61 enum {
62 VectorizedCast = 1,
63 SrcCoeffRatio = 1,
64 TgtCoeffRatio = 1
65 };
66};
67
68template <>
69struct type_casting_traits<float, bfloat16> {
70 enum {
71 VectorizedCast = 1,
72 SrcCoeffRatio = 1,
73 TgtCoeffRatio = 1
74 };
75};
76
77#endif // EIGEN_VECTORIZE_AVX512
78
79template<> EIGEN_STRONG_INLINE Packet8i pcast<Packet8f, Packet8i>(const Packet8f& a) {
80 return _mm256_cvttps_epi32(a);
81}
82
83template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8i, Packet8f>(const Packet8i& a) {
84 return _mm256_cvtepi32_ps(a);
85}
86
87template<> EIGEN_STRONG_INLINE Packet8i preinterpret<Packet8i,Packet8f>(const Packet8f& a) {
88 return _mm256_castps_si256(a);
89}
90
91template<> EIGEN_STRONG_INLINE Packet8f preinterpret<Packet8f,Packet8i>(const Packet8i& a) {
92 return _mm256_castsi256_ps(a);
93}
94
95template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8h, Packet8f>(const Packet8h& a) {
96 return half2float(a);
97}
98
99template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8bf, Packet8f>(const Packet8bf& a) {
100 return Bf16ToF32(a);
101}
102
103template<> EIGEN_STRONG_INLINE Packet8h pcast<Packet8f, Packet8h>(const Packet8f& a) {
104 return float2half(a);
105}
106
107template<> EIGEN_STRONG_INLINE Packet8bf pcast<Packet8f, Packet8bf>(const Packet8f& a) {
108 return F32ToBf16(a);
109}
110
111} // end namespace internal
112
113} // end namespace Eigen
114
115#endif // EIGEN_TYPE_CASTING_AVX_H
Namespace containing all symbols from the Eigen library.
Definition: Core:141