3394
|
1 /*
|
|
2 * imdct.c
|
|
3 * Copyright (C) 2000-2001 Michel Lespinasse <walken@zoy.org>
|
|
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
|
5 *
|
|
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
|
|
7 * See http://liba52.sourceforge.net/ for updates.
|
|
8 *
|
|
9 * a52dec is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU General Public License as published by
|
|
11 * the Free Software Foundation; either version 2 of the License, or
|
|
12 * (at your option) any later version.
|
|
13 *
|
|
14 * a52dec is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
3579
|
22 *
|
|
23 * SSE optimizations from Michael Niedermayer (michaelni@gmx.at)
|
3394
|
24 */
|
|
25
|
|
26 #include "config.h"
|
3579
|
27 #include "../cpudetect.h"
|
3394
|
28
|
|
29 #include <math.h>
|
|
30 #include <stdio.h>
|
|
31 #ifndef M_PI
|
|
32 #define M_PI 3.1415926535897932384626433832795029
|
|
33 #endif
|
|
34 #include <inttypes.h>
|
|
35
|
|
36 #include "a52.h"
|
|
37 #include "a52_internal.h"
|
|
38 #include "mm_accel.h"
|
|
39
|
|
40 void (* imdct_256) (sample_t data[], sample_t delay[], sample_t bias);
|
|
41 void (* imdct_512) (sample_t data[], sample_t delay[], sample_t bias);
|
|
42
|
|
43 typedef struct complex_s {
|
|
44 sample_t real;
|
|
45 sample_t imag;
|
|
46 } complex_t;
|
|
47
|
|
48
|
|
49 /* 128 point bit-reverse LUT */
|
|
50 static uint8_t bit_reverse_512[] = {
|
|
51 0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70,
|
|
52 0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78,
|
|
53 0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74,
|
|
54 0x0c, 0x4c, 0x2c, 0x6c, 0x1c, 0x5c, 0x3c, 0x7c,
|
|
55 0x02, 0x42, 0x22, 0x62, 0x12, 0x52, 0x32, 0x72,
|
|
56 0x0a, 0x4a, 0x2a, 0x6a, 0x1a, 0x5a, 0x3a, 0x7a,
|
|
57 0x06, 0x46, 0x26, 0x66, 0x16, 0x56, 0x36, 0x76,
|
|
58 0x0e, 0x4e, 0x2e, 0x6e, 0x1e, 0x5e, 0x3e, 0x7e,
|
|
59 0x01, 0x41, 0x21, 0x61, 0x11, 0x51, 0x31, 0x71,
|
|
60 0x09, 0x49, 0x29, 0x69, 0x19, 0x59, 0x39, 0x79,
|
|
61 0x05, 0x45, 0x25, 0x65, 0x15, 0x55, 0x35, 0x75,
|
|
62 0x0d, 0x4d, 0x2d, 0x6d, 0x1d, 0x5d, 0x3d, 0x7d,
|
|
63 0x03, 0x43, 0x23, 0x63, 0x13, 0x53, 0x33, 0x73,
|
|
64 0x0b, 0x4b, 0x2b, 0x6b, 0x1b, 0x5b, 0x3b, 0x7b,
|
|
65 0x07, 0x47, 0x27, 0x67, 0x17, 0x57, 0x37, 0x77,
|
|
66 0x0f, 0x4f, 0x2f, 0x6f, 0x1f, 0x5f, 0x3f, 0x7f};
|
|
67
|
|
68 static uint8_t bit_reverse_256[] = {
|
|
69 0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38,
|
|
70 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c,
|
|
71 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a,
|
|
72 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e,
|
|
73 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39,
|
|
74 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d,
|
|
75 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b,
|
|
76 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f};
|
|
77
|
3579
|
78 #ifdef ARCH_X86
|
3508
|
79 // NOTE: SSE needs 16byte alignment or it will segfault
|
3581
|
80 //
|
3508
|
81 static complex_t __attribute__((aligned(16))) buf[128];
|
3581
|
82 static float __attribute__((aligned(16))) sseSinCos1c[256];
|
|
83 static float __attribute__((aligned(16))) sseSinCos1d[256];
|
3512
|
84 static float __attribute__((aligned(16))) ps111_1[4]={1,1,1,-1};
|
3534
|
85 //static float __attribute__((aligned(16))) sseW0[4];
|
|
86 static float __attribute__((aligned(16))) sseW1[8];
|
|
87 static float __attribute__((aligned(16))) sseW2[16];
|
|
88 static float __attribute__((aligned(16))) sseW3[32];
|
|
89 static float __attribute__((aligned(16))) sseW4[64];
|
|
90 static float __attribute__((aligned(16))) sseW5[128];
|
|
91 static float __attribute__((aligned(16))) sseW6[256];
|
|
92 static float __attribute__((aligned(16))) *sseW[7]=
|
|
93 {NULL /*sseW0*/,sseW1,sseW2,sseW3,sseW4,sseW5,sseW6};
|
3553
|
94 static float __attribute__((aligned(16))) sseWindow[512];
|
3508
|
95 #else
|
3394
|
96 static complex_t buf[128];
|
3508
|
97 #endif
|
3394
|
98
|
|
99 /* Twiddle factor LUT */
|
|
100 static complex_t w_1[1];
|
|
101 static complex_t w_2[2];
|
|
102 static complex_t w_4[4];
|
|
103 static complex_t w_8[8];
|
|
104 static complex_t w_16[16];
|
|
105 static complex_t w_32[32];
|
|
106 static complex_t w_64[64];
|
|
107 static complex_t * w[7] = {w_1, w_2, w_4, w_8, w_16, w_32, w_64};
|
|
108
|
|
109 /* Twiddle factors for IMDCT */
|
|
110 static sample_t xcos1[128];
|
|
111 static sample_t xsin1[128];
|
|
112 static sample_t xcos2[64];
|
|
113 static sample_t xsin2[64];
|
|
114
|
|
115 /* Windowing function for Modified DCT - Thank you acroread */
|
|
116 sample_t imdct_window[] = {
|
|
117 0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130,
|
|
118 0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443,
|
|
119 0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061,
|
|
120 0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121,
|
|
121 0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770,
|
|
122 0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153,
|
|
123 0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389,
|
|
124 0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563,
|
|
125 0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699,
|
|
126 0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757,
|
|
127 0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626,
|
|
128 0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126,
|
|
129 0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019,
|
|
130 0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031,
|
|
131 0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873,
|
|
132 0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269,
|
|
133 0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981,
|
|
134 0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831,
|
|
135 0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716,
|
|
136 0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610,
|
|
137 0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560,
|
|
138 0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674,
|
|
139 0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099,
|
|
140 0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994,
|
|
141 0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513,
|
|
142 0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788,
|
|
143 0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919,
|
|
144 0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974,
|
|
145 0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993,
|
|
146 0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999,
|
|
147 0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000,
|
|
148 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000 };
|
|
149
|
|
150
|
|
151 static inline void swap_cmplx(complex_t *a, complex_t *b)
|
|
152 {
|
|
153 complex_t tmp;
|
|
154
|
|
155 tmp = *a;
|
|
156 *a = *b;
|
|
157 *b = tmp;
|
|
158 }
|
|
159
|
|
160
|
|
161
|
|
162 static inline complex_t cmplx_mult(complex_t a, complex_t b)
|
|
163 {
|
|
164 complex_t ret;
|
|
165
|
|
166 ret.real = a.real * b.real - a.imag * b.imag;
|
|
167 ret.imag = a.real * b.imag + a.imag * b.real;
|
|
168
|
|
169 return ret;
|
|
170 }
|
|
171
|
|
172 void
|
|
173 imdct_do_512(sample_t data[],sample_t delay[], sample_t bias)
|
|
174 {
|
|
175 int i,k;
|
|
176 int p,q;
|
|
177 int m;
|
|
178 int two_m;
|
|
179 int two_m_plus_one;
|
|
180
|
|
181 sample_t tmp_a_i;
|
|
182 sample_t tmp_a_r;
|
|
183 sample_t tmp_b_i;
|
|
184 sample_t tmp_b_r;
|
|
185
|
|
186 sample_t *data_ptr;
|
|
187 sample_t *delay_ptr;
|
|
188 sample_t *window_ptr;
|
|
189
|
|
190 /* 512 IMDCT with source and dest data in 'data' */
|
|
191
|
3529
|
192 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
|
3394
|
193 for( i=0; i < 128; i++) {
|
|
194 /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
|
|
195 buf[i].real = (data[256-2*i-1] * xcos1[i]) - (data[2*i] * xsin1[i]);
|
|
196 buf[i].imag = -1.0 * ((data[2*i] * xcos1[i]) + (data[256-2*i-1] * xsin1[i]));
|
|
197 }
|
|
198
|
|
199 /* Bit reversed shuffling */
|
|
200 for(i=0; i<128; i++) {
|
|
201 k = bit_reverse_512[i];
|
|
202 if (k < i)
|
|
203 swap_cmplx(&buf[i],&buf[k]);
|
|
204 }
|
3529
|
205
|
3394
|
206
|
|
207 /* FFT Merge */
|
3549
|
208 /* unoptimized variant
|
|
209 for (m=1; m < 7; m++) {
|
|
210 if(m)
|
|
211 two_m = (1 << m);
|
|
212 else
|
|
213 two_m = 1;
|
|
214
|
|
215 two_m_plus_one = (1 << (m+1));
|
|
216
|
|
217 for(i = 0; i < 128; i += two_m_plus_one) {
|
|
218 for(k = 0; k < two_m; k++) {
|
|
219 p = k + i;
|
|
220 q = p + two_m;
|
3508
|
221 tmp_a_r = buf[p].real;
|
|
222 tmp_a_i = buf[p].imag;
|
3549
|
223 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
|
|
224 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
|
3508
|
225 buf[p].real = tmp_a_r + tmp_b_r;
|
|
226 buf[p].imag = tmp_a_i + tmp_b_i;
|
|
227 buf[q].real = tmp_a_r - tmp_b_r;
|
|
228 buf[q].imag = tmp_a_i - tmp_b_i;
|
3549
|
229 }
|
|
230 }
|
|
231 }
|
|
232 */
|
3623
|
233 /* 1. iteration */
|
3579
|
234 for(i = 0; i < 128; i += 2) {
|
|
235 tmp_a_r = buf[i].real;
|
|
236 tmp_a_i = buf[i].imag;
|
|
237 tmp_b_r = buf[i+1].real;
|
|
238 tmp_b_i = buf[i+1].imag;
|
|
239 buf[i].real = tmp_a_r + tmp_b_r;
|
|
240 buf[i].imag = tmp_a_i + tmp_b_i;
|
|
241 buf[i+1].real = tmp_a_r - tmp_b_r;
|
|
242 buf[i+1].imag = tmp_a_i - tmp_b_i;
|
|
243 }
|
|
244
|
3623
|
245 /* 2. iteration */
|
3579
|
246 // Note w[1]={{1,0}, {0,-1}}
|
|
247 for(i = 0; i < 128; i += 4) {
|
|
248 tmp_a_r = buf[i].real;
|
|
249 tmp_a_i = buf[i].imag;
|
|
250 tmp_b_r = buf[i+2].real;
|
|
251 tmp_b_i = buf[i+2].imag;
|
|
252 buf[i].real = tmp_a_r + tmp_b_r;
|
|
253 buf[i].imag = tmp_a_i + tmp_b_i;
|
|
254 buf[i+2].real = tmp_a_r - tmp_b_r;
|
|
255 buf[i+2].imag = tmp_a_i - tmp_b_i;
|
|
256 tmp_a_r = buf[i+1].real;
|
|
257 tmp_a_i = buf[i+1].imag;
|
|
258 tmp_b_r = buf[i+3].imag;
|
|
259 tmp_b_i = buf[i+3].real;
|
|
260 buf[i+1].real = tmp_a_r + tmp_b_r;
|
|
261 buf[i+1].imag = tmp_a_i - tmp_b_i;
|
|
262 buf[i+3].real = tmp_a_r - tmp_b_r;
|
|
263 buf[i+3].imag = tmp_a_i + tmp_b_i;
|
|
264 }
|
|
265
|
3623
|
266 /* 3. iteration */
|
3579
|
267 for(i = 0; i < 128; i += 8) {
|
|
268 tmp_a_r = buf[i].real;
|
|
269 tmp_a_i = buf[i].imag;
|
|
270 tmp_b_r = buf[i+4].real;
|
|
271 tmp_b_i = buf[i+4].imag;
|
|
272 buf[i].real = tmp_a_r + tmp_b_r;
|
|
273 buf[i].imag = tmp_a_i + tmp_b_i;
|
|
274 buf[i+4].real = tmp_a_r - tmp_b_r;
|
|
275 buf[i+4].imag = tmp_a_i - tmp_b_i;
|
|
276 tmp_a_r = buf[1+i].real;
|
|
277 tmp_a_i = buf[1+i].imag;
|
|
278 tmp_b_r = (buf[i+5].real + buf[i+5].imag) * w[2][1].real;
|
|
279 tmp_b_i = (buf[i+5].imag - buf[i+5].real) * w[2][1].real;
|
|
280 buf[1+i].real = tmp_a_r + tmp_b_r;
|
|
281 buf[1+i].imag = tmp_a_i + tmp_b_i;
|
|
282 buf[i+5].real = tmp_a_r - tmp_b_r;
|
|
283 buf[i+5].imag = tmp_a_i - tmp_b_i;
|
|
284 tmp_a_r = buf[i+2].real;
|
|
285 tmp_a_i = buf[i+2].imag;
|
|
286 tmp_b_r = buf[i+6].imag;
|
|
287 tmp_b_i = - buf[i+6].real;
|
|
288 buf[i+2].real = tmp_a_r + tmp_b_r;
|
|
289 buf[i+2].imag = tmp_a_i + tmp_b_i;
|
|
290 buf[i+6].real = tmp_a_r - tmp_b_r;
|
|
291 buf[i+6].imag = tmp_a_i - tmp_b_i;
|
|
292 tmp_a_r = buf[i+3].real;
|
|
293 tmp_a_i = buf[i+3].imag;
|
|
294 tmp_b_r = (buf[i+7].real - buf[i+7].imag) * w[2][3].imag;
|
|
295 tmp_b_i = (buf[i+7].imag + buf[i+7].real) * w[2][3].imag;
|
|
296 buf[i+3].real = tmp_a_r + tmp_b_r;
|
|
297 buf[i+3].imag = tmp_a_i + tmp_b_i;
|
|
298 buf[i+7].real = tmp_a_r - tmp_b_r;
|
|
299 buf[i+7].imag = tmp_a_i - tmp_b_i;
|
|
300 }
|
|
301
|
3623
|
302 /* 4-7. iterations */
|
3579
|
303 for (m=3; m < 7; m++) {
|
|
304 two_m = (1 << m);
|
|
305
|
|
306 two_m_plus_one = two_m<<1;
|
|
307
|
|
308 for(i = 0; i < 128; i += two_m_plus_one) {
|
|
309 for(k = 0; k < two_m; k++) {
|
|
310 int p = k + i;
|
|
311 int q = p + two_m;
|
|
312 tmp_a_r = buf[p].real;
|
|
313 tmp_a_i = buf[p].imag;
|
|
314 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
|
|
315 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
|
|
316 buf[p].real = tmp_a_r + tmp_b_r;
|
|
317 buf[p].imag = tmp_a_i + tmp_b_i;
|
|
318 buf[q].real = tmp_a_r - tmp_b_r;
|
|
319 buf[q].imag = tmp_a_i - tmp_b_i;
|
|
320 }
|
|
321 }
|
|
322 }
|
|
323
|
|
324 /* Post IFFT complex multiply plus IFFT complex conjugate*/
|
|
325 for( i=0; i < 128; i++) {
|
|
326 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
|
|
327 tmp_a_r = buf[i].real;
|
|
328 tmp_a_i = -1.0 * buf[i].imag;
|
|
329 buf[i].real =(tmp_a_r * xcos1[i]) - (tmp_a_i * xsin1[i]);
|
|
330 buf[i].imag =(tmp_a_r * xsin1[i]) + (tmp_a_i * xcos1[i]);
|
|
331 }
|
|
332
|
|
333 data_ptr = data;
|
|
334 delay_ptr = delay;
|
|
335 window_ptr = imdct_window;
|
|
336
|
|
337 /* Window and convert to real valued signal */
|
|
338 for(i=0; i< 64; i++) {
|
|
339 *data_ptr++ = -buf[64+i].imag * *window_ptr++ + *delay_ptr++ + bias;
|
|
340 *data_ptr++ = buf[64-i-1].real * *window_ptr++ + *delay_ptr++ + bias;
|
|
341 }
|
|
342
|
|
343 for(i=0; i< 64; i++) {
|
|
344 *data_ptr++ = -buf[i].real * *window_ptr++ + *delay_ptr++ + bias;
|
|
345 *data_ptr++ = buf[128-i-1].imag * *window_ptr++ + *delay_ptr++ + bias;
|
|
346 }
|
|
347
|
|
348 /* The trailing edge of the window goes into the delay line */
|
|
349 delay_ptr = delay;
|
|
350
|
|
351 for(i=0; i< 64; i++) {
|
|
352 *delay_ptr++ = -buf[64+i].real * *--window_ptr;
|
|
353 *delay_ptr++ = buf[64-i-1].imag * *--window_ptr;
|
|
354 }
|
|
355
|
|
356 for(i=0; i<64; i++) {
|
|
357 *delay_ptr++ = buf[i].imag * *--window_ptr;
|
|
358 *delay_ptr++ = -buf[128-i-1].real * *--window_ptr;
|
|
359 }
|
|
360 }
|
|
361
|
|
362 #ifdef ARCH_X86
|
|
363 void
|
|
364 imdct_do_512_sse(sample_t data[],sample_t delay[], sample_t bias)
|
|
365 {
|
|
366 int i,k;
|
|
367 int p,q;
|
|
368 int m;
|
|
369 int two_m;
|
|
370 int two_m_plus_one;
|
|
371
|
|
372 sample_t tmp_a_i;
|
|
373 sample_t tmp_a_r;
|
|
374 sample_t tmp_b_i;
|
|
375 sample_t tmp_b_r;
|
|
376
|
|
377 sample_t *data_ptr;
|
|
378 sample_t *delay_ptr;
|
|
379 sample_t *window_ptr;
|
|
380
|
|
381 /* 512 IMDCT with source and dest data in 'data' */
|
3623
|
382 /* see the c version (dct_do_512()), its allmost identical, just in C */
|
|
383
|
3579
|
384 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
|
|
385 /* Bit reversed shuffling */
|
|
386 asm volatile(
|
|
387 "xorl %%esi, %%esi \n\t"
|
|
388 "leal bit_reverse_512, %%eax \n\t"
|
|
389 "movl $1008, %%edi \n\t"
|
|
390 "pushl %%ebp \n\t" //use ebp without telling gcc
|
|
391 ".balign 16 \n\t"
|
|
392 "1: \n\t"
|
3584
|
393 "movlps (%0, %%esi), %%xmm0 \n\t" // XXXI
|
|
394 "movhps 8(%0, %%edi), %%xmm0 \n\t" // RXXI
|
|
395 "movlps 8(%0, %%esi), %%xmm1 \n\t" // XXXi
|
|
396 "movhps (%0, %%edi), %%xmm1 \n\t" // rXXi
|
|
397 "shufps $0x33, %%xmm1, %%xmm0 \n\t" // irIR
|
|
398 "movaps sseSinCos1c(%%esi), %%xmm2 \n\t"
|
|
399 "mulps %%xmm0, %%xmm2 \n\t"
|
|
400 "shufps $0xB1, %%xmm0, %%xmm0 \n\t" // riRI
|
|
401 "mulps sseSinCos1d(%%esi), %%xmm0 \n\t"
|
|
402 "subps %%xmm0, %%xmm2 \n\t"
|
3579
|
403 "movzbl (%%eax), %%edx \n\t"
|
|
404 "movzbl 1(%%eax), %%ebp \n\t"
|
3584
|
405 "movlps %%xmm2, (%1, %%edx,8) \n\t"
|
|
406 "movhps %%xmm2, (%1, %%ebp,8) \n\t"
|
3579
|
407 "addl $16, %%esi \n\t"
|
|
408 "addl $2, %%eax \n\t" // avoid complex addressing for P4 crap
|
|
409 "subl $16, %%edi \n\t"
|
|
410 " jnc 1b \n\t"
|
|
411 "popl %%ebp \n\t"//no we didnt touch ebp *g*
|
|
412 :: "b" (data), "c" (buf)
|
|
413 : "%esi", "%edi", "%eax", "%edx"
|
|
414 );
|
|
415
|
|
416
|
|
417 /* FFT Merge */
|
|
418 /* unoptimized variant
|
|
419 for (m=1; m < 7; m++) {
|
|
420 if(m)
|
|
421 two_m = (1 << m);
|
|
422 else
|
|
423 two_m = 1;
|
|
424
|
|
425 two_m_plus_one = (1 << (m+1));
|
|
426
|
|
427 for(i = 0; i < 128; i += two_m_plus_one) {
|
|
428 for(k = 0; k < two_m; k++) {
|
|
429 p = k + i;
|
|
430 q = p + two_m;
|
|
431 tmp_a_r = buf[p].real;
|
|
432 tmp_a_i = buf[p].imag;
|
|
433 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
|
|
434 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
|
|
435 buf[p].real = tmp_a_r + tmp_b_r;
|
|
436 buf[p].imag = tmp_a_i + tmp_b_i;
|
|
437 buf[q].real = tmp_a_r - tmp_b_r;
|
|
438 buf[q].imag = tmp_a_i - tmp_b_i;
|
|
439 }
|
|
440 }
|
|
441 }
|
|
442 */
|
|
443
|
3623
|
444 /* 1. iteration */
|
3549
|
445 // Note w[0][0]={1,0}
|
3508
|
446 asm volatile(
|
|
447 "xorps %%xmm1, %%xmm1 \n\t"
|
|
448 "xorps %%xmm2, %%xmm2 \n\t"
|
|
449 "movl %0, %%esi \n\t"
|
3529
|
450 ".balign 16 \n\t"
|
3508
|
451 "1: \n\t"
|
|
452 "movlps (%%esi), %%xmm0 \n\t" //buf[p]
|
|
453 "movlps 8(%%esi), %%xmm1\n\t" //buf[q]
|
|
454 "movhps (%%esi), %%xmm0 \n\t" //buf[p]
|
|
455 "movhps 8(%%esi), %%xmm2\n\t" //buf[q]
|
|
456 "addps %%xmm1, %%xmm0 \n\t"
|
|
457 "subps %%xmm2, %%xmm0 \n\t"
|
|
458 "movaps %%xmm0, (%%esi) \n\t"
|
|
459 "addl $16, %%esi \n\t"
|
|
460 "cmpl %1, %%esi \n\t"
|
|
461 " jb 1b \n\t"
|
|
462 :: "g" (buf), "r" (buf + 128)
|
|
463 : "%esi"
|
|
464 );
|
3549
|
465
|
3623
|
466 /* 2. iteration */
|
3512
|
467 // Note w[1]={{1,0}, {0,-1}}
|
|
468 asm volatile(
|
|
469 "movaps ps111_1, %%xmm7 \n\t" // 1,1,1,-1
|
|
470 "movl %0, %%esi \n\t"
|
3529
|
471 ".balign 16 \n\t"
|
3512
|
472 "1: \n\t"
|
|
473 "movaps 16(%%esi), %%xmm2 \n\t" //r2,i2,r3,i3
|
|
474 "shufps $0xB4, %%xmm2, %%xmm2 \n\t" //r2,i2,i3,r3
|
|
475 "mulps %%xmm7, %%xmm2 \n\t" //r2,i2,i3,-r3
|
|
476 "movaps (%%esi), %%xmm0 \n\t" //r0,i0,r1,i1
|
|
477 "movaps (%%esi), %%xmm1 \n\t" //r0,i0,r1,i1
|
|
478 "addps %%xmm2, %%xmm0 \n\t"
|
|
479 "subps %%xmm2, %%xmm1 \n\t"
|
|
480 "movaps %%xmm0, (%%esi) \n\t"
|
|
481 "movaps %%xmm1, 16(%%esi) \n\t"
|
|
482 "addl $32, %%esi \n\t"
|
|
483 "cmpl %1, %%esi \n\t"
|
|
484 " jb 1b \n\t"
|
|
485 :: "g" (buf), "r" (buf + 128)
|
|
486 : "%esi"
|
|
487 );
|
3549
|
488
|
3623
|
489 /* 3. iteration */
|
3534
|
490 /*
|
|
491 Note sseW2+0={1,1,sqrt(2),sqrt(2))
|
|
492 Note sseW2+16={0,0,sqrt(2),-sqrt(2))
|
|
493 Note sseW2+32={0,0,-sqrt(2),-sqrt(2))
|
|
494 Note sseW2+48={1,-1,sqrt(2),-sqrt(2))
|
|
495 */
|
|
496 asm volatile(
|
3537
|
497 "movaps 48+sseW2, %%xmm6 \n\t"
|
3534
|
498 "movaps 16+sseW2, %%xmm7 \n\t"
|
|
499 "xorps %%xmm5, %%xmm5 \n\t"
|
|
500 "xorps %%xmm2, %%xmm2 \n\t"
|
|
501 "movl %0, %%esi \n\t"
|
|
502 ".balign 16 \n\t"
|
|
503 "1: \n\t"
|
3537
|
504 "movaps 32(%%esi), %%xmm2 \n\t" //r4,i4,r5,i5
|
3534
|
505 "movaps 48(%%esi), %%xmm3 \n\t" //r6,i6,r7,i7
|
3537
|
506 "movaps sseW2, %%xmm4 \n\t" //r4,i4,r5,i5
|
|
507 "movaps 32+sseW2, %%xmm5 \n\t" //r6,i6,r7,i7
|
|
508 "mulps %%xmm2, %%xmm4 \n\t"
|
|
509 "mulps %%xmm3, %%xmm5 \n\t"
|
3534
|
510 "shufps $0xB1, %%xmm2, %%xmm2 \n\t" //i4,r4,i5,r5
|
|
511 "shufps $0xB1, %%xmm3, %%xmm3 \n\t" //i6,r6,i7,r7
|
3537
|
512 "mulps %%xmm6, %%xmm3 \n\t"
|
3534
|
513 "mulps %%xmm7, %%xmm2 \n\t"
|
|
514 "movaps (%%esi), %%xmm0 \n\t" //r0,i0,r1,i1
|
|
515 "movaps 16(%%esi), %%xmm1 \n\t" //r2,i2,r3,i3
|
|
516 "addps %%xmm4, %%xmm2 \n\t"
|
|
517 "addps %%xmm5, %%xmm3 \n\t"
|
|
518 "movaps %%xmm2, %%xmm4 \n\t"
|
|
519 "movaps %%xmm3, %%xmm5 \n\t"
|
|
520 "addps %%xmm0, %%xmm2 \n\t"
|
|
521 "addps %%xmm1, %%xmm3 \n\t"
|
|
522 "subps %%xmm4, %%xmm0 \n\t"
|
|
523 "subps %%xmm5, %%xmm1 \n\t"
|
|
524 "movaps %%xmm2, (%%esi) \n\t"
|
|
525 "movaps %%xmm3, 16(%%esi) \n\t"
|
|
526 "movaps %%xmm0, 32(%%esi) \n\t"
|
|
527 "movaps %%xmm1, 48(%%esi) \n\t"
|
|
528 "addl $64, %%esi \n\t"
|
|
529 "cmpl %1, %%esi \n\t"
|
|
530 " jb 1b \n\t"
|
|
531 :: "g" (buf), "r" (buf + 128)
|
|
532 : "%esi"
|
|
533 );
|
3508
|
534
|
3623
|
535 /* 4-7. iterations */
|
3546
|
536 for (m=3; m < 7; m++) {
|
|
537 two_m = (1 << m);
|
|
538 two_m_plus_one = two_m<<1;
|
|
539 asm volatile(
|
|
540 "movl %0, %%esi \n\t"
|
|
541 ".balign 16 \n\t"
|
|
542 "1: \n\t"
|
|
543 "xorl %%edi, %%edi \n\t" // k
|
|
544 "leal (%%esi, %3), %%edx \n\t"
|
|
545 "2: \n\t"
|
|
546 "movaps (%%edx, %%edi), %%xmm1 \n\t"
|
|
547 "movaps (%4, %%edi, 2), %%xmm2 \n\t"
|
|
548 "mulps %%xmm1, %%xmm2 \n\t"
|
|
549 "shufps $0xB1, %%xmm1, %%xmm1 \n\t"
|
|
550 "mulps 16(%4, %%edi, 2), %%xmm1 \n\t"
|
|
551 "movaps (%%esi, %%edi), %%xmm0 \n\t"
|
|
552 "addps %%xmm2, %%xmm1 \n\t"
|
|
553 "movaps %%xmm1, %%xmm2 \n\t"
|
|
554 "addps %%xmm0, %%xmm1 \n\t"
|
|
555 "subps %%xmm2, %%xmm0 \n\t"
|
|
556 "movaps %%xmm1, (%%esi, %%edi) \n\t"
|
|
557 "movaps %%xmm0, (%%edx, %%edi) \n\t"
|
|
558 "addl $16, %%edi \n\t"
|
|
559 "cmpl %3, %%edi \n\t" //FIXME (opt) count against 0
|
|
560 " jb 2b \n\t"
|
|
561 "addl %2, %%esi \n\t"
|
|
562 "cmpl %1, %%esi \n\t"
|
|
563 " jb 1b \n\t"
|
|
564 :: "g" (buf), "m" (buf+128), "m" (two_m_plus_one<<3), "r" (two_m<<3),
|
|
565 "r" (sseW[m])
|
|
566 : "%esi", "%edi", "%edx"
|
|
567 );
|
|
568 }
|
|
569
|
3623
|
570 /* Post IFFT complex multiply plus IFFT complex conjugate*/
|
3581
|
571 asm volatile(
|
|
572 "movl $-1024, %%esi \n\t"
|
|
573 ".balign 16 \n\t"
|
|
574 "1: \n\t"
|
|
575 "movaps (%0, %%esi), %%xmm0 \n\t"
|
|
576 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
577 "shufps $0xB1, %%xmm0, %%xmm0 \n\t"
|
|
578 "mulps 1024+sseSinCos1c(%%esi), %%xmm1 \n\t"
|
|
579 "mulps 1024+sseSinCos1d(%%esi), %%xmm0 \n\t"
|
|
580 "addps %%xmm1, %%xmm0 \n\t"
|
|
581 "movaps %%xmm0, (%0, %%esi) \n\t"
|
|
582 "addl $16, %%esi \n\t"
|
|
583 " jnz 1b \n\t"
|
|
584 :: "r" (buf+128)
|
|
585 : "%esi"
|
|
586 );
|
|
587
|
3394
|
588
|
|
589 data_ptr = data;
|
|
590 delay_ptr = delay;
|
|
591 window_ptr = imdct_window;
|
|
592
|
|
593 /* Window and convert to real valued signal */
|
3552
|
594 asm volatile(
|
|
595 "xorl %%edi, %%edi \n\t" // 0
|
|
596 "xorl %%esi, %%esi \n\t" // 0
|
|
597 "movss %3, %%xmm2 \n\t" // bias
|
|
598 "shufps $0x00, %%xmm2, %%xmm2 \n\t" // bias, bias, ...
|
|
599 ".balign 16 \n\t"
|
|
600 "1: \n\t"
|
|
601 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? A ?
|
|
602 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? C ?
|
|
603 "movhps -16(%0, %%edi), %%xmm1 \n\t" // ? D C ?
|
|
604 "movhps -8(%0, %%edi), %%xmm0 \n\t" // ? B A ?
|
|
605 "shufps $0x99, %%xmm1, %%xmm0 \n\t" // D C B A
|
|
606 "mulps sseWindow(%%esi), %%xmm0 \n\t"
|
|
607 "addps (%2, %%esi), %%xmm0 \n\t"
|
|
608 "addps %%xmm2, %%xmm0 \n\t"
|
|
609 "movaps %%xmm0, (%1, %%esi) \n\t"
|
|
610 "addl $16, %%esi \n\t"
|
|
611 "subl $16, %%edi \n\t"
|
|
612 "cmpl $512, %%esi \n\t"
|
|
613 " jb 1b \n\t"
|
|
614 :: "r" (buf+64), "r" (data_ptr), "r" (delay_ptr), "m" (bias)
|
|
615 : "%esi", "%edi"
|
|
616 );
|
|
617 data_ptr+=128;
|
|
618 delay_ptr+=128;
|
3553
|
619 // window_ptr+=128;
|
3579
|
620
|
3552
|
621 asm volatile(
|
|
622 "movl $1024, %%edi \n\t" // 512
|
|
623 "xorl %%esi, %%esi \n\t" // 0
|
|
624 "movss %3, %%xmm2 \n\t" // bias
|
|
625 "shufps $0x00, %%xmm2, %%xmm2 \n\t" // bias, bias, ...
|
|
626 ".balign 16 \n\t"
|
|
627 "1: \n\t"
|
|
628 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? ? A
|
|
629 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? ? C
|
|
630 "movhps -16(%0, %%edi), %%xmm1 \n\t" // D ? ? C
|
|
631 "movhps -8(%0, %%edi), %%xmm0 \n\t" // B ? ? A
|
|
632 "shufps $0xCC, %%xmm1, %%xmm0 \n\t" // D C B A
|
|
633 "mulps 512+sseWindow(%%esi), %%xmm0 \n\t"
|
|
634 "addps (%2, %%esi), %%xmm0 \n\t"
|
|
635 "addps %%xmm2, %%xmm0 \n\t"
|
|
636 "movaps %%xmm0, (%1, %%esi) \n\t"
|
|
637 "addl $16, %%esi \n\t"
|
|
638 "subl $16, %%edi \n\t"
|
|
639 "cmpl $512, %%esi \n\t"
|
|
640 " jb 1b \n\t"
|
|
641 :: "r" (buf), "r" (data_ptr), "r" (delay_ptr), "m" (bias)
|
|
642 : "%esi", "%edi"
|
|
643 );
|
|
644 data_ptr+=128;
|
3553
|
645 // window_ptr+=128;
|
3394
|
646
|
|
647 /* The trailing edge of the window goes into the delay line */
|
|
648 delay_ptr = delay;
|
|
649
|
3553
|
650 asm volatile(
|
|
651 "xorl %%edi, %%edi \n\t" // 0
|
|
652 "xorl %%esi, %%esi \n\t" // 0
|
|
653 ".balign 16 \n\t"
|
|
654 "1: \n\t"
|
|
655 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? ? A
|
|
656 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? ? C
|
|
657 "movhps -16(%0, %%edi), %%xmm1 \n\t" // D ? ? C
|
|
658 "movhps -8(%0, %%edi), %%xmm0 \n\t" // B ? ? A
|
|
659 "shufps $0xCC, %%xmm1, %%xmm0 \n\t" // D C B A
|
|
660 "mulps 1024+sseWindow(%%esi), %%xmm0 \n\t"
|
|
661 "movaps %%xmm0, (%1, %%esi) \n\t"
|
|
662 "addl $16, %%esi \n\t"
|
|
663 "subl $16, %%edi \n\t"
|
|
664 "cmpl $512, %%esi \n\t"
|
|
665 " jb 1b \n\t"
|
|
666 :: "r" (buf+64), "r" (delay_ptr)
|
|
667 : "%esi", "%edi"
|
|
668 );
|
|
669 delay_ptr+=128;
|
|
670 // window_ptr-=128;
|
3579
|
671
|
3553
|
672 asm volatile(
|
|
673 "movl $1024, %%edi \n\t" // 1024
|
|
674 "xorl %%esi, %%esi \n\t" // 0
|
|
675 ".balign 16 \n\t"
|
|
676 "1: \n\t"
|
|
677 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? A ?
|
|
678 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? C ?
|
|
679 "movhps -16(%0, %%edi), %%xmm1 \n\t" // ? D C ?
|
|
680 "movhps -8(%0, %%edi), %%xmm0 \n\t" // ? B A ?
|
|
681 "shufps $0x99, %%xmm1, %%xmm0 \n\t" // D C B A
|
|
682 "mulps 1536+sseWindow(%%esi), %%xmm0 \n\t"
|
|
683 "movaps %%xmm0, (%1, %%esi) \n\t"
|
|
684 "addl $16, %%esi \n\t"
|
|
685 "subl $16, %%edi \n\t"
|
|
686 "cmpl $512, %%esi \n\t"
|
|
687 " jb 1b \n\t"
|
|
688 :: "r" (buf), "r" (delay_ptr)
|
|
689 : "%esi", "%edi"
|
|
690 );
|
3394
|
691 }
|
3579
|
692 #endif //arch_x86
|
3394
|
693
|
|
694 void
|
|
695 imdct_do_256(sample_t data[],sample_t delay[],sample_t bias)
|
|
696 {
|
|
697 int i,k;
|
|
698 int p,q;
|
|
699 int m;
|
|
700 int two_m;
|
|
701 int two_m_plus_one;
|
|
702
|
|
703 sample_t tmp_a_i;
|
|
704 sample_t tmp_a_r;
|
|
705 sample_t tmp_b_i;
|
|
706 sample_t tmp_b_r;
|
|
707
|
|
708 sample_t *data_ptr;
|
|
709 sample_t *delay_ptr;
|
|
710 sample_t *window_ptr;
|
|
711
|
|
712 complex_t *buf_1, *buf_2;
|
|
713
|
|
714 buf_1 = &buf[0];
|
|
715 buf_2 = &buf[64];
|
|
716
|
|
717 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
|
|
718 for(k=0; k<64; k++) {
|
|
719 /* X1[k] = X[2*k] */
|
|
720 /* X2[k] = X[2*k+1] */
|
|
721
|
|
722 p = 2 * (128-2*k-1);
|
|
723 q = 2 * (2 * k);
|
|
724
|
|
725 /* Z1[k] = (X1[128-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */
|
|
726 buf_1[k].real = data[p] * xcos2[k] - data[q] * xsin2[k];
|
|
727 buf_1[k].imag = -1.0f * (data[q] * xcos2[k] + data[p] * xsin2[k]);
|
|
728 /* Z2[k] = (X2[128-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */
|
|
729 buf_2[k].real = data[p + 1] * xcos2[k] - data[q + 1] * xsin2[k];
|
|
730 buf_2[k].imag = -1.0f * ( data[q + 1] * xcos2[k] + data[p + 1] * xsin2[k]);
|
|
731 }
|
|
732
|
|
733 /* IFFT Bit reversed shuffling */
|
|
734 for(i=0; i<64; i++) {
|
|
735 k = bit_reverse_256[i];
|
|
736 if (k < i) {
|
|
737 swap_cmplx(&buf_1[i],&buf_1[k]);
|
|
738 swap_cmplx(&buf_2[i],&buf_2[k]);
|
|
739 }
|
|
740 }
|
|
741
|
|
742 /* FFT Merge */
|
|
743 for (m=0; m < 6; m++) {
|
|
744 two_m = (1 << m);
|
|
745 two_m_plus_one = (1 << (m+1));
|
|
746
|
|
747 /* FIXME */
|
|
748 if(m)
|
|
749 two_m = (1 << m);
|
|
750 else
|
|
751 two_m = 1;
|
|
752
|
|
753 for(k = 0; k < two_m; k++) {
|
|
754 for(i = 0; i < 64; i += two_m_plus_one) {
|
|
755 p = k + i;
|
|
756 q = p + two_m;
|
|
757 /* Do block 1 */
|
|
758 tmp_a_r = buf_1[p].real;
|
|
759 tmp_a_i = buf_1[p].imag;
|
|
760 tmp_b_r = buf_1[q].real * w[m][k].real - buf_1[q].imag * w[m][k].imag;
|
|
761 tmp_b_i = buf_1[q].imag * w[m][k].real + buf_1[q].real * w[m][k].imag;
|
|
762 buf_1[p].real = tmp_a_r + tmp_b_r;
|
|
763 buf_1[p].imag = tmp_a_i + tmp_b_i;
|
|
764 buf_1[q].real = tmp_a_r - tmp_b_r;
|
|
765 buf_1[q].imag = tmp_a_i - tmp_b_i;
|
|
766
|
|
767 /* Do block 2 */
|
|
768 tmp_a_r = buf_2[p].real;
|
|
769 tmp_a_i = buf_2[p].imag;
|
|
770 tmp_b_r = buf_2[q].real * w[m][k].real - buf_2[q].imag * w[m][k].imag;
|
|
771 tmp_b_i = buf_2[q].imag * w[m][k].real + buf_2[q].real * w[m][k].imag;
|
|
772 buf_2[p].real = tmp_a_r + tmp_b_r;
|
|
773 buf_2[p].imag = tmp_a_i + tmp_b_i;
|
|
774 buf_2[q].real = tmp_a_r - tmp_b_r;
|
|
775 buf_2[q].imag = tmp_a_i - tmp_b_i;
|
|
776 }
|
|
777 }
|
|
778 }
|
|
779
|
|
780 /* Post IFFT complex multiply */
|
|
781 for( i=0; i < 64; i++) {
|
|
782 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
|
|
783 tmp_a_r = buf_1[i].real;
|
|
784 tmp_a_i = -buf_1[i].imag;
|
|
785 buf_1[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
|
|
786 buf_1[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
|
|
787 /* y2[n] = z2[n] * (xcos2[n] + j * xsin2[n]) ; */
|
|
788 tmp_a_r = buf_2[i].real;
|
|
789 tmp_a_i = -buf_2[i].imag;
|
|
790 buf_2[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
|
|
791 buf_2[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
|
|
792 }
|
|
793
|
|
794 data_ptr = data;
|
|
795 delay_ptr = delay;
|
|
796 window_ptr = imdct_window;
|
|
797
|
|
798 /* Window and convert to real valued signal */
|
|
799 for(i=0; i< 64; i++) {
|
|
800 *data_ptr++ = -buf_1[i].imag * *window_ptr++ + *delay_ptr++ + bias;
|
|
801 *data_ptr++ = buf_1[64-i-1].real * *window_ptr++ + *delay_ptr++ + bias;
|
|
802 }
|
|
803
|
|
804 for(i=0; i< 64; i++) {
|
|
805 *data_ptr++ = -buf_1[i].real * *window_ptr++ + *delay_ptr++ + bias;
|
|
806 *data_ptr++ = buf_1[64-i-1].imag * *window_ptr++ + *delay_ptr++ + bias;
|
|
807 }
|
|
808
|
|
809 delay_ptr = delay;
|
|
810
|
|
811 for(i=0; i< 64; i++) {
|
|
812 *delay_ptr++ = -buf_2[i].real * *--window_ptr;
|
|
813 *delay_ptr++ = buf_2[64-i-1].imag * *--window_ptr;
|
|
814 }
|
|
815
|
|
816 for(i=0; i< 64; i++) {
|
|
817 *delay_ptr++ = buf_2[i].imag * *--window_ptr;
|
|
818 *delay_ptr++ = -buf_2[64-i-1].real * *--window_ptr;
|
|
819 }
|
|
820 }
|
|
821
|
|
822 void imdct_init (uint32_t mm_accel)
|
|
823 {
|
|
824 #ifdef LIBA52_MLIB
|
|
825 if (mm_accel & MM_ACCEL_MLIB) {
|
|
826 fprintf (stderr, "Using mlib for IMDCT transform\n");
|
|
827 imdct_512 = imdct_do_512_mlib;
|
|
828 imdct_256 = imdct_do_256_mlib;
|
|
829 } else
|
|
830 #endif
|
|
831 {
|
|
832 int i, j, k;
|
|
833
|
3579
|
834 if(gCpuCaps.hasSSE) fprintf (stderr, "Using SSE optimized IMDCT transform\n");
|
|
835 else fprintf (stderr, "No accelerated IMDCT transform found\n");
|
3394
|
836
|
|
837 /* Twiddle factors to turn IFFT into IMDCT */
|
|
838 for (i = 0; i < 128; i++) {
|
|
839 xcos1[i] = -cos ((M_PI / 2048) * (8 * i + 1));
|
|
840 xsin1[i] = -sin ((M_PI / 2048) * (8 * i + 1));
|
|
841 }
|
3579
|
842 #ifdef ARCH_X86
|
3527
|
843 for (i = 0; i < 128; i++) {
|
3581
|
844 sseSinCos1c[2*i+0]= xcos1[i];
|
|
845 sseSinCos1c[2*i+1]= -xcos1[i];
|
|
846 sseSinCos1d[2*i+0]= xsin1[i];
|
|
847 sseSinCos1d[2*i+1]= xsin1[i];
|
3527
|
848 }
|
|
849 #endif
|
3394
|
850
|
|
851 /* More twiddle factors to turn IFFT into IMDCT */
|
|
852 for (i = 0; i < 64; i++) {
|
|
853 xcos2[i] = -cos ((M_PI / 1024) * (8 * i + 1));
|
|
854 xsin2[i] = -sin ((M_PI / 1024) * (8 * i + 1));
|
|
855 }
|
|
856
|
|
857 for (i = 0; i < 7; i++) {
|
|
858 j = 1 << i;
|
|
859 for (k = 0; k < j; k++) {
|
|
860 w[i][k].real = cos (-M_PI * k / j);
|
|
861 w[i][k].imag = sin (-M_PI * k / j);
|
|
862 }
|
|
863 }
|
3579
|
864 #ifdef ARCH_X86
|
3534
|
865 for (i = 1; i < 7; i++) {
|
|
866 j = 1 << i;
|
|
867 for (k = 0; k < j; k+=2) {
|
|
868
|
|
869 sseW[i][4*k + 0] = w[i][k+0].real;
|
|
870 sseW[i][4*k + 1] = w[i][k+0].real;
|
|
871 sseW[i][4*k + 2] = w[i][k+1].real;
|
|
872 sseW[i][4*k + 3] = w[i][k+1].real;
|
|
873
|
|
874 sseW[i][4*k + 4] = -w[i][k+0].imag;
|
|
875 sseW[i][4*k + 5] = w[i][k+0].imag;
|
|
876 sseW[i][4*k + 6] = -w[i][k+1].imag;
|
|
877 sseW[i][4*k + 7] = w[i][k+1].imag;
|
|
878
|
|
879 //we multiply more or less uninitalized numbers so we need to use exactly 0.0
|
|
880 if(k==0)
|
|
881 {
|
|
882 // sseW[i][4*k + 0]= sseW[i][4*k + 1]= 1.0;
|
|
883 sseW[i][4*k + 4]= sseW[i][4*k + 5]= 0.0;
|
|
884 }
|
|
885
|
|
886 if(2*k == j)
|
|
887 {
|
|
888 sseW[i][4*k + 0]= sseW[i][4*k + 1]= 0.0;
|
|
889 // sseW[i][4*k + 4]= -(sseW[i][4*k + 5]= -1.0);
|
|
890 }
|
|
891 }
|
|
892 }
|
3552
|
893
|
|
894 for(i=0; i<128; i++)
|
|
895 {
|
|
896 sseWindow[2*i+0]= -imdct_window[2*i+0];
|
3553
|
897 sseWindow[2*i+1]= imdct_window[2*i+1];
|
3552
|
898 }
|
3553
|
899
|
|
900 for(i=0; i<64; i++)
|
|
901 {
|
|
902 sseWindow[256 + 2*i+0]= -imdct_window[254 - 2*i+1];
|
|
903 sseWindow[256 + 2*i+1]= imdct_window[254 - 2*i+0];
|
|
904 sseWindow[384 + 2*i+0]= imdct_window[126 - 2*i+1];
|
|
905 sseWindow[384 + 2*i+1]= -imdct_window[126 - 2*i+0];
|
|
906 }
|
3579
|
907 #endif // arch_x86
|
|
908
|
|
909 if(gCpuCaps.hasSSE) imdct_512 = imdct_do_512_sse;
|
|
910 else imdct_512 = imdct_do_512;
|
3394
|
911 imdct_256 = imdct_do_256;
|
|
912 }
|
|
913 }
|