Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.5/simd-support/simd-vsx.h @ 42:2cd0e3b3e1fd
Current fftw source
author | Chris Cannam |
---|---|
date | Tue, 18 Oct 2016 13:40:26 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
41:481f5f8c5634 | 42:2cd0e3b3e1fd |
---|---|
1 /* | |
2 * Copyright (c) 2003, 2007-14 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology | |
4 * | |
5 * VSX SIMD implementation added 2015 Erik Lindahl. | |
6 * Erik Lindahl places his modifications in the public domain. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 * | |
22 */ | |
23 | |
24 #if defined(FFTW_LDOUBLE) || defined(FFTW_QUAD) | |
25 # error "VSX only works in single or double precision" | |
26 #endif | |
27 | |
28 #ifdef FFTW_SINGLE | |
29 # define DS(d,s) s /* single-precision option */ | |
30 # define SUFF(name) name ## s | |
31 #else | |
32 # define DS(d,s) d /* double-precision option */ | |
33 # define SUFF(name) name ## d | |
34 #endif | |
35 | |
36 #define SIMD_SUFFIX _vsx /* for renaming */ | |
37 #define VL DS(1,2) /* SIMD vector length, in term of complex numbers */ | |
38 #define SIMD_VSTRIDE_OKA(x) DS(1,((x) == 2)) | |
39 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OK | |
40 | |
41 #include <altivec.h> | |
42 #include <stdio.h> | |
43 | |
44 typedef DS(vector double,vector float) V; | |
45 | |
46 #define VADD(a,b) vec_add(a,b) | |
47 #define VSUB(a,b) vec_sub(a,b) | |
48 #define VMUL(a,b) vec_mul(a,b) | |
49 #define VXOR(a,b) vec_xor(a,b) | |
50 #define UNPCKL(a,b) vec_mergel(a,b) | |
51 #define UNPCKH(a,b) vec_mergeh(a,b) | |
52 #ifdef FFTW_SINGLE | |
53 # define VDUPL(a) ({ const vector unsigned char perm = {0,1,2,3,0,1,2,3,8,9,10,11,8,9,10,11}; vec_perm(a,a,perm); }) | |
54 # define VDUPH(a) ({ const vector unsigned char perm = {4,5,6,7,4,5,6,7,12,13,14,15,12,13,14,15}; vec_perm(a,a,perm); }) | |
55 #else | |
56 # define VDUPL(a) ({ const vector unsigned char perm = {0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7}; vec_perm(a,a,perm); }) | |
57 # define VDUPH(a) ({ const vector unsigned char perm = {8,9,10,11,12,13,14,15,8,9,10,11,12,13,14,15}; vec_perm(a,a,perm); }) | |
58 #endif | |
59 | |
60 static inline V LDK(R f) { return vec_splats(f); } | |
61 | |
62 #define DVK(var, val) const R var = K(val) | |
63 | |
64 static inline V VCONJ(V x) | |
65 { | |
66 const V pmpm = vec_mergel(vec_splats((R)0.0),-(vec_splats((R)0.0))); | |
67 return vec_xor(x, pmpm); | |
68 } | |
69 | |
70 static inline V LDA(const R *x, INT ivs, const R *aligned_like) | |
71 { | |
72 #ifdef __ibmxl__ | |
73 return vec_xl(0,(DS(double,float) *)x); | |
74 #else | |
75 return (*(const V *)(x)); | |
76 #endif | |
77 } | |
78 | |
79 static inline void STA(R *x, V v, INT ovs, const R *aligned_like) | |
80 { | |
81 #ifdef __ibmxl__ | |
82 vec_xst(v,0,x); | |
83 #else | |
84 *(V *)x = v; | |
85 #endif | |
86 } | |
87 | |
88 static inline V FLIP_RI(V x) | |
89 { | |
90 #ifdef FFTW_SINGLE | |
91 const vector unsigned char perm = { 4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11 }; | |
92 #else | |
93 const vector unsigned char perm = { 8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7 }; | |
94 #endif | |
95 return vec_perm(x,x,perm); | |
96 } | |
97 | |
98 #ifdef FFTW_SINGLE | |
99 | |
100 static inline V LD(const R *x, INT ivs, const R *aligned_like) | |
101 { | |
102 const vector unsigned char perm = {0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23}; | |
103 | |
104 return vec_perm((vector float)vec_splats(*(double *)(x)), | |
105 (vector float)vec_splats(*(double *)(x+ivs)),perm); | |
106 } | |
107 | |
108 static inline void ST(R *x, V v, INT ovs, const R *aligned_like) | |
109 { | |
110 *(double *)(x+ovs) = vec_extract( (vector double)v, 1 ); | |
111 *(double *)x = vec_extract( (vector double)v, 0 ); | |
112 } | |
113 #else | |
114 /* DOUBLE */ | |
115 | |
116 # define LD LDA | |
117 # define ST STA | |
118 | |
119 #endif | |
120 | |
121 #define STM2 DS(STA,ST) | |
122 #define STN2(x, v0, v1, ovs) /* nop */ | |
123 | |
124 #ifdef FFTW_SINGLE | |
125 | |
126 # define STM4(x, v, ovs, aligned_like) /* no-op */ | |
127 static inline void STN4(R *x, V v0, V v1, V v2, V v3, int ovs) | |
128 { | |
129 V xxx0, xxx1, xxx2, xxx3; | |
130 xxx0 = vec_mergeh(v0,v1); | |
131 xxx1 = vec_mergel(v0,v1); | |
132 xxx2 = vec_mergeh(v2,v3); | |
133 xxx3 = vec_mergel(v2,v3); | |
134 *(double *)x = vec_extract( (vector double)xxx0, 0 ); | |
135 *(double *)(x+ovs) = vec_extract( (vector double)xxx0, 1 ); | |
136 *(double *)(x+2*ovs) = vec_extract( (vector double)xxx1, 0 ); | |
137 *(double *)(x+3*ovs) = vec_extract( (vector double)xxx1, 1 ); | |
138 *(double *)(x+2) = vec_extract( (vector double)xxx2, 0 ); | |
139 *(double *)(x+ovs+2) = vec_extract( (vector double)xxx2, 1 ); | |
140 *(double *)(x+2*ovs+2) = vec_extract( (vector double)xxx3, 0 ); | |
141 *(double *)(x+3*ovs+2) = vec_extract( (vector double)xxx3, 1 ); | |
142 } | |
143 #else /* !FFTW_SINGLE */ | |
144 | |
145 static inline void STM4(R *x, V v, INT ovs, const R *aligned_like) | |
146 { | |
147 (void)aligned_like; /* UNUSED */ | |
148 x[0] = vec_extract(v,0); | |
149 x[ovs] = vec_extract(v,1); | |
150 } | |
151 # define STN4(x, v0, v1, v2, v3, ovs) /* nothing */ | |
152 #endif | |
153 | |
154 static inline V VBYI(V x) | |
155 { | |
156 /* Complicated low-level stuff. vpermxor is really a cryptographic instruction that is only | |
157 * available in the low-level inteface both for GCC and XLC. However, on little-endian | |
158 * platforms there is also the complicated swapping going on. XLC does this here too, but | |
159 * not GCC, so we need different permute constants. | |
160 */ | |
161 #if defined(__POWER8_VECTOR__) && defined(__GNUC__) && defined(__LITTLE_ENDIAN__) | |
162 # ifdef FFTW_SINGLE | |
163 const vector unsigned char perm = { 0xbb, 0xaa, 0x99, 0x88, 0xff, 0xee, 0xdd, 0xcc, 0x33, 0x22, 0x11, 0x00, 0x77, 0x66, 0x55, 0x44 }; | |
164 # else | |
165 const vector unsigned char perm = { 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88 }; | |
166 # endif | |
167 const V pmpm = vec_mergel(vec_splats((R)0.0),-(vec_splats((R)0.0))); | |
168 return (V)__builtin_crypto_vpermxor((vector unsigned char)x,(vector unsigned char)pmpm,perm); | |
169 #elif defined(__POWER8_VECTOR__) && (defined(__ibmxl__) || (defined(__GNUC__) && !defined(__LITTLE_ENDIAN__))) | |
170 # ifdef FFTW_SINGLE | |
171 const vector unsigned char perm = { 0x44, 0x55, 0x66, 0x77, 0x00, 0x11, 0x22, 0x33, 0xCC, 0xDD, 0xEE, 0xFF, 0x88, 0x99, 0xAA, 0xBB }; | |
172 # else | |
173 const vector unsigned char perm = { 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }; | |
174 # endif | |
175 const V pmpm = vec_mergel(vec_splats((R)0.0),-(vec_splats((R)0.0))); | |
176 return (V)__vpermxor((vector unsigned char)x,(vector unsigned char)pmpm,perm); | |
177 #else | |
178 /* The safe option */ | |
179 return FLIP_RI(VCONJ(x)); | |
180 #endif | |
181 } | |
182 | |
183 /* FMA support */ | |
184 #define VFMA(a, b, c) vec_madd(a,b,c) | |
185 #define VFNMS(a, b, c) vec_nmsub(a,b,c) | |
186 #define VFMS(a, b, c) vec_msub(a,b,c) | |
187 #define VFMAI(b, c) VADD(c, VBYI(b)) | |
188 #define VFNMSI(b, c) VSUB(c, VBYI(b)) | |
189 #define VFMACONJ(b,c) VADD(VCONJ(b),c) | |
190 #define VFMSCONJ(b,c) VSUB(VCONJ(b),c) | |
191 #define VFNMSCONJ(b,c) VSUB(c, VCONJ(b)) | |
192 | |
193 static inline V VZMUL(V tx, V sr) | |
194 { | |
195 V tr = VDUPL(tx); | |
196 V ti = VDUPH(tx); | |
197 tr = VMUL(sr, tr); | |
198 sr = VBYI(sr); | |
199 return VFMA(ti, sr, tr); | |
200 } | |
201 | |
202 static inline V VZMULJ(V tx, V sr) | |
203 { | |
204 V tr = VDUPL(tx); | |
205 V ti = VDUPH(tx); | |
206 tr = VMUL(sr, tr); | |
207 sr = VBYI(sr); | |
208 return VFNMS(ti, sr, tr); | |
209 } | |
210 | |
211 static inline V VZMULI(V tx, V sr) | |
212 { | |
213 V tr = VDUPL(tx); | |
214 V ti = VDUPH(tx); | |
215 ti = VMUL(ti, sr); | |
216 sr = VBYI(sr); | |
217 return VFMS(tr, sr, ti); | |
218 } | |
219 | |
220 static inline V VZMULIJ(V tx, V sr) | |
221 { | |
222 V tr = VDUPL(tx); | |
223 V ti = VDUPH(tx); | |
224 ti = VMUL(ti, sr); | |
225 sr = VBYI(sr); | |
226 return VFMA(tr, sr, ti); | |
227 } | |
228 | |
229 /* twiddle storage #1: compact, slower */ | |
230 #ifdef FFTW_SINGLE | |
231 # define VTW1(v,x) \ | |
232 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x} | |
233 static inline V BYTW1(const R *t, V sr) | |
234 { | |
235 V tx = LDA(t,0,t); | |
236 V tr = UNPCKH(tx, tx); | |
237 V ti = UNPCKL(tx, tx); | |
238 tr = VMUL(tr, sr); | |
239 sr = VBYI(sr); | |
240 return VFMA(ti, sr, tr); | |
241 } | |
242 static inline V BYTWJ1(const R *t, V sr) | |
243 { | |
244 V tx = LDA(t,0,t); | |
245 V tr = UNPCKH(tx, tx); | |
246 V ti = UNPCKL(tx, tx); | |
247 tr = VMUL(tr, sr); | |
248 sr = VBYI(sr); | |
249 return VFNMS(ti, sr, tr); | |
250 } | |
251 #else /* !FFTW_SINGLE */ | |
252 # define VTW1(v,x) {TW_CEXP, v, x} | |
253 static inline V BYTW1(const R *t, V sr) | |
254 { | |
255 V tx = LD(t, 1, t); | |
256 return VZMUL(tx, sr); | |
257 } | |
258 static inline V BYTWJ1(const R *t, V sr) | |
259 { | |
260 V tx = LD(t, 1, t); | |
261 return VZMULJ(tx, sr); | |
262 } | |
263 #endif | |
264 #define TWVL1 (VL) | |
265 | |
266 /* twiddle storage #2: twice the space, faster (when in cache) */ | |
267 #ifdef FFTW_SINGLE | |
268 # define VTW2(v,x) \ | |
269 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \ | |
270 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x} | |
271 #else /* !FFTW_SINGLE */ | |
272 # define VTW2(v,x) \ | |
273 {TW_COS, v, x}, {TW_COS, v, x}, {TW_SIN, v, -x}, {TW_SIN, v, x} | |
274 #endif | |
275 #define TWVL2 (2 * VL) | |
276 static inline V BYTW2(const R *t, V sr) | |
277 { | |
278 V si = FLIP_RI(sr); | |
279 V ti = LDA(t+2*VL,0,t); | |
280 V tt = VMUL(ti, si); | |
281 V tr = LDA(t,0,t); | |
282 return VFMA(tr, sr, tt); | |
283 } | |
284 static inline V BYTWJ2(const R *t, V sr) | |
285 { | |
286 V si = FLIP_RI(sr); | |
287 V tr = LDA(t,0,t); | |
288 V tt = VMUL(tr, sr); | |
289 V ti = LDA(t+2*VL,0,t); | |
290 return VFNMS(ti, si, tt); | |
291 } | |
292 | |
293 /* twiddle storage #3 */ | |
294 #ifdef FFTW_SINGLE | |
295 # define VTW3(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x} | |
296 # define TWVL3 (VL) | |
297 #else | |
298 # define VTW3(v,x) VTW1(v,x) | |
299 # define TWVL3 TWVL1 | |
300 #endif | |
301 | |
302 /* twiddle storage for split arrays */ | |
303 #ifdef FFTW_SINGLE | |
304 # define VTWS(v,x) \ | |
305 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \ | |
306 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x} | |
307 #else | |
308 # define VTWS(v,x) \ | |
309 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x} | |
310 #endif | |
311 #define TWVLS (2 * VL) | |
312 | |
313 #define VLEAVE() /* nothing */ | |
314 | |
315 #include "simd-common.h" |