Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / dsputil_h264_template_mmx.c @ 9fa35729

History | View | Annotate | Download (10.8 KB)

1
/*
2
 * Copyright (c) 2005 Zoltan Hidvegi <hzoli -a- hzoli -d- com>,
3
 *                    Loren Merritt
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * 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
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

    
22
/**
23
 * MMX optimized version of (put|avg)_h264_chroma_mc8.
24
 * 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
 */
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, int rnd)
29
{
30
    DECLARE_ALIGNED_8(static const uint64_t, ff_pw_28) = 0x001C001C001C001CULL;
31
    const uint64_t *rnd_reg;
32
    DECLARE_ALIGNED_8(uint64_t, AA);
33
    DECLARE_ALIGNED_8(uint64_t, DD);
34
    int i;
35

    
36
    if(y==0 && x==0) {
37
        /* no filter needed */
38
        H264_CHROMA_MC8_MV0(dst, src, stride, h);
39
        return;
40
    }
41

    
42
    assert(x<8 && y<8 && x>=0 && y>=0);
43

    
44
    if(y==0 || x==0)
45
    {
46
        /* 1 dimensional filter only */
47
        const int dxy = x ? 1 : stride;
48

    
49
        rnd_reg = rnd ? &ff_pw_4 : &ff_pw_3;
50

    
51
        asm volatile(
52
            "movd %0, %%mm5\n\t"
53
            "movq %1, %%mm4\n\t"
54
            "movq %2, %%mm6\n\t"         /* mm6 = rnd */
55
            "punpcklwd %%mm5, %%mm5\n\t"
56
            "punpckldq %%mm5, %%mm5\n\t" /* mm5 = B = x */
57
            "pxor %%mm7, %%mm7\n\t"
58
            "psubw %%mm5, %%mm4\n\t"     /* mm4 = A = 8-x */
59
            :: "rm"(x+y), "m"(ff_pw_8), "m"(*rnd_reg));
60

    
61
        for(i=0; i<h; i++) {
62
            asm volatile(
63
                /* mm0 = src[0..7], mm1 = src[1..8] */
64
                "movq %0, %%mm0\n\t"
65
                "movq %1, %%mm2\n\t"
66
                :: "m"(src[0]), "m"(src[dxy]));
67

    
68
            asm volatile(
69
                /* [mm0,mm1] = A * src[0..7] */
70
                /* [mm2,mm3] = B * src[1..8] */
71
                "movq %%mm0, %%mm1\n\t"
72
                "movq %%mm2, %%mm3\n\t"
73
                "punpcklbw %%mm7, %%mm0\n\t"
74
                "punpckhbw %%mm7, %%mm1\n\t"
75
                "punpcklbw %%mm7, %%mm2\n\t"
76
                "punpckhbw %%mm7, %%mm3\n\t"
77
                "pmullw %%mm4, %%mm0\n\t"
78
                "pmullw %%mm4, %%mm1\n\t"
79
                "pmullw %%mm5, %%mm2\n\t"
80
                "pmullw %%mm5, %%mm3\n\t"
81

    
82
                /* dst[0..7] = (A * src[0..7] + B * src[1..8] + 4) >> 3 */
83
                "paddw %%mm6, %%mm0\n\t"
84
                "paddw %%mm6, %%mm1\n\t"
85
                "paddw %%mm2, %%mm0\n\t"
86
                "paddw %%mm3, %%mm1\n\t"
87
                "psrlw $3, %%mm0\n\t"
88
                "psrlw $3, %%mm1\n\t"
89
                "packuswb %%mm1, %%mm0\n\t"
90
                H264_CHROMA_OP(%0, %%mm0)
91
                "movq %%mm0, %0\n\t"
92
                : "=m" (dst[0]));
93

    
94
            src += stride;
95
            dst += stride;
96
        }
97
        return;
98
    }
99

    
100
    /* general case, bilinear */
101
    rnd_reg = rnd ? &ff_pw_32 : &ff_pw_28;
102
    asm volatile("movd %2, %%mm4\n\t"
103
                 "movd %3, %%mm6\n\t"
104
                 "punpcklwd %%mm4, %%mm4\n\t"
105
                 "punpcklwd %%mm6, %%mm6\n\t"
106
                 "punpckldq %%mm4, %%mm4\n\t" /* mm4 = x words */
107
                 "punpckldq %%mm6, %%mm6\n\t" /* mm6 = y words */
108
                 "movq %%mm4, %%mm5\n\t"
109
                 "pmullw %%mm6, %%mm4\n\t"    /* mm4 = x * y */
110
                 "psllw $3, %%mm5\n\t"
111
                 "psllw $3, %%mm6\n\t"
112
                 "movq %%mm5, %%mm7\n\t"
113
                 "paddw %%mm6, %%mm7\n\t"
114
                 "movq %%mm4, %1\n\t"         /* DD = x * y */
115
                 "psubw %%mm4, %%mm5\n\t"     /* mm5 = B = 8x - xy */
116
                 "psubw %%mm4, %%mm6\n\t"     /* mm6 = C = 8y - xy */
117
                 "paddw %4, %%mm4\n\t"
118
                 "psubw %%mm7, %%mm4\n\t"     /* mm4 = A = xy - (8x+8y) + 64 */
119
                 "pxor %%mm7, %%mm7\n\t"
120
                 "movq %%mm4, %0\n\t"
121
                 : "=m" (AA), "=m" (DD) : "rm" (x), "rm" (y), "m" (ff_pw_64));
122

    
123
    asm volatile(
124
        /* mm0 = src[0..7], mm1 = src[1..8] */
125
        "movq %0, %%mm0\n\t"
126
        "movq %1, %%mm1\n\t"
127
        : : "m" (src[0]), "m" (src[1]));
128

    
129
    for(i=0; i<h; i++) {
130
        src += stride;
131

    
132
        asm volatile(
133
            /* mm2 = A * src[0..3] + B * src[1..4] */
134
            /* mm3 = A * src[4..7] + B * src[5..8] */
135
            "movq %%mm0, %%mm2\n\t"
136
            "movq %%mm1, %%mm3\n\t"
137
            "punpckhbw %%mm7, %%mm0\n\t"
138
            "punpcklbw %%mm7, %%mm1\n\t"
139
            "punpcklbw %%mm7, %%mm2\n\t"
140
            "punpckhbw %%mm7, %%mm3\n\t"
141
            "pmullw %0, %%mm0\n\t"
142
            "pmullw %0, %%mm2\n\t"
143
            "pmullw %%mm5, %%mm1\n\t"
144
            "pmullw %%mm5, %%mm3\n\t"
145
            "paddw %%mm1, %%mm2\n\t"
146
            "paddw %%mm0, %%mm3\n\t"
147
            : : "m" (AA));
148

    
149
        asm volatile(
150
            /* [mm2,mm3] += C * src[0..7] */
151
            "movq %0, %%mm0\n\t"
152
            "movq %%mm0, %%mm1\n\t"
153
            "punpcklbw %%mm7, %%mm0\n\t"
154
            "punpckhbw %%mm7, %%mm1\n\t"
155
            "pmullw %%mm6, %%mm0\n\t"
156
            "pmullw %%mm6, %%mm1\n\t"
157
            "paddw %%mm0, %%mm2\n\t"
158
            "paddw %%mm1, %%mm3\n\t"
159
            : : "m" (src[0]));
160

    
161
        asm volatile(
162
            /* [mm2,mm3] += D * src[1..8] */
163
            "movq %1, %%mm1\n\t"
164
            "movq %%mm1, %%mm0\n\t"
165
            "movq %%mm1, %%mm4\n\t"
166
            "punpcklbw %%mm7, %%mm0\n\t"
167
            "punpckhbw %%mm7, %%mm4\n\t"
168
            "pmullw %2, %%mm0\n\t"
169
            "pmullw %2, %%mm4\n\t"
170
            "paddw %%mm0, %%mm2\n\t"
171
            "paddw %%mm4, %%mm3\n\t"
172
            "movq %0, %%mm0\n\t"
173
            : : "m" (src[0]), "m" (src[1]), "m" (DD));
174

    
175
        asm volatile(
176
            /* dst[0..7] = ([mm2,mm3] + 32) >> 6 */
177
            "paddw %1, %%mm2\n\t"
178
            "paddw %1, %%mm3\n\t"
179
            "psrlw $6, %%mm2\n\t"
180
            "psrlw $6, %%mm3\n\t"
181
            "packuswb %%mm3, %%mm2\n\t"
182
            H264_CHROMA_OP(%0, %%mm2)
183
            "movq %%mm2, %0\n\t"
184
            : "=m" (dst[0]) : "m" (*rnd_reg));
185
        dst+= stride;
186
    }
187
}
188

    
189
static void H264_CHROMA_MC4_TMPL(uint8_t *dst/*align 4*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
190
{
191
    asm volatile(
192
        "pxor   %%mm7, %%mm7        \n\t"
193
        "movd %5, %%mm2             \n\t"
194
        "movd %6, %%mm3             \n\t"
195
        "movq "MANGLE(ff_pw_8)", %%mm4\n\t"
196
        "movq "MANGLE(ff_pw_8)", %%mm5\n\t"
197
        "punpcklwd %%mm2, %%mm2     \n\t"
198
        "punpcklwd %%mm3, %%mm3     \n\t"
199
        "punpcklwd %%mm2, %%mm2     \n\t"
200
        "punpcklwd %%mm3, %%mm3     \n\t"
201
        "psubw %%mm2, %%mm4         \n\t"
202
        "psubw %%mm3, %%mm5         \n\t"
203

    
204
        "movd  (%1), %%mm0          \n\t"
205
        "movd 1(%1), %%mm6          \n\t"
206
        "add %3, %1                 \n\t"
207
        "punpcklbw %%mm7, %%mm0     \n\t"
208
        "punpcklbw %%mm7, %%mm6     \n\t"
209
        "pmullw %%mm4, %%mm0        \n\t"
210
        "pmullw %%mm2, %%mm6        \n\t"
211
        "paddw %%mm0, %%mm6         \n\t"
212

    
213
        "1:                         \n\t"
214
        "movd  (%1), %%mm0          \n\t"
215
        "movd 1(%1), %%mm1          \n\t"
216
        "add %3, %1                 \n\t"
217
        "punpcklbw %%mm7, %%mm0     \n\t"
218
        "punpcklbw %%mm7, %%mm1     \n\t"
219
        "pmullw %%mm4, %%mm0        \n\t"
220
        "pmullw %%mm2, %%mm1        \n\t"
221
        "paddw %%mm0, %%mm1         \n\t"
222
        "movq %%mm1, %%mm0          \n\t"
223
        "pmullw %%mm5, %%mm6        \n\t"
224
        "pmullw %%mm3, %%mm1        \n\t"
225
        "paddw %4, %%mm6            \n\t"
226
        "paddw %%mm6, %%mm1         \n\t"
227
        "psrlw $6, %%mm1            \n\t"
228
        "packuswb %%mm1, %%mm1      \n\t"
229
        H264_CHROMA_OP4((%0), %%mm1, %%mm6)
230
        "movd %%mm1, (%0)           \n\t"
231
        "add %3, %0                 \n\t"
232
        "movd  (%1), %%mm6          \n\t"
233
        "movd 1(%1), %%mm1          \n\t"
234
        "add %3, %1                 \n\t"
235
        "punpcklbw %%mm7, %%mm6     \n\t"
236
        "punpcklbw %%mm7, %%mm1     \n\t"
237
        "pmullw %%mm4, %%mm6        \n\t"
238
        "pmullw %%mm2, %%mm1        \n\t"
239
        "paddw %%mm6, %%mm1         \n\t"
240
        "movq %%mm1, %%mm6          \n\t"
241
        "pmullw %%mm5, %%mm0        \n\t"
242
        "pmullw %%mm3, %%mm1        \n\t"
243
        "paddw %4, %%mm0            \n\t"
244
        "paddw %%mm0, %%mm1         \n\t"
245
        "psrlw $6, %%mm1            \n\t"
246
        "packuswb %%mm1, %%mm1      \n\t"
247
        H264_CHROMA_OP4((%0), %%mm1, %%mm0)
248
        "movd %%mm1, (%0)           \n\t"
249
        "add %3, %0                 \n\t"
250
        "sub $2, %2                 \n\t"
251
        "jnz 1b                     \n\t"
252
        : "+r"(dst), "+r"(src), "+r"(h)
253
        : "r"((long)stride), "m"(ff_pw_32), "m"(x), "m"(y)
254
    );
255
}
256

    
257
#ifdef H264_CHROMA_MC2_TMPL
258
static void H264_CHROMA_MC2_TMPL(uint8_t *dst/*align 2*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
259
{
260
    int tmp = ((1<<16)-1)*x + 8;
261
    int CD= tmp*y;
262
    int AB= (tmp<<3) - CD;
263
    asm volatile(
264
        /* mm5 = {A,B,A,B} */
265
        /* mm6 = {C,D,C,D} */
266
        "movd %0, %%mm5\n\t"
267
        "movd %1, %%mm6\n\t"
268
        "punpckldq %%mm5, %%mm5\n\t"
269
        "punpckldq %%mm6, %%mm6\n\t"
270
        "pxor %%mm7, %%mm7\n\t"
271
        /* mm0 = src[0,1,1,2] */
272
        "movd %2, %%mm2\n\t"
273
        "punpcklbw %%mm7, %%mm2\n\t"
274
        "pshufw $0x94, %%mm2, %%mm2\n\t"
275
        :: "r"(AB), "r"(CD), "m"(src[0]));
276

    
277

    
278
    asm volatile(
279
        "1:\n\t"
280
        "add %4, %1\n\t"
281
        /* mm1 = A * src[0,1] + B * src[1,2] */
282
        "movq    %%mm2, %%mm1\n\t"
283
        "pmaddwd %%mm5, %%mm1\n\t"
284
        /* mm0 = src[0,1,1,2] */
285
        "movd (%1), %%mm0\n\t"
286
        "punpcklbw %%mm7, %%mm0\n\t"
287
        "pshufw $0x94, %%mm0, %%mm0\n\t"
288
        /* mm1 += C * src[0,1] + D * src[1,2] */
289
        "movq    %%mm0, %%mm2\n\t"
290
        "pmaddwd %%mm6, %%mm0\n\t"
291
        "paddw      %3, %%mm1\n\t"
292
        "paddw   %%mm0, %%mm1\n\t"
293
        /* dst[0,1] = pack((mm1 + 32) >> 6) */
294
        "psrlw $6, %%mm1\n\t"
295
        "packssdw %%mm7, %%mm1\n\t"
296
        "packuswb %%mm7, %%mm1\n\t"
297
        H264_CHROMA_OP4((%0), %%mm1, %%mm3)
298
        "movd %%mm1, %%esi\n\t"
299
        "movw %%si, (%0)\n\t"
300
        "add %4, %0\n\t"
301
        "sub $1, %2\n\t"
302
        "jnz 1b\n\t"
303
        : "+r" (dst), "+r"(src), "+r"(h)
304
        : "m" (ff_pw_32), "r"((long)stride)
305
        : "%esi");
306

    
307
}
308
#endif
309