annotate i386/fft_sse.c @ 3746:2ec498208c6a libavcodec

sse implementation of imdct. patch mostly by Zuxy Meng (zuxy dot meng at gmail dot com)
author lorenm
date Thu, 21 Sep 2006 16:37:39 +0000
parents a3d97c60ea07
children c8c591fe26f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
1 /*
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
2 * FFT/MDCT transform with SSE optimizations
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard.
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
4 *
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
9 *
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
14 *
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
18 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
19 #include "../dsputil.h"
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
20
3166
ab1273ffe275 use xorps instead of mulps to toggle the sign of a float, as suggested by Software Optimization Guide for AMD64 Processors.
gpoirier
parents: 3036
diff changeset
21 static const int p1p1p1m1[4] __attribute__((aligned(16))) =
ab1273ffe275 use xorps instead of mulps to toggle the sign of a float, as suggested by Software Optimization Guide for AMD64 Processors.
gpoirier
parents: 3036
diff changeset
22 { 0, 0, 0, 1 << 31 };
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
23
3166
ab1273ffe275 use xorps instead of mulps to toggle the sign of a float, as suggested by Software Optimization Guide for AMD64 Processors.
gpoirier
parents: 3036
diff changeset
24 static const int p1p1m1p1[4] __attribute__((aligned(16))) =
ab1273ffe275 use xorps instead of mulps to toggle the sign of a float, as suggested by Software Optimization Guide for AMD64 Processors.
gpoirier
parents: 3036
diff changeset
25 { 0, 0, 1 << 31, 0 };
968
64f1a11b5f86 added define for builtins use - inverse fix by Romain Dolbeau
bellard
parents: 781
diff changeset
26
3166
ab1273ffe275 use xorps instead of mulps to toggle the sign of a float, as suggested by Software Optimization Guide for AMD64 Processors.
gpoirier
parents: 3036
diff changeset
27 static const int p1p1m1m1[4] __attribute__((aligned(16))) =
ab1273ffe275 use xorps instead of mulps to toggle the sign of a float, as suggested by Software Optimization Guide for AMD64 Processors.
gpoirier
parents: 3036
diff changeset
28 { 0, 0, 1 << 31, 1 << 31 };
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
29
3746
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
30 static const int p1m1p1m1[4] __attribute__((aligned(16))) =
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
31 { 0, 1 << 31, 0, 1 << 31 };
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
32
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
33 static const int m1m1m1m1[4] __attribute__((aligned(16))) =
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
34 { 1 << 31, 1 << 31, 1 << 31, 1 << 31 };
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
35
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
36 #if 0
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
37 static void print_v4sf(const char *str, __m128 a)
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
38 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
39 float *p = (float *)&a;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
40 printf("%s: %f %f %f %f\n",
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
41 str, p[0], p[1], p[2], p[3]);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
42 }
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
43 #endif
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
44
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
45 /* XXX: handle reverse case */
1879
dd63cb7e5080 fft_*() renamed into ff_fft_*() patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 968
diff changeset
46 void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
47 {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
48 int ln = s->nbits;
3590
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
49 long i, j;
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
50 long nblocks, nloops;
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
51 FFTComplex *p, *cptr;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
52
3590
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
53 asm volatile(
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
54 "movaps %0, %%xmm4 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
55 "movaps %1, %%xmm5 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
56 ::"m"(*p1p1m1m1),
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
57 "m"(*(s->inverse ? p1p1m1p1 : p1p1p1m1))
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
58 );
968
64f1a11b5f86 added define for builtins use - inverse fix by Romain Dolbeau
bellard
parents: 781
diff changeset
59
3590
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
60 i = 8 << ln;
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
61 asm volatile(
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
62 "1: \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
63 "sub $32, %0 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
64 /* do the pass 0 butterfly */
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
65 "movaps (%0,%1), %%xmm0 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
66 "movaps %%xmm0, %%xmm1 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
67 "shufps $0x4E, %%xmm0, %%xmm0 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
68 "xorps %%xmm4, %%xmm1 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
69 "addps %%xmm1, %%xmm0 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
70 "movaps 16(%0,%1), %%xmm2 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
71 "movaps %%xmm2, %%xmm3 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
72 "shufps $0x4E, %%xmm2, %%xmm2 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
73 "xorps %%xmm4, %%xmm3 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
74 "addps %%xmm3, %%xmm2 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
75 /* multiply third by -i */
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
76 /* by toggling the sign bit */
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
77 "shufps $0xB4, %%xmm2, %%xmm2 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
78 "xorps %%xmm5, %%xmm2 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
79 /* do the pass 1 butterfly */
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
80 "movaps %%xmm0, %%xmm1 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
81 "addps %%xmm2, %%xmm0 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
82 "subps %%xmm2, %%xmm1 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
83 "movaps %%xmm0, (%0,%1) \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
84 "movaps %%xmm1, 16(%0,%1) \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
85 "jg 1b \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
86 :"+r"(i)
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
87 :"r"(z)
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
88 );
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
89 /* pass 2 .. ln-1 */
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
90
3590
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
91 nblocks = 1 << (ln-3);
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
92 nloops = 1 << 2;
3590
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
93 cptr = s->exptab1;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
94 do {
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
95 p = z;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
96 j = nblocks;
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
97 do {
3590
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
98 i = nloops*8;
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
99 asm volatile(
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
100 "1: \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
101 "sub $16, %0 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
102 "movaps (%2,%0), %%xmm1 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
103 "movaps (%1,%0), %%xmm0 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
104 "movaps %%xmm1, %%xmm2 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
105 "shufps $0xA0, %%xmm1, %%xmm1 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
106 "shufps $0xF5, %%xmm2, %%xmm2 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
107 "mulps (%3,%0,2), %%xmm1 \n\t" // cre*re cim*re
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
108 "mulps 16(%3,%0,2), %%xmm2 \n\t" // -cim*im cre*im
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
109 "addps %%xmm2, %%xmm1 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
110 "movaps %%xmm0, %%xmm3 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
111 "addps %%xmm1, %%xmm0 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
112 "subps %%xmm1, %%xmm3 \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
113 "movaps %%xmm0, (%1,%0) \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
114 "movaps %%xmm3, (%2,%0) \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
115 "jg 1b \n\t"
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
116 :"+r"(i)
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
117 :"r"(p), "r"(p + nloops), "r"(cptr)
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
118 );
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
119 p += nloops*2;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
120 } while (--j);
3590
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
121 cptr += nloops*2;
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
122 nblocks >>= 1;
a3d97c60ea07 ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
lorenm
parents: 3166
diff changeset
123 nloops <<= 1;
781
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
124 } while (nblocks != 0);
6f5e87957bcb new generic FFT/MDCT code for audio codecs
bellard
parents:
diff changeset
125 }
968
64f1a11b5f86 added define for builtins use - inverse fix by Romain Dolbeau
bellard
parents: 781
diff changeset
126
3746
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
127 void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output,
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
128 const FFTSample *input, FFTSample *tmp)
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
129 {
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
130 long k, n8, n4, n2, n;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
131 const uint16_t *revtab = s->fft.revtab;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
132 const FFTSample *tcos = s->tcos;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
133 const FFTSample *tsin = s->tsin;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
134 const FFTSample *in1, *in2;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
135 FFTComplex *z = (FFTComplex *)tmp;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
136
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
137 n = 1 << s->nbits;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
138 n2 = n >> 1;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
139 n4 = n >> 2;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
140 n8 = n >> 3;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
141
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
142 asm volatile ("movaps %0, %%xmm7\n\t"::"m"(*p1m1p1m1));
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
143
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
144 /* pre rotation */
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
145 in1 = input;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
146 in2 = input + n2 - 4;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
147
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
148 /* Complex multiplication
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
149 Two complex products per iteration, we could have 4 with 8 xmm
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
150 registers, 8 with 16 xmm registers.
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
151 Maybe we should unroll more.
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
152 */
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
153 for (k = 0; k < n4; k += 2) {
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
154 asm volatile (
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
155 "movaps %0, %%xmm0 \n\t" // xmm0 = r0 X r1 X : in2
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
156 "movaps %1, %%xmm3 \n\t" // xmm3 = X i1 X i0: in1
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
157 "movlps %2, %%xmm1 \n\t" // xmm1 = X X R1 R0: tcos
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
158 "movlps %3, %%xmm2 \n\t" // xmm2 = X X I1 I0: tsin
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
159 "shufps $95, %%xmm0, %%xmm0 \n\t" // xmm0 = r1 r1 r0 r0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
160 "shufps $160,%%xmm3, %%xmm3 \n\t" // xmm3 = i1 i1 i0 i0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
161 "unpcklps %%xmm2, %%xmm1 \n\t" // xmm1 = I1 R1 I0 R0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
162 "movaps %%xmm1, %%xmm2 \n\t" // xmm2 = I1 R1 I0 R0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
163 "xorps %%xmm7, %%xmm2 \n\t" // xmm2 = -I1 R1 -I0 R0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
164 "mulps %%xmm1, %%xmm0 \n\t" // xmm0 = rI rR rI rR
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
165 "shufps $177,%%xmm2, %%xmm2 \n\t" // xmm2 = R1 -I1 R0 -I0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
166 "mulps %%xmm2, %%xmm3 \n\t" // xmm3 = Ri -Ii Ri -Ii
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
167 "addps %%xmm3, %%xmm0 \n\t" // xmm0 = result
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
168 ::"m"(in2[-2*k]), "m"(in1[2*k]),
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
169 "m"(tcos[k]), "m"(tsin[k])
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
170 );
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
171 /* Should be in the same block, hack for gcc2.95 & gcc3 */
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
172 asm (
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
173 "movlps %%xmm0, %0 \n\t"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
174 "movhps %%xmm0, %1 \n\t"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
175 :"=m"(z[revtab[k]]), "=m"(z[revtab[k + 1]])
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
176 );
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
177 }
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
178
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
179 ff_fft_calc_sse(&s->fft, z);
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
180
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
181 /* Not currently needed, added for safety */
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
182 asm volatile ("movaps %0, %%xmm7\n\t"::"m"(*p1m1p1m1));
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
183
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
184 /* post rotation + reordering */
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
185 for (k = 0; k < n4; k += 2) {
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
186 asm (
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
187 "movaps %0, %%xmm0 \n\t" // xmm0 = i1 r1 i0 r0: z
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
188 "movlps %1, %%xmm1 \n\t" // xmm1 = X X R1 R0: tcos
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
189 "movaps %%xmm0, %%xmm3 \n\t" // xmm3 = i1 r1 i0 r0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
190 "movlps %2, %%xmm2 \n\t" // xmm2 = X X I1 I0: tsin
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
191 "shufps $160,%%xmm0, %%xmm0 \n\t" // xmm0 = r1 r1 r0 r0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
192 "shufps $245,%%xmm3, %%xmm3 \n\t" // xmm3 = i1 i1 i0 i0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
193 "unpcklps %%xmm2, %%xmm1 \n\t" // xmm1 = I1 R1 I0 R0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
194 "movaps %%xmm1, %%xmm2 \n\t" // xmm2 = I1 R1 I0 R0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
195 "xorps %%xmm7, %%xmm2 \n\t" // xmm2 = -I1 R1 -I0 R0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
196 "mulps %%xmm1, %%xmm0 \n\t" // xmm0 = rI rR rI rR
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
197 "shufps $177,%%xmm2, %%xmm2 \n\t" // xmm2 = R1 -I1 R0 -I0
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
198 "mulps %%xmm2, %%xmm3 \n\t" // xmm3 = Ri -Ii Ri -Ii
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
199 "addps %%xmm3, %%xmm0 \n\t" // xmm0 = result
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
200 "movaps %%xmm0, %0 \n\t"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
201 :"+m"(z[k])
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
202 :"m"(tcos[k]), "m"(tsin[k])
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
203 );
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
204 }
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
205
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
206 /*
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
207 Mnemonics:
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
208 0 = z[k].re
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
209 1 = z[k].im
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
210 2 = z[k + 1].re
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
211 3 = z[k + 1].im
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
212 4 = z[-k - 2].re
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
213 5 = z[-k - 2].im
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
214 6 = z[-k - 1].re
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
215 7 = z[-k - 1].im
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
216 */
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
217 k = 16-n;
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
218 asm volatile("movaps %0, %%xmm7 \n\t"::"m"(*m1m1m1m1));
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
219 asm volatile(
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
220 "1: \n\t"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
221 "movaps -16(%4,%0), %%xmm1 \n\t" // xmm1 = 4 5 6 7 = z[-2-k]
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
222 "neg %0 \n\t"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
223 "movaps (%4,%0), %%xmm0 \n\t" // xmm0 = 0 1 2 3 = z[k]
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
224 "xorps %%xmm7, %%xmm0 \n\t" // xmm0 = -0 -1 -2 -3
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
225 "movaps %%xmm0, %%xmm2 \n\t" // xmm2 = -0 -1 -2 -3
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
226 "shufps $141,%%xmm1, %%xmm0 \n\t" // xmm0 = -1 -3 4 6
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
227 "shufps $216,%%xmm1, %%xmm2 \n\t" // xmm2 = -0 -2 5 7
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
228 "shufps $156,%%xmm0, %%xmm0 \n\t" // xmm0 = -1 6 -3 4 !
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
229 "shufps $156,%%xmm2, %%xmm2 \n\t" // xmm2 = -0 7 -2 5 !
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
230 "movaps %%xmm0, (%1,%0) \n\t" // output[2*k]
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
231 "movaps %%xmm2, (%2,%0) \n\t" // output[n2+2*k]
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
232 "neg %0 \n\t"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
233 "shufps $27, %%xmm0, %%xmm0 \n\t" // xmm0 = 4 -3 6 -1
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
234 "xorps %%xmm7, %%xmm0 \n\t" // xmm0 = -4 3 -6 1 !
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
235 "shufps $27, %%xmm2, %%xmm2 \n\t" // xmm2 = 5 -2 7 -0 !
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
236 "movaps %%xmm0, -16(%2,%0) \n\t" // output[n2-4-2*k]
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
237 "movaps %%xmm2, -16(%3,%0) \n\t" // output[n-4-2*k]
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
238 "add $16, %0 \n\t"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
239 "jle 1b \n\t"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
240 :"+r"(k)
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
241 :"r"(output), "r"(output+n2), "r"(output+n), "r"(z+n8)
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
242 :"memory"
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
243 );
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
244 }
2ec498208c6a sse implementation of imdct.
lorenm
parents: 3590
diff changeset
245