Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / dsputil_h264_template_mmx.c @ ce611a27

History | View | Annotate | Download (10.6 KB)

1 3072f0cb Zoltán Hidvégi
/*
2 a6624e21 Loren Merritt
 * Copyright (c) 2005 Zoltan Hidvegi <hzoli -a- hzoli -d- com>,
3
 *                    Loren Merritt
4 3072f0cb Zoltán Hidvégi
 *
5 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8 3072f0cb Zoltán Hidvégi
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
11 3072f0cb Zoltán Hidvégi
 *
12 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
13 3072f0cb Zoltán Hidvégi
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
19 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 3072f0cb Zoltán Hidvégi
 */
21
22
/**
23
 * MMX optimized version of (put|avg)_h264_chroma_mc8.
24 a6624e21 Loren Merritt
 * H264_CHROMA_MC8_TMPL must be defined to the desired function name
25
 * H264_CHROMA_OP must be defined to empty for put and pavgb/pavgusb for avg
26
 * H264_CHROMA_MC8_MV0 must be defined to a (put|avg)_pixels8 function
27 3072f0cb Zoltán Hidvégi
 */
28
static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
29
{
30 68b51e58 Steve L'Homme
    DECLARE_ALIGNED_8(uint64_t, AA);
31
    DECLARE_ALIGNED_8(uint64_t, DD);
32 3072f0cb Zoltán Hidvégi
    int i;
33
34 a6624e21 Loren Merritt
    if(y==0 && x==0) {
35
        /* no filter needed */
36
        H264_CHROMA_MC8_MV0(dst, src, stride, h);
37
        return;
38
    }
39
40 3072f0cb Zoltán Hidvégi
    assert(x<8 && y<8 && x>=0 && y>=0);
41
42 5e8b787a Loren Merritt
    if(y==0 || x==0)
43 a6624e21 Loren Merritt
    {
44 5e8b787a Loren Merritt
        /* 1 dimensional filter only */
45
        const int dxy = x ? 1 : stride;
46
47
        asm volatile(
48
            "movd %0, %%mm5\n\t"
49
            "movq %1, %%mm4\n\t"
50
            "punpcklwd %%mm5, %%mm5\n\t"
51
            "punpckldq %%mm5, %%mm5\n\t" /* mm5 = B = x */
52
            "movq %%mm4, %%mm6\n\t"
53
            "pxor %%mm7, %%mm7\n\t"
54
            "psubw %%mm5, %%mm4\n\t"     /* mm4 = A = 8-x */
55
            "psrlw $1, %%mm6\n\t"        /* mm6 = 4 */
56
            :: "rm"(x+y), "m"(ff_pw_8));
57 a6624e21 Loren Merritt
58
        for(i=0; i<h; i++) {
59
            asm volatile(
60
                /* mm0 = src[0..7], mm1 = src[1..8] */
61
                "movq %0, %%mm0\n\t"
62 5e8b787a Loren Merritt
                "movq %1, %%mm2\n\t"
63
                :: "m"(src[0]), "m"(src[dxy]));
64 a6624e21 Loren Merritt
65
            asm volatile(
66 5e8b787a Loren Merritt
                /* [mm0,mm1] = A * src[0..7] */
67
                /* [mm2,mm3] = B * src[1..8] */
68
                "movq %%mm0, %%mm1\n\t"
69
                "movq %%mm2, %%mm3\n\t"
70 a6624e21 Loren Merritt
                "punpcklbw %%mm7, %%mm0\n\t"
71
                "punpckhbw %%mm7, %%mm1\n\t"
72 5e8b787a Loren Merritt
                "punpcklbw %%mm7, %%mm2\n\t"
73
                "punpckhbw %%mm7, %%mm3\n\t"
74
                "pmullw %%mm4, %%mm0\n\t"
75
                "pmullw %%mm4, %%mm1\n\t"
76
                "pmullw %%mm5, %%mm2\n\t"
77
                "pmullw %%mm5, %%mm3\n\t"
78
79
                /* dst[0..7] = (A * src[0..7] + B * src[1..8] + 4) >> 3 */
80
                "paddw %%mm6, %%mm0\n\t"
81
                "paddw %%mm6, %%mm1\n\t"
82
                "paddw %%mm2, %%mm0\n\t"
83
                "paddw %%mm3, %%mm1\n\t"
84
                "psrlw $3, %%mm0\n\t"
85
                "psrlw $3, %%mm1\n\t"
86
                "packuswb %%mm1, %%mm0\n\t"
87
                H264_CHROMA_OP(%0, %%mm0)
88
                "movq %%mm0, %0\n\t"
89
                : "=m" (dst[0]));
90 a6624e21 Loren Merritt
91
            src += stride;
92
            dst += stride;
93
        }
94
        return;
95
    }
96
97
    /* general case, bilinear */
98
    asm volatile("movd %2, %%mm4\n\t"
99
                 "movd %3, %%mm6\n\t"
100 3072f0cb Zoltán Hidvégi
                 "punpcklwd %%mm4, %%mm4\n\t"
101
                 "punpcklwd %%mm6, %%mm6\n\t"
102
                 "punpckldq %%mm4, %%mm4\n\t" /* mm4 = x words */
103
                 "punpckldq %%mm6, %%mm6\n\t" /* mm6 = y words */
104
                 "movq %%mm4, %%mm5\n\t"
105
                 "pmullw %%mm6, %%mm4\n\t"    /* mm4 = x * y */
106
                 "psllw $3, %%mm5\n\t"
107
                 "psllw $3, %%mm6\n\t"
108
                 "movq %%mm5, %%mm7\n\t"
109
                 "paddw %%mm6, %%mm7\n\t"
110 a6624e21 Loren Merritt
                 "movq %%mm4, %1\n\t"         /* DD = x * y */
111 3072f0cb Zoltán Hidvégi
                 "psubw %%mm4, %%mm5\n\t"     /* mm5 = B = 8x - xy */
112
                 "psubw %%mm4, %%mm6\n\t"     /* mm6 = C = 8y - xy */
113 a6624e21 Loren Merritt
                 "paddw %4, %%mm4\n\t"
114 3072f0cb Zoltán Hidvégi
                 "psubw %%mm7, %%mm4\n\t"     /* mm4 = A = xy - (8x+8y) + 64 */
115
                 "pxor %%mm7, %%mm7\n\t"
116 a6624e21 Loren Merritt
                 "movq %%mm4, %0\n\t"
117
                 : "=m" (AA), "=m" (DD) : "rm" (x), "rm" (y), "m" (ff_pw_64));
118 3072f0cb Zoltán Hidvégi
119
    asm volatile(
120
        /* mm0 = src[0..7], mm1 = src[1..8] */
121 a6624e21 Loren Merritt
        "movq %0, %%mm0\n\t"
122
        "movq %1, %%mm1\n\t"
123
        : : "m" (src[0]), "m" (src[1]));
124 3072f0cb Zoltán Hidvégi
125
    for(i=0; i<h; i++) {
126 5e8b787a Loren Merritt
        src += stride;
127
128 3072f0cb Zoltán Hidvégi
        asm volatile(
129 5e8b787a Loren Merritt
            /* mm2 = A * src[0..3] + B * src[1..4] */
130
            /* mm3 = A * src[4..7] + B * src[5..8] */
131 3072f0cb Zoltán Hidvégi
            "movq %%mm0, %%mm2\n\t"
132 5e8b787a Loren Merritt
            "movq %%mm1, %%mm3\n\t"
133
            "punpckhbw %%mm7, %%mm0\n\t"
134
            "punpcklbw %%mm7, %%mm1\n\t"
135 3072f0cb Zoltán Hidvégi
            "punpcklbw %%mm7, %%mm2\n\t"
136
            "punpckhbw %%mm7, %%mm3\n\t"
137 5e8b787a Loren Merritt
            "pmullw %0, %%mm0\n\t"
138
            "pmullw %0, %%mm2\n\t"
139
            "pmullw %%mm5, %%mm1\n\t"
140
            "pmullw %%mm5, %%mm3\n\t"
141
            "paddw %%mm1, %%mm2\n\t"
142
            "paddw %%mm0, %%mm3\n\t"
143
            : : "m" (AA));
144 3072f0cb Zoltán Hidvégi
145 5e8b787a Loren Merritt
        asm volatile(
146
            /* [mm2,mm3] += C * src[0..7] */
147
            "movq %0, %%mm0\n\t"
148
            "movq %%mm0, %%mm1\n\t"
149 3072f0cb Zoltán Hidvégi
            "punpcklbw %%mm7, %%mm0\n\t"
150
            "punpckhbw %%mm7, %%mm1\n\t"
151 5e8b787a Loren Merritt
            "pmullw %%mm6, %%mm0\n\t"
152
            "pmullw %%mm6, %%mm1\n\t"
153 3072f0cb Zoltán Hidvégi
            "paddw %%mm0, %%mm2\n\t"
154
            "paddw %%mm1, %%mm3\n\t"
155 5e8b787a Loren Merritt
            : : "m" (src[0]));
156 3072f0cb Zoltán Hidvégi
157
        asm volatile(
158 5e8b787a Loren Merritt
            /* [mm2,mm3] += D * src[1..8] */
159 a6624e21 Loren Merritt
            "movq %1, %%mm1\n\t"
160 5e8b787a Loren Merritt
            "movq %%mm1, %%mm0\n\t"
161 3072f0cb Zoltán Hidvégi
            "movq %%mm1, %%mm4\n\t"
162 5e8b787a Loren Merritt
            "punpcklbw %%mm7, %%mm0\n\t"
163 3072f0cb Zoltán Hidvégi
            "punpckhbw %%mm7, %%mm4\n\t"
164 5e8b787a Loren Merritt
            "pmullw %2, %%mm0\n\t"
165
            "pmullw %2, %%mm4\n\t"
166
            "paddw %%mm0, %%mm2\n\t"
167 3072f0cb Zoltán Hidvégi
            "paddw %%mm4, %%mm3\n\t"
168 5e8b787a Loren Merritt
            "movq %0, %%mm0\n\t"
169
            : : "m" (src[0]), "m" (src[1]), "m" (DD));
170 3072f0cb Zoltán Hidvégi
171
        asm volatile(
172 5e8b787a Loren Merritt
            /* dst[0..7] = ([mm2,mm3] + 32) >> 6 */
173 3072f0cb Zoltán Hidvégi
            "paddw %1, %%mm2\n\t"
174
            "paddw %1, %%mm3\n\t"
175
            "psrlw $6, %%mm2\n\t"
176
            "psrlw $6, %%mm3\n\t"
177
            "packuswb %%mm3, %%mm2\n\t"
178
            H264_CHROMA_OP(%0, %%mm2)
179
            "movq %%mm2, %0\n\t"
180 d2bb7db1 Loren Merritt
            : "=m" (dst[0]) : "m" (ff_pw_32));
181 3072f0cb Zoltán Hidvégi
        dst+= stride;
182
    }
183
}
184 a6624e21 Loren Merritt
185 fdd30579 Loren Merritt
static void H264_CHROMA_MC4_TMPL(uint8_t *dst/*align 4*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
186 a6624e21 Loren Merritt
{
187
    asm volatile(
188 b21e0b6d Michael Niedermayer
        "pxor   %%mm7, %%mm7        \n\t"
189
        "movd %5, %%mm2             \n\t"
190
        "movd %6, %%mm3             \n\t"
191 470d2d03 Michael Niedermayer
        "movq "MANGLE(ff_pw_8)", %%mm4\n\t"
192
        "movq "MANGLE(ff_pw_8)", %%mm5\n\t"
193 b21e0b6d Michael Niedermayer
        "punpcklwd %%mm2, %%mm2     \n\t"
194
        "punpcklwd %%mm3, %%mm3     \n\t"
195
        "punpcklwd %%mm2, %%mm2     \n\t"
196
        "punpcklwd %%mm3, %%mm3     \n\t"
197
        "psubw %%mm2, %%mm4         \n\t"
198
        "psubw %%mm3, %%mm5         \n\t"
199 a6624e21 Loren Merritt
200 b21e0b6d Michael Niedermayer
        "movd  (%1), %%mm0          \n\t"
201
        "movd 1(%1), %%mm6          \n\t"
202
        "add %3, %1                 \n\t"
203
        "punpcklbw %%mm7, %%mm0     \n\t"
204
        "punpcklbw %%mm7, %%mm6     \n\t"
205
        "pmullw %%mm4, %%mm0        \n\t"
206
        "pmullw %%mm2, %%mm6        \n\t"
207
        "paddw %%mm0, %%mm6         \n\t"
208 a6624e21 Loren Merritt
209 b21e0b6d Michael Niedermayer
        "1:                         \n\t"
210
        "movd  (%1), %%mm0          \n\t"
211
        "movd 1(%1), %%mm1          \n\t"
212
        "add %3, %1                 \n\t"
213
        "punpcklbw %%mm7, %%mm0     \n\t"
214
        "punpcklbw %%mm7, %%mm1     \n\t"
215
        "pmullw %%mm4, %%mm0        \n\t"
216
        "pmullw %%mm2, %%mm1        \n\t"
217
        "paddw %%mm0, %%mm1         \n\t"
218
        "movq %%mm1, %%mm0          \n\t"
219
        "pmullw %%mm5, %%mm6        \n\t"
220
        "pmullw %%mm3, %%mm1        \n\t"
221 58e31fb1 Michael Niedermayer
        "paddw %4, %%mm6            \n\t"
222 b21e0b6d Michael Niedermayer
        "paddw %%mm6, %%mm1         \n\t"
223
        "psrlw $6, %%mm1            \n\t"
224
        "packuswb %%mm1, %%mm1      \n\t"
225
        H264_CHROMA_OP4((%0), %%mm1, %%mm6)
226
        "movd %%mm1, (%0)           \n\t"
227
        "add %3, %0                 \n\t"
228
        "movd  (%1), %%mm6          \n\t"
229
        "movd 1(%1), %%mm1          \n\t"
230
        "add %3, %1                 \n\t"
231
        "punpcklbw %%mm7, %%mm6     \n\t"
232
        "punpcklbw %%mm7, %%mm1     \n\t"
233
        "pmullw %%mm4, %%mm6        \n\t"
234
        "pmullw %%mm2, %%mm1        \n\t"
235
        "paddw %%mm6, %%mm1         \n\t"
236
        "movq %%mm1, %%mm6          \n\t"
237
        "pmullw %%mm5, %%mm0        \n\t"
238
        "pmullw %%mm3, %%mm1        \n\t"
239 58e31fb1 Michael Niedermayer
        "paddw %4, %%mm0            \n\t"
240 b21e0b6d Michael Niedermayer
        "paddw %%mm0, %%mm1         \n\t"
241
        "psrlw $6, %%mm1            \n\t"
242
        "packuswb %%mm1, %%mm1      \n\t"
243
        H264_CHROMA_OP4((%0), %%mm1, %%mm0)
244
        "movd %%mm1, (%0)           \n\t"
245
        "add %3, %0                 \n\t"
246
        "sub $2, %2                 \n\t"
247
        "jnz 1b                     \n\t"
248
        : "+r"(dst), "+r"(src), "+r"(h)
249 470d2d03 Michael Niedermayer
        : "r"((long)stride), "m"(ff_pw_32), "m"(x), "m"(y)
250 b21e0b6d Michael Niedermayer
    );
251 a6624e21 Loren Merritt
}
252 fdd30579 Loren Merritt
253
#ifdef H264_CHROMA_MC2_TMPL
254 8657d5e5 Måns Rullgård
static void H264_CHROMA_MC2_TMPL(uint8_t *dst/*align 2*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
255 fdd30579 Loren Merritt
{
256 7c4fd7eb Michael Niedermayer
    int tmp = ((1<<16)-1)*x + 8;
257
    int CD= tmp*y;
258
    int AB= (tmp<<3) - CD;
259 fdd30579 Loren Merritt
    asm volatile(
260
        /* mm5 = {A,B,A,B} */
261
        /* mm6 = {C,D,C,D} */
262
        "movd %0, %%mm5\n\t"
263
        "movd %1, %%mm6\n\t"
264
        "punpckldq %%mm5, %%mm5\n\t"
265
        "punpckldq %%mm6, %%mm6\n\t"
266
        "pxor %%mm7, %%mm7\n\t"
267
        /* mm0 = src[0,1,1,2] */
268 0c67082e Michael Niedermayer
        "movd %2, %%mm2\n\t"
269
        "punpcklbw %%mm7, %%mm2\n\t"
270
        "pshufw $0x94, %%mm2, %%mm2\n\t"
271 9301a0b4 Michael Niedermayer
        :: "r"(AB), "r"(CD), "m"(src[0]));
