1 --- include/a52.h 2005-03-22 19:58:53.000000000 +0100
2 +++ a52.h 2004-03-19 01:15:49.000000000 +0100
4 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
11 typedef float sample_t;
14 void a52_dynrng (a52_state_t * state,
15 sample_t (* call) (sample_t, void *), void * data);
16 int a52_block (a52_state_t * state, sample_t * samples);
18 +void* a52_resample_init(uint32_t mm_accel,int flags,int chans);
19 +extern int (* a52_resample) (float * _f, int16_t * s16);
21 +uint16_t crc16_block(uint8_t *data,uint32_t num_bytes);
24 --- liba52/a52_internal.h 2005-03-22 19:59:35.000000000 +0100
25 +++ a52_internal.h 2004-03-19 01:15:49.000000000 +0100
28 int downmix_init (int input, int flags, sample_t * level,
29 sample_t clev, sample_t slev);
30 +void downmix_accel_init(uint32_t mm_accel);
31 int downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level,
32 sample_t clev, sample_t slev);
33 -void downmix (sample_t * samples, int acmod, int output, sample_t bias,
34 +extern void (*downmix) (sample_t * samples, int acmod, int output, sample_t bias,
35 sample_t clev, sample_t slev);
36 -void upmix (sample_t * samples, int acmod, int output);
37 +extern void (*upmix) (sample_t * samples, int acmod, int output);
39 void imdct_init (uint32_t mm_accel);
40 extern void (* imdct_256) (sample_t * data, sample_t * delay, sample_t bias);
41 --- liba52/bitstream.c 2005-03-22 19:59:35.000000000 +0100
42 +++ bitstream.c 2004-03-19 01:15:49.000000000 +0100
45 #define BUFFER_SIZE 4096
47 +#ifdef ALT_BITSTREAM_READER
49 +uint32_t * buffer_start;
51 static uint32_t * buffer_start;
55 uint32_t current_word;
58 buffer_start = (uint32_t *) (buf - align);
60 +#ifdef ALT_BITSTREAM_READER
63 bitstream_get (align * 8);
66 --- liba52/bitstream.h 2005-03-22 19:59:35.000000000 +0100
67 +++ bitstream.h 2004-03-19 01:15:49.000000000 +0100
69 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
72 +/* code from ffmpeg/libavcodec */
73 +#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC_ == 3 && __GNUC_MINOR__ > 0)
74 +# define always_inline __attribute__((always_inline)) inline
76 +# define always_inline inline
79 +#if defined(__sparc__) || defined(hpux)
81 + * the alt bitstream reader performs unaligned memory accesses; that doesn't work
82 + * on sparc/hpux. For now, disable ALT_BITSTREAM_READER.
84 +#undef ALT_BITSTREAM_READER
86 +// alternative (faster) bitstram reader (reades upto 3 bytes over the end of the input)
87 +#define ALT_BITSTREAM_READER
89 +/* used to avoid missaligned exceptions on some archs (alpha, ...) */
90 +#if defined (ARCH_X86) || defined(ARCH_ARMV4L)
91 +# define unaligned32(a) (*(uint32_t*)(a))
94 +static always_inline uint32_t unaligned32(const void *v) {
97 + } __attribute__((packed));
99 + return ((const struct Unaligned *) v)->i;
101 +# elif defined(__DECC)
102 +static inline uint32_t unaligned32(const void *v) {
103 + return *(const __unaligned uint32_t *) v;
106 +static inline uint32_t unaligned32(const void *v) {
107 + return *(const uint32_t *) v;
114 /* (stolen from the kernel) */
115 #ifdef WORDS_BIGENDIAN
118 # if defined (__i386__)
120 # define swab32(x) __i386_swab32(x)
121 - static inline const uint32_t __i386_swab32(uint32_t x)
122 + static always_inline const uint32_t __i386_swab32(uint32_t x)
124 __asm__("bswap %0" : "=r" (x) : "0" (x));
131 -((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \
132 - (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3]))
134 +# define swab32(x) __generic_swab32(x)
135 + static always_inline const uint32_t __generic_swab32(uint32_t x)
137 + return ((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) |
138 + (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3]));
143 +#ifdef ALT_BITSTREAM_READER
144 +extern uint32_t *buffer_start;
147 extern uint32_t bits_left;
148 extern uint32_t current_word;
151 void bitstream_set_ptr (uint8_t * buf);
152 uint32_t bitstream_get_bh(uint32_t num_bits);
153 int32_t bitstream_get_bh_2(uint32_t num_bits);
156 static inline uint32_t
157 -bitstream_get(uint32_t num_bits)
158 +bitstream_get(uint32_t num_bits) // note num_bits is practically a constant due to inlineing
160 +#ifdef ALT_BITSTREAM_READER
161 + uint32_t result= swab32( unaligned32(((uint8_t *)buffer_start)+(indx>>3)) );
163 + result<<= (indx&0x07);
164 + result>>= 32 - num_bits;
172 if(num_bits < bits_left) {
173 result = (current_word << (32 - bits_left)) >> (32 - num_bits);
174 bits_left -= num_bits;
178 return bitstream_get_bh(num_bits);
182 +static inline void bitstream_skip(int num_bits)
184 +#ifdef ALT_BITSTREAM_READER
187 + bitstream_get(num_bits);
191 static inline int32_t
192 bitstream_get_2(uint32_t num_bits)
194 +#ifdef ALT_BITSTREAM_READER
195 + int32_t result= swab32( unaligned32(((uint8_t *)buffer_start)+(indx>>3)) );
197 + result<<= (indx&0x07);
198 + result>>= 32 - num_bits;
205 if(num_bits < bits_left) {
209 return bitstream_get_bh_2(num_bits);
212 --- liba52/downmix.c 2005-03-22 19:59:35.000000000 +0100
213 +++ downmix.c 2004-04-12 18:42:14.000000000 +0200
215 * You should have received a copy of the GNU General Public License
216 * along with this program; if not, write to the Free Software
217 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
219 + * SSE optimizations from Michael Niedermayer (michaelni@gmx.at)
224 -#include <inttypes.h>
226 +#include <inttypes.h>
229 #include "a52_internal.h"
230 +#include "mm_accel.h"
232 #define CONVERT(acmod,output) (((output) << 3) + (acmod))
235 +void (*downmix)(sample_t * samples, int acmod, int output, sample_t bias,
236 + sample_t clev, sample_t slev)= NULL;
237 +void (*upmix)(sample_t * samples, int acmod, int output)= NULL;
239 +static void downmix_SSE (sample_t * samples, int acmod, int output, sample_t bias,
240 + sample_t clev, sample_t slev);
241 +static void downmix_3dnow (sample_t * samples, int acmod, int output, sample_t bias,
242 + sample_t clev, sample_t slev);
243 +static void downmix_C (sample_t * samples, int acmod, int output, sample_t bias,
244 + sample_t clev, sample_t slev);
245 +static void upmix_MMX (sample_t * samples, int acmod, int output);
246 +static void upmix_C (sample_t * samples, int acmod, int output);
248 +void downmix_accel_init(uint32_t mm_accel)
251 + downmix= downmix_C;
253 + if(mm_accel & MM_ACCEL_X86_MMX) upmix= upmix_MMX;
254 + if(mm_accel & MM_ACCEL_X86_SSE) downmix= downmix_SSE;
255 + if(mm_accel & MM_ACCEL_X86_3DNOW) downmix= downmix_3dnow;
259 int downmix_init (int input, int flags, sample_t * level,
260 sample_t clev, sample_t slev)
263 output = flags & A52_CHANNEL_MASK;
264 if (output > A52_DOLBY)
268 output = table[output][input & 7];
270 if ((output == A52_STEREO) &&
272 *level *= 1 / (1 + 3 * LEVEL_3DB);
279 @@ -440,12 +473,11 @@
280 static void zero (sample_t * samples)
284 for (i = 0; i < 256; i++)
288 -void downmix (sample_t * samples, int acmod, int output, sample_t bias,
289 +static void downmix_C (sample_t * samples, int acmod, int output, sample_t bias,
290 sample_t clev, sample_t slev)
292 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
296 case CONVERT (A52_3F2R, A52_2F1R):
297 - mix3to2 (samples, bias);
298 + mix3to2 (samples, bias); //FIXME possible bug? (output doesnt seem to be used)
299 move2to1 (samples + 768, samples + 512, bias);
302 @@ -581,12 +613,12 @@
305 case CONVERT (A52_3F1R, A52_3F2R):
306 - memcpy (samples + 1027, samples + 768, 256 * sizeof (sample_t));
307 + memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
312 -void upmix (sample_t * samples, int acmod, int output)
313 +static void upmix_C (sample_t * samples, int acmod, int output)
315 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
317 @@ -651,3 +683,1137 @@
323 +static void mix2to1_SSE (sample_t * dest, sample_t * src, sample_t bias)
326 + "movlps %2, %%xmm7 \n\t"
327 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
328 + "movl $-1024, %%esi \n\t"
331 + "movaps (%0, %%esi), %%xmm0 \n\t"
332 + "movaps 16(%0, %%esi), %%xmm1 \n\t"
333 + "addps (%1, %%esi), %%xmm0 \n\t"
334 + "addps 16(%1, %%esi), %%xmm1 \n\t"
335 + "addps %%xmm7, %%xmm0 \n\t"
336 + "addps %%xmm7, %%xmm1 \n\t"
337 + "movaps %%xmm0, (%1, %%esi) \n\t"
338 + "movaps %%xmm1, 16(%1, %%esi) \n\t"
339 + "addl $32, %%esi \n\t"
341 + :: "r" (src+256), "r" (dest+256), "m" (bias)
346 +static void mix3to1_SSE (sample_t * samples, sample_t bias)
349 + "movlps %1, %%xmm7 \n\t"
350 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
351 + "movl $-1024, %%esi \n\t"
354 + "movaps (%0, %%esi), %%xmm0 \n\t"
355 + "movaps 1024(%0, %%esi), %%xmm1 \n\t"
356 + "addps 2048(%0, %%esi), %%xmm0 \n\t"
357 + "addps %%xmm7, %%xmm1 \n\t"
358 + "addps %%xmm1, %%xmm0 \n\t"
359 + "movaps %%xmm0, (%0, %%esi) \n\t"
360 + "addl $16, %%esi \n\t"
362 + :: "r" (samples+256), "m" (bias)
367 +static void mix4to1_SSE (sample_t * samples, sample_t bias)
370 + "movlps %1, %%xmm7 \n\t"
371 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
372 + "movl $-1024, %%esi \n\t"
375 + "movaps (%0, %%esi), %%xmm0 \n\t"
376 + "movaps 1024(%0, %%esi), %%xmm1 \n\t"
377 + "addps 2048(%0, %%esi), %%xmm0 \n\t"
378 + "addps 3072(%0, %%esi), %%xmm1 \n\t"
379 + "addps %%xmm7, %%xmm0 \n\t"
380 + "addps %%xmm1, %%xmm0 \n\t"
381 + "movaps %%xmm0, (%0, %%esi) \n\t"
382 + "addl $16, %%esi \n\t"
384 + :: "r" (samples+256), "m" (bias)
389 +static void mix5to1_SSE (sample_t * samples, sample_t bias)
392 + "movlps %1, %%xmm7 \n\t"
393 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
394 + "movl $-1024, %%esi \n\t"
397 + "movaps (%0, %%esi), %%xmm0 \n\t"
398 + "movaps 1024(%0, %%esi), %%xmm1 \n\t"
399 + "addps 2048(%0, %%esi), %%xmm0 \n\t"
400 + "addps 3072(%0, %%esi), %%xmm1 \n\t"
401 + "addps %%xmm7, %%xmm0 \n\t"
402 + "addps 4096(%0, %%esi), %%xmm1 \n\t"
403 + "addps %%xmm1, %%xmm0 \n\t"
404 + "movaps %%xmm0, (%0, %%esi) \n\t"
405 + "addl $16, %%esi \n\t"
407 + :: "r" (samples+256), "m" (bias)
412 +static void mix3to2_SSE (sample_t * samples, sample_t bias)
415 + "movlps %1, %%xmm7 \n\t"
416 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
417 + "movl $-1024, %%esi \n\t"
420 + "movaps 1024(%0, %%esi), %%xmm0 \n\t"
421 + "addps %%xmm7, %%xmm0 \n\t" //common
422 + "movaps (%0, %%esi), %%xmm1 \n\t"
423 + "movaps 2048(%0, %%esi), %%xmm2 \n\t"
424 + "addps %%xmm0, %%xmm1 \n\t"
425 + "addps %%xmm0, %%xmm2 \n\t"
426 + "movaps %%xmm1, (%0, %%esi) \n\t"
427 + "movaps %%xmm2, 1024(%0, %%esi) \n\t"
428 + "addl $16, %%esi \n\t"
430 + :: "r" (samples+256), "m" (bias)
435 +static void mix21to2_SSE (sample_t * left, sample_t * right, sample_t bias)
438 + "movlps %2, %%xmm7 \n\t"
439 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
440 + "movl $-1024, %%esi \n\t"
443 + "movaps 1024(%1, %%esi), %%xmm0 \n\t"
444 + "addps %%xmm7, %%xmm0 \n\t" //common
445 + "movaps (%0, %%esi), %%xmm1 \n\t"
446 + "movaps (%1, %%esi), %%xmm2 \n\t"
447 + "addps %%xmm0, %%xmm1 \n\t"
448 + "addps %%xmm0, %%xmm2 \n\t"
449 + "movaps %%xmm1, (%0, %%esi) \n\t"
450 + "movaps %%xmm2, (%1, %%esi) \n\t"
451 + "addl $16, %%esi \n\t"
453 + :: "r" (left+256), "r" (right+256), "m" (bias)
458 +static void mix21toS_SSE (sample_t * samples, sample_t bias)
461 + "movlps %1, %%xmm7 \n\t"
462 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
463 + "movl $-1024, %%esi \n\t"
466 + "movaps 2048(%0, %%esi), %%xmm0 \n\t" // surround
467 + "movaps (%0, %%esi), %%xmm1 \n\t"
468 + "movaps 1024(%0, %%esi), %%xmm2 \n\t"
469 + "addps %%xmm7, %%xmm1 \n\t"
470 + "addps %%xmm7, %%xmm2 \n\t"
471 + "subps %%xmm0, %%xmm1 \n\t"
472 + "addps %%xmm0, %%xmm2 \n\t"
473 + "movaps %%xmm1, (%0, %%esi) \n\t"
474 + "movaps %%xmm2, 1024(%0, %%esi) \n\t"
475 + "addl $16, %%esi \n\t"
477 + :: "r" (samples+256), "m" (bias)
482 +static void mix31to2_SSE (sample_t * samples, sample_t bias)
485 + "movlps %1, %%xmm7 \n\t"
486 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
487 + "movl $-1024, %%esi \n\t"
490 + "movaps 1024(%0, %%esi), %%xmm0 \n\t"
491 + "addps 3072(%0, %%esi), %%xmm0 \n\t"
492 + "addps %%xmm7, %%xmm0 \n\t" // common
493 + "movaps (%0, %%esi), %%xmm1 \n\t"
494 + "movaps 2048(%0, %%esi), %%xmm2 \n\t"
495 + "addps %%xmm0, %%xmm1 \n\t"
496 + "addps %%xmm0, %%xmm2 \n\t"
497 + "movaps %%xmm1, (%0, %%esi) \n\t"
498 + "movaps %%xmm2, 1024(%0, %%esi) \n\t"
499 + "addl $16, %%esi \n\t"
501 + :: "r" (samples+256), "m" (bias)
506 +static void mix31toS_SSE (sample_t * samples, sample_t bias)
509 + "movlps %1, %%xmm7 \n\t"
510 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
511 + "movl $-1024, %%esi \n\t"
514 + "movaps 1024(%0, %%esi), %%xmm0 \n\t"
515 + "movaps 3072(%0, %%esi), %%xmm3 \n\t" // surround
516 + "addps %%xmm7, %%xmm0 \n\t" // common
517 + "movaps (%0, %%esi), %%xmm1 \n\t"
518 + "movaps 2048(%0, %%esi), %%xmm2 \n\t"
519 + "addps %%xmm0, %%xmm1 \n\t"
520 + "addps %%xmm0, %%xmm2 \n\t"
521 + "subps %%xmm3, %%xmm1 \n\t"
522 + "addps %%xmm3, %%xmm2 \n\t"
523 + "movaps %%xmm1, (%0, %%esi) \n\t"
524 + "movaps %%xmm2, 1024(%0, %%esi) \n\t"
525 + "addl $16, %%esi \n\t"
527 + :: "r" (samples+256), "m" (bias)
532 +static void mix22toS_SSE (sample_t * samples, sample_t bias)
535 + "movlps %1, %%xmm7 \n\t"
536 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
537 + "movl $-1024, %%esi \n\t"
540 + "movaps 2048(%0, %%esi), %%xmm0 \n\t"
541 + "addps 3072(%0, %%esi), %%xmm0 \n\t" // surround
542 + "movaps (%0, %%esi), %%xmm1 \n\t"
543 + "movaps 1024(%0, %%esi), %%xmm2 \n\t"
544 + "addps %%xmm7, %%xmm1 \n\t"
545 + "addps %%xmm7, %%xmm2 \n\t"
546 + "subps %%xmm0, %%xmm1 \n\t"
547 + "addps %%xmm0, %%xmm2 \n\t"
548 + "movaps %%xmm1, (%0, %%esi) \n\t"
549 + "movaps %%xmm2, 1024(%0, %%esi) \n\t"
550 + "addl $16, %%esi \n\t"
552 + :: "r" (samples+256), "m" (bias)
557 +static void mix32to2_SSE (sample_t * samples, sample_t bias)
560 + "movlps %1, %%xmm7 \n\t"
561 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
562 + "movl $-1024, %%esi \n\t"
565 + "movaps 1024(%0, %%esi), %%xmm0 \n\t"
566 + "addps %%xmm7, %%xmm0 \n\t" // common
567 + "movaps %%xmm0, %%xmm1 \n\t" // common
568 + "addps (%0, %%esi), %%xmm0 \n\t"
569 + "addps 2048(%0, %%esi), %%xmm1 \n\t"
570 + "addps 3072(%0, %%esi), %%xmm0 \n\t"
571 + "addps 4096(%0, %%esi), %%xmm1 \n\t"
572 + "movaps %%xmm0, (%0, %%esi) \n\t"
573 + "movaps %%xmm1, 1024(%0, %%esi) \n\t"
574 + "addl $16, %%esi \n\t"
576 + :: "r" (samples+256), "m" (bias)
581 +static void mix32toS_SSE (sample_t * samples, sample_t bias)
584 + "movlps %1, %%xmm7 \n\t"
585 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
586 + "movl $-1024, %%esi \n\t"
589 + "movaps 1024(%0, %%esi), %%xmm0 \n\t"
590 + "movaps 3072(%0, %%esi), %%xmm2 \n\t"
591 + "addps %%xmm7, %%xmm0 \n\t" // common
592 + "addps 4096(%0, %%esi), %%xmm2 \n\t" // surround
593 + "movaps (%0, %%esi), %%xmm1 \n\t"
594 + "movaps 2048(%0, %%esi), %%xmm3 \n\t"
595 + "subps %%xmm2, %%xmm1 \n\t"
596 + "addps %%xmm2, %%xmm3 \n\t"
597 + "addps %%xmm0, %%xmm1 \n\t"
598 + "addps %%xmm0, %%xmm3 \n\t"
599 + "movaps %%xmm1, (%0, %%esi) \n\t"
600 + "movaps %%xmm3, 1024(%0, %%esi) \n\t"
601 + "addl $16, %%esi \n\t"
603 + :: "r" (samples+256), "m" (bias)
608 +static void move2to1_SSE (sample_t * src, sample_t * dest, sample_t bias)
611 + "movlps %2, %%xmm7 \n\t"
612 + "shufps $0x00, %%xmm7, %%xmm7 \n\t"
613 + "movl $-1024, %%esi \n\t"
616 + "movaps (%0, %%esi), %%xmm0 \n\t"
617 + "movaps 16(%0, %%esi), %%xmm1 \n\t"
618 + "addps 1024(%0, %%esi), %%xmm0 \n\t"
619 + "addps 1040(%0, %%esi), %%xmm1 \n\t"
620 + "addps %%xmm7, %%xmm0 \n\t"
621 + "addps %%xmm7, %%xmm1 \n\t"
622 + "movaps %%xmm0, (%1, %%esi) \n\t"
623 + "movaps %%xmm1, 16(%1, %%esi) \n\t"
624 + "addl $32, %%esi \n\t"
626 + :: "r" (src+256), "r" (dest+256), "m" (bias)
631 +static void zero_MMX(sample_t * samples)
634 + "movl $-1024, %%esi \n\t"
635 + "pxor %%mm0, %%mm0 \n\t"
638 + "movq %%mm0, (%0, %%esi) \n\t"
639 + "movq %%mm0, 8(%0, %%esi) \n\t"
640 + "movq %%mm0, 16(%0, %%esi) \n\t"
641 + "movq %%mm0, 24(%0, %%esi) \n\t"
642 + "addl $32, %%esi \n\t"
645 + :: "r" (samples+256)
651 + I hope dest and src will be at least 8 byte aligned and size
652 + will devide on 8 without remain
653 + Note: untested and unused.
655 +static void copy_MMX(void *dest,const void *src,unsigned size)
659 + for(i=0;i<size;i++)
662 + "movq %0, %%mm0\n\t"
663 + "movq 8%0, %%mm1\n\t"
664 + "movq 16%0, %%mm2\n\t"
665 + "movq 24%0, %%mm3\n\t"
666 + "movq 32%0, %%mm4\n\t"
667 + "movq 40%0, %%mm5\n\t"
668 + "movq 48%0, %%mm6\n\t"
669 + "movq 56%0, %%mm7\n\t"
670 + "movq %%mm0, %1\n\t"
671 + "movq %%mm1, 8%1\n\t"
672 + "movq %%mm2, 16%1\n\t"
673 + "movq %%mm3, 24%1\n\t"
674 + "movq %%mm4, 32%1\n\t"
675 + "movq %%mm5, 40%1\n\t"
676 + "movq %%mm6, 48%1\n\t"
677 + "movq %%mm7, 56%1\n\t"
679 + :"m"(src),"m"(dest));
683 +static void downmix_SSE (sample_t * samples, int acmod, int output, sample_t bias,
684 + sample_t clev, sample_t slev)
686 + switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
688 + case CONVERT (A52_CHANNEL, A52_CHANNEL2):
689 + memcpy (samples, samples + 256, 256 * sizeof (sample_t));
692 + case CONVERT (A52_CHANNEL, A52_MONO):
693 + case CONVERT (A52_STEREO, A52_MONO):
695 + mix2to1_SSE (samples, samples + 256, bias);
698 + case CONVERT (A52_2F1R, A52_MONO):
701 + case CONVERT (A52_3F, A52_MONO):
703 + mix3to1_SSE (samples, bias);
706 + case CONVERT (A52_3F1R, A52_MONO):
709 + case CONVERT (A52_2F2R, A52_MONO):
712 + mix4to1_SSE (samples, bias);
715 + case CONVERT (A52_3F2R, A52_MONO):
718 + mix5to1_SSE (samples, bias);
721 + case CONVERT (A52_MONO, A52_DOLBY):
722 + memcpy (samples + 256, samples, 256 * sizeof (sample_t));
725 + case CONVERT (A52_3F, A52_STEREO):
726 + case CONVERT (A52_3F, A52_DOLBY):
728 + mix3to2_SSE (samples, bias);
731 + case CONVERT (A52_2F1R, A52_STEREO):
734 + mix21to2_SSE (samples, samples + 256, bias);
737 + case CONVERT (A52_2F1R, A52_DOLBY):
738 + mix21toS_SSE (samples, bias);
741 + case CONVERT (A52_3F1R, A52_STEREO):
744 + mix31to2_SSE (samples, bias);
747 + case CONVERT (A52_3F1R, A52_DOLBY):
748 + mix31toS_SSE (samples, bias);
751 + case CONVERT (A52_2F2R, A52_STEREO):
754 + mix2to1_SSE (samples, samples + 512, bias);
755 + mix2to1_SSE (samples + 256, samples + 768, bias);
758 + case CONVERT (A52_2F2R, A52_DOLBY):
759 + mix22toS_SSE (samples, bias);
762 + case CONVERT (A52_3F2R, A52_STEREO):
765 + mix32to2_SSE (samples, bias);
768 + case CONVERT (A52_3F2R, A52_DOLBY):
769 + mix32toS_SSE (samples, bias);
772 + case CONVERT (A52_3F1R, A52_3F):
775 + mix21to2_SSE (samples, samples + 512, bias);
778 + case CONVERT (A52_3F2R, A52_3F):
781 + mix2to1_SSE (samples, samples + 768, bias);
782 + mix2to1_SSE (samples + 512, samples + 1024, bias);
785 + case CONVERT (A52_3F1R, A52_2F1R):
786 + mix3to2_SSE (samples, bias);
787 + memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
790 + case CONVERT (A52_2F2R, A52_2F1R):
791 + mix2to1_SSE (samples + 512, samples + 768, bias);
794 + case CONVERT (A52_3F2R, A52_2F1R):
795 + mix3to2_SSE (samples, bias); //FIXME possible bug? (output doesnt seem to be used)
796 + move2to1_SSE (samples + 768, samples + 512, bias);
799 + case CONVERT (A52_3F2R, A52_3F1R):
800 + mix2to1_SSE (samples + 768, samples + 1024, bias);
803 + case CONVERT (A52_2F1R, A52_2F2R):
804 + memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
807 + case CONVERT (A52_3F1R, A52_2F2R):
808 + mix3to2_SSE (samples, bias);
809 + memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
812 + case CONVERT (A52_3F2R, A52_2F2R):
813 + mix3to2_SSE (samples, bias);
814 + memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
815 + memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
818 + case CONVERT (A52_3F1R, A52_3F2R):
819 + memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
824 +static void upmix_MMX (sample_t * samples, int acmod, int output)
826 + switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
828 + case CONVERT (A52_CHANNEL, A52_CHANNEL2):
829 + memcpy (samples + 256, samples, 256 * sizeof (sample_t));
832 + case CONVERT (A52_3F2R, A52_MONO):
833 + zero_MMX (samples + 1024);
834 + case CONVERT (A52_3F1R, A52_MONO):
835 + case CONVERT (A52_2F2R, A52_MONO):
836 + zero_MMX (samples + 768);
837 + case CONVERT (A52_3F, A52_MONO):
838 + case CONVERT (A52_2F1R, A52_MONO):
839 + zero_MMX (samples + 512);
840 + case CONVERT (A52_CHANNEL, A52_MONO):
841 + case CONVERT (A52_STEREO, A52_MONO):
842 + zero_MMX (samples + 256);
845 + case CONVERT (A52_3F2R, A52_STEREO):
846 + case CONVERT (A52_3F2R, A52_DOLBY):
847 + zero_MMX (samples + 1024);
848 + case CONVERT (A52_3F1R, A52_STEREO):
849 + case CONVERT (A52_3F1R, A52_DOLBY):
850 + zero_MMX (samples + 768);
851 + case CONVERT (A52_3F, A52_STEREO):
852 + case CONVERT (A52_3F, A52_DOLBY):
854 + memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
855 + zero_MMX (samples + 256);
858 + case CONVERT (A52_2F2R, A52_STEREO):
859 + case CONVERT (A52_2F2R, A52_DOLBY):
860 + zero_MMX (samples + 768);
861 + case CONVERT (A52_2F1R, A52_STEREO):
862 + case CONVERT (A52_2F1R, A52_DOLBY):
863 + zero_MMX (samples + 512);
866 + case CONVERT (A52_3F2R, A52_3F):
867 + zero_MMX (samples + 1024);
868 + case CONVERT (A52_3F1R, A52_3F):
869 + case CONVERT (A52_2F2R, A52_2F1R):
870 + zero_MMX (samples + 768);
873 + case CONVERT (A52_3F2R, A52_3F1R):
874 + zero_MMX (samples + 1024);
877 + case CONVERT (A52_3F2R, A52_2F1R):
878 + zero_MMX (samples + 1024);
879 + case CONVERT (A52_3F1R, A52_2F1R):
881 + memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
884 + case CONVERT (A52_3F2R, A52_2F2R):
885 + memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
886 + goto mix_31to21_MMX;
890 +static void mix2to1_3dnow (sample_t * dest, sample_t * src, sample_t bias)
893 + "movd %2, %%mm7 \n\t"
894 + "punpckldq %2, %%mm7 \n\t"
895 + "movl $-1024, %%esi \n\t"
898 + "movq (%0, %%esi), %%mm0 \n\t"
899 + "movq 8(%0, %%esi), %%mm1 \n\t"
900 + "movq 16(%0, %%esi), %%mm2 \n\t"
901 + "movq 24(%0, %%esi), %%mm3 \n\t"
902 + "pfadd (%1, %%esi), %%mm0 \n\t"
903 + "pfadd 8(%1, %%esi), %%mm1 \n\t"
904 + "pfadd 16(%1, %%esi), %%mm2 \n\t"
905 + "pfadd 24(%1, %%esi), %%mm3 \n\t"
906 + "pfadd %%mm7, %%mm0 \n\t"
907 + "pfadd %%mm7, %%mm1 \n\t"
908 + "pfadd %%mm7, %%mm2 \n\t"
909 + "pfadd %%mm7, %%mm3 \n\t"
910 + "movq %%mm0, (%1, %%esi) \n\t"
911 + "movq %%mm1, 8(%1, %%esi) \n\t"
912 + "movq %%mm2, 16(%1, %%esi) \n\t"
913 + "movq %%mm3, 24(%1, %%esi) \n\t"
914 + "addl $32, %%esi \n\t"
916 + :: "r" (src+256), "r" (dest+256), "m" (bias)
921 +static void mix3to1_3dnow (sample_t * samples, sample_t bias)
924 + "movd %1, %%mm7 \n\t"
925 + "punpckldq %1, %%mm7 \n\t"
926 + "movl $-1024, %%esi \n\t"
929 + "movq (%0, %%esi), %%mm0 \n\t"
930 + "movq 8(%0, %%esi), %%mm1 \n\t"
931 + "movq 1024(%0, %%esi), %%mm2 \n\t"
932 + "movq 1032(%0, %%esi), %%mm3 \n\t"
933 + "pfadd 2048(%0, %%esi), %%mm0 \n\t"
934 + "pfadd 2056(%0, %%esi), %%mm1 \n\t"
935 + "pfadd %%mm7, %%mm0 \n\t"
936 + "pfadd %%mm7, %%mm1 \n\t"
937 + "pfadd %%mm2, %%mm0 \n\t"
938 + "pfadd %%mm3, %%mm1 \n\t"
939 + "movq %%mm0, (%0, %%esi) \n\t"
940 + "movq %%mm1, 8(%0, %%esi) \n\t"
941 + "addl $16, %%esi \n\t"
943 + :: "r" (samples+256), "m" (bias)
948 +static void mix4to1_3dnow (sample_t * samples, sample_t bias)
951 + "movd %1, %%mm7 \n\t"
952 + "punpckldq %1, %%mm7 \n\t"
953 + "movl $-1024, %%esi \n\t"
956 + "movq (%0, %%esi), %%mm0 \n\t"
957 + "movq 8(%0, %%esi), %%mm1 \n\t"
958 + "movq 1024(%0, %%esi), %%mm2 \n\t"
959 + "movq 1032(%0, %%esi), %%mm3 \n\t"
960 + "pfadd 2048(%0, %%esi), %%mm0 \n\t"
961 + "pfadd 2056(%0, %%esi), %%mm1 \n\t"
962 + "pfadd 3072(%0, %%esi), %%mm2 \n\t"
963 + "pfadd 3080(%0, %%esi), %%mm3 \n\t"
964 + "pfadd %%mm7, %%mm0 \n\t"
965 + "pfadd %%mm7, %%mm1 \n\t"
966 + "pfadd %%mm2, %%mm0 \n\t"
967 + "pfadd %%mm3, %%mm1 \n\t"
968 + "movq %%mm0, (%0, %%esi) \n\t"
969 + "movq %%mm1, 8(%0, %%esi) \n\t"
970 + "addl $16, %%esi \n\t"
972 + :: "r" (samples+256), "m" (bias)
977 +static void mix5to1_3dnow (sample_t * samples, sample_t bias)
980 + "movd %1, %%mm7 \n\t"
981 + "punpckldq %1, %%mm7 \n\t"
982 + "movl $-1024, %%esi \n\t"
985 + "movq (%0, %%esi), %%mm0 \n\t"
986 + "movq 8(%0, %%esi), %%mm1 \n\t"
987 + "movq 1024(%0, %%esi), %%mm2 \n\t"
988 + "movq 1032(%0, %%esi), %%mm3 \n\t"
989 + "pfadd 2048(%0, %%esi), %%mm0 \n\t"
990 + "pfadd 2056(%0, %%esi), %%mm1 \n\t"
991 + "pfadd 3072(%0, %%esi), %%mm2 \n\t"
992 + "pfadd 3080(%0, %%esi), %%mm3 \n\t"
993 + "pfadd %%mm7, %%mm0 \n\t"
994 + "pfadd %%mm7, %%mm1 \n\t"
995 + "pfadd 4096(%0, %%esi), %%mm2 \n\t"
996 + "pfadd 4104(%0, %%esi), %%mm3 \n\t"
997 + "pfadd %%mm2, %%mm0 \n\t"
998 + "pfadd %%mm3, %%mm1 \n\t"
999 + "movq %%mm0, (%0, %%esi) \n\t"
1000 + "movq %%mm1, 8(%0, %%esi) \n\t"
1001 + "addl $16, %%esi \n\t"
1003 + :: "r" (samples+256), "m" (bias)
1008 +static void mix3to2_3dnow (sample_t * samples, sample_t bias)
1011 + "movd %1, %%mm7 \n\t"
1012 + "punpckldq %1, %%mm7 \n\t"
1013 + "movl $-1024, %%esi \n\t"
1016 + "movq 1024(%0, %%esi), %%mm0 \n\t"
1017 + "movq 1032(%0, %%esi), %%mm1 \n\t"
1018 + "pfadd %%mm7, %%mm0 \n\t" //common
1019 + "pfadd %%mm7, %%mm1 \n\t" //common
1020 + "movq (%0, %%esi), %%mm2 \n\t"
1021 + "movq 8(%0, %%esi), %%mm3 \n\t"
1022 + "movq 2048(%0, %%esi), %%mm4 \n\t"
1023 + "movq 2056(%0, %%esi), %%mm5 \n\t"
1024 + "pfadd %%mm0, %%mm2 \n\t"
1025 + "pfadd %%mm1, %%mm3 \n\t"
1026 + "pfadd %%mm0, %%mm4 \n\t"
1027 + "pfadd %%mm1, %%mm5 \n\t"
1028 + "movq %%mm2, (%0, %%esi) \n\t"
1029 + "movq %%mm3, 8(%0, %%esi) \n\t"
1030 + "movq %%mm4, 1024(%0, %%esi) \n\t"
1031 + "movq %%mm5, 1032(%0, %%esi) \n\t"
1032 + "addl $16, %%esi \n\t"
1034 + :: "r" (samples+256), "m" (bias)
1039 +static void mix21to2_3dnow (sample_t * left, sample_t * right, sample_t bias)
1042 + "movd %2, %%mm7 \n\t"
1043 + "punpckldq %2, %%mm7 \n\t"
1044 + "movl $-1024, %%esi \n\t"
1047 + "movq 1024(%1, %%esi), %%mm0 \n\t"
1048 + "movq 1032(%1, %%esi), %%mm1 \n\t"
1049 + "pfadd %%mm7, %%mm0 \n\t" //common
1050 + "pfadd %%mm7, %%mm1 \n\t" //common
1051 + "movq (%0, %%esi), %%mm2 \n\t"
1052 + "movq 8(%0, %%esi), %%mm3 \n\t"
1053 + "movq (%1, %%esi), %%mm4 \n\t"
1054 + "movq 8(%1, %%esi), %%mm5 \n\t"
1055 + "pfadd %%mm0, %%mm2 \n\t"
1056 + "pfadd %%mm1, %%mm3 \n\t"
1057 + "pfadd %%mm0, %%mm4 \n\t"
1058 + "pfadd %%mm1, %%mm5 \n\t"
1059 + "movq %%mm2, (%0, %%esi) \n\t"
1060 + "movq %%mm3, 8(%0, %%esi) \n\t"
1061 + "movq %%mm4, (%1, %%esi) \n\t"
1062 + "movq %%mm5, 8(%1, %%esi) \n\t"
1063 + "addl $16, %%esi \n\t"
1065 + :: "r" (left+256), "r" (right+256), "m" (bias)
1070 +static void mix21toS_3dnow (sample_t * samples, sample_t bias)
1073 + "movd %1, %%mm7 \n\t"
1074 + "punpckldq %1, %%mm7 \n\t"
1075 + "movl $-1024, %%esi \n\t"
1078 + "movq 2048(%0, %%esi), %%mm0 \n\t" // surround
1079 + "movq 2056(%0, %%esi), %%mm1 \n\t" // surround
1080 + "movq (%0, %%esi), %%mm2 \n\t"
1081 + "movq 8(%0, %%esi), %%mm3 \n\t"
1082 + "movq 1024(%0, %%esi), %%mm4 \n\t"
1083 + "movq 1032(%0, %%esi), %%mm5 \n\t"
1084 + "pfadd %%mm7, %%mm2 \n\t"
1085 + "pfadd %%mm7, %%mm3 \n\t"
1086 + "pfadd %%mm7, %%mm4 \n\t"
1087 + "pfadd %%mm7, %%mm5 \n\t"
1088 + "pfsub %%mm0, %%mm2 \n\t"
1089 + "pfsub %%mm1, %%mm3 \n\t"
1090 + "pfadd %%mm0, %%mm4 \n\t"
1091 + "pfadd %%mm1, %%mm5 \n\t"
1092 + "movq %%mm2, (%0, %%esi) \n\t"
1093 + "movq %%mm3, 8(%0, %%esi) \n\t"
1094 + "movq %%mm4, 1024(%0, %%esi) \n\t"
1095 + "movq %%mm5, 1032(%0, %%esi) \n\t"
1096 + "addl $16, %%esi \n\t"
1098 + :: "r" (samples+256), "m" (bias)
1103 +static void mix31to2_3dnow (sample_t * samples, sample_t bias)
1106 + "movd %1, %%mm7 \n\t"
1107 + "punpckldq %1, %%mm7 \n\t"
1108 + "movl $-1024, %%esi \n\t"
1111 + "movq 1024(%0, %%esi), %%mm0 \n\t"
1112 + "movq 1032(%0, %%esi), %%mm1 \n\t"
1113 + "pfadd 3072(%0, %%esi), %%mm0 \n\t"
1114 + "pfadd 3080(%0, %%esi), %%mm1 \n\t"
1115 + "pfadd %%mm7, %%mm0 \n\t" // common
1116 + "pfadd %%mm7, %%mm1 \n\t" // common
1117 + "movq (%0, %%esi), %%mm2 \n\t"
1118 + "movq 8(%0, %%esi), %%mm3 \n\t"
1119 + "movq 2048(%0, %%esi), %%mm4 \n\t"
1120 + "movq 2056(%0, %%esi), %%mm5 \n\t"
1121 + "pfadd %%mm0, %%mm2 \n\t"
1122 + "pfadd %%mm1, %%mm3 \n\t"
1123 + "pfadd %%mm0, %%mm4 \n\t"
1124 + "pfadd %%mm1, %%mm5 \n\t"
1125 + "movq %%mm2, (%0, %%esi) \n\t"
1126 + "movq %%mm3, 8(%0, %%esi) \n\t"
1127 + "movq %%mm4, 1024(%0, %%esi) \n\t"
1128 + "movq %%mm5, 1032(%0, %%esi) \n\t"
1129 + "addl $16, %%esi \n\t"
1131 + :: "r" (samples+256), "m" (bias)
1136 +static void mix31toS_3dnow (sample_t * samples, sample_t bias)
1139 + "movd %1, %%mm7 \n\t"
1140 + "punpckldq %1, %%mm7 \n\t"
1141 + "movl $-1024, %%esi \n\t"
1144 + "movq 1024(%0, %%esi), %%mm0 \n\t"
1145 + "movq 1032(%0, %%esi), %%mm1 \n\t"
1146 + "pfadd %%mm7, %%mm0 \n\t" // common
1147 + "pfadd %%mm7, %%mm1 \n\t" // common
1148 + "movq (%0, %%esi), %%mm2 \n\t"
1149 + "movq 8(%0, %%esi), %%mm3 \n\t"
1150 + "movq 2048(%0, %%esi), %%mm4 \n\t"
1151 + "movq 2056(%0, %%esi), %%mm5 \n\t"
1152 + "pfadd %%mm0, %%mm2 \n\t"
1153 + "pfadd %%mm1, %%mm3 \n\t"
1154 + "pfadd %%mm0, %%mm4 \n\t"
1155 + "pfadd %%mm1, %%mm5 \n\t"
1156 + "movq 3072(%0, %%esi), %%mm0 \n\t" // surround
1157 + "movq 3080(%0, %%esi), %%mm1 \n\t" // surround
1158 + "pfsub %%mm0, %%mm2 \n\t"
1159 + "pfsub %%mm1, %%mm3 \n\t"
1160 + "pfadd %%mm0, %%mm4 \n\t"
1161 + "pfadd %%mm1, %%mm5 \n\t"
1162 + "movq %%mm2, (%0, %%esi) \n\t"
1163 + "movq %%mm3, 8(%0, %%esi) \n\t"
1164 + "movq %%mm4, 1024(%0, %%esi) \n\t"
1165 + "movq %%mm5, 1032(%0, %%esi) \n\t"
1166 + "addl $16, %%esi \n\t"
1168 + :: "r" (samples+256), "m" (bias)
1173 +static void mix22toS_3dnow (sample_t * samples, sample_t bias)
1176 + "movd %1, %%mm7 \n\t"
1177 + "punpckldq %1, %%mm7 \n\t"
1178 + "movl $-1024, %%esi \n\t"
1181 + "movq 2048(%0, %%esi), %%mm0 \n\t"
1182 + "movq 2056(%0, %%esi), %%mm1 \n\t"
1183 + "pfadd 3072(%0, %%esi), %%mm0 \n\t" // surround
1184 + "pfadd 3080(%0, %%esi), %%mm1 \n\t" // surround
1185 + "movq (%0, %%esi), %%mm2 \n\t"
1186 + "movq 8(%0, %%esi), %%mm3 \n\t"
1187 + "movq 1024(%0, %%esi), %%mm4 \n\t"
1188 + "movq 1032(%0, %%esi), %%mm5 \n\t"
1189 + "pfadd %%mm7, %%mm2 \n\t"
1190 + "pfadd %%mm7, %%mm3 \n\t"
1191 + "pfadd %%mm7, %%mm4 \n\t"
1192 + "pfadd %%mm7, %%mm5 \n\t"
1193 + "pfsub %%mm0, %%mm2 \n\t"
1194 + "pfsub %%mm1, %%mm3 \n\t"
1195 + "pfadd %%mm0, %%mm4 \n\t"
1196 + "pfadd %%mm1, %%mm5 \n\t"
1197 + "movq %%mm2, (%0, %%esi) \n\t"
1198 + "movq %%mm3, 8(%0, %%esi) \n\t"
1199 + "movq %%mm4, 1024(%0, %%esi) \n\t"
1200 + "movq %%mm5, 1032(%0, %%esi) \n\t"
1201 + "addl $16, %%esi \n\t"
1203 + :: "r" (samples+256), "m" (bias)
1208 +static void mix32to2_3dnow (sample_t * samples, sample_t bias)
1211 + "movd %1, %%mm7 \n\t"
1212 + "punpckldq %1, %%mm7 \n\t"
1213 + "movl $-1024, %%esi \n\t"
1216 + "movq 1024(%0, %%esi), %%mm0 \n\t"
1217 + "movq 1032(%0, %%esi), %%mm1 \n\t"
1218 + "pfadd %%mm7, %%mm0 \n\t" // common
1219 + "pfadd %%mm7, %%mm1 \n\t" // common
1220 + "movq %%mm0, %%mm2 \n\t" // common
1221 + "movq %%mm1, %%mm3 \n\t" // common
1222 + "pfadd (%0, %%esi), %%mm0 \n\t"
1223 + "pfadd 8(%0, %%esi), %%mm1 \n\t"
1224 + "pfadd 2048(%0, %%esi), %%mm2 \n\t"
1225 + "pfadd 2056(%0, %%esi), %%mm3 \n\t"
1226 + "pfadd 3072(%0, %%esi), %%mm0 \n\t"
1227 + "pfadd 3080(%0, %%esi), %%mm1 \n\t"
1228 + "pfadd 4096(%0, %%esi), %%mm2 \n\t"
1229 + "pfadd 4104(%0, %%esi), %%mm3 \n\t"
1230 + "movq %%mm0, (%0, %%esi) \n\t"
1231 + "movq %%mm1, 8(%0, %%esi) \n\t"
1232 + "movq %%mm2, 1024(%0, %%esi) \n\t"
1233 + "movq %%mm3, 1032(%0, %%esi) \n\t"
1234 + "addl $16, %%esi \n\t"
1236 + :: "r" (samples+256), "m" (bias)
1241 +/* todo: should be optimized better */
1242 +static void mix32toS_3dnow (sample_t * samples, sample_t bias)
1245 + "movl $-1024, %%esi \n\t"
1248 + "movd %1, %%mm7 \n\t"
1249 + "punpckldq %1, %%mm7 \n\t"
1250 + "movq 1024(%0, %%esi), %%mm0 \n\t"
1251 + "movq 1032(%0, %%esi), %%mm1 \n\t"
1252 + "movq 3072(%0, %%esi), %%mm4 \n\t"
1253 + "movq 3080(%0, %%esi), %%mm5 \n\t"
1254 + "pfadd %%mm7, %%mm0 \n\t" // common
1255 + "pfadd %%mm7, %%mm1 \n\t" // common
1256 + "pfadd 4096(%0, %%esi), %%mm4 \n\t" // surround
1257 + "pfadd 4104(%0, %%esi), %%mm5 \n\t" // surround
1258 + "movq (%0, %%esi), %%mm2 \n\t"
1259 + "movq 8(%0, %%esi), %%mm3 \n\t"
1260 + "movq 2048(%0, %%esi), %%mm6 \n\t"
1261 + "movq 2056(%0, %%esi), %%mm7 \n\t"
1262 + "pfsub %%mm4, %%mm2 \n\t"
1263 + "pfsub %%mm5, %%mm3 \n\t"
1264 + "pfadd %%mm4, %%mm6 \n\t"
1265 + "pfadd %%mm5, %%mm7 \n\t"
1266 + "pfadd %%mm0, %%mm2 \n\t"
1267 + "pfadd %%mm1, %%mm3 \n\t"
1268 + "pfadd %%mm0, %%mm6 \n\t"
1269 + "pfadd %%mm1, %%mm7 \n\t"
1270 + "movq %%mm2, (%0, %%esi) \n\t"
1271 + "movq %%mm3, 8(%0, %%esi) \n\t"
1272 + "movq %%mm6, 1024(%0, %%esi) \n\t"
1273 + "movq %%mm7, 1032(%0, %%esi) \n\t"
1274 + "addl $16, %%esi \n\t"
1276 + :: "r" (samples+256), "m" (bias)
1281 +static void move2to1_3dnow (sample_t * src, sample_t * dest, sample_t bias)
1284 + "movd %2, %%mm7 \n\t"
1285 + "punpckldq %2, %%mm7 \n\t"
1286 + "movl $-1024, %%esi \n\t"
1289 + "movq (%0, %%esi), %%mm0 \n\t"
1290 + "movq 8(%0, %%esi), %%mm1 \n\t"
1291 + "movq 16(%0, %%esi), %%mm2 \n\t"
1292 + "movq 24(%0, %%esi), %%mm3 \n\t"
1293 + "pfadd 1024(%0, %%esi), %%mm0 \n\t"
1294 + "pfadd 1032(%0, %%esi), %%mm1 \n\t"
1295 + "pfadd 1040(%0, %%esi), %%mm2 \n\t"
1296 + "pfadd 1048(%0, %%esi), %%mm3 \n\t"
1297 + "pfadd %%mm7, %%mm0 \n\t"
1298 + "pfadd %%mm7, %%mm1 \n\t"
1299 + "pfadd %%mm7, %%mm2 \n\t"
1300 + "pfadd %%mm7, %%mm3 \n\t"
1301 + "movq %%mm0, (%1, %%esi) \n\t"
1302 + "movq %%mm1, 8(%1, %%esi) \n\t"
1303 + "movq %%mm2, 16(%1, %%esi) \n\t"
1304 + "movq %%mm3, 24(%1, %%esi) \n\t"
1305 + "addl $32, %%esi \n\t"
1307 + :: "r" (src+256), "r" (dest+256), "m" (bias)
1312 +static void downmix_3dnow (sample_t * samples, int acmod, int output, sample_t bias,
1313 + sample_t clev, sample_t slev)
1315 + switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
1317 + case CONVERT (A52_CHANNEL, A52_CHANNEL2):
1318 + memcpy (samples, samples + 256, 256 * sizeof (sample_t));
1321 + case CONVERT (A52_CHANNEL, A52_MONO):
1322 + case CONVERT (A52_STEREO, A52_MONO):
1324 + mix2to1_3dnow (samples, samples + 256, bias);
1327 + case CONVERT (A52_2F1R, A52_MONO):
1329 + goto mix_2to1_3dnow;
1330 + case CONVERT (A52_3F, A52_MONO):
1332 + mix3to1_3dnow (samples, bias);
1335 + case CONVERT (A52_3F1R, A52_MONO):
1337 + goto mix_3to1_3dnow;
1338 + case CONVERT (A52_2F2R, A52_MONO):
1340 + goto mix_2to1_3dnow;
1341 + mix4to1_3dnow (samples, bias);
1344 + case CONVERT (A52_3F2R, A52_MONO):
1346 + goto mix_3to1_3dnow;
1347 + mix5to1_3dnow (samples, bias);
1350 + case CONVERT (A52_MONO, A52_DOLBY):
1351 + memcpy (samples + 256, samples, 256 * sizeof (sample_t));
1354 + case CONVERT (A52_3F, A52_STEREO):
1355 + case CONVERT (A52_3F, A52_DOLBY):
1357 + mix3to2_3dnow (samples, bias);
1360 + case CONVERT (A52_2F1R, A52_STEREO):
1363 + mix21to2_3dnow (samples, samples + 256, bias);
1366 + case CONVERT (A52_2F1R, A52_DOLBY):
1367 + mix21toS_3dnow (samples, bias);
1370 + case CONVERT (A52_3F1R, A52_STEREO):
1372 + goto mix_3to2_3dnow;
1373 + mix31to2_3dnow (samples, bias);
1376 + case CONVERT (A52_3F1R, A52_DOLBY):
1377 + mix31toS_3dnow (samples, bias);
1380 + case CONVERT (A52_2F2R, A52_STEREO):
1383 + mix2to1_3dnow (samples, samples + 512, bias);
1384 + mix2to1_3dnow (samples + 256, samples + 768, bias);
1387 + case CONVERT (A52_2F2R, A52_DOLBY):
1388 + mix22toS_3dnow (samples, bias);
1391 + case CONVERT (A52_3F2R, A52_STEREO):
1393 + goto mix_3to2_3dnow;
1394 + mix32to2_3dnow (samples, bias);
1397 + case CONVERT (A52_3F2R, A52_DOLBY):
1398 + mix32toS_3dnow (samples, bias);
1401 + case CONVERT (A52_3F1R, A52_3F):
1404 + mix21to2_3dnow (samples, samples + 512, bias);
1407 + case CONVERT (A52_3F2R, A52_3F):
1410 + mix2to1_3dnow (samples, samples + 768, bias);
1411 + mix2to1_3dnow (samples + 512, samples + 1024, bias);
1414 + case CONVERT (A52_3F1R, A52_2F1R):
1415 + mix3to2_3dnow (samples, bias);
1416 + memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
1419 + case CONVERT (A52_2F2R, A52_2F1R):
1420 + mix2to1_3dnow (samples + 512, samples + 768, bias);
1423 + case CONVERT (A52_3F2R, A52_2F1R):
1424 + mix3to2_3dnow (samples, bias); //FIXME possible bug? (output doesnt seem to be used)
1425 + move2to1_3dnow (samples + 768, samples + 512, bias);
1428 + case CONVERT (A52_3F2R, A52_3F1R):
1429 + mix2to1_3dnow (samples + 768, samples + 1024, bias);
1432 + case CONVERT (A52_2F1R, A52_2F2R):
1433 + memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
1436 + case CONVERT (A52_3F1R, A52_2F2R):
1437 + mix3to2_3dnow (samples, bias);
1438 + memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
1441 + case CONVERT (A52_3F2R, A52_2F2R):
1442 + mix3to2_3dnow (samples, bias);
1443 + memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
1444 + memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
1447 + case CONVERT (A52_3F1R, A52_3F2R):
1448 + memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
1451 + __asm __volatile("femms":::"memory");
1455 --- liba52/imdct.c 2005-03-22 19:59:35.000000000 +0100
1456 +++ imdct.c 2004-04-26 22:00:57.000000000 +0200
1458 * You should have received a copy of the GNU General Public License
1459 * along with this program; if not, write to the Free Software
1460 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1462 + * SSE optimizations from Michael Niedermayer (michaelni@gmx.at)
1463 + * 3DNOW optimizations from Nick Kurshev <nickols_k@mail.ru>
1464 + * michael did port them from libac3 (untested, perhaps totally broken)
1465 + * AltiVec optimizations from Romain Dolbeau (romain@dolbeau.org)
1470 -#include <inttypes.h>
1474 +#define M_PI 3.1415926535897932384626433832795029
1476 +#include <inttypes.h>
1479 #include "a52_internal.h"
1480 #include "mm_accel.h"
1481 +#include "mangle.h"
1483 +#ifdef RUNTIME_CPUDETECT
1484 +#undef HAVE_3DNOWEX
1489 void (* imdct_256) (sample_t data[], sample_t delay[], sample_t bias);
1490 void (* imdct_512) (sample_t data[], sample_t delay[], sample_t bias);
1495 +static void fft_128p(complex_t *a);
1497 +static const int pm128[128] attribute_used __attribute__((aligned(16))) =
1499 + 0, 16, 32, 48, 64, 80, 96, 112, 8, 40, 72, 104, 24, 56, 88, 120,
1500 + 4, 20, 36, 52, 68, 84, 100, 116, 12, 28, 44, 60, 76, 92, 108, 124,
1501 + 2, 18, 34, 50, 66, 82, 98, 114, 10, 42, 74, 106, 26, 58, 90, 122,
1502 + 6, 22, 38, 54, 70, 86, 102, 118, 14, 46, 78, 110, 30, 62, 94, 126,
1503 + 1, 17, 33, 49, 65, 81, 97, 113, 9, 41, 73, 105, 25, 57, 89, 121,
1504 + 5, 21, 37, 53, 69, 85, 101, 117, 13, 29, 45, 61, 77, 93, 109, 125,
1505 + 3, 19, 35, 51, 67, 83, 99, 115, 11, 43, 75, 107, 27, 59, 91, 123,
1506 + 7, 23, 39, 55, 71, 87, 103, 119, 15, 31, 47, 63, 79, 95, 111, 127
1509 /* 128 point bit-reverse LUT */
1510 -static uint8_t bit_reverse_512[] = {
1511 +static uint8_t attribute_used bit_reverse_512[] = {
1512 0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70,
1513 0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78,
1514 0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74,
1515 @@ -67,23 +101,42 @@
1516 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b,
1517 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f};
1519 -static complex_t buf[128];
1521 +// NOTE: SSE needs 16byte alignment or it will segfault
1523 +static complex_t __attribute__((aligned(16))) buf[128];
1524 +static float __attribute__((aligned(16))) sseSinCos1c[256];
1525 +static float __attribute__((aligned(16))) sseSinCos1d[256];
1526 +static float attribute_used __attribute__((aligned(16))) ps111_1[4]={1,1,1,-1};
1527 +//static float __attribute__((aligned(16))) sseW0[4];
1528 +static float __attribute__((aligned(16))) sseW1[8];
1529 +static float __attribute__((aligned(16))) sseW2[16];
1530 +static float __attribute__((aligned(16))) sseW3[32];
1531 +static float __attribute__((aligned(16))) sseW4[64];
1532 +static float __attribute__((aligned(16))) sseW5[128];
1533 +static float __attribute__((aligned(16))) sseW6[256];
1534 +static float __attribute__((aligned(16))) *sseW[7]=
1535 + {NULL /*sseW0*/,sseW1,sseW2,sseW3,sseW4,sseW5,sseW6};
1536 +static float __attribute__((aligned(16))) sseWindow[512];
1538 +static complex_t __attribute__((aligned(16))) buf[128];
1541 /* Twiddle factor LUT */
1542 -static complex_t w_1[1];
1543 -static complex_t w_2[2];
1544 -static complex_t w_4[4];
1545 -static complex_t w_8[8];
1546 -static complex_t w_16[16];
1547 -static complex_t w_32[32];
1548 -static complex_t w_64[64];
1549 -static complex_t * w[7] = {w_1, w_2, w_4, w_8, w_16, w_32, w_64};
1550 +static complex_t __attribute__((aligned(16))) w_1[1];
1551 +static complex_t __attribute__((aligned(16))) w_2[2];
1552 +static complex_t __attribute__((aligned(16))) w_4[4];
1553 +static complex_t __attribute__((aligned(16))) w_8[8];
1554 +static complex_t __attribute__((aligned(16))) w_16[16];
1555 +static complex_t __attribute__((aligned(16))) w_32[32];
1556 +static complex_t __attribute__((aligned(16))) w_64[64];
1557 +static complex_t __attribute__((aligned(16))) * w[7] = {w_1, w_2, w_4, w_8, w_16, w_32, w_64};
1559 /* Twiddle factors for IMDCT */
1560 -static sample_t xcos1[128];
1561 -static sample_t xsin1[128];
1562 -static sample_t xcos2[64];
1563 -static sample_t xsin2[64];
1564 +static sample_t __attribute__((aligned(16))) xcos1[128];
1565 +static sample_t __attribute__((aligned(16))) xsin1[128];
1566 +static sample_t __attribute__((aligned(16))) xcos2[64];
1567 +static sample_t __attribute__((aligned(16))) xsin2[64];
1569 /* Windowing function for Modified DCT - Thank you acroread */
1570 sample_t imdct_window[] = {
1571 @@ -145,16 +198,19 @@
1573 imdct_do_512(sample_t data[],sample_t delay[], sample_t bias)
1593 sample_t *delay_ptr;
1594 @@ -162,22 +218,21 @@
1596 /* 512 IMDCT with source and dest data in 'data' */
1598 - /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
1599 + /* Pre IFFT complex multiply plus IFFT cmplx conjugate & reordering*/
1600 for( i=0; i < 128; i++) {
1601 /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
1602 - buf[i].real = (data[256-2*i-1] * xcos1[i]) - (data[2*i] * xsin1[i]);
1603 - buf[i].imag = -1.0 * ((data[2*i] * xcos1[i]) + (data[256-2*i-1] * xsin1[i]));
1606 - /* Bit reversed shuffling */
1607 - for(i=0; i<128; i++) {
1608 - k = bit_reverse_512[i];
1610 - swap_cmplx(&buf[i],&buf[k]);
1614 + int j= bit_reverse_512[i];
1616 + buf[i].real = (data[256-2*j-1] * xcos1[j]) - (data[2*j] * xsin1[j]);
1617 + buf[i].imag = -1.0 * ((data[2*j] * xcos1[j]) + (data[256-2*j-1] * xsin1[j]));
1621 - for (m=0; m < 7; m++) {
1622 +/* unoptimized variant
1623 + for (m=1; m < 7; m++) {
1629 two_m_plus_one = (1 << (m+1));
1631 - for(k = 0; k < two_m; k++) {
1632 - for(i = 0; i < 128; i += two_m_plus_one) {
1633 + for(i = 0; i < 128; i += two_m_plus_one) {
1634 + for(k = 0; k < two_m; k++) {
1637 tmp_a_r = buf[p].real;
1638 @@ -200,7 +255,102 @@
1644 + fft_128p (&buf[0]);
1647 + /* 1. iteration */
1648 + for(i = 0; i < 128; i += 2) {
1649 + tmp_a_r = buf[i].real;
1650 + tmp_a_i = buf[i].imag;
1651 + tmp_b_r = buf[i+1].real;
1652 + tmp_b_i = buf[i+1].imag;
1653 + buf[i].real = tmp_a_r + tmp_b_r;
1654 + buf[i].imag = tmp_a_i + tmp_b_i;
1655 + buf[i+1].real = tmp_a_r - tmp_b_r;
1656 + buf[i+1].imag = tmp_a_i - tmp_b_i;
1659 + /* 2. iteration */
1660 + // Note w[1]={{1,0}, {0,-1}}
1661 + for(i = 0; i < 128; i += 4) {
1662 + tmp_a_r = buf[i].real;
1663 + tmp_a_i = buf[i].imag;
1664 + tmp_b_r = buf[i+2].real;
1665 + tmp_b_i = buf[i+2].imag;
1666 + buf[i].real = tmp_a_r + tmp_b_r;
1667 + buf[i].imag = tmp_a_i + tmp_b_i;
1668 + buf[i+2].real = tmp_a_r - tmp_b_r;
1669 + buf[i+2].imag = tmp_a_i - tmp_b_i;
1670 + tmp_a_r = buf[i+1].real;
1671 + tmp_a_i = buf[i+1].imag;
1672 + tmp_b_r = buf[i+3].imag;
1673 + tmp_b_i = buf[i+3].real;
1674 + buf[i+1].real = tmp_a_r + tmp_b_r;
1675 + buf[i+1].imag = tmp_a_i - tmp_b_i;
1676 + buf[i+3].real = tmp_a_r - tmp_b_r;
1677 + buf[i+3].imag = tmp_a_i + tmp_b_i;
1680 + /* 3. iteration */
1681 + for(i = 0; i < 128; i += 8) {
1682 + tmp_a_r = buf[i].real;
1683 + tmp_a_i = buf[i].imag;
1684 + tmp_b_r = buf[i+4].real;
1685 + tmp_b_i = buf[i+4].imag;
1686 + buf[i].real = tmp_a_r + tmp_b_r;
1687 + buf[i].imag = tmp_a_i + tmp_b_i;
1688 + buf[i+4].real = tmp_a_r - tmp_b_r;
1689 + buf[i+4].imag = tmp_a_i - tmp_b_i;
1690 + tmp_a_r = buf[1+i].real;
1691 + tmp_a_i = buf[1+i].imag;
1692 + tmp_b_r = (buf[i+5].real + buf[i+5].imag) * w[2][1].real;
1693 + tmp_b_i = (buf[i+5].imag - buf[i+5].real) * w[2][1].real;
1694 + buf[1+i].real = tmp_a_r + tmp_b_r;
1695 + buf[1+i].imag = tmp_a_i + tmp_b_i;
1696 + buf[i+5].real = tmp_a_r - tmp_b_r;
1697 + buf[i+5].imag = tmp_a_i - tmp_b_i;
1698 + tmp_a_r = buf[i+2].real;
1699 + tmp_a_i = buf[i+2].imag;
1700 + tmp_b_r = buf[i+6].imag;
1701 + tmp_b_i = - buf[i+6].real;
1702 + buf[i+2].real = tmp_a_r + tmp_b_r;
1703 + buf[i+2].imag = tmp_a_i + tmp_b_i;
1704 + buf[i+6].real = tmp_a_r - tmp_b_r;
1705 + buf[i+6].imag = tmp_a_i - tmp_b_i;
1706 + tmp_a_r = buf[i+3].real;
1707 + tmp_a_i = buf[i+3].imag;
1708 + tmp_b_r = (buf[i+7].real - buf[i+7].imag) * w[2][3].imag;
1709 + tmp_b_i = (buf[i+7].imag + buf[i+7].real) * w[2][3].imag;
1710 + buf[i+3].real = tmp_a_r + tmp_b_r;
1711 + buf[i+3].imag = tmp_a_i + tmp_b_i;
1712 + buf[i+7].real = tmp_a_r - tmp_b_r;
1713 + buf[i+7].imag = tmp_a_i - tmp_b_i;
1716 + /* 4-7. iterations */
1717 + for (m=3; m < 7; m++) {
1720 + two_m_plus_one = two_m<<1;
1722 + for(i = 0; i < 128; i += two_m_plus_one) {
1723 + for(k = 0; k < two_m; k++) {
1725 + int q = p + two_m;
1726 + tmp_a_r = buf[p].real;
1727 + tmp_a_i = buf[p].imag;
1728 + tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
1729 + tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
1730 + buf[p].real = tmp_a_r + tmp_b_r;
1731 + buf[p].imag = tmp_a_i + tmp_b_i;
1732 + buf[q].real = tmp_a_r - tmp_b_r;
1733 + buf[q].imag = tmp_a_i - tmp_b_i;
1738 /* Post IFFT complex multiply plus IFFT complex conjugate*/
1739 for( i=0; i < 128; i++) {
1740 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
1741 @@ -219,12 +369,12 @@
1742 *data_ptr++ = -buf[64+i].imag * *window_ptr++ + *delay_ptr++ + bias;
1743 *data_ptr++ = buf[64-i-1].real * *window_ptr++ + *delay_ptr++ + bias;
1747 for(i=0; i< 64; i++) {
1748 *data_ptr++ = -buf[i].real * *window_ptr++ + *delay_ptr++ + bias;
1749 *data_ptr++ = buf[128-i-1].imag * *window_ptr++ + *delay_ptr++ + bias;
1753 /* The trailing edge of the window goes into the delay line */
1756 @@ -232,13 +382,717 @@
1757 *delay_ptr++ = -buf[64+i].real * *--window_ptr;
1758 *delay_ptr++ = buf[64-i-1].imag * *--window_ptr;
1762 for(i=0; i<64; i++) {
1763 *delay_ptr++ = buf[i].imag * *--window_ptr;
1764 *delay_ptr++ = -buf[128-i-1].real * *--window_ptr;
1768 +#ifdef HAVE_ALTIVEC
1771 +#include <altivec.h>
1774 +// used to build registers permutation vectors (vcprm)
1775 +// the 's' are for words in the _s_econd vector
1776 +#define WORD_0 0x00,0x01,0x02,0x03
1777 +#define WORD_1 0x04,0x05,0x06,0x07
1778 +#define WORD_2 0x08,0x09,0x0a,0x0b
1779 +#define WORD_3 0x0c,0x0d,0x0e,0x0f
1780 +#define WORD_s0 0x10,0x11,0x12,0x13
1781 +#define WORD_s1 0x14,0x15,0x16,0x17
1782 +#define WORD_s2 0x18,0x19,0x1a,0x1b
1783 +#define WORD_s3 0x1c,0x1d,0x1e,0x1f
1786 +#define vcprm(a,b,c,d) (const vector unsigned char)(WORD_ ## a, WORD_ ## b, WORD_ ## c, WORD_ ## d)
1788 +#define vcprm(a,b,c,d) (const vector unsigned char){WORD_ ## a, WORD_ ## b, WORD_ ## c, WORD_ ## d}
1791 +// vcprmle is used to keep the same index as in the SSE version.
1792 +// it's the same as vcprm, with the index inversed
1793 +// ('le' is Little Endian)
1794 +#define vcprmle(a,b,c,d) vcprm(d,c,b,a)
1796 +// used to build inverse/identity vectors (vcii)
1797 +// n is _n_egative, p is _p_ositive
1798 +#define FLOAT_n -1.
1802 +#define vcii(a,b,c,d) (const vector float)(FLOAT_ ## a, FLOAT_ ## b, FLOAT_ ## c, FLOAT_ ## d)
1804 +#define vcii(a,b,c,d) (const vector float){FLOAT_ ## a, FLOAT_ ## b, FLOAT_ ## c, FLOAT_ ## d}
1808 +#define FOUROF(a) (a)
1810 +#define FOUROF(a) {a,a,a,a}
1815 +imdct_do_512_altivec(sample_t data[],sample_t delay[], sample_t bias)
1822 + int two_m_plus_one;
1829 + sample_t *data_ptr;
1830 + sample_t *delay_ptr;
1831 + sample_t *window_ptr;
1833 + /* 512 IMDCT with source and dest data in 'data' */
1835 + /* Pre IFFT complex multiply plus IFFT cmplx conjugate & reordering*/
1836 + for( i=0; i < 128; i++) {
1837 + /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
1838 + int j= bit_reverse_512[i];
1839 + buf[i].real = (data[256-2*j-1] * xcos1[j]) - (data[2*j] * xsin1[j]);
1840 + buf[i].imag = -1.0 * ((data[2*j] * xcos1[j]) + (data[256-2*j-1] * xsin1[j]));
1843 + /* 1. iteration */
1844 + for(i = 0; i < 128; i += 2) {
1846 + tmp_a_r = buf[i].real;
1847 + tmp_a_i = buf[i].imag;
1848 + tmp_b_r = buf[i+1].real;
1849 + tmp_b_i = buf[i+1].imag;
1850 + buf[i].real = tmp_a_r + tmp_b_r;
1851 + buf[i].imag = tmp_a_i + tmp_b_i;
1852 + buf[i+1].real = tmp_a_r - tmp_b_r;
1853 + buf[i+1].imag = tmp_a_i - tmp_b_i;
1855 + vector float temp, bufv;
1857 + bufv = vec_ld(i << 3, (float*)buf);
1858 + temp = vec_perm(bufv, bufv, vcprm(2,3,0,1));
1859 + bufv = vec_madd(bufv, vcii(p,p,n,n), temp);
1860 + vec_st(bufv, i << 3, (float*)buf);
1864 + /* 2. iteration */
1865 + // Note w[1]={{1,0}, {0,-1}}
1866 + for(i = 0; i < 128; i += 4) {
1868 + tmp_a_r = buf[i].real;
1869 + tmp_a_i = buf[i].imag;
1870 + tmp_b_r = buf[i+2].real;
1871 + tmp_b_i = buf[i+2].imag;
1872 + buf[i].real = tmp_a_r + tmp_b_r;
1873 + buf[i].imag = tmp_a_i + tmp_b_i;
1874 + buf[i+2].real = tmp_a_r - tmp_b_r;
1875 + buf[i+2].imag = tmp_a_i - tmp_b_i;
1876 + tmp_a_r = buf[i+1].real;
1877 + tmp_a_i = buf[i+1].imag;
1878 + /* WARNING: im <-> re here ! */
1879 + tmp_b_r = buf[i+3].imag;
1880 + tmp_b_i = buf[i+3].real;
1881 + buf[i+1].real = tmp_a_r + tmp_b_r;
1882 + buf[i+1].imag = tmp_a_i - tmp_b_i;
1883 + buf[i+3].real = tmp_a_r - tmp_b_r;
1884 + buf[i+3].imag = tmp_a_i + tmp_b_i;
1886 + vector float buf01, buf23, temp1, temp2;
1888 + buf01 = vec_ld((i + 0) << 3, (float*)buf);
1889 + buf23 = vec_ld((i + 2) << 3, (float*)buf);
1890 + buf23 = vec_perm(buf23,buf23,vcprm(0,1,3,2));
1892 + temp1 = vec_madd(buf23, vcii(p,p,p,n), buf01);
1893 + temp2 = vec_madd(buf23, vcii(n,n,n,p), buf01);
1895 + vec_st(temp1, (i + 0) << 3, (float*)buf);
1896 + vec_st(temp2, (i + 2) << 3, (float*)buf);
1900 + /* 3. iteration */
1901 + for(i = 0; i < 128; i += 8) {
1903 + tmp_a_r = buf[i].real;
1904 + tmp_a_i = buf[i].imag;
1905 + tmp_b_r = buf[i+4].real;
1906 + tmp_b_i = buf[i+4].imag;
1907 + buf[i].real = tmp_a_r + tmp_b_r;
1908 + buf[i].imag = tmp_a_i + tmp_b_i;
1909 + buf[i+4].real = tmp_a_r - tmp_b_r;
1910 + buf[i+4].imag = tmp_a_i - tmp_b_i;
1911 + tmp_a_r = buf[1+i].real;
1912 + tmp_a_i = buf[1+i].imag;
1913 + tmp_b_r = (buf[i+5].real + buf[i+5].imag) * w[2][1].real;
1914 + tmp_b_i = (buf[i+5].imag - buf[i+5].real) * w[2][1].real;
1915 + buf[1+i].real = tmp_a_r + tmp_b_r;
1916 + buf[1+i].imag = tmp_a_i + tmp_b_i;
1917 + buf[i+5].real = tmp_a_r - tmp_b_r;
1918 + buf[i+5].imag = tmp_a_i - tmp_b_i;
1919 + tmp_a_r = buf[i+2].real;
1920 + tmp_a_i = buf[i+2].imag;
1921 + /* WARNING re <-> im & sign */
1922 + tmp_b_r = buf[i+6].imag;
1923 + tmp_b_i = - buf[i+6].real;
1924 + buf[i+2].real = tmp_a_r + tmp_b_r;
1925 + buf[i+2].imag = tmp_a_i + tmp_b_i;
1926 + buf[i+6].real = tmp_a_r - tmp_b_r;
1927 + buf[i+6].imag = tmp_a_i - tmp_b_i;
1928 + tmp_a_r = buf[i+3].real;
1929 + tmp_a_i = buf[i+3].imag;
1930 + tmp_b_r = (buf[i+7].real - buf[i+7].imag) * w[2][3].imag;
1931 + tmp_b_i = (buf[i+7].imag + buf[i+7].real) * w[2][3].imag;
1932 + buf[i+3].real = tmp_a_r + tmp_b_r;
1933 + buf[i+3].imag = tmp_a_i + tmp_b_i;
1934 + buf[i+7].real = tmp_a_r - tmp_b_r;
1935 + buf[i+7].imag = tmp_a_i - tmp_b_i;
1937 + vector float buf01, buf23, buf45, buf67;
1939 + buf01 = vec_ld((i + 0) << 3, (float*)buf);
1940 + buf23 = vec_ld((i + 2) << 3, (float*)buf);
1942 + tmp_b_r = (buf[i+5].real + buf[i+5].imag) * w[2][1].real;
1943 + tmp_b_i = (buf[i+5].imag - buf[i+5].real) * w[2][1].real;
1944 + buf[i+5].real = tmp_b_r;
1945 + buf[i+5].imag = tmp_b_i;
1946 + tmp_b_r = (buf[i+7].real - buf[i+7].imag) * w[2][3].imag;
1947 + tmp_b_i = (buf[i+7].imag + buf[i+7].real) * w[2][3].imag;
1948 + buf[i+7].real = tmp_b_r;
1949 + buf[i+7].imag = tmp_b_i;
1951 + buf23 = vec_ld((i + 2) << 3, (float*)buf);
1952 + buf45 = vec_ld((i + 4) << 3, (float*)buf);
1953 + buf67 = vec_ld((i + 6) << 3, (float*)buf);
1954 + buf67 = vec_perm(buf67, buf67, vcprm(1,0,2,3));
1956 + vec_st(vec_add(buf01, buf45), (i + 0) << 3, (float*)buf);
1957 + vec_st(vec_madd(buf67, vcii(p,n,p,p), buf23), (i + 2) << 3, (float*)buf);
1958 + vec_st(vec_sub(buf01, buf45), (i + 4) << 3, (float*)buf);
1959 + vec_st(vec_nmsub(buf67, vcii(p,n,p,p), buf23), (i + 6) << 3, (float*)buf);
1963 + /* 4-7. iterations */
1964 + for (m=3; m < 7; m++) {
1967 + two_m_plus_one = two_m<<1;
1969 + for(i = 0; i < 128; i += two_m_plus_one) {
1970 + for(k = 0; k < two_m; k+=2) {
1973 + int q = p + two_m;
1974 + tmp_a_r = buf[p].real;
1975 + tmp_a_i = buf[p].imag;
1977 + buf[q].real * w[m][k].real -
1978 + buf[q].imag * w[m][k].imag;
1980 + buf[q].imag * w[m][k].real +
1981 + buf[q].real * w[m][k].imag;
1982 + buf[p].real = tmp_a_r + tmp_b_r;
1983 + buf[p].imag = tmp_a_i + tmp_b_i;
1984 + buf[q].real = tmp_a_r - tmp_b_r;
1985 + buf[q].imag = tmp_a_i - tmp_b_i;
1987 + tmp_a_r = buf[(p + 1)].real;
1988 + tmp_a_i = buf[(p + 1)].imag;
1990 + buf[(q + 1)].real * w[m][(k + 1)].real -
1991 + buf[(q + 1)].imag * w[m][(k + 1)].imag;
1993 + buf[(q + 1)].imag * w[m][(k + 1)].real +
1994 + buf[(q + 1)].real * w[m][(k + 1)].imag;
1995 + buf[(p + 1)].real = tmp_a_r + tmp_b_r;
1996 + buf[(p + 1)].imag = tmp_a_i + tmp_b_i;
1997 + buf[(q + 1)].real = tmp_a_r - tmp_b_r;
1998 + buf[(q + 1)].imag = tmp_a_i - tmp_b_i;
2001 + int q = p + two_m;
2002 + vector float vecp, vecq, vecw, temp1, temp2, temp3, temp4;
2003 + const vector float vczero = (const vector float)FOUROF(0.);
2004 + // first compute buf[q] and buf[q+1]
2005 + vecq = vec_ld(q << 3, (float*)buf);
2006 + vecw = vec_ld(0, (float*)&(w[m][k]));
2007 + temp1 = vec_madd(vecq, vecw, vczero);
2008 + temp2 = vec_perm(vecq, vecq, vcprm(1,0,3,2));
2009 + temp2 = vec_madd(temp2, vecw, vczero);
2010 + temp3 = vec_perm(temp1, temp2, vcprm(0,s0,2,s2));
2011 + temp4 = vec_perm(temp1, temp2, vcprm(1,s1,3,s3));
2012 + vecq = vec_madd(temp4, vcii(n,p,n,p), temp3);
2013 + // then butterfly with buf[p] and buf[p+1]
2014 + vecp = vec_ld(p << 3, (float*)buf);
2016 + temp1 = vec_add(vecp, vecq);
2017 + temp2 = vec_sub(vecp, vecq);
2019 + vec_st(temp1, p << 3, (float*)buf);
2020 + vec_st(temp2, q << 3, (float*)buf);
2026 + /* Post IFFT complex multiply plus IFFT complex conjugate*/
2027 + for( i=0; i < 128; i+=4) {
2028 + /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
2030 + tmp_a_r = buf[(i + 0)].real;
2031 + tmp_a_i = -1.0 * buf[(i + 0)].imag;
2032 + buf[(i + 0)].real =
2033 + (tmp_a_r * xcos1[(i + 0)]) - (tmp_a_i * xsin1[(i + 0)]);
2034 + buf[(i + 0)].imag =
2035 + (tmp_a_r * xsin1[(i + 0)]) + (tmp_a_i * xcos1[(i + 0)]);
2037 + tmp_a_r = buf[(i + 1)].real;
2038 + tmp_a_i = -1.0 * buf[(i + 1)].imag;
2039 + buf[(i + 1)].real =
2040 + (tmp_a_r * xcos1[(i + 1)]) - (tmp_a_i * xsin1[(i + 1)]);
2041 + buf[(i + 1)].imag =
2042 + (tmp_a_r * xsin1[(i + 1)]) + (tmp_a_i * xcos1[(i + 1)]);
2044 + tmp_a_r = buf[(i + 2)].real;
2045 + tmp_a_i = -1.0 * buf[(i + 2)].imag;
2046 + buf[(i + 2)].real =
2047 + (tmp_a_r * xcos1[(i + 2)]) - (tmp_a_i * xsin1[(i + 2)]);
2048 + buf[(i + 2)].imag =
2049 + (tmp_a_r * xsin1[(i + 2)]) + (tmp_a_i * xcos1[(i + 2)]);
2051 + tmp_a_r = buf[(i + 3)].real;
2052 + tmp_a_i = -1.0 * buf[(i + 3)].imag;
2053 + buf[(i + 3)].real =
2054 + (tmp_a_r * xcos1[(i + 3)]) - (tmp_a_i * xsin1[(i + 3)]);
2055 + buf[(i + 3)].imag =
2056 + (tmp_a_r * xsin1[(i + 3)]) + (tmp_a_i * xcos1[(i + 3)]);
2058 + vector float bufv_0, bufv_2, cosv, sinv, temp1, temp2;
2059 + vector float temp0022, temp1133, tempCS01;
2060 + const vector float vczero = (const vector float)FOUROF(0.);
2062 + bufv_0 = vec_ld((i + 0) << 3, (float*)buf);
2063 + bufv_2 = vec_ld((i + 2) << 3, (float*)buf);
2065 + cosv = vec_ld(i << 2, xcos1);
2066 + sinv = vec_ld(i << 2, xsin1);
2068 + temp0022 = vec_perm(bufv_0, bufv_0, vcprm(0,0,2,2));
2069 + temp1133 = vec_perm(bufv_0, bufv_0, vcprm(1,1,3,3));
2070 + tempCS01 = vec_perm(cosv, sinv, vcprm(0,s0,1,s1));
2071 + temp1 = vec_madd(temp0022, tempCS01, vczero);
2072 + tempCS01 = vec_perm(cosv, sinv, vcprm(s0,0,s1,1));
2073 + temp2 = vec_madd(temp1133, tempCS01, vczero);
2074 + bufv_0 = vec_madd(temp2, vcii(p,n,p,n), temp1);
2076 + vec_st(bufv_0, (i + 0) << 3, (float*)buf);
2078 + /* idem with bufv_2 and high-order cosv/sinv */
2080 + temp0022 = vec_perm(bufv_2, bufv_2, vcprm(0,0,2,2));
2081 + temp1133 = vec_perm(bufv_2, bufv_2, vcprm(1,1,3,3));
2082 + tempCS01 = vec_perm(cosv, sinv, vcprm(2,s2,3,s3));
2083 + temp1 = vec_madd(temp0022, tempCS01, vczero);
2084 + tempCS01 = vec_perm(cosv, sinv, vcprm(s2,2,s3,3));
2085 + temp2 = vec_madd(temp1133, tempCS01, vczero);
2086 + bufv_2 = vec_madd(temp2, vcii(p,n,p,n), temp1);
2088 + vec_st(bufv_2, (i + 2) << 3, (float*)buf);
2094 + delay_ptr = delay;
2095 + window_ptr = imdct_window;
2097 + /* Window and convert to real valued signal */
2098 + for(i=0; i< 64; i++) {
2099 + *data_ptr++ = -buf[64+i].imag * *window_ptr++ + *delay_ptr++ + bias;
2100 + *data_ptr++ = buf[64-i-1].real * *window_ptr++ + *delay_ptr++ + bias;
2103 + for(i=0; i< 64; i++) {
2104 + *data_ptr++ = -buf[i].real * *window_ptr++ + *delay_ptr++ + bias;
2105 + *data_ptr++ = buf[128-i-1].imag * *window_ptr++ + *delay_ptr++ + bias;
2108 + /* The trailing edge of the window goes into the delay line */
2109 + delay_ptr = delay;
2111 + for(i=0; i< 64; i++) {
2112 + *delay_ptr++ = -buf[64+i].real * *--window_ptr;
2113 + *delay_ptr++ = buf[64-i-1].imag * *--window_ptr;
2116 + for(i=0; i<64; i++) {
2117 + *delay_ptr++ = buf[i].imag * *--window_ptr;
2118 + *delay_ptr++ = -buf[128-i-1].real * *--window_ptr;
2124 +// Stuff below this line is borrowed from libac3
2125 +#include "srfftp.h"
2128 +#define HAVE_3DNOW 1
2130 +#include "srfftp_3dnow.h"
2132 +const i_cmplx_t x_plus_minus_3dnow __attribute__ ((aligned (8))) = {{ 0x00000000UL, 0x80000000UL }};
2133 +const i_cmplx_t x_minus_plus_3dnow __attribute__ ((aligned (8))) = {{ 0x80000000UL, 0x00000000UL }};
2134 +const complex_t HSQRT2_3DNOW __attribute__ ((aligned (8))) = { 0.707106781188, 0.707106781188 };
2136 +#undef HAVE_3DNOWEX
2137 +#include "imdct_3dnow.h"
2138 +#define HAVE_3DNOWEX
2139 +#include "imdct_3dnow.h"
2142 +imdct_do_512_sse(sample_t data[],sample_t delay[], sample_t bias)
2148 + int two_m_plus_one;
2150 +/* sample_t tmp_a_i;
2153 + sample_t tmp_b_r;*/
2155 + sample_t *data_ptr;
2156 + sample_t *delay_ptr;
2157 + sample_t *window_ptr;
2159 + /* 512 IMDCT with source and dest data in 'data' */
2160 + /* see the c version (dct_do_512()), its allmost identical, just in C */
2162 + /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
2163 + /* Bit reversed shuffling */
2165 + "xorl %%esi, %%esi \n\t"
2166 + "leal "MANGLE(bit_reverse_512)", %%eax \n\t"
2167 + "movl $1008, %%edi \n\t"
2168 + "pushl %%ebp \n\t" //use ebp without telling gcc
2171 + "movlps (%0, %%esi), %%xmm0 \n\t" // XXXI
2172 + "movhps 8(%0, %%edi), %%xmm0 \n\t" // RXXI
2173 + "movlps 8(%0, %%esi), %%xmm1 \n\t" // XXXi
2174 + "movhps (%0, %%edi), %%xmm1 \n\t" // rXXi
2175 + "shufps $0x33, %%xmm1, %%xmm0 \n\t" // irIR
2176 + "movaps "MANGLE(sseSinCos1c)"(%%esi), %%xmm2\n\t"
2177 + "mulps %%xmm0, %%xmm2 \n\t"
2178 + "shufps $0xB1, %%xmm0, %%xmm0 \n\t" // riRI
2179 + "mulps "MANGLE(sseSinCos1d)"(%%esi), %%xmm0\n\t"
2180 + "subps %%xmm0, %%xmm2 \n\t"
2181 + "movzbl (%%eax), %%edx \n\t"
2182 + "movzbl 1(%%eax), %%ebp \n\t"
2183 + "movlps %%xmm2, (%1, %%edx,8) \n\t"
2184 + "movhps %%xmm2, (%1, %%ebp,8) \n\t"
2185 + "addl $16, %%esi \n\t"
2186 + "addl $2, %%eax \n\t" // avoid complex addressing for P4 crap
2187 + "subl $16, %%edi \n\t"
2189 + "popl %%ebp \n\t"//no we didnt touch ebp *g*
2190 + :: "b" (data), "c" (buf)
2191 + : "%esi", "%edi", "%eax", "%edx"
2196 +/* unoptimized variant
2197 + for (m=1; m < 7; m++) {
2203 + two_m_plus_one = (1 << (m+1));
2205 + for(i = 0; i < 128; i += two_m_plus_one) {
2206 + for(k = 0; k < two_m; k++) {
2209 + tmp_a_r = buf[p].real;
2210 + tmp_a_i = buf[p].imag;
2211 + tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
2212 + tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
2213 + buf[p].real = tmp_a_r + tmp_b_r;
2214 + buf[p].imag = tmp_a_i + tmp_b_i;
2215 + buf[q].real = tmp_a_r - tmp_b_r;
2216 + buf[q].imag = tmp_a_i - tmp_b_i;
2222 + /* 1. iteration */
2223 + // Note w[0][0]={1,0}
2225 + "xorps %%xmm1, %%xmm1 \n\t"
2226 + "xorps %%xmm2, %%xmm2 \n\t"
2227 + "movl %0, %%esi \n\t"
2230 + "movlps (%%esi), %%xmm0 \n\t" //buf[p]
2231 + "movlps 8(%%esi), %%xmm1\n\t" //buf[q]
2232 + "movhps (%%esi), %%xmm0 \n\t" //buf[p]
2233 + "movhps 8(%%esi), %%xmm2\n\t" //buf[q]
2234 + "addps %%xmm1, %%xmm0 \n\t"
2235 + "subps %%xmm2, %%xmm0 \n\t"
2236 + "movaps %%xmm0, (%%esi) \n\t"
2237 + "addl $16, %%esi \n\t"
2238 + "cmpl %1, %%esi \n\t"
2240 + :: "g" (buf), "r" (buf + 128)
2244 + /* 2. iteration */
2245 + // Note w[1]={{1,0}, {0,-1}}
2247 + "movaps "MANGLE(ps111_1)", %%xmm7\n\t" // 1,1,1,-1
2248 + "movl %0, %%esi \n\t"
2251 + "movaps 16(%%esi), %%xmm2 \n\t" //r2,i2,r3,i3
2252 + "shufps $0xB4, %%xmm2, %%xmm2 \n\t" //r2,i2,i3,r3
2253 + "mulps %%xmm7, %%xmm2 \n\t" //r2,i2,i3,-r3
2254 + "movaps (%%esi), %%xmm0 \n\t" //r0,i0,r1,i1
2255 + "movaps (%%esi), %%xmm1 \n\t" //r0,i0,r1,i1
2256 + "addps %%xmm2, %%xmm0 \n\t"
2257 + "subps %%xmm2, %%xmm1 \n\t"
2258 + "movaps %%xmm0, (%%esi) \n\t"
2259 + "movaps %%xmm1, 16(%%esi) \n\t"
2260 + "addl $32, %%esi \n\t"
2261 + "cmpl %1, %%esi \n\t"
2263 + :: "g" (buf), "r" (buf + 128)
2267 + /* 3. iteration */
2269 + Note sseW2+0={1,1,sqrt(2),sqrt(2))
2270 + Note sseW2+16={0,0,sqrt(2),-sqrt(2))
2271 + Note sseW2+32={0,0,-sqrt(2),-sqrt(2))
2272 + Note sseW2+48={1,-1,sqrt(2),-sqrt(2))
2275 + "movaps 48+"MANGLE(sseW2)", %%xmm6\n\t"
2276 + "movaps 16+"MANGLE(sseW2)", %%xmm7\n\t"
2277 + "xorps %%xmm5, %%xmm5 \n\t"
2278 + "xorps %%xmm2, %%xmm2 \n\t"
2279 + "movl %0, %%esi \n\t"
2282 + "movaps 32(%%esi), %%xmm2 \n\t" //r4,i4,r5,i5
2283 + "movaps 48(%%esi), %%xmm3 \n\t" //r6,i6,r7,i7
2284 + "movaps "MANGLE(sseW2)", %%xmm4 \n\t" //r4,i4,r5,i5
2285 + "movaps 32+"MANGLE(sseW2)", %%xmm5\n\t" //r6,i6,r7,i7
2286 + "mulps %%xmm2, %%xmm4 \n\t"
2287 + "mulps %%xmm3, %%xmm5 \n\t"
2288 + "shufps $0xB1, %%xmm2, %%xmm2 \n\t" //i4,r4,i5,r5
2289 + "shufps $0xB1, %%xmm3, %%xmm3 \n\t" //i6,r6,i7,r7
2290 + "mulps %%xmm6, %%xmm3 \n\t"
2291 + "mulps %%xmm7, %%xmm2 \n\t"
2292 + "movaps (%%esi), %%xmm0 \n\t" //r0,i0,r1,i1
2293 + "movaps 16(%%esi), %%xmm1 \n\t" //r2,i2,r3,i3
2294 + "addps %%xmm4, %%xmm2 \n\t"
2295 + "addps %%xmm5, %%xmm3 \n\t"
2296 + "movaps %%xmm2, %%xmm4 \n\t"
2297 + "movaps %%xmm3, %%xmm5 \n\t"
2298 + "addps %%xmm0, %%xmm2 \n\t"
2299 + "addps %%xmm1, %%xmm3 \n\t"
2300 + "subps %%xmm4, %%xmm0 \n\t"
2301 + "subps %%xmm5, %%xmm1 \n\t"
2302 + "movaps %%xmm2, (%%esi) \n\t"
2303 + "movaps %%xmm3, 16(%%esi) \n\t"
2304 + "movaps %%xmm0, 32(%%esi) \n\t"
2305 + "movaps %%xmm1, 48(%%esi) \n\t"
2306 + "addl $64, %%esi \n\t"
2307 + "cmpl %1, %%esi \n\t"
2309 + :: "g" (buf), "r" (buf + 128)
2313 + /* 4-7. iterations */
2314 + for (m=3; m < 7; m++) {
2316 + two_m_plus_one = two_m<<1;
2318 + "movl %0, %%esi \n\t"
2321 + "xorl %%edi, %%edi \n\t" // k
2322 + "leal (%%esi, %3), %%edx \n\t"
2324 + "movaps (%%edx, %%edi), %%xmm1 \n\t"
2325 + "movaps (%4, %%edi, 2), %%xmm2 \n\t"
2326 + "mulps %%xmm1, %%xmm2 \n\t"
2327 + "shufps $0xB1, %%xmm1, %%xmm1 \n\t"
2328 + "mulps 16(%4, %%edi, 2), %%xmm1 \n\t"
2329 + "movaps (%%esi, %%edi), %%xmm0 \n\t"
2330 + "addps %%xmm2, %%xmm1 \n\t"
2331 + "movaps %%xmm1, %%xmm2 \n\t"
2332 + "addps %%xmm0, %%xmm1 \n\t"
2333 + "subps %%xmm2, %%xmm0 \n\t"
2334 + "movaps %%xmm1, (%%esi, %%edi) \n\t"
2335 + "movaps %%xmm0, (%%edx, %%edi) \n\t"
2336 + "addl $16, %%edi \n\t"
2337 + "cmpl %3, %%edi \n\t" //FIXME (opt) count against 0
2339 + "addl %2, %%esi \n\t"
2340 + "cmpl %1, %%esi \n\t"
2342 + :: "g" (buf), "m" (buf+128), "m" (two_m_plus_one<<3), "r" (two_m<<3),
2344 + : "%esi", "%edi", "%edx"
2348 + /* Post IFFT complex multiply plus IFFT complex conjugate*/
2350 + "movl $-1024, %%esi \n\t"
2353 + "movaps (%0, %%esi), %%xmm0 \n\t"
2354 + "movaps (%0, %%esi), %%xmm1 \n\t"
2355 + "shufps $0xB1, %%xmm0, %%xmm0 \n\t"
2356 + "mulps 1024+"MANGLE(sseSinCos1c)"(%%esi), %%xmm1\n\t"
2357 + "mulps 1024+"MANGLE(sseSinCos1d)"(%%esi), %%xmm0\n\t"
2358 + "addps %%xmm1, %%xmm0 \n\t"
2359 + "movaps %%xmm0, (%0, %%esi) \n\t"
2360 + "addl $16, %%esi \n\t"
2368 + delay_ptr = delay;
2369 + window_ptr = imdct_window;
2371 + /* Window and convert to real valued signal */
2373 + "xorl %%edi, %%edi \n\t" // 0
2374 + "xorl %%esi, %%esi \n\t" // 0
2375 + "movss %3, %%xmm2 \n\t" // bias
2376 + "shufps $0x00, %%xmm2, %%xmm2 \n\t" // bias, bias, ...
2379 + "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? A ?
2380 + "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? C ?
2381 + "movhps -16(%0, %%edi), %%xmm1 \n\t" // ? D C ?
2382 + "movhps -8(%0, %%edi), %%xmm0 \n\t" // ? B A ?
2383 + "shufps $0x99, %%xmm1, %%xmm0 \n\t" // D C B A
2384 + "mulps "MANGLE(sseWindow)"(%%esi), %%xmm0\n\t"
2385 + "addps (%2, %%esi), %%xmm0 \n\t"
2386 + "addps %%xmm2, %%xmm0 \n\t"
2387 + "movaps %%xmm0, (%1, %%esi) \n\t"
2388 + "addl $16, %%esi \n\t"
2389 + "subl $16, %%edi \n\t"
2390 + "cmpl $512, %%esi \n\t"
2392 + :: "r" (buf+64), "r" (data_ptr), "r" (delay_ptr), "m" (bias)
2397 +// window_ptr+=128;
2400 + "movl $1024, %%edi \n\t" // 512
2401 + "xorl %%esi, %%esi \n\t" // 0
2402 + "movss %3, %%xmm2 \n\t" // bias
2403 + "shufps $0x00, %%xmm2, %%xmm2 \n\t" // bias, bias, ...
2406 + "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? ? A
2407 + "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? ? C
2408 + "movhps -16(%0, %%edi), %%xmm1 \n\t" // D ? ? C
2409 + "movhps -8(%0, %%edi), %%xmm0 \n\t" // B ? ? A
2410 + "shufps $0xCC, %%xmm1, %%xmm0 \n\t" // D C B A
2411 + "mulps 512+"MANGLE(sseWindow)"(%%esi), %%xmm0\n\t"
2412 + "addps (%2, %%esi), %%xmm0 \n\t"
2413 + "addps %%xmm2, %%xmm0 \n\t"
2414 + "movaps %%xmm0, (%1, %%esi) \n\t"
2415 + "addl $16, %%esi \n\t"
2416 + "subl $16, %%edi \n\t"
2417 + "cmpl $512, %%esi \n\t"
2419 + :: "r" (buf), "r" (data_ptr), "r" (delay_ptr), "m" (bias)
2423 +// window_ptr+=128;
2425 + /* The trailing edge of the window goes into the delay line */
2426 + delay_ptr = delay;
2429 + "xorl %%edi, %%edi \n\t" // 0
2430 + "xorl %%esi, %%esi \n\t" // 0
2433 + "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? ? A
2434 + "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? ? C
2435 + "movhps -16(%0, %%edi), %%xmm1 \n\t" // D ? ? C
2436 + "movhps -8(%0, %%edi), %%xmm0 \n\t" // B ? ? A
2437 + "shufps $0xCC, %%xmm1, %%xmm0 \n\t" // D C B A
2438 + "mulps 1024+"MANGLE(sseWindow)"(%%esi), %%xmm0\n\t"
2439 + "movaps %%xmm0, (%1, %%esi) \n\t"
2440 + "addl $16, %%esi \n\t"
2441 + "subl $16, %%edi \n\t"
2442 + "cmpl $512, %%esi \n\t"
2444 + :: "r" (buf+64), "r" (delay_ptr)
2448 +// window_ptr-=128;
2451 + "movl $1024, %%edi \n\t" // 1024
2452 + "xorl %%esi, %%esi \n\t" // 0
2455 + "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? A ?
2456 + "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? C ?
2457 + "movhps -16(%0, %%edi), %%xmm1 \n\t" // ? D C ?
2458 + "movhps -8(%0, %%edi), %%xmm0 \n\t" // ? B A ?
2459 + "shufps $0x99, %%xmm1, %%xmm0 \n\t" // D C B A
2460 + "mulps 1536+"MANGLE(sseWindow)"(%%esi), %%xmm0\n\t"
2461 + "movaps %%xmm0, (%1, %%esi) \n\t"
2462 + "addl $16, %%esi \n\t"
2463 + "subl $16, %%edi \n\t"
2464 + "cmpl $512, %%esi \n\t"
2466 + :: "r" (buf), "r" (delay_ptr)
2473 imdct_do_256(sample_t data[],sample_t delay[],sample_t bias)
2475 @@ -379,13 +1233,19 @@
2479 - fprintf (stderr, "No accelerated IMDCT transform found\n");
2481 /* Twiddle factors to turn IFFT into IMDCT */
2482 for (i = 0; i < 128; i++) {
2483 xcos1[i] = -cos ((M_PI / 2048) * (8 * i + 1));
2484 xsin1[i] = -sin ((M_PI / 2048) * (8 * i + 1));
2487 + for (i = 0; i < 128; i++) {
2488 + sseSinCos1c[2*i+0]= xcos1[i];
2489 + sseSinCos1c[2*i+1]= -xcos1[i];
2490 + sseSinCos1d[2*i+0]= xsin1[i];
2491 + sseSinCos1d[2*i+1]= xsin1[i];
2495 /* More twiddle factors to turn IFFT into IMDCT */
2496 for (i = 0; i < 64; i++) {
2497 @@ -400,7 +1260,334 @@
2498 w[i][k].imag = sin (-M_PI * k / j);
2502 + for (i = 1; i < 7; i++) {
2504 + for (k = 0; k < j; k+=2) {
2506 + sseW[i][4*k + 0] = w[i][k+0].real;
2507 + sseW[i][4*k + 1] = w[i][k+0].real;
2508 + sseW[i][4*k + 2] = w[i][k+1].real;
2509 + sseW[i][4*k + 3] = w[i][k+1].real;
2511 + sseW[i][4*k + 4] = -w[i][k+0].imag;
2512 + sseW[i][4*k + 5] = w[i][k+0].imag;
2513 + sseW[i][4*k + 6] = -w[i][k+1].imag;
2514 + sseW[i][4*k + 7] = w[i][k+1].imag;
2516 + //we multiply more or less uninitalized numbers so we need to use exactly 0.0
2519 +// sseW[i][4*k + 0]= sseW[i][4*k + 1]= 1.0;
2520 + sseW[i][4*k + 4]= sseW[i][4*k + 5]= 0.0;
2525 + sseW[i][4*k + 0]= sseW[i][4*k + 1]= 0.0;
2526 +// sseW[i][4*k + 4]= -(sseW[i][4*k + 5]= -1.0);
2531 + for(i=0; i<128; i++)
2533 + sseWindow[2*i+0]= -imdct_window[2*i+0];
2534 + sseWindow[2*i+1]= imdct_window[2*i+1];
2537 + for(i=0; i<64; i++)
2539 + sseWindow[256 + 2*i+0]= -imdct_window[254 - 2*i+1];
2540 + sseWindow[256 + 2*i+1]= imdct_window[254 - 2*i+0];
2541 + sseWindow[384 + 2*i+0]= imdct_window[126 - 2*i+1];
2542 + sseWindow[384 + 2*i+1]= -imdct_window[126 - 2*i+0];
2546 imdct_512 = imdct_do_512;
2548 + if(mm_accel & MM_ACCEL_X86_SSE)
2550 + fprintf (stderr, "Using SSE optimized IMDCT transform\n");
2551 + imdct_512 = imdct_do_512_sse;
2554 + if(mm_accel & MM_ACCEL_X86_3DNOWEXT)
2556 + fprintf (stderr, "Using 3DNowEx optimized IMDCT transform\n");
2557 + imdct_512 = imdct_do_512_3dnowex;
2560 + if(mm_accel & MM_ACCEL_X86_3DNOW)
2562 + fprintf (stderr, "Using 3DNow optimized IMDCT transform\n");
2563 + imdct_512 = imdct_do_512_3dnow;
2567 +#ifdef HAVE_ALTIVEC
2568 + if (mm_accel & MM_ACCEL_PPC_ALTIVEC)
2570 + fprintf(stderr, "Using AltiVec optimized IMDCT transform\n");
2571 + imdct_512 = imdct_do_512_altivec;
2575 + fprintf (stderr, "No accelerated IMDCT transform found\n");
2576 imdct_256 = imdct_do_256;
2580 +static void fft_asmb(int k, complex_t *x, complex_t *wTB,
2581 + const complex_t *d, const complex_t *d_3)
2583 + register complex_t *x2k, *x3k, *x4k, *wB;
2584 + register float a_r, a_i, a1_r, a1_i, u_r, u_i, v_r, v_i;
2587 + x3k = x2k + 2 * k;
2588 + x4k = x3k + 2 * k;
2591 + TRANSZERO(x[0],x2k[0],x3k[0],x4k[0]);
2592 + TRANS(x[1],x2k[1],x3k[1],x4k[1],wTB[1],wB[1],d[1],d_3[1]);
2596 + TRANS(x[2],x2k[2],x3k[2],x4k[2],wTB[2],wB[2],d[2],d_3[2]);
2597 + TRANS(x[3],x2k[3],x3k[3],x4k[3],wTB[3],wB[3],d[3],d_3[3]);
2611 +static void fft_asmb16(complex_t *x, complex_t *wTB)
2613 + register float a_r, a_i, a1_r, a1_i, u_r, u_i, v_r, v_i;
2616 + /* transform x[0], x[8], x[4], x[12] */
2617 + TRANSZERO(x[0],x[4],x[8],x[12]);
2619 + /* transform x[1], x[9], x[5], x[13] */
2620 + TRANS(x[1],x[5],x[9],x[13],wTB[1],wTB[5],delta16[1],delta16_3[1]);
2622 + /* transform x[2], x[10], x[6], x[14] */
2623 + TRANSHALF_16(x[2],x[6],x[10],x[14]);
2625 + /* transform x[3], x[11], x[7], x[15] */
2626 + TRANS(x[3],x[7],x[11],x[15],wTB[3],wTB[7],delta16[3],delta16_3[3]);
2630 +static void fft_4(complex_t *x)
2632 + /* delta_p = 1 here */
2633 + /* x[k] = sum_{i=0..3} x[i] * w^{i*k}, w=e^{-2*pi/4}
2636 + register float yt_r, yt_i, yb_r, yb_i, u_r, u_i, vi_r, vi_i;
2639 + yb_r = yt_r - x[2].real;
2640 + yt_r += x[2].real;
2643 + vi_i = x[3].real - u_r;
2647 + vi_r = u_i - x[3].imag;
2662 + yb_i = yt_i - x[2].imag;
2663 + yt_i += x[2].imag;
2678 +static void fft_8(complex_t *x)
2680 + /* delta_p = diag{1, sqrt(i)} here */
2681 + /* x[k] = sum_{i=0..7} x[i] * w^{i*k}, w=e^{-2*pi/8}
2683 + register float wT1_r, wT1_i, wB1_r, wB1_i, wT2_r, wT2_i, wB2_r, wB2_i;
2685 + wT1_r = x[1].real;
2686 + wT1_i = x[1].imag;
2687 + wB1_r = x[3].real;
2688 + wB1_i = x[3].imag;
2697 + wT2_r = x[5].real;
2698 + wT2_r += x[7].real;
2702 + wT2_r += x[0].real;
2703 + wT2_i = x[0].real - wT2_i;
2704 + x[0].real = wT2_r;
2705 + x[4].real = wT2_i;
2707 + wT2_i = x[5].imag;
2708 + wT2_i += x[7].imag;
2712 + wT2_r += x[0].imag;
2713 + wT2_i = x[0].imag - wT2_i;
2714 + x[0].imag = wT2_r;
2715 + x[4].imag = wT2_i;
2718 + wT2_r = x[5].imag;
2719 + wT2_r -= x[7].imag;
2723 + wT2_r += x[2].real;
2724 + wT2_i = x[2].real - wT2_i;
2725 + x[2].real = wT2_r;
2726 + x[6].real = wT2_i;
2728 + wT2_i = x[5].real;
2729 + wT2_i -= x[7].real;
2733 + wT2_r += x[2].imag;
2734 + wT2_i = x[2].imag - wT2_i;
2735 + x[2].imag = wT2_i;
2736 + x[6].imag = wT2_r;
2742 + wT2_r -= x[5].real;
2743 + wT2_r -= x[7].imag;
2746 + wT2_i -= x[5].imag;
2747 + wT2_i += x[7].real;
2755 + wB2_r += x[1].real;
2756 + wT2_r = x[1].real - wT2_r;
2758 + wB2_i = x[5].real;
2759 + x[1].real = wB2_r;
2760 + x[5].real = wT2_r;
2763 + wT2_r += x[1].imag;
2764 + wT2_i = x[1].imag - wT2_i;
2765 + wB2_r = x[5].imag;
2766 + x[1].imag = wT2_r;
2767 + x[5].imag = wT2_i;
2772 + wB1_r = wB2_i - x[7].imag;
2773 + wB1_i = wB2_r + x[7].real;
2776 + wB1_r = wT1_r + wT1_i;
2780 + wB2_r = x[3].real;
2781 + wB2_i = wB2_r + wT1_i;
2783 + x[3].real = wB2_i;
2784 + x[7].real = wB2_r;
2785 + wB2_i = x[3].imag;
2786 + wB2_r = wB2_i + wB1_r;
2788 + x[3].imag = wB2_i;
2789 + x[7].imag = wB2_r;
2793 +static void fft_128p(complex_t *a)
2795 + fft_8(&a[0]); fft_4(&a[8]); fft_4(&a[12]);
2796 + fft_asmb16(&a[0], &a[8]);
2798 + fft_8(&a[16]), fft_8(&a[24]);
2799 + fft_asmb(4, &a[0], &a[16],&delta32[0], &delta32_3[0]);
2801 + fft_8(&a[32]); fft_4(&a[40]); fft_4(&a[44]);
2802 + fft_asmb16(&a[32], &a[40]);
2804 + fft_8(&a[48]); fft_4(&a[56]); fft_4(&a[60]);
2805 + fft_asmb16(&a[48], &a[56]);
2807 + fft_asmb(8, &a[0], &a[32],&delta64[0], &delta64_3[0]);
2809 + fft_8(&a[64]); fft_4(&a[72]); fft_4(&a[76]);
2810 + /* fft_16(&a[64]); */
2811 + fft_asmb16(&a[64], &a[72]);
2813 + fft_8(&a[80]); fft_8(&a[88]);
2815 + /* fft_32(&a[64]); */
2816 + fft_asmb(4, &a[64], &a[80],&delta32[0], &delta32_3[0]);
2818 + fft_8(&a[96]); fft_4(&a[104]), fft_4(&a[108]);
2819 + /* fft_16(&a[96]); */
2820 + fft_asmb16(&a[96], &a[104]);
2822 + fft_8(&a[112]), fft_8(&a[120]);
2823 + /* fft_32(&a[96]); */
2824 + fft_asmb(4, &a[96], &a[112], &delta32[0], &delta32_3[0]);
2826 + /* fft_128(&a[0]); */
2827 + fft_asmb(16, &a[0], &a[64], &delta128[0], &delta128_3[0]);
2832 --- liba52/imdct_mlib.c 2005-03-22 19:59:35.000000000 +0100
2833 +++ imdct_mlib.c 2004-03-19 01:15:51.000000000 +0100
2838 -#include <inttypes.h>
2839 -#include <string.h>
2840 #include <mlib_types.h>
2841 #include <mlib_status.h>
2842 #include <mlib_signal.h>
2843 +#include <string.h>
2844 +#include <inttypes.h>
2847 #include "a52_internal.h"
2850 sample_t *delay_ptr;
2851 sample_t *window_ptr;
2852 - sample_t tmp[256] __attribute__ ((__aligned__ (16)));
2853 + sample_t tmp[256] __attribute__((aligned(16)));
2856 memcpy(tmp, data, 256 * sizeof(sample_t));
2859 sample_t *delay_ptr;
2860 sample_t *window_ptr;
2861 - sample_t tmp[256] __attribute__ ((__aligned__ (16)));
2862 + sample_t tmp[256] __attribute__((aligned(16)));
2865 memcpy(tmp, data, 256 * sizeof(sample_t));
2866 --- include/mm_accel.h 2005-03-22 19:58:53.000000000 +0100
2867 +++ mm_accel.h 2004-03-19 01:15:52.000000000 +0100
2869 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2875 /* generic accelerations */
2876 #define MM_ACCEL_MLIB 0x00000001
2878 /* x86 accelerations */
2879 #define MM_ACCEL_X86_MMX 0x80000000
2880 #define MM_ACCEL_X86_3DNOW 0x40000000
2881 +#define MM_ACCEL_X86_3DNOWEXT 0x08000000
2882 #define MM_ACCEL_X86_MMXEXT 0x20000000
2883 +#define MM_ACCEL_X86_SSE 0x10000000
2885 +/* PPC accelerations */
2886 +#define MM_ACCEL_PPC_ALTIVEC 0x00010000
2888 uint32_t mm_accel (void);
2890 +#endif /* MM_ACCEL_H */
2891 --- liba52/parse.c 2005-03-22 19:59:35.000000000 +0100
2892 +++ parse.c 2004-04-01 15:41:29.000000000 +0200
2897 -#include <inttypes.h>
2900 +#include <inttypes.h>
2903 #include "a52_internal.h"
2904 #include "bitstream.h"
2906 +#include "mm_accel.h"
2908 #ifdef HAVE_MEMALIGN
2909 /* some systems have memalign() but no declaration for it */
2910 void * memalign (size_t align, size_t size);
2912 -/* assume malloc alignment is sufficient */
2913 -#define memalign(align,size) malloc (size)
2921 - imdct_init (mm_accel);
2923 samples = memalign (16, 256 * 12 * sizeof (sample_t));
2924 +#if defined(__MINGW32__) && defined(HAVE_SSE)
2925 + for(i=0;i<10;i++){
2926 + if((int)samples%16){
2927 + sample_t* samplestmp=malloc(256 * 12 * sizeof (sample_t));
2929 + samples = samplestmp;
2934 + if(((int)samples%16) && (mm_accel&MM_ACCEL_X86_SSE)){
2935 + mm_accel &=~MM_ACCEL_X86_SSE;
2936 + printf("liba52: unable to get 16 byte aligned memory disabling usage of SSE instructions\n");
2939 if (samples == NULL)
2944 + imdct_init (mm_accel);
2945 + downmix_accel_init(mm_accel);
2947 for (i = 0; i < 256 * 12; i++)
2951 state->acmod = acmod = buf[6] >> 5;
2953 bitstream_set_ptr (buf + 6);
2954 - bitstream_get (3); /* skip acmod we already parsed */
2955 + bitstream_skip (3); /* skip acmod we already parsed */
2957 if ((acmod == 2) && (bitstream_get (2) == 2)) /* dsurmod */
2960 if (state->lfeon && (*flags & A52_LFE))
2961 state->output |= A52_LFE;
2962 *flags = state->output;
2963 - // the 2* compensates for differences in imdct
2964 + /* the 2* compensates for differences in imdct */
2965 state->dynrng = state->level = 2 * *level;
2968 @@ -152,28 +172,28 @@
2972 - bitstream_get (5); /* dialnorm */
2973 + bitstream_skip (5); /* dialnorm */
2974 if (bitstream_get (1)) /* compre */
2975 - bitstream_get (8); /* compr */
2976 + bitstream_skip (8); /* compr */
2977 if (bitstream_get (1)) /* langcode */
2978 - bitstream_get (8); /* langcod */
2979 + bitstream_skip (8); /* langcod */
2980 if (bitstream_get (1)) /* audprodie */
2981 - bitstream_get (7); /* mixlevel + roomtyp */
2982 + bitstream_skip (7); /* mixlevel + roomtyp */
2983 } while (chaninfo--);
2985 - bitstream_get (2); /* copyrightb + origbs */
2986 + bitstream_skip (2); /* copyrightb + origbs */
2988 if (bitstream_get (1)) /* timecod1e */
2989 - bitstream_get (14); /* timecod1 */
2990 + bitstream_skip (14); /* timecod1 */
2991 if (bitstream_get (1)) /* timecod2e */
2992 - bitstream_get (14); /* timecod2 */
2993 + bitstream_skip (14); /* timecod2 */
2995 if (bitstream_get (1)) { /* addbsie */
2998 addbsil = bitstream_get (6);
3000 - bitstream_get (8); /* addbsi */
3001 + bitstream_skip (8); /* addbsi */
3002 } while (addbsil--);
3006 if (parse_exponents (chexpstr[i], nchgrps, state->fbw_exp[i][0],
3007 state->fbw_exp[i] + 1))
3009 - bitstream_get (2); /* gainrng */
3010 + bitstream_skip (2); /* gainrng */
3012 if (lfeexpstr != EXP_REUSE) {
3015 if (bitstream_get (1)) { /* skiple */
3016 i = bitstream_get (9); /* skipl */
3018 - bitstream_get (8);
3019 + bitstream_skip (8);
3022 if (state->output & A52_LFE)