2 * DSP utils : QNS functions are compiled 3 times for mmx/3dnow/ssse3
3 * Copyright (c) 2004 Michael Niedermayer
5 * MMX optimization by Michael Niedermayer <michaelni@gmx.at>
6 * 3DNow! and SSSE3 optimization by Zuxy Meng <zuxy.meng@gmail.com>
8 * This file is part of FFmpeg.
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * FFmpeg 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 GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 /* This header intentionally has no multiple inclusion guards. It is meant to
26 * be included multiple times and generates different code depending on the
27 * value of certain #defines. */
29 #define MAX_ABS (512 >> (SCALE_OFFSET>0 ? SCALE_OFFSET : 0))
31 static int DEF(try_8x8basis
)(int16_t rem
[64], int16_t weight
[64], int16_t basis
[64], int scale
)
35 assert(FFABS(scale
) < MAX_ABS
);
36 scale
<<= 16 + SCALE_OFFSET
- BASIS_SHIFT
+ RECON_SHIFT
;
40 "pxor %%mm7, %%mm7 \n\t"
42 "punpcklwd %%mm5, %%mm5 \n\t"
43 "punpcklwd %%mm5, %%mm5 \n\t"
46 "movq (%1, %0), %%mm0 \n\t"
47 "movq 8(%1, %0), %%mm1 \n\t"
48 PMULHRW(%%mm0
, %%mm1
, %%mm5
, %%mm6
)
49 "paddw (%2, %0), %%mm0 \n\t"
50 "paddw 8(%2, %0), %%mm1 \n\t"
51 "psraw $6, %%mm0 \n\t"
52 "psraw $6, %%mm1 \n\t"
53 "pmullw (%3, %0), %%mm0 \n\t"
54 "pmullw 8(%3, %0), %%mm1 \n\t"
55 "pmaddwd %%mm0, %%mm0 \n\t"
56 "pmaddwd %%mm1, %%mm1 \n\t"
57 "paddd %%mm1, %%mm0 \n\t"
58 "psrld $4, %%mm0 \n\t"
59 "paddd %%mm0, %%mm7 \n\t"
61 "cmp $128, %0 \n\t" //FIXME optimize & bench
64 "psrld $2, %%mm7 \n\t"
68 : "r"(basis
), "r"(rem
), "r"(weight
), "g"(scale
)
73 static void DEF(add_8x8basis
)(int16_t rem
[64], int16_t basis
[64], int scale
)
77 if(FFABS(scale
) < MAX_ABS
){
78 scale
<<= 16 + SCALE_OFFSET
- BASIS_SHIFT
+ RECON_SHIFT
;
82 "punpcklwd %%mm5, %%mm5 \n\t"
83 "punpcklwd %%mm5, %%mm5 \n\t"
86 "movq (%1, %0), %%mm0 \n\t"
87 "movq 8(%1, %0), %%mm1 \n\t"
88 PMULHRW(%%mm0
, %%mm1
, %%mm5
, %%mm6
)
89 "paddw (%2, %0), %%mm0 \n\t"
90 "paddw 8(%2, %0), %%mm1 \n\t"
91 "movq %%mm0, (%2, %0) \n\t"
92 "movq %%mm1, 8(%2, %0) \n\t"
94 "cmp $128, %0 \n\t" // FIXME optimize & bench
98 : "r"(basis
), "r"(rem
), "g"(scale
)
101 for(i
=0; i
<8*8; i
++){
102 rem
[i
] += (basis
[i
]*scale
+ (1<<(BASIS_SHIFT
- RECON_SHIFT
-1)))>>(BASIS_SHIFT
- RECON_SHIFT
);