272 fdd30579 Loren Merritt
273
274 9301a0b4 Michael Niedermayer
    asm volatile(
275
        "1:\n\t"
276 392b76ca Reimar Döffinger
        "add %4, %1\n\t"
277 9301a0b4 Michael Niedermayer
        /* mm1 = A * src[0,1] + B * src[1,2] */
278 0c67082e Michael Niedermayer
        "movq    %%mm2, %%mm1\n\t"
279 9301a0b4 Michael Niedermayer
        "pmaddwd %%mm5, %%mm1\n\t"
280
        /* mm0 = src[0,1,1,2] */
281
        "movd (%1), %%mm0\n\t"
282
        "punpcklbw %%mm7, %%mm0\n\t"
283
        "pshufw $0x94, %%mm0, %%mm0\n\t"
284
        /* mm1 += C * src[0,1] + D * src[1,2] */
285
        "movq    %%mm0, %%mm2\n\t"
286 0c67082e Michael Niedermayer
        "pmaddwd %%mm6, %%mm0\n\t"
287 b4fe9769 Michael Niedermayer
        "paddw      %3, %%mm1\n\t"
288 0c67082e Michael Niedermayer
        "paddw   %%mm0, %%mm1\n\t"
289 9301a0b4 Michael Niedermayer
        /* dst[0,1] = pack((mm1 + 32) >> 6) */
290
        "psrlw $6, %%mm1\n\t"
291
        "packssdw %%mm7, %%mm1\n\t"
292
        "packuswb %%mm7, %%mm1\n\t"
293
        H264_CHROMA_OP4((%0), %%mm1, %%mm3)
294 61240ae5 Michael Niedermayer
        "movd %%mm1, %%esi\n\t"
295
        "movw %%si, (%0)\n\t"
296 9bc0d3ef Michael Niedermayer
        "add %4, %0\n\t"
297
        "sub $1, %2\n\t"
298 9301a0b4 Michael Niedermayer
        "jnz 1b\n\t"
299 61240ae5 Michael Niedermayer
        : "+r" (dst), "+r"(src), "+r"(h)
300 8657d5e5 Måns Rullgård
        : "m" (ff_pw_32), "r"((long)stride)
301 61240ae5 Michael Niedermayer
        : "%esi");
302 fdd30579 Loren Merritt
303
}
304
#endif