Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/simd-support/simd-vsx.h @ 82:d0c2a83c1364
Add FFTW 3.3.8 source, and a Linux build
author | Chris Cannam |
---|---|
date | Tue, 19 Nov 2019 14:52:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
81:7029a4916348 | 82:d0c2a83c1364 |
---|---|
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 /* FIXME [matteof 2017-09-21] It is possible to use vpermxor(), | |
157 but gcc and xlc treat the permutation bits differently, and | |
158 gcc-6 seems to generate incorrect code when using | |
159 __builtin_crypto_vpermxor() (i.e., VBYI() works for a small | |
160 test case but fails in the large). | |
161 | |
162 Punt on vpermxor() for now and do the simple thing. | |
163 */ | |
164 return FLIP_RI(VCONJ(x)); | |
165 } | |
166 | |
167 /* FMA support */ | |
168 #define VFMA(a, b, c) vec_madd(a,b,c) | |
169 #define VFNMS(a, b, c) vec_nmsub(a,b,c) | |
170 #define VFMS(a, b, c) vec_msub(a,b,c) | |
171 #define VFMAI(b, c) VADD(c, VBYI(b)) | |
172 #define VFNMSI(b, c) VSUB(c, VBYI(b)) | |
173 #define VFMACONJ(b,c) VADD(VCONJ(b),c) | |
174 #define VFMSCONJ(b,c) VSUB(VCONJ(b),c) | |
175 #define VFNMSCONJ(b,c) VSUB(c, VCONJ(b)) | |
176 | |
177 static inline V VZMUL(V tx, V sr) | |
178 { | |
179 V tr = VDUPL(tx); | |
180 V ti = VDUPH(tx); | |
181 tr = VMUL(sr, tr); | |
182 sr = VBYI(sr); | |
183 return VFMA(ti, sr, tr); | |
184 } | |
185 | |
186 static inline V VZMULJ(V tx, V sr) | |
187 { | |
188 V tr = VDUPL(tx); | |
189 V ti = VDUPH(tx); | |
190 tr = VMUL(sr, tr); | |
191 sr = VBYI(sr); | |
192 return VFNMS(ti, sr, tr); | |
193 } | |
194 | |
195 static inline V VZMULI(V tx, V sr) | |
196 { | |
197 V tr = VDUPL(tx); | |
198 V ti = VDUPH(tx); | |
199 ti = VMUL(ti, sr); | |
200 sr = VBYI(sr); | |
201 return VFMS(tr, sr, ti); | |
202 } | |
203 | |
204 static inline V VZMULIJ(V tx, V sr) | |
205 { | |
206 V tr = VDUPL(tx); | |
207 V ti = VDUPH(tx); | |
208 ti = VMUL(ti, sr); | |
209 sr = VBYI(sr); | |
210 return VFMA(tr, sr, ti); | |
211 } | |
212 | |
213 /* twiddle storage #1: compact, slower */ | |
214 #ifdef FFTW_SINGLE | |
215 # define VTW1(v,x) \ | |
216 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x} | |
217 static inline V BYTW1(const R *t, V sr) | |
218 { | |
219 V tx = LDA(t,0,t); | |
220 V tr = UNPCKH(tx, tx); | |
221 V ti = UNPCKL(tx, tx); | |
222 tr = VMUL(tr, sr); | |
223 sr = VBYI(sr); | |
224 return VFMA(ti, sr, tr); | |
225 } | |
226 static inline V BYTWJ1(const R *t, V sr) | |
227 { | |
228 V tx = LDA(t,0,t); | |
229 V tr = UNPCKH(tx, tx); | |
230 V ti = UNPCKL(tx, tx); | |
231 tr = VMUL(tr, sr); | |
232 sr = VBYI(sr); | |
233 return VFNMS(ti, sr, tr); | |
234 } | |
235 #else /* !FFTW_SINGLE */ | |
236 # define VTW1(v,x) {TW_CEXP, v, x} | |
237 static inline V BYTW1(const R *t, V sr) | |
238 { | |
239 V tx = LD(t, 1, t); | |
240 return VZMUL(tx, sr); | |
241 } | |
242 static inline V BYTWJ1(const R *t, V sr) | |
243 { | |
244 V tx = LD(t, 1, t); | |
245 return VZMULJ(tx, sr); | |
246 } | |
247 #endif | |
248 #define TWVL1 (VL) | |
249 | |
250 /* twiddle storage #2: twice the space, faster (when in cache) */ | |
251 #ifdef FFTW_SINGLE | |
252 # define VTW2(v,x) \ | |
253 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \ | |
254 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x} | |
255 #else /* !FFTW_SINGLE */ | |
256 # define VTW2(v,x) \ | |
257 {TW_COS, v, x}, {TW_COS, v, x}, {TW_SIN, v, -x}, {TW_SIN, v, x} | |
258 #endif | |
259 #define TWVL2 (2 * VL) | |
260 static inline V BYTW2(const R *t, V sr) | |
261 { | |
262 V si = FLIP_RI(sr); | |
263 V ti = LDA(t+2*VL,0,t); | |
264 V tt = VMUL(ti, si); | |
265 V tr = LDA(t,0,t); | |
266 return VFMA(tr, sr, tt); | |
267 } | |
268 static inline V BYTWJ2(const R *t, V sr) | |
269 { | |
270 V si = FLIP_RI(sr); | |
271 V tr = LDA(t,0,t); | |
272 V tt = VMUL(tr, sr); | |
273 V ti = LDA(t+2*VL,0,t); | |
274 return VFNMS(ti, si, tt); | |
275 } | |
276 | |
277 /* twiddle storage #3 */ | |
278 #ifdef FFTW_SINGLE | |
279 # define VTW3(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x} | |
280 # define TWVL3 (VL) | |
281 #else | |
282 # define VTW3(v,x) VTW1(v,x) | |
283 # define TWVL3 TWVL1 | |
284 #endif | |
285 | |
286 /* twiddle storage for split arrays */ | |
287 #ifdef FFTW_SINGLE | |
288 # define VTWS(v,x) \ | |
289 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \ | |
290 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x} | |
291 #else | |
292 # define VTWS(v,x) \ | |
293 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x} | |
294 #endif | |
295 #define TWVLS (2 * VL) | |
296 | |
297 #define VLEAVE() /* nothing */ | |
298 | |
299 #include "simd-common.h" |