QDP++
qdp_scalarvecsite_sse.h
Go to the documentation of this file.
1// -*- C++ -*-
2
8
9#ifndef QDP_SCALARVECSITE_SSE_H
10#define QDP_SCALARVECSITE_SSE_H
11
12
13// These SSE asm instructions are only supported under GCC/G++
14// Only supported on gcc >= 3.2
15#if defined(__GNUC__) && __GNUC_MINOR__ >= 2
16
17namespace QDP {
18
19typedef REAL32 vReal32 __attribute__ ((aligned (16),mode(V4SF)));
20
21
22static inline vReal32 vmk1(REAL32 a)
23{
24 vReal32 v = _mm_load_ss((float *)&a);
25 // asm("shufps\t$0,%0,%0" : "+x" (v));
26 v = _mm_shuffle_ps(v,v,0);
27 return v;
28}
29
30static inline vReal32 vmk4(REAL32 a0, REAL32 a1, REAL32 a2, REAL32 a3)
31{
32 vReal32 v;
33 REAL32 *r = (REAL32 *)&v;
34 r[0] = a0;
35 r[1] = a1;
36 r[2] = a2;
37 r[3] = a3;
38 return v;
39}
40
41
43
44template<> class ILattice<REAL32,4>
45{
46public:
47 typedef REAL32 T;
48 static const int N = 4;
49
50 ILattice() {}
51 ~ILattice() {}
52
53 //---------------------------------------------------------
55 ILattice(REAL32 a0, REAL32 a1, REAL32 a2, REAL32 a3) : v(vmk4(a0,a1,a2,a3)) {}
56
58 ILattice(REAL32 rhs) : v(vmk1(rhs)) {}
59
61 template<class T1>
62 ILattice(const ILattice<T1,N>& rhs)
63 {
64 vput_0(rhs.elem(0));
65 vput_1(rhs.elem(1));
66 vput_2(rhs.elem(2));
67 vput_3(rhs.elem(3));
68 }
69
71 ILattice(vReal32 rhs) : v(rhs) {}
72
74 template<class T1>
75 ILattice(const IScalar<T1>& rhs) : v(vmk1(REAL32(rhs.elem()))) {}
76
78 template<class T1>
79 ILattice(const T1& rhs) : v(vmk1(REAL32(rhs))) {}
80
81
82 //---------------------------------------------------------
84
85 template<class T1>
86 inline
87 ILattice& operator=(const IScalar<T1>& rhs)
88 {
89 v = vmk1(REAL32(rhs.elem()));
90 return *this;
91 }
92
94 template<class T1>
95 inline
96 ILattice& operator+=(const IScalar<T1>& rhs)
97 {
98 v = _mm_add_ps(v, vmk1(REAL32(rhs.elem())));
99 return *this;
100 }
101
103 template<class T1>
104 inline
105 ILattice& operator-=(const IScalar<T1>& rhs)
106 {
107 v = _mm_sub_ps(v, vmk1(REAL32(rhs.elem())));
108 return *this;
109 }
110
112 template<class T1>
113 inline
114 ILattice& operator*=(const IScalar<T1>& rhs)
115 {
116 v = _mm_mul_ps(v, vmk1(REAL32(rhs.elem())));
117 return *this;
118 }
119
121 template<class T1>
122 inline
123 ILattice& operator/=(const IScalar<T1>& rhs)
124 {
125 v = _mm_div_ps(v, vmk1(REAL32(rhs.elem())));
126 return *this;
127 }
128
129
130 //---------------------------------------------------------
132
133 inline
134 ILattice& operator=(const ILattice& rhs)
135 {
136 v = rhs.v;
137 return *this;
138 }
139
141 inline
142 ILattice& operator+=(const ILattice& rhs)
143 {
144 v = _mm_add_ps(v, rhs.v);
145 return *this;
146 }
147
149 inline
150 ILattice& operator-=(const ILattice& rhs)
151 {
152 v = _mm_sub_ps(v, rhs.v);
153 return *this;
154 }
155
157 inline
158 ILattice& operator*=(const ILattice& rhs)
159 {
160 v = _mm_mul_ps(v, rhs.v);
161 return *this;
162 }
163
165 inline
166 ILattice& operator/=(const ILattice& rhs)
167 {
168 v = _mm_div_ps(v, rhs.v);
169 return *this;
170 }
171
172
174 ILattice(const ILattice& a) : v(a.v) {}
175
176
177public:
179
183 inline T* data() {return (REAL32*)&v;}
184
185
186public:
187 void vput_0(REAL32 a) { ((REAL32 *)&v)[0] = a; }
188 void vput_1(REAL32 a) { ((REAL32 *)&v)[1] = a; }
189 void vput_2(REAL32 a) { ((REAL32 *)&v)[2] = a; }
190 void vput_3(REAL32 a) { ((REAL32 *)&v)[3] = a; }
191
192 T& elem(int i) {return ((REAL32*)&v)[i];}
193 const T& elem(int i) const {return ((REAL32*)&v)[i];}
194
195 vReal32& elem_v() {return v;}
196 const vReal32 elem_v() const {return v;}
197
198private:
199 // SSE attributes
200 vReal32 v;
201
203
204
205} // namespace QDP
206
207// Use SSE specific Linalg stuff (inline assembler etc)
209
210// Use SSE specific blas stuff (inline assembler etc)
212
213#else
214#error "This is not a GNUC 3.2 or greater compiler, and therefore does not support the GNU specific asm directives."
215#endif // gnuc
216
217#endif // guard
218
ILattice & operator*=(const IScalar< T1 > &rhs)
ILattice *= IScalar.
Definition qdp_inner.h:339
ILattice & operator=(const IScalar< T1 > &rhs)
ILattice = IScalar.
Definition qdp_inner.h:306
ILattice & operator-=(const IScalar< T1 > &rhs)
ILattice -= IScalar.
Definition qdp_inner.h:328
T & elem(int i)
Definition qdp_inner.h:577
ILattice & operator/=(const IScalar< T1 > &rhs)
ILattice /= IScalar.
Definition qdp_inner.h:350
ILattice & operator+=(const IScalar< T1 > &rhs)
ILattice += IScalar.
Definition qdp_inner.h:317
T * data()
The backdoor.
Definition qdp_inner.h:573
Yet another random number generator.
#define QDP_ALIGN16
Definition qdp.h:61
Blas optimizations.
Intel SSE optimizations.