/proc/self/cwd/external/faac/libfaar/fft.c
Line | Count | Source |
1 | | /* |
2 | | * FAAR - Freeware Advanced Audio Resampler |
3 | | * Copyright (C) 2002 Krzysztof Nikiel |
4 | | * |
5 | | * This library is free software; you can redistribute it and/or |
6 | | * modify it under the terms of the GNU Lesser General Public |
7 | | * License as published by the Free Software Foundation; either |
8 | | * version 2.1 of the License, or (at your option) any later version. |
9 | | * |
10 | | * This library is distributed in the hope that it will be useful, |
11 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | | * Lesser General Public License for more details. |
14 | | */ |
15 | | |
16 | | /* Generalized from FAAC 17fbbf8a. */ |
17 | | #ifndef FAAR_FFT_TEMPLATE |
18 | | #define FAAR_FFT_TEMPLATE |
19 | | #include "fft.h" |
20 | | #include "libfaar_internal.h" |
21 | | #include <math.h> |
22 | | #include <stdlib.h> |
23 | | #include <string.h> |
24 | 0 | #define JOIN_(a, b) a##b |
25 | 0 | #define JOIN(a, b) JOIN_(a, b) |
26 | 0 | #define FN(name) JOIN(PREFIX, name) |
27 | 0 | #define REAL float |
28 | | #define PLAN faar_fftf_plan |
29 | | #define PREFIX faar_fftf_ |
30 | | #include "fft.c" |
31 | | #undef REAL |
32 | | #undef PLAN |
33 | | #undef PREFIX |
34 | | /* Double transforms serve the native-double High kernels. */ |
35 | | #if !FAAR_RESAMPLER_FLOAT |
36 | 0 | #define REAL double |
37 | | #define PLAN faar_fftd_plan |
38 | | #define PREFIX faar_fftd_ |
39 | | #include "fft.c" |
40 | | #undef REAL |
41 | | #undef PLAN |
42 | | #undef PREFIX |
43 | | #endif |
44 | | #else |
45 | | #define BUTTERFLY_SUMS \ |
46 | 0 | REAL t1 = r1 + r3, t2 = i1 + i3; \ |
47 | 0 | REAL t3 = r2 + r4, t4 = i2 + i4; \ |
48 | 0 | REAL t5 = r1 - r3, t6 = i1 - i3; \ |
49 | 0 | REAL t7 = r2 - r4, t8 = i2 - i4 |
50 | | |
51 | | /* Padding separates butterfly streams that otherwise alias the same L1 sets. |
52 | | * Early stages use 256-element blocks; later stages pad each B-element run. */ |
53 | 0 | #define PAD_BLOCK ((sizeof(REAL) == sizeof(float) ? 1024 : 2048) / (int)sizeof(REAL)) |
54 | 0 | #define PAD_COUNT ((sizeof(REAL) == sizeof(float) ? 128 : 64) / (int)sizeof(REAL)) |
55 | 0 | #define PAD_INDEX(x) ((x) + ((x) / PAD_BLOCK) * PAD_COUNT) |
56 | 0 | #define IDX(sk, x) ((sk) ? PAD_INDEX(x) : (x)) |
57 | | |
58 | | /* Stage 0: a single sub-transform, so the twiddle changes every butterfly |
59 | | * and the four outputs of butterfly j are adjacent at 4j. Its twiddles are |
60 | | * stored as six planes below 8192 complex points, for unit-stride loads. |
61 | | * Larger transforms use interleaved records to reduce twiddle set aliasing. |
62 | | * The identity twiddle is not special-cased: one butterfly in n/4 does not |
63 | | * justify another loop body. */ |
64 | | static void FN(radix4_first_stage)( |
65 | | const REAL * restrict sr, |
66 | | const REAL * restrict si, |
67 | | REAL * restrict dr, |
68 | | REAL * restrict di, |
69 | | int n4, |
70 | | const REAL * restrict tw, |
71 | | int skout) |
72 | 0 | { |
73 | 0 | const int tp = n4; |
74 | 0 | int j; |
75 | |
|
76 | 0 | for (j = 0; j < n4; j++) { |
77 | 0 | const REAL c1 = tw[j], s1 = tw[tp + j]; |
78 | 0 | const REAL c2 = tw[2 * tp + j], s2 = tw[3 * tp + j]; |
79 | 0 | const REAL c3 = tw[4 * tp + j], s3 = tw[5 * tp + j]; |
80 | 0 | REAL * restrict o = dr + IDX(skout, 4 * j); |
81 | 0 | REAL * restrict p = di + IDX(skout, 4 * j); |
82 | |
|
83 | 0 | REAL r1 = sr[j], i1 = si[j]; |
84 | 0 | REAL r2 = sr[j + n4], i2 = si[j + n4]; |
85 | 0 | REAL r3 = sr[j + 2 * n4], i3 = si[j + 2 * n4]; |
86 | 0 | REAL r4 = sr[j + 3 * n4], i4 = si[j + 3 * n4]; |
87 | 0 | BUTTERFLY_SUMS; |
88 | |
|
89 | 0 | o[0] = t1 + t3; |
90 | 0 | p[0] = t2 + t4; |
91 | |
|
92 | 0 | r1 = t1 - t3; i1 = t2 - t4; |
93 | 0 | r2 = t5 + t8; i2 = t6 - t7; |
94 | 0 | r3 = t5 - t8; i3 = t6 + t7; |
95 | |
|
96 | 0 | o[1] = r2 * c1 - i2 * s1; |
97 | 0 | p[1] = r2 * s1 + i2 * c1; |
98 | 0 | o[2] = r1 * c2 - i1 * s2; |
99 | 0 | p[2] = r1 * s2 + i1 * c2; |
100 | 0 | o[3] = r3 * c3 - i3 * s3; |
101 | 0 | p[3] = r3 * s3 + i3 * c3; |
102 | 0 | } |
103 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_radix4_first_stage Unexecuted instantiation: fft.c:faar_fftd_radix4_first_stage |
104 | | |
105 | | static void FN(radix4_first_interleaved)( |
106 | | const REAL * restrict sr, |
107 | | const REAL * restrict si, |
108 | | REAL * restrict dr, |
109 | | REAL * restrict di, |
110 | | int n4, |
111 | | const REAL * restrict tw, |
112 | | int skout) |
113 | 0 | { |
114 | 0 | int j; |
115 | |
|
116 | 0 | for (j = 0; j < n4; j++) { |
117 | 0 | const REAL c1 = tw[6 * j], s1 = tw[6 * j + 1]; |
118 | 0 | const REAL c2 = tw[6 * j + 2], s2 = tw[6 * j + 3]; |
119 | 0 | const REAL c3 = tw[6 * j + 4], s3 = tw[6 * j + 5]; |
120 | 0 | REAL * restrict o = dr + IDX(skout, 4 * j); |
121 | 0 | REAL * restrict p = di + IDX(skout, 4 * j); |
122 | |
|
123 | 0 | REAL r1 = sr[j], i1 = si[j]; |
124 | 0 | REAL r2 = sr[j + n4], i2 = si[j + n4]; |
125 | 0 | REAL r3 = sr[j + 2 * n4], i3 = si[j + 2 * n4]; |
126 | 0 | REAL r4 = sr[j + 3 * n4], i4 = si[j + 3 * n4]; |
127 | 0 | BUTTERFLY_SUMS; |
128 | |
|
129 | 0 | o[0] = t1 + t3; |
130 | 0 | p[0] = t2 + t4; |
131 | |
|
132 | 0 | r1 = t1 - t3; i1 = t2 - t4; |
133 | 0 | r2 = t5 + t8; i2 = t6 - t7; |
134 | 0 | r3 = t5 - t8; i3 = t6 + t7; |
135 | |
|
136 | 0 | o[1] = r2 * c1 - i2 * s1; |
137 | 0 | p[1] = r2 * s1 + i2 * c1; |
138 | 0 | o[2] = r1 * c2 - i1 * s2; |
139 | 0 | p[2] = r1 * s2 + i1 * c2; |
140 | 0 | o[3] = r3 * c3 - i3 * s3; |
141 | 0 | p[3] = r3 * s3 + i3 * c3; |
142 | 0 | } |
143 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_radix4_first_interleaved Unexecuted instantiation: fft.c:faar_fftd_radix4_first_interleaved |
144 | | |
145 | | /* B butterflies sharing one twiddle: element c of each of the four input |
146 | | * quarters to element c of each of the four output runs. A restrict pointer |
147 | | * per output run tells the vectorizer the runs can't overlap. */ |
148 | | static inline void FN(radix4_butterflies)( |
149 | | const REAL * restrict sr, const REAL * restrict si, int n4, |
150 | | REAL * restrict o1r, REAL * restrict o1i, |
151 | | REAL * restrict o2r, REAL * restrict o2i, |
152 | | REAL * restrict o3r, REAL * restrict o3i, |
153 | | REAL * restrict o4r, REAL * restrict o4i, |
154 | | int B, |
155 | | const REAL * restrict tw) |
156 | 0 | { |
157 | 0 | const REAL c1 = tw[0], s1 = tw[1]; |
158 | 0 | const REAL c2 = tw[2], s2 = tw[3]; |
159 | 0 | const REAL c3 = tw[4], s3 = tw[5]; |
160 | 0 | int c; |
161 | |
|
162 | 0 | for (c = 0; c < B; c++) { |
163 | 0 | REAL r1 = sr[c], i1 = si[c]; |
164 | 0 | REAL r2 = sr[c + n4], i2 = si[c + n4]; |
165 | 0 | REAL r3 = sr[c + 2 * n4], i3 = si[c + 2 * n4]; |
166 | 0 | REAL r4 = sr[c + 3 * n4], i4 = si[c + 3 * n4]; |
167 | 0 | BUTTERFLY_SUMS; |
168 | |
|
169 | 0 | o1r[c] = t1 + t3; |
170 | 0 | o1i[c] = t2 + t4; |
171 | |
|
172 | 0 | r1 = t1 - t3; i1 = t2 - t4; |
173 | 0 | r2 = t5 + t8; i2 = t6 - t7; |
174 | 0 | r3 = t5 - t8; i3 = t6 + t7; |
175 | |
|
176 | 0 | o2r[c] = r2 * c1 - i2 * s1; |
177 | 0 | o2i[c] = r2 * s1 + i2 * c1; |
178 | 0 | o3r[c] = r1 * c2 - i1 * s2; |
179 | 0 | o3i[c] = r1 * s2 + i1 * c2; |
180 | 0 | o4r[c] = r3 * c3 - i3 * s3; |
181 | 0 | o4i[c] = r3 * s3 + i3 * c3; |
182 | 0 | } |
183 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_radix4_butterflies Unexecuted instantiation: fft.c:faar_fftd_radix4_butterflies |
184 | | |
185 | | /* Later stages: B sub-transforms share each twiddle, so the inner loop is |
186 | | * unit-stride over c. Early stages use fixed padding blocks; quarters and |
187 | | * output runs are whole blocks or fit entirely between padding gaps. */ |
188 | | static void FN(radix4_stage)( |
189 | | const REAL * restrict sr, |
190 | | const REAL * restrict si, |
191 | | REAL * restrict dr, |
192 | | REAL * restrict di, |
193 | | int n4, |
194 | | int B, |
195 | | const REAL * restrict tw, |
196 | | int skin, |
197 | | int skout) |
198 | 0 | { |
199 | 0 | const int L = (skin || skout) && B > PAD_BLOCK ? PAD_BLOCK : B; |
200 | 0 | const int qs = IDX(skin, n4); |
201 | 0 | const int n2 = n4 / B; |
202 | 0 | int j, c0; |
203 | |
|
204 | 0 | for (j = 0; j < n2; j++, tw += 6) { |
205 | 0 | for (c0 = 0; c0 < B; c0 += L) { |
206 | 0 | const int a = IDX(skin, j * B + c0); |
207 | 0 | REAL *o1r = dr + IDX(skout, 4 * B * j + c0); |
208 | 0 | REAL *o1i = di + IDX(skout, 4 * B * j + c0); |
209 | 0 | REAL *o2r = dr + IDX(skout, 4 * B * j + B + c0); |
210 | 0 | REAL *o2i = di + IDX(skout, 4 * B * j + B + c0); |
211 | 0 | REAL *o3r = dr + IDX(skout, 4 * B * j + 2 * B + c0); |
212 | 0 | REAL *o3i = di + IDX(skout, 4 * B * j + 2 * B + c0); |
213 | 0 | REAL *o4r = dr + IDX(skout, 4 * B * j + 3 * B + c0); |
214 | 0 | REAL *o4i = di + IDX(skout, 4 * B * j + 3 * B + c0); |
215 | 0 | FN(radix4_butterflies)(sr + a, si + a, qs, o1r, o1i, o2r, o2i, |
216 | 0 | o3r, o3i, o4r, o4i, L, tw); |
217 | 0 | } |
218 | 0 | } |
219 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_radix4_stage Unexecuted instantiation: fft.c:faar_fftd_radix4_stage |
220 | | |
221 | | /* Read the preceding stage's padded runs without crossing a gap. The final |
222 | | * stage writes directly to the caller-visible, unpadded buffer. */ |
223 | | static void FN(padded_stage)(const REAL * restrict sr, const REAL * restrict si, |
224 | | REAL * restrict dr, REAL * restrict di, int n4, int B, |
225 | | const REAL * restrict tw, int last) |
226 | 0 | { |
227 | 0 | const int L = B / 4 < PAD_BLOCK ? PAD_BLOCK : B / 4; |
228 | 0 | const int pieces = B / L; |
229 | 0 | const int qs = n4 + (n4 / L) * PAD_COUNT; |
230 | 0 | const int ds = last ? B : B + PAD_COUNT; |
231 | 0 | int j, c; |
232 | |
|
233 | 0 | for (j = 0; j < n4 / B; j++, tw += 6) { |
234 | 0 | for (c = 0; c < pieces; c++) { |
235 | 0 | int a = j * (B + pieces * PAD_COUNT) + c * (L + PAD_COUNT); |
236 | 0 | int o = j * 4 * ds + c * L; |
237 | 0 | FN(radix4_butterflies)(sr + a, si + a, qs, |
238 | 0 | dr + o, di + o, dr + o + ds, di + o + ds, |
239 | 0 | dr + o + 2 * ds, di + o + 2 * ds, dr + o + 3 * ds, di + o + 3 * ds, L, tw); |
240 | 0 | } |
241 | 0 | } |
242 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_padded_stage Unexecuted instantiation: fft.c:faar_fftd_padded_stage |
243 | | |
244 | | /* odd logm: 4^k can't fill it, one radix-2 stage mops up the remainder */ |
245 | | static void FN(radix2_stage)( |
246 | | const REAL * restrict sr, |
247 | | const REAL * restrict si, |
248 | | REAL * restrict dr, |
249 | | REAL * restrict di, |
250 | | int n2, |
251 | | int skin) |
252 | 0 | { |
253 | 0 | const int L = skin && n2 > PAD_BLOCK ? PAD_BLOCK : n2; |
254 | 0 | int c, c0; |
255 | |
|
256 | 0 | for (c0 = 0; c0 < n2; c0 += L) { |
257 | 0 | const REAL * restrict r1p = sr + IDX(skin, c0); |
258 | 0 | const REAL * restrict i1p = si + IDX(skin, c0); |
259 | 0 | const REAL * restrict r2p = sr + IDX(skin, n2 + c0); |
260 | 0 | const REAL * restrict i2p = si + IDX(skin, n2 + c0); |
261 | 0 | REAL * restrict o1r = dr + c0, * restrict o1i = di + c0; |
262 | 0 | REAL * restrict o2r = dr + n2 + c0, * restrict o2i = di + n2 + c0; |
263 | |
|
264 | 0 | for (c = 0; c < L; c++) { |
265 | 0 | REAL r1 = r1p[c], i1 = i1p[c]; |
266 | 0 | REAL r2 = r2p[c], i2 = i2p[c]; |
267 | 0 | o1r[c] = r1 + r2; o1i[c] = i1 + i2; |
268 | 0 | o2r[c] = r1 - r2; o2i[c] = i1 - i2; |
269 | 0 | } |
270 | 0 | } |
271 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_radix2_stage Unexecuted instantiation: fft.c:faar_fftd_radix2_stage |
272 | | |
273 | | /* Separate the real and imaginary planes to avoid L1 set aliasing. */ |
274 | 0 | #define PAD_IM(n) (PAD_INDEX(n) + 3 * PAD_COUNT) |
275 | | |
276 | | /* Small transforms ping-pong in the public buffers. Larger transforms use |
277 | | * padded scratch and return to the input buffer in natural order. */ |
278 | | static REAL *FN(core)(const PLAN *plan, REAL *in) |
279 | 0 | { |
280 | 0 | int n = plan->size / 2, n4 = n / 4, B = 4; |
281 | 0 | const int padded = n >= (sizeof(REAL) == sizeof(float) ? 4096 : 2048); |
282 | 0 | const int im = PAD_IM(n); |
283 | 0 | REAL *sa = plan->scratch; |
284 | 0 | REAL *sb = sa + 2 * im; |
285 | 0 | REAL *src, *dst; |
286 | 0 | const REAL *tw = plan->twiddle; |
287 | |
|
288 | 0 | if (padded) { |
289 | 0 | if (n4 >= 2048) |
290 | 0 | FN(radix4_first_interleaved)(in, in + n, sa, sa + im, n4, tw, 1); |
291 | 0 | else |
292 | 0 | FN(radix4_first_stage)(in, in + n, sa, sa + im, n4, tw, 1); |
293 | 0 | src = sa; dst = sb; |
294 | 0 | } else { |
295 | 0 | src = in == plan->work ? in + 2 * n : plan->work; |
296 | 0 | dst = in; |
297 | 0 | FN(radix4_first_stage)(dst, dst + n, src, src + n, n4, tw, 0); |
298 | 0 | } |
299 | 0 | tw += 6 * n4; |
300 | 0 | while (B <= n4) { |
301 | 0 | REAL *tmp; |
302 | 0 | if (padded && B * 4 == n) { |
303 | 0 | FN(padded_stage)(src, src + im, in, in + n, n4, B, tw, 1); |
304 | 0 | return in; |
305 | 0 | } |
306 | 0 | if (!padded) |
307 | 0 | FN(radix4_stage)(src, src + n, dst, dst + n, n4, B, tw, 0, 0); |
308 | 0 | else if (B < PAD_BLOCK) |
309 | 0 | FN(radix4_stage)(src, src + im, dst, dst + im, n4, B, tw, 1, 1); |
310 | 0 | else |
311 | 0 | FN(padded_stage)(src, src + im, dst, dst + im, n4, B, tw, 0); |
312 | 0 | tw += 6 * (n4 / B); |
313 | 0 | B *= 4; |
314 | 0 | tmp = src; src = dst; dst = tmp; |
315 | 0 | } |
316 | 0 | if (B < n) { |
317 | 0 | if (padded) { |
318 | 0 | int ib = B / 4 > PAD_BLOCK ? B / 4 : PAD_BLOCK; |
319 | 0 | int q = n / 2 + (n / 2 / ib) * PAD_COUNT; |
320 | 0 | int c; |
321 | 0 | for (c = 0; c < n / 2; c += ib) { |
322 | 0 | int a = c + (c / ib) * PAD_COUNT; |
323 | 0 | int k; |
324 | 0 | const REAL * restrict r1 = src + a, * restrict i1 = src + im + a; |
325 | 0 | const REAL * restrict r2 = r1 + q, * restrict i2 = i1 + q; |
326 | 0 | REAL * restrict o1 = in + c, * restrict p1 = in + n + c; |
327 | 0 | REAL * restrict o2 = o1 + n / 2, * restrict p2 = p1 + n / 2; |
328 | 0 | for (k = 0; k < ib; k++) { |
329 | 0 | o1[k] = r1[k] + r2[k]; p1[k] = i1[k] + i2[k]; |
330 | 0 | o2[k] = r1[k] - r2[k]; p2[k] = i1[k] - i2[k]; |
331 | 0 | } |
332 | 0 | } |
333 | 0 | return in; |
334 | 0 | } |
335 | 0 | FN(radix2_stage)(src, src + n, dst, dst + n, n / 2, 0); |
336 | 0 | src = dst; |
337 | 0 | } |
338 | 0 | return src; |
339 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_core Unexecuted instantiation: fft.c:faar_fftd_core |
340 | | |
341 | | /* Each plan owns its twiddles; plans that share a filter borrow the owner's. */ |
342 | | static void FN(build_twiddle)(REAL *tw, int m) |
343 | 0 | { |
344 | 0 | int n2, j, b; |
345 | 0 | for (n2 = m / 4; n2 >= 1; n2 >>= 2) { |
346 | 0 | for (j = 0; j < n2; j++) { |
347 | 0 | for (b = 1; b <= 3; b++) { |
348 | 0 | double a = 6.283185307179586476925286766559 * b * j / (4 * n2); |
349 | 0 | REAL *t = n2 == m / 4 && n2 < 2048 ? tw + 2 * (b - 1) * n2 + j : tw + 6 * j + 2 * (b - 1); |
350 | 0 | t[0] = (REAL)cos(a); |
351 | 0 | t[n2 == m / 4 && n2 < 2048 ? n2 : 1] = (REAL)-sin(a); |
352 | 0 | } |
353 | 0 | } |
354 | 0 | tw += 6 * n2; |
355 | 0 | } |
356 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_build_twiddle Unexecuted instantiation: fft.c:faar_fftd_build_twiddle |
357 | | |
358 | | void FN(clear)(PLAN *plan) |
359 | 0 | { |
360 | 0 | if (!plan) return; |
361 | 0 | if (plan->twiddle_owned) FreeMemory(plan->twiddle); |
362 | 0 | FreeMemory(plan->work); |
363 | 0 | memset(plan, 0, sizeof(*plan)); |
364 | 0 | } Unexecuted instantiation: faar_fftf_clear Unexecuted instantiation: faar_fftd_clear |
365 | | |
366 | | void FN(prepare)(PLAN *plan, int both_buffers) |
367 | 0 | { |
368 | 0 | if (!plan || !plan->work) return; |
369 | 0 | int m = plan->size / 2; |
370 | 0 | int padded = m >= (sizeof(REAL) == sizeof(float) ? 4096 : 2048); |
371 | | /* Padded transforms return in their input buffer; a separate inverse |
372 | | * plan never needs buffer 1. Small transforms ping-pong through both. */ |
373 | 0 | size_t count = (both_buffers || !padded ? 4 : 2) * (size_t)m; |
374 | 0 | size_t work_count = plan->work_buffers * (size_t)plan->size; |
375 | 0 | if (count > work_count) count = work_count; |
376 | 0 | memset(plan->work, 0, count * sizeof(REAL)); |
377 | 0 | if (padded && plan->scratch == plan->work + work_count) |
378 | 0 | memset(plan->scratch, 0, 4 * (size_t)PAD_IM(m) * sizeof(REAL)); |
379 | 0 | } Unexecuted instantiation: faar_fftf_prepare Unexecuted instantiation: faar_fftd_prepare |
380 | | |
381 | | /* m complex points. */ |
382 | | static int FN(setup)(PLAN *plan, int m, REAL *scratch, int single, |
383 | | const PLAN *filter_owner) |
384 | 0 | { |
385 | 0 | int j; |
386 | |
|
387 | 0 | plan->size = 2 * m; |
388 | 0 | for (j = m; j > 1; j >>= 1) plan->logm++; |
389 | 0 | plan->twiddle = filter_owner ? filter_owner->twiddle : NULL; |
390 | 0 | plan->twiddle_owned = !filter_owner; |
391 | 0 | if (plan->twiddle_owned) { |
392 | 0 | plan->twiddle = AllocMemory(2 * m * sizeof(REAL)); |
393 | 0 | if (plan->twiddle) FN(build_twiddle)(plan->twiddle, m); |
394 | 0 | } |
395 | 0 | int padded = m >= (sizeof(REAL) == sizeof(float) ? 4096 : 2048); |
396 | 0 | plan->work_buffers = single && padded ? 1 : 2; |
397 | 0 | size_t work_count = plan->work_buffers * (size_t)plan->size; |
398 | | /* Small transforms do not use scratch. Tiny plans retain it to keep |
399 | | * the core's second scratch pointer within the allocation. */ |
400 | 0 | int separate_scratch = padded || 2 * (size_t)PAD_IM(m) > work_count; |
401 | 0 | size_t scratch_count = separate_scratch && !scratch ? 4 * (size_t)PAD_IM(m) : 0; |
402 | 0 | plan->work = AllocMemory((work_count + scratch_count) * sizeof(REAL)); |
403 | 0 | plan->scratch = scratch ? scratch : plan->work |
404 | 0 | ? plan->work + (separate_scratch ? work_count : 0) : NULL; |
405 | 0 | if (!plan->twiddle || !plan->work) { |
406 | 0 | FN(clear)(plan); |
407 | 0 | return -1; |
408 | 0 | } |
409 | 0 | return 0; |
410 | 0 | } Unexecuted instantiation: fft.c:faar_fftf_setup Unexecuted instantiation: fft.c:faar_fftd_setup |
411 | | |
412 | | int FN(cinit)(PLAN *plan, int n) |
413 | 0 | { |
414 | 0 | if (!plan) return -1; |
415 | 0 | memset(plan, 0, sizeof(*plan)); |
416 | 0 | if (n < 16 || n > (1 << 22) || (n & (n - 1))) return -1; |
417 | 0 | return FN(setup)(plan, n, NULL, 0, NULL); |
418 | 0 | } Unexecuted instantiation: faar_fftf_cinit Unexecuted instantiation: faar_fftd_cinit |
419 | | |
420 | | /* Different-sized FIR plans consume the forward spectrum in a separate plan, |
421 | | * so a padded borrower never needs a second complex buffer. */ |
422 | | int FN(cinit_shared_single)(PLAN *plan, int n, const PLAN *owner) |
423 | 0 | { |
424 | 0 | if (!plan || !owner || n < 16 || n >= owner->size / 2 |
425 | 0 | || (n & (n - 1))) return -1; |
426 | 0 | memset(plan, 0, sizeof(*plan)); |
427 | 0 | return FN(setup)(plan, n, owner->scratch, 1, NULL); |
428 | 0 | } Unexecuted instantiation: faar_fftf_cinit_shared_single Unexecuted instantiation: faar_fftd_cinit_shared_single |
429 | | |
430 | | /* Borrow an immutable same-size filter plan's twiddles, with private work. |
431 | | * Only workspace_owner belongs to this stream; filter_owner may be a shared |
432 | | * prototype with its mutable workspace already released. */ |
433 | | int FN(cinit_filter_shared)(PLAN *plan, int n, const PLAN *filter_owner, |
434 | | const PLAN *workspace_owner, int single) |
435 | 0 | { |
436 | 0 | if (!plan || !filter_owner || plan == filter_owner || plan == workspace_owner |
437 | 0 | || n < 16 || n > (1 << 22) || (n & (n - 1)) |
438 | 0 | || filter_owner->size / 2 != n || !filter_owner->twiddle |
439 | 0 | || (workspace_owner && (n > workspace_owner->size / 2 |
440 | 0 | || !workspace_owner->scratch)) |
441 | 0 | || (single && (!workspace_owner || n >= workspace_owner->size / 2))) |
442 | 0 | return -1; |
443 | 0 | memset(plan, 0, sizeof(*plan)); |
444 | 0 | return FN(setup)(plan, n, |
445 | 0 | workspace_owner ? workspace_owner->scratch : NULL, single, filter_owner); |
446 | 0 | } Unexecuted instantiation: faar_fftf_cinit_filter_shared Unexecuted instantiation: faar_fftd_cinit_filter_shared |
447 | | |
448 | | REAL *FN(cbuffer)(const PLAN *plan, int which) |
449 | 0 | { |
450 | 0 | return plan->work + (which ? plan->size : 0); |
451 | 0 | } Unexecuted instantiation: faar_fftf_cbuffer Unexecuted instantiation: faar_fftd_cbuffer |
452 | | |
453 | | REAL *FN(cforward)(const PLAN *plan, REAL *in) |
454 | 0 | { |
455 | 0 | return FN(core)(plan, in); |
456 | 0 | } Unexecuted instantiation: faar_fftf_cforward Unexecuted instantiation: faar_fftd_cforward |
457 | | |
458 | | #undef PAD_BLOCK |
459 | | #undef PAD_COUNT |
460 | | #undef PAD_INDEX |
461 | | #undef PAD_IM |
462 | | #undef IDX |
463 | | #undef BUTTERFLY_SUMS |
464 | | #endif |