ac3_downmix_3dn.c 8.62 KB
Newer Older
Sam Hocevar's avatar
 
Sam Hocevar committed
1 2 3 4
/*****************************************************************************
 * ac3_downmix_3dn.c: accelerated 3D Now! ac3 downmix functions
 *****************************************************************************
 * Copyright (C) 1999, 2000, 2001 VideoLAN
Gildas Bazin's avatar
 
Gildas Bazin committed
5
 * $Id: ac3_downmix_3dn.c,v 1.5 2001/11/25 22:52:21 gbazin Exp $
Sam Hocevar's avatar
 
Sam Hocevar committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 *
 * Authors: Renaud Dartus <reno@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#define MODULE_NAME downmix3dn
#include "modules_inner.h"

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include "defs.h"

#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"
#include "tests.h"

#include "ac3_downmix.h"

Gildas Bazin's avatar
 
Gildas Bazin committed
40
static const float sqrt2_3dn __asm__ ("sqrt2_3dn") = 0.7071068;
Sam Hocevar's avatar
 
Sam Hocevar committed
41 42 43 44

void _M( downmix_3f_2r_to_2ch ) (float * samples, dm_par_t * dm_par)
{
    __asm__ __volatile__ (
45
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
46 47
    "pushl %%ebx\n"
    "movl  $128,  %%ebx\n"            /* loop counter */
Sam Hocevar's avatar
 
Sam Hocevar committed
48

Sam Hocevar's avatar
 
Sam Hocevar committed
49
    "movd    (%%ecx), %%mm5\n"        /* unit */
Sam Hocevar's avatar
 
Sam Hocevar committed
50 51
    "punpckldq %%mm5, %%mm5\n"        /* unit | unit */

Sam Hocevar's avatar
 
Sam Hocevar committed
52
    "movd    4(%%ecx), %%mm6\n"        /* clev */
Sam Hocevar's avatar
 
Sam Hocevar committed
53 54
    "punpckldq %%mm6, %%mm6\n"        /* clev | clev */

Sam Hocevar's avatar
 
Sam Hocevar committed
55
    "movd    8(%%ecx), %%mm7\n"        /* slev */
Sam Hocevar's avatar
 
Sam Hocevar committed
56 57
    "punpckldq %%mm7, %%mm7\n"        /* slev | slev */

58
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
".loop:\n"
    "movq    (%%eax),     %%mm0\n"   /* left */
    "movq    2048(%%eax), %%mm1\n"   /* right */
    "movq   1024(%%eax), %%mm2\n"    /* center */
    "movq    3072(%%eax), %%mm3\n"    /* leftsur */
    "movq    4096(%%eax), %%mm4\n"    /* rightsur */
    "pfmul    %%mm5, %%mm0\n"
    "pfmul    %%mm5, %%mm1\n"
    "pfmul    %%mm6, %%mm2\n"
    "pfadd    %%mm2, %%mm0\n"
    "pfadd     %%mm2, %%mm1\n"
    "pfmul  %%mm7, %%mm3\n"
    "pfmul    %%mm7, %%mm4\n"
    "pfadd    %%mm3, %%mm0\n"
    "pfadd    %%mm4, %%mm1\n"

    "movq    %%mm0, (%%eax)\n"
    "movq    %%mm1, 1024(%%eax)\n"

    "addl    $8, %%eax\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
79
    "decl     %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
80 81
    "jnz    .loop\n"
    
Sam Hocevar's avatar
 
Sam Hocevar committed
82
    "popl   %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
83 84
    "femms\n"
    : "=a" (samples)
Sam Hocevar's avatar
 
Sam Hocevar committed
85
    : "a" (samples), "c" (dm_par));
Sam Hocevar's avatar
 
Sam Hocevar committed
86 87 88 89 90
}

void _M( downmix_2f_2r_to_2ch ) (float *samples, dm_par_t * dm_par)
{
    __asm__ __volatile__ (
91
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
92 93
    "pushl %%ebx\n"
    "movl  $128, %%ebx\n"       /* loop counter */
Sam Hocevar's avatar
 
Sam Hocevar committed
94

Sam Hocevar's avatar
 
Sam Hocevar committed
95
    "movd  (%%ecx), %%mm5\n"    /* unit */
Sam Hocevar's avatar
 
Sam Hocevar committed
96 97
    "punpckldq %%mm5, %%mm5\n"  /* unit | unit */

Sam Hocevar's avatar
 
Sam Hocevar committed
98
    "movd    8(%%ecx), %%mm7\n"    /* slev */
Sam Hocevar's avatar
 
Sam Hocevar committed
99 100
    "punpckldq %%mm7, %%mm7\n"    /* slev | slev */

101
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
".loop3:\n"
    "movq   (%%eax), %%mm0\n"       /* left */
    "movq   1024(%%eax), %%mm1\n"   /* right */
    "movq   2048(%%eax), %%mm3\n"    /* leftsur */
    "movq   3072(%%eax), %%mm4\n"    /* rightsur */
    "pfmul    %%mm5, %%mm0\n"
    "pfmul    %%mm5, %%mm1\n"
    "pfmul    %%mm7, %%mm3\n"
    "pfmul    %%mm7, %%mm4\n"
    "pfadd    %%mm3, %%mm0\n"
    "pfadd    %%mm4, %%mm1\n"

    "movq    %%mm0, (%%eax)\n"
    "movq    %%mm1, 1024(%%eax)\n"

    "addl    $8, %%eax\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
118
    "decl     %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
119 120
    "jnz    .loop3\n"

Sam Hocevar's avatar
 
Sam Hocevar committed
121
    "popl    %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
122 123
    "femms\n"
    : "=a" (samples)
Sam Hocevar's avatar
 
Sam Hocevar committed
124
    : "a" (samples), "c" (dm_par));
Sam Hocevar's avatar
 
Sam Hocevar committed
125 126 127 128 129
}

void _M( downmix_3f_1r_to_2ch ) (float *samples, dm_par_t * dm_par)
{
    __asm__ __volatile__ (
130
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
131 132
    "pushl    %%ebx\n"
    "movl    $128, %%ebx\n"            /* loop counter */
Sam Hocevar's avatar
 
Sam Hocevar committed
133

Sam Hocevar's avatar
 
Sam Hocevar committed
134
    "movd    (%%ecx), %%mm5\n"        /* unit */
Sam Hocevar's avatar
 
Sam Hocevar committed
135 136
    "punpckldq %%mm5, %%mm5\n"        /* unit | unit */

Sam Hocevar's avatar
 
Sam Hocevar committed
137
    "movd    4(%%ecx), %%mm6\n"        /* clev */
Sam Hocevar's avatar
 
Sam Hocevar committed
138 139
    "punpckldq %%mm6, %%mm6\n"        /* clev | clev */

Sam Hocevar's avatar
 
Sam Hocevar committed
140
    "movd    8(%%ecx), %%mm7\n"        /* slev */
Sam Hocevar's avatar
 
Sam Hocevar committed
141 142
    "punpckldq %%mm7, %%mm7\n"      /* slev | slev */

143
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
".loop4:\n"
    "movq    (%%eax), %%mm0\n"       /* left */
    "movq    2048(%%eax), %%mm1\n"   /* right */
    "movq    1024(%%eax), %%mm2\n"    /* center */
    "movq    3072(%%eax), %%mm3\n"    /* sur */
    "pfmul    %%mm5, %%mm0\n"
    "pfmul    %%mm5, %%mm1\n"
    "pfmul    %%mm6, %%mm2\n"
    "pfadd    %%mm2, %%mm0\n"
    "pfmul    %%mm7, %%mm3\n"
    "pfadd     %%mm2, %%mm1\n"
    "pfsub    %%mm3, %%mm0\n"
    "pfadd    %%mm3, %%mm1\n"

    "movq    %%mm0, (%%eax)\n"
    "movq    %%mm1, 1024(%%eax)\n"

    "addl    $8, %%eax\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
162
    "decl     %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
163 164
    "jnz    .loop4\n"

Sam Hocevar's avatar
 
Sam Hocevar committed
165
    "popl    %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
166 167
    "femms\n"
    : "=a" (samples)
Sam Hocevar's avatar
 
Sam Hocevar committed
168
    : "a" (samples), "c" (dm_par));
Sam Hocevar's avatar
 
Sam Hocevar committed
169 170 171 172 173
}

void _M( downmix_2f_1r_to_2ch ) (float *samples, dm_par_t * dm_par)
{
    __asm__ __volatile__ (
174
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
175 176
    "pushl    %%ebx\n"
    "movl    $128, %%ebx\n"            /* loop counter */
Sam Hocevar's avatar
 
Sam Hocevar committed
177

Sam Hocevar's avatar
 
Sam Hocevar committed
178
    "movd    (%%ecx), %%mm5\n"        /* unit */
Sam Hocevar's avatar
 
Sam Hocevar committed
179 180
    "punpckldq %%mm5, %%mm5\n"        /* unit | unit */

Sam Hocevar's avatar
 
Sam Hocevar committed
181
    "movd    8(%%ecx), %%mm7\n"        /* slev */
Sam Hocevar's avatar
 
Sam Hocevar committed
182 183
    "punpckldq %%mm7, %%mm7\n"      /* slev | slev */

184
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198
".loop5:\n"
    "movq    (%%eax), %%mm0\n"       /* left */
    "movq    1024(%%eax), %%mm1\n"   /* right */
    "movq    2048(%%eax), %%mm3\n"    /* sur */
    "pfmul    %%mm5, %%mm0\n"
    "pfmul    %%mm5, %%mm1\n"
    "pfmul    %%mm7, %%mm3\n"
    "pfsub    %%mm3, %%mm0\n"
    "pfadd    %%mm3, %%mm1\n"

    "movq    %%mm0, (%%eax)\n"
    "movq    %%mm1, 1024(%%eax)\n"

    "addl    $8, %%eax\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
199
    "decl     %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
200 201
    "jnz    .loop5\n"

Sam Hocevar's avatar
 
Sam Hocevar committed
202
    "popl    %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
203 204
    "femms\n"
    : "=a" (samples)
Sam Hocevar's avatar
 
Sam Hocevar committed
205
    : "a" (samples), "c" (dm_par));
Sam Hocevar's avatar
 
Sam Hocevar committed
206 207 208 209 210
}

void _M( downmix_3f_0r_to_2ch ) (float *samples, dm_par_t * dm_par)
{
    __asm__ __volatile__ (
211
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
212 213
    "pushl    %%ebx\n"
    "movl    $128, %%ebx\n"            /* loop counter */
Sam Hocevar's avatar
 
Sam Hocevar committed
214

Sam Hocevar's avatar
 
Sam Hocevar committed
215
    "movd    (%%ecx), %%mm5\n"        /* unit */
Sam Hocevar's avatar
 
Sam Hocevar committed
216 217
    "punpckldq %%mm5, %%mm5\n"        /* unit | unit */

Sam Hocevar's avatar
 
Sam Hocevar committed
218
    "movd    4(%%ecx), %%mm6\n"        /* clev */
Sam Hocevar's avatar
 
Sam Hocevar committed
219 220
    "punpckldq %%mm6, %%mm6\n"      /* clev | clev */

221
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235
".loop6:\n"
    "movq    (%%eax), %%mm0\n"       /*left */
    "movq    2048(%%eax), %%mm1\n"   /* right */
    "movq   1024(%%eax), %%mm2\n"   /* center */
    "pfmul    %%mm5, %%mm0\n"
    "pfmul    %%mm5, %%mm1\n"
    "pfmul    %%mm6, %%mm2\n"
    "pfadd    %%mm2, %%mm0\n"
    "pfadd     %%mm2, %%mm1\n"

    "movq    %%mm0, (%%eax)\n"
    "movq    %%mm1, 1024(%%eax)\n"

    "addl    $8, %%eax\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
236
    "decl     %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
237 238
    "jnz    .loop6\n"

Sam Hocevar's avatar
 
Sam Hocevar committed
239
    "popl    %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
240 241
    "femms\n"
    : "=a" (samples)
Sam Hocevar's avatar
 
Sam Hocevar committed
242
    : "a" (samples), "c" (dm_par));
Sam Hocevar's avatar
 
Sam Hocevar committed
243 244 245 246 247
}

void _M( stream_sample_1ch_to_s16 ) (s16 *s16_samples, float *left)
{
    __asm__ __volatile__ (
248
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
249
    "pushl %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
250 251 252 253 254
    "pushl %%edx\n"

    "movl   $sqrt2_3dn, %%edx\n"
    "movd  (%%edx), %%mm7\n"
    "punpckldq %%mm7, %%mm7\n"   /* sqrt2 | sqrt2 */
Sam Hocevar's avatar
 
Sam Hocevar committed
255
    "movl $128, %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
256

257
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
258
".loop2:\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
259
    "movq (%%ecx), %%mm0\n"        /* c1 | c0 */
Sam Hocevar's avatar
 
Sam Hocevar committed
260 261 262 263 264 265 266 267
    "pfmul   %%mm7, %%mm0\n"

    "pf2id %%mm0, %%mm0\n"        /* c1 c0 --> mm0, int_32 */

    "packssdw %%mm0, %%mm0\n"        /* c1 c1 c0 c0 --> mm0, int_16 */

    "movq %%mm0, (%%eax)\n"
    "addl $8, %%eax\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
268
    "addl $8, %%ecx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
269

Sam Hocevar's avatar
 
Sam Hocevar committed
270
    "decl %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
271 272 273
    "jnz .loop2\n"

    "popl %%edx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
274
    "popl %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
275
    "femms\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
276 277
    : "=a" (s16_samples), "=c" (left)
    : "a" (s16_samples), "c" (left));
Sam Hocevar's avatar
 
Sam Hocevar committed
278 279 280 281 282 283
}

void _M( stream_sample_2ch_to_s16 ) (s16 *s16_samples, float *left, float *right)
{

    __asm__ __volatile__ (
284
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
285 286
    "pushl %%ebx\n"
    "movl $128, %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
287

288
    ".align 16\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
289
".loop1:\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
290
    "movq  (%%ecx), %%mm0\n"    /* l1 | l0 */
Sam Hocevar's avatar
 
Sam Hocevar committed
291 292 293 294 295 296 297 298 299 300 301 302 303
    "movq  (%%edx), %%mm1\n"    /* r1 | r0 */
    "movq   %%mm0,  %%mm2\n"    /* l1 | l0 */
    "punpckldq %%mm1, %%mm0\n"    /* r0 | l0 */
    "punpckhdq %%mm1, %%mm2\n"    /* r1 | l1 */

    "pf2id    %%mm0, %%mm0\n"    /* r0 l0 --> mm0, int_32 */
    "pf2id    %%mm2, %%mm2\n"    /* r0 l0 --> mm0, int_32 */
    
    "packssdw %%mm2, %%mm0\n"    /* r1 l1 r0 l0 --> mm0, int_16 */

    "movq %%mm0, (%%eax)\n"
    "movq %%mm2, 8(%%eax)\n"
    "addl $8, %%eax\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
304
    "addl $8, %%ecx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
305 306
    "addl $8, %%edx\n"

Sam Hocevar's avatar
 
Sam Hocevar committed
307
    "decl %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
308 309
    "jnz .loop1\n"

Sam Hocevar's avatar
 
Sam Hocevar committed
310
    "popl %%ebx\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
311
    "femms\n"
Sam Hocevar's avatar
 
Sam Hocevar committed
312 313
    : "=a" (s16_samples), "=c" (left), "=d" (right)
    : "a" (s16_samples), "c" (left), "d" (right));
Sam Hocevar's avatar
 
Sam Hocevar committed
314 315 316
    
}