1 /*****************************************************************************
2 * ac3_downmix_sse.c: accelerated SSE ac3 downmix functions
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: ac3_downmix_sse.c,v 1.1 2001/05/15 16:19:42 sam Exp $
7 * Authors: Renaud Dartus <reno@videolan.org>
8 * Aaron Holtzman <aholtzma@engr.uvic.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 #define MODULE_NAME downmixsse
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
39 #include "ac3_downmix.h"
43 __asm__ (".float 0f0.7071068");
46 void _M( downmix_3f_2r_to_2ch ) (float * samples, dm_par_t * dm_par)
48 __asm__ __volatile__ (
50 "movl $64, %%ecx\n" /* loop counter */
52 "movss (%%ebx), %%xmm5\n" /* unit */
53 "shufps $0, %%xmm5, %%xmm5\n" /* unit | unit | unit | unit */
55 "movss 4(%%ebx), %%xmm6\n" /* clev */
56 "shufps $0, %%xmm6, %%xmm6\n" /* clev | clev | clev | clev */
58 "movss 8(%%ebx), %%xmm7\n" /* slev */
59 "shufps $0, %%xmm7, %%xmm7\n" /* slev | slev | slev | slev */
62 "movups (%%eax), %%xmm0\n" /* left */
63 "movups 2048(%%eax), %%xmm1\n" /* right */
64 "movups 1024(%%eax), %%xmm2\n" /* center */
65 "movups 3072(%%eax), %%xmm3\n" /* leftsur */
66 "movups 4096(%%eax), %%xmm4\n" /* rithgsur */
67 "mulps %%xmm5, %%xmm0\n"
68 "mulps %%xmm5, %%xmm1\n"
69 "mulps %%xmm6, %%xmm2\n"
70 "addps %%xmm2, %%xmm0\n"
71 "addps %%xmm2, %%xmm1\n"
72 "mulps %%xmm7, %%xmm3\n"
73 "mulps %%xmm7, %%xmm4\n"
74 "addps %%xmm3, %%xmm0\n"
75 "addps %%xmm4, %%xmm1\n"
77 "movups %%xmm0, (%%eax)\n"
78 "movups %%xmm1, 1024(%%eax)\n"
86 : "a" (samples), "b" (dm_par));
89 void _M( downmix_2f_2r_to_2ch ) (float *samples, dm_par_t * dm_par)
91 __asm__ __volatile__ (
93 "movl $64, %%ecx\n" /* loop counter */
95 "movss (%%ebx), %%xmm5\n" /* unit */
96 "shufps $0, %%xmm5, %%xmm5\n" /* unit | unit | unit | unit */
98 "movss 8(%%ebx), %%xmm7\n" /* slev */
99 "shufps $0, %%xmm7, %%xmm7\n" /* slev | slev | slev | slev */
102 "movups (%%eax), %%xmm0\n" /* left */
103 "movups 1024(%%eax), %%xmm1\n" /* right */
104 "movups 2048(%%eax), %%xmm3\n" /* leftsur */
105 "movups 3072(%%eax), %%xmm4\n" /* rightsur */
106 "mulps %%xmm5, %%xmm0\n"
107 "mulps %%xmm5, %%xmm1\n"
108 "mulps %%xmm7, %%xmm3\n"
109 "mulps %%xmm7, %%xmm4\n"
110 "addps %%xmm3, %%xmm0\n"
111 "addps %%xmm4, %%xmm1\n"
113 "movups %%xmm0, (%%eax)\n"
114 "movups %%xmm1, 1024(%%eax)\n"
122 : "a" (samples), "b" (dm_par));
125 void _M( downmix_3f_1r_to_2ch ) (float *samples, dm_par_t * dm_par)
127 __asm__ __volatile__ (
130 "movl $64, %%ecx\n" /* loop counter */
132 "movss (%%ebx), %%xmm5\n" /* unit */
133 "shufps $0, %%xmm5, %%xmm5\n" /* unit | unit | unit | unit */
135 "movss 4(%%ebx), %%xmm6\n" /* clev */
136 "shufps $0, %%xmm6, %%xmm6\n" /* clev | clev | clev | clev */
138 "movss 8(%%ebx), %%xmm7\n" /* slev */
139 "shufps $0, %%xmm7, %%xmm7\n" /* slev | slev | slev | slev */
142 "movups (%%eax), %%xmm0\n" /* left */
143 "movups 2048(%%eax), %%xmm1\n" /* right */
144 "movups 1024(%%eax), %%xmm2\n" /* center */
145 "movups 3072(%%eax), %%xmm3\n" /* sur */
146 "mulps %%xmm5, %%xmm0\n"
147 "mulps %%xmm5, %%xmm1\n"
148 "mulps %%xmm6, %%xmm2\n"
149 "addps %%xmm2, %%xmm0\n"
150 "mulps %%xmm7, %%xmm3\n"
151 "addps %%xmm2, %%xmm1\n"
152 "subps %%xmm3, %%xmm0\n"
153 "addps %%xmm3, %%xmm1\n"
155 "movups %%xmm0, (%%eax)\n"
156 "movups %%xmm1, 1024(%%eax)\n"
164 : "a" (samples), "b" (dm_par));
168 void _M( downmix_2f_1r_to_2ch ) (float *samples, dm_par_t * dm_par)
170 __asm__ __volatile__ (
172 "movl $64, %%ecx\n" /* loop counter */
174 "movss (%%ebx), %%xmm5\n" /* unit */
175 "shufps $0, %%xmm5, %%xmm5\n" /* unit | unit | unit | unit */
177 "movss 8(%%ebx), %%xmm7\n" /* slev */
178 "shufps $0, %%xmm7, %%xmm7\n" /* slev | slev | slev | slev */
181 "movups (%%eax), %%xmm0\n" /* left */
182 "movups 1024(%%eax), %%xmm1\n" /* right */
183 "movups 2048(%%eax), %%xmm3\n" /* sur */
184 "mulps %%xmm5, %%xmm0\n"
185 "mulps %%xmm5, %%xmm1\n"
186 "mulps %%xmm7, %%xmm3\n"
187 "subps %%xmm3, %%xmm0\n"
188 "addps %%xmm3, %%xmm1\n"
190 "movups %%xmm0, (%%eax)\n"
191 "movups %%xmm1, 1024(%%eax)\n"
199 : "a" (samples), "b" (dm_par));
204 void _M( downmix_3f_0r_to_2ch ) (float *samples, dm_par_t * dm_par)
206 __asm__ __volatile__ (
208 "movl $64, %%ecx\n" /* loop counter */
210 "movss (%%ebx), %%xmm5\n" /* unit */
211 "shufps $0, %%xmm5, %%xmm5\n" /* unit | unit | unit | unit */
213 "movss 4(%%ebx), %%xmm6\n" /* clev */
214 "shufps $0, %%xmm6, %%xmm6\n" /* clev | clev | clev | clev */
217 "movups (%%eax), %%xmm0\n" /*left */
218 "movups 2048(%%eax), %%xmm1\n" /* right */
219 "movups 1024(%%eax), %%xmm2\n" /* center */
220 "mulps %%xmm5, %%xmm0\n"
221 "mulps %%xmm5, %%xmm1\n"
222 "mulps %%xmm6, %%xmm2\n"
223 "addps %%xmm2, %%xmm0\n"
224 "addps %%xmm2, %%xmm1\n"
226 "movups %%xmm0, (%%eax)\n"
227 "movups %%xmm1, 1024(%%eax)\n"
235 : "a" (samples), "b" (dm_par));
238 void _M( stream_sample_1ch_to_s16 ) (s16 *s16_samples, float *left)
240 __asm__ __volatile__ (
244 "movl $sqrt2_sse, %%edx\n"
245 "movss (%%edx), %%xmm7\n"
246 "shufps $0, %%xmm7, %%xmm7\n" /* sqrt2 | sqrt2 | sqrt2 | sqrt2 */
250 "movups (%%ebx), %%xmm0\n" /* c3 | c2 | c1 | c0 */
251 "mulps %%xmm7, %%xmm0\n"
252 "movhlps %%xmm0, %%xmm2\n" /* c3 | c2 */
254 "cvtps2pi %%xmm0, %%mm0\n" /* c1 c0 --> mm0, int_32 */
255 "cvtps2pi %%xmm2, %%mm1\n" /* c3 c2 --> mm1, int_32 */
257 "packssdw %%mm0, %%mm0\n" /* c1 c1 c0 c0 --> mm0, int_16 */
258 "packssdw %%mm1, %%mm1\n" /* c3 c3 c2 c2 --> mm1, int_16 */
260 "movq %%mm0, (%%eax)\n"
261 "movq %%mm1, 8(%%eax)\n"
271 : "=a" (s16_samples), "=b" (left)
272 : "a" (s16_samples), "b" (left));
275 void _M( stream_sample_2ch_to_s16 ) (s16 *s16_samples, float *left, float *right)
278 __asm__ __volatile__ (
283 "movups (%%ebx), %%xmm0\n" /* l3 | l2 | l1 | l0 */
284 "movups (%%edx), %%xmm1\n" /* r3 | r2 | r1 | r0 */
285 "movhlps %%xmm0, %%xmm2\n" /* l3 | l2 */
286 "movhlps %%xmm1, %%xmm3\n" /* r3 | r2 */
287 "unpcklps %%xmm1, %%xmm0\n" /* r1 | l1 | r0 | l0 */
288 "unpcklps %%xmm3, %%xmm2\n" /* r3 | l3 | r2 | l2 */
290 "cvtps2pi %%xmm0, %%mm0\n" /* r0 l0 --> mm0, int_32 */
291 "movhlps %%xmm0, %%xmm0\n"
292 "cvtps2pi %%xmm0, %%mm1\n" /* r1 l1 --> mm1, int_32 */
293 "cvtps2pi %%xmm2, %%mm2\n" /* r2 l2 --> mm2, int_32 */
294 "movhlps %%xmm2, %%xmm2\n"
295 "cvtps2pi %%xmm2, %%mm3\n" /* r3 l3 --> mm3, int_32 */
297 "packssdw %%mm1, %%mm0\n" /* r1 l1 r0 l0 --> mm0, int_16 */
298 "packssdw %%mm3, %%mm2\n" /* r3 l3 r2 l2 --> mm2, int_16 */
300 "movq %%mm0, (%%eax)\n"
301 "movq %%mm2, 8(%%eax)\n"
311 : "=a" (s16_samples), "=b" (left), "=d" (right)
312 : "a" (s16_samples), "b" (left), "d" (right));