Statistics
| Branch: | Revision:

ffmpeg / libavcodec / x86 / h264dsp_mmx.c @ 9ac4548f

History | View | Annotate | Download (93.7 KB)

1 d2bb7db1 Loren Merritt
/*
2
 * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
3
 *
4 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7 d2bb7db1 Loren Merritt
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 d2bb7db1 Loren Merritt
 *
11 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
12 d2bb7db1 Loren Merritt
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
18 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 d2bb7db1 Loren Merritt
 */
20
21 182f56cb Aurelien Jacobs
#include "dsputil_mmx.h"
22 d2bb7db1 Loren Merritt
23 4f20b45f Michael Niedermayer
DECLARE_ALIGNED_8 (static const uint64_t, ff_pb_3_1  ) = 0x0103010301030103ULL;
24
DECLARE_ALIGNED_8 (static const uint64_t, ff_pb_7_3  ) = 0x0307030703070307ULL;
25
26 d2bb7db1 Loren Merritt
/***********************************/
27
/* IDCT */
28
29
#define SUMSUB_BADC( a, b, c, d ) \
30
    "paddw "#b", "#a" \n\t"\
31
    "paddw "#d", "#c" \n\t"\
32
    "paddw "#b", "#b" \n\t"\
33
    "paddw "#d", "#d" \n\t"\
34
    "psubw "#a", "#b" \n\t"\
35
    "psubw "#c", "#d" \n\t"
36
37
#define SUMSUBD2_AB( a, b, t ) \
38
    "movq  "#b", "#t" \n\t"\
39
    "psraw  $1 , "#b" \n\t"\
40
    "paddw "#a", "#b" \n\t"\
41
    "psraw  $1 , "#a" \n\t"\
42
    "psubw "#t", "#a" \n\t"
43
44
#define IDCT4_1D( s02, s13, d02, d13, t ) \
45
    SUMSUB_BA  ( s02, d02 )\
46
    SUMSUBD2_AB( s13, d13, t )\
47
    SUMSUB_BADC( d13, s02, s13, d02 )
48
49
#define STORE_DIFF_4P( p, t, z ) \
50
    "psraw      $6,     "#p" \n\t"\
51
    "movd       (%0),   "#t" \n\t"\
52
    "punpcklbw "#z",    "#t" \n\t"\
53
    "paddsw    "#t",    "#p" \n\t"\
54
    "packuswb  "#z",    "#p" \n\t"\
55
    "movd      "#p",    (%0) \n\t"
56
57 6da971f1 Loren Merritt
static void ff_h264_idct_add_mmx(uint8_t *dst, int16_t *block, int stride)
58 d2bb7db1 Loren Merritt
{
59
    /* Load dct coeffs */
60 be449fca Diego Pettenò
    __asm__ volatile(
61 d2bb7db1 Loren Merritt
        "movq   (%0), %%mm0 \n\t"
62
        "movq  8(%0), %%mm1 \n\t"
63
        "movq 16(%0), %%mm2 \n\t"
64
        "movq 24(%0), %%mm3 \n\t"
65
    :: "r"(block) );
66
67 be449fca Diego Pettenò
    __asm__ volatile(
68 d2bb7db1 Loren Merritt
        /* mm1=s02+s13  mm2=s02-s13  mm4=d02+d13  mm0=d02-d13 */
69
        IDCT4_1D( %%mm2, %%mm1, %%mm0, %%mm3, %%mm4 )
70
71
        "movq      %0,    %%mm6 \n\t"
72
        /* in: 1,4,0,2  out: 1,2,3,0 */
73
        TRANSPOSE4( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 )
74
75
        "paddw     %%mm6, %%mm3 \n\t"
76
77
        /* mm2=s02+s13  mm3=s02-s13  mm4=d02+d13  mm1=d02-d13 */
78
        IDCT4_1D( %%mm4, %%mm2, %%mm3, %%mm0, %%mm1 )
79
80
        "pxor %%mm7, %%mm7    \n\t"
81 fa9b873e Loren Merritt
    :: "m"(ff_pw_32));
82 d2bb7db1 Loren Merritt
83 be449fca Diego Pettenò
    __asm__ volatile(
84 d2bb7db1 Loren Merritt
    STORE_DIFF_4P( %%mm0, %%mm1, %%mm7)
85
        "add %1, %0             \n\t"
86
    STORE_DIFF_4P( %%mm2, %%mm1, %%mm7)
87
        "add %1, %0             \n\t"
88
    STORE_DIFF_4P( %%mm3, %%mm1, %%mm7)
89
        "add %1, %0             \n\t"
90
    STORE_DIFF_4P( %%mm4, %%mm1, %%mm7)
91
        : "+r"(dst)
92 40d0e665 Ramiro Polla
        : "r" ((x86_reg)stride)
93 d2bb7db1 Loren Merritt
    );
94
}
95
96 548a1c8a Loren Merritt
static inline void h264_idct8_1d(int16_t *block)
97
{
98 be449fca Diego Pettenò
    __asm__ volatile(
99 548a1c8a Loren Merritt
        "movq 112(%0), %%mm7  \n\t"
100 51f0ac65 Loren Merritt
        "movq  80(%0), %%mm0  \n\t"
101 548a1c8a Loren Merritt
        "movq  48(%0), %%mm3  \n\t"
102 51f0ac65 Loren Merritt
        "movq  16(%0), %%mm5  \n\t"
103 548a1c8a Loren Merritt
104 51f0ac65 Loren Merritt
        "movq   %%mm0, %%mm4  \n\t"
105
        "movq   %%mm5, %%mm1  \n\t"
106 548a1c8a Loren Merritt
        "psraw  $1,    %%mm4  \n\t"
107 51f0ac65 Loren Merritt
        "psraw  $1,    %%mm1  \n\t"
108
        "paddw  %%mm0, %%mm4  \n\t"
109
        "paddw  %%mm5, %%mm1  \n\t"
110 548a1c8a Loren Merritt
        "paddw  %%mm7, %%mm4  \n\t"
111 51f0ac65 Loren Merritt
        "paddw  %%mm0, %%mm1  \n\t"
112
        "psubw  %%mm5, %%mm4  \n\t"
113
        "paddw  %%mm3, %%mm1  \n\t"
114
115
        "psubw  %%mm3, %%mm5  \n\t"
116
        "psubw  %%mm3, %%mm0  \n\t"
117
        "paddw  %%mm7, %%mm5  \n\t"
118
        "psubw  %%mm7, %%mm0  \n\t"
119
        "psraw  $1,    %%mm3  \n\t"
120
        "psraw  $1,    %%mm7  \n\t"
121
        "psubw  %%mm3, %%mm5  \n\t"
122
        "psubw  %%mm7, %%mm0  \n\t"
123 548a1c8a Loren Merritt
124
        "movq   %%mm4, %%mm3  \n\t"
125 51f0ac65 Loren Merritt
        "movq   %%mm1, %%mm7  \n\t"
126
        "psraw  $2,    %%mm1  \n\t"
127 548a1c8a Loren Merritt
        "psraw  $2,    %%mm3  \n\t"
128 51f0ac65 Loren Merritt
        "paddw  %%mm5, %%mm3  \n\t"
129 548a1c8a Loren Merritt
        "psraw  $2,    %%mm5  \n\t"
130 51f0ac65 Loren Merritt
        "paddw  %%mm0, %%mm1  \n\t"
131 548a1c8a Loren Merritt
        "psraw  $2,    %%mm0  \n\t"
132
        "psubw  %%mm4, %%mm5  \n\t"
133
        "psubw  %%mm0, %%mm7  \n\t"
134
135
        "movq  32(%0), %%mm2  \n\t"
136
        "movq  96(%0), %%mm6  \n\t"
137
        "movq   %%mm2, %%mm4  \n\t"
138
        "movq   %%mm6, %%mm0  \n\t"
139
        "psraw  $1,    %%mm4  \n\t"
140
        "psraw  $1,    %%mm6  \n\t"
141
        "psubw  %%mm0, %%mm4  \n\t"
142
        "paddw  %%mm2, %%mm6  \n\t"
143
144
        "movq    (%0), %%mm2  \n\t"
145
        "movq  64(%0), %%mm0  \n\t"
146
        SUMSUB_BA( %%mm0, %%mm2 )
147
        SUMSUB_BA( %%mm6, %%mm0 )
148
        SUMSUB_BA( %%mm4, %%mm2 )
149
        SUMSUB_BA( %%mm7, %%mm6 )
150
        SUMSUB_BA( %%mm5, %%mm4 )
151
        SUMSUB_BA( %%mm3, %%mm2 )
152
        SUMSUB_BA( %%mm1, %%mm0 )
153
        :: "r"(block)
154
    );
155
}
156
157
static void ff_h264_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride)
158
{
159
    int i;
160 74a841af Ramiro Polla
    DECLARE_ALIGNED_8(int16_t, b2[64]);
161 548a1c8a Loren Merritt
162
    block[0] += 32;
163
164
    for(i=0; i<2; i++){
165 079e61db Michael Niedermayer
        DECLARE_ALIGNED_8(uint64_t, tmp);
166 548a1c8a Loren Merritt
167
        h264_idct8_1d(block+4*i);
168
169 be449fca Diego Pettenò
        __asm__ volatile(
170 548a1c8a Loren Merritt
            "movq   %%mm7,    %0   \n\t"
171
            TRANSPOSE4( %%mm0, %%mm2, %%mm4, %%mm6, %%mm7 )
172
            "movq   %%mm0,  8(%1)  \n\t"
173
            "movq   %%mm6, 24(%1)  \n\t"
174
            "movq   %%mm7, 40(%1)  \n\t"
175
            "movq   %%mm4, 56(%1)  \n\t"
176
            "movq    %0,    %%mm7  \n\t"
177
            TRANSPOSE4( %%mm7, %%mm5, %%mm3, %%mm1, %%mm0 )
178
            "movq   %%mm7,   (%1)  \n\t"
179
            "movq   %%mm1, 16(%1)  \n\t"
180
            "movq   %%mm0, 32(%1)  \n\t"
181
            "movq   %%mm3, 48(%1)  \n\t"
182
            : "=m"(tmp)
183
            : "r"(b2+32*i)
184
            : "memory"
185
        );
186
    }
187
188
    for(i=0; i<2; i++){
189
        h264_idct8_1d(b2+4*i);
190
191 be449fca Diego Pettenò
        __asm__ volatile(
192 548a1c8a Loren Merritt
            "psraw     $6, %%mm7  \n\t"
193
            "psraw     $6, %%mm6  \n\t"
194
            "psraw     $6, %%mm5  \n\t"
195
            "psraw     $6, %%mm4  \n\t"
196
            "psraw     $6, %%mm3  \n\t"
197
            "psraw     $6, %%mm2  \n\t"
198
            "psraw     $6, %%mm1  \n\t"
199
            "psraw     $6, %%mm0  \n\t"
200
201
            "movq   %%mm7,    (%0)  \n\t"
202
            "movq   %%mm5,  16(%0)  \n\t"
203
            "movq   %%mm3,  32(%0)  \n\t"
204
            "movq   %%mm1,  48(%0)  \n\t"
205
            "movq   %%mm0,  64(%0)  \n\t"
206
            "movq   %%mm2,  80(%0)  \n\t"
207
            "movq   %%mm4,  96(%0)  \n\t"
208
            "movq   %%mm6, 112(%0)  \n\t"
209
            :: "r"(b2+4*i)
210
            : "memory"
211
        );
212
    }
213
214
    add_pixels_clamped_mmx(b2, dst, stride);
215
}
216
217 ed5d7a53 Loren Merritt
#define STORE_DIFF_8P( p, d, t, z )\
218
        "movq       "#d", "#t" \n"\
219
        "psraw       $6,  "#p" \n"\
220
        "punpcklbw  "#z", "#t" \n"\
221
        "paddsw     "#t", "#p" \n"\
222
        "packuswb   "#p", "#p" \n"\
223
        "movq       "#p", "#d" \n"
224
225
#define H264_IDCT8_1D_SSE2(a,b,c,d,e,f,g,h)\
226
        "movdqa     "#c", "#a" \n"\
227
        "movdqa     "#g", "#e" \n"\
228
        "psraw       $1,  "#c" \n"\
229
        "psraw       $1,  "#g" \n"\
230
        "psubw      "#e", "#c" \n"\
231
        "paddw      "#a", "#g" \n"\
232
        "movdqa     "#b", "#e" \n"\
233
        "psraw       $1,  "#e" \n"\
234
        "paddw      "#b", "#e" \n"\
235
        "paddw      "#d", "#e" \n"\
236
        "paddw      "#f", "#e" \n"\
237
        "movdqa     "#f", "#a" \n"\
238
        "psraw       $1,  "#a" \n"\
239
        "paddw      "#f", "#a" \n"\
240
        "paddw      "#h", "#a" \n"\
241
        "psubw      "#b", "#a" \n"\
242
        "psubw      "#d", "#b" \n"\
243
        "psubw      "#d", "#f" \n"\
244
        "paddw      "#h", "#b" \n"\
245
        "psubw      "#h", "#f" \n"\
246
        "psraw       $1,  "#d" \n"\
247
        "psraw       $1,  "#h" \n"\
248
        "psubw      "#d", "#b" \n"\
249
        "psubw      "#h", "#f" \n"\
250
        "movdqa     "#e", "#d" \n"\
251
        "movdqa     "#a", "#h" \n"\
252
        "psraw       $2,  "#d" \n"\
253
        "psraw       $2,  "#h" \n"\
254
        "paddw      "#f", "#d" \n"\
255
        "paddw      "#b", "#h" \n"\
256
        "psraw       $2,  "#f" \n"\
257
        "psraw       $2,  "#b" \n"\
258
        "psubw      "#f", "#e" \n"\
259
        "psubw      "#a", "#b" \n"\
260
        "movdqa 0x00(%1), "#a" \n"\
261
        "movdqa 0x40(%1), "#f" \n"\
262
        SUMSUB_BA(f, a)\
263
        SUMSUB_BA(g, f)\
264
        SUMSUB_BA(c, a)\
265
        SUMSUB_BA(e, g)\
266
        SUMSUB_BA(b, c)\
267
        SUMSUB_BA(h, a)\
268
        SUMSUB_BA(d, f)
269
270
static void ff_h264_idct8_add_sse2(uint8_t *dst, int16_t *block, int stride)
271
{
272 be449fca Diego Pettenò
    __asm__ volatile(
273 ed5d7a53 Loren Merritt
        "movdqa   0x10(%1), %%xmm1 \n"
274
        "movdqa   0x20(%1), %%xmm2 \n"
275
        "movdqa   0x30(%1), %%xmm3 \n"
276
        "movdqa   0x50(%1), %%xmm5 \n"
277
        "movdqa   0x60(%1), %%xmm6 \n"
278
        "movdqa   0x70(%1), %%xmm7 \n"
279
        H264_IDCT8_1D_SSE2(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm6, %%xmm7)
280
        TRANSPOSE8(%%xmm4, %%xmm1, %%xmm7, %%xmm3, %%xmm5, %%xmm0, %%xmm2, %%xmm6, (%1))
281
        "paddw          %4, %%xmm4 \n"
282
        "movdqa     %%xmm4, 0x00(%1) \n"
283
        "movdqa     %%xmm2, 0x40(%1) \n"
284
        H264_IDCT8_1D_SSE2(%%xmm4, %%xmm0, %%xmm6, %%xmm3, %%xmm2, %%xmm5, %%xmm7, %%xmm1)
285
        "movdqa     %%xmm6, 0x60(%1) \n"
286
        "movdqa     %%xmm7, 0x70(%1) \n"
287
        "pxor       %%xmm7, %%xmm7 \n"
288
        STORE_DIFF_8P(%%xmm2, (%0),      %%xmm6, %%xmm7)
289
        STORE_DIFF_8P(%%xmm0, (%0,%2),   %%xmm6, %%xmm7)
290
        STORE_DIFF_8P(%%xmm1, (%0,%2,2), %%xmm6, %%xmm7)
291
        STORE_DIFF_8P(%%xmm3, (%0,%3),   %%xmm6, %%xmm7)
292
        "lea     (%0,%2,4), %0 \n"
293
        STORE_DIFF_8P(%%xmm5, (%0),      %%xmm6, %%xmm7)
294
        STORE_DIFF_8P(%%xmm4, (%0,%2),   %%xmm6, %%xmm7)
295
        "movdqa   0x60(%1), %%xmm0 \n"
296
        "movdqa   0x70(%1), %%xmm1 \n"
297
        STORE_DIFF_8P(%%xmm0, (%0,%2,2), %%xmm6, %%xmm7)
298
        STORE_DIFF_8P(%%xmm1, (%0,%3),   %%xmm6, %%xmm7)
299
        :"+r"(dst)
300 40d0e665 Ramiro Polla
        :"r"(block), "r"((x86_reg)stride), "r"((x86_reg)3L*stride), "m"(ff_pw_32)
301 ed5d7a53 Loren Merritt
    );
302
}
303
304 6da971f1 Loren Merritt
static void ff_h264_idct_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
305 ef9d1d15 Loren Merritt
{
306
    int dc = (block[0] + 32) >> 6;
307 be449fca Diego Pettenò
    __asm__ volatile(
308 ef9d1d15 Loren Merritt
        "movd          %0, %%mm0 \n\t"
309
        "pshufw $0, %%mm0, %%mm0 \n\t"
310
        "pxor       %%mm1, %%mm1 \n\t"
311
        "psubw      %%mm0, %%mm1 \n\t"
312
        "packuswb   %%mm0, %%mm0 \n\t"
313
        "packuswb   %%mm1, %%mm1 \n\t"
314
        ::"r"(dc)
315
    );
316 be449fca Diego Pettenò
    __asm__ volatile(
317 ef9d1d15 Loren Merritt
        "movd          %0, %%mm2 \n\t"
318
        "movd          %1, %%mm3 \n\t"
319
        "movd          %2, %%mm4 \n\t"
320
        "movd          %3, %%mm5 \n\t"
321
        "paddusb    %%mm0, %%mm2 \n\t"
322
        "paddusb    %%mm0, %%mm3 \n\t"
323
        "paddusb    %%mm0, %%mm4 \n\t"
324
        "paddusb    %%mm0, %%mm5 \n\t"
325
        "psubusb    %%mm1, %%mm2 \n\t"
326
        "psubusb    %%mm1, %%mm3 \n\t"
327
        "psubusb    %%mm1, %%mm4 \n\t"
328
        "psubusb    %%mm1, %%mm5 \n\t"
329
        "movd       %%mm2, %0    \n\t"
330
        "movd       %%mm3, %1    \n\t"
331
        "movd       %%mm4, %2    \n\t"
332
        "movd       %%mm5, %3    \n\t"
333
        :"+m"(*(uint32_t*)(dst+0*stride)),
334
         "+m"(*(uint32_t*)(dst+1*stride)),
335
         "+m"(*(uint32_t*)(dst+2*stride)),
336
         "+m"(*(uint32_t*)(dst+3*stride))
337
    );
338
}
339
340 6da971f1 Loren Merritt
static void ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
341 ef9d1d15 Loren Merritt
{
342
    int dc = (block[0] + 32) >> 6;
343
    int y;
344 be449fca Diego Pettenò
    __asm__ volatile(
345 ef9d1d15 Loren Merritt
        "movd          %0, %%mm0 \n\t"
346
        "pshufw $0, %%mm0, %%mm0 \n\t"
347
        "pxor       %%mm1, %%mm1 \n\t"
348
        "psubw      %%mm0, %%mm1 \n\t"
349
        "packuswb   %%mm0, %%mm0 \n\t"
350
        "packuswb   %%mm1, %%mm1 \n\t"
351
        ::"r"(dc)
352
    );
353
    for(y=2; y--; dst += 4*stride){
354 be449fca Diego Pettenò
    __asm__ volatile(
355 ef9d1d15 Loren Merritt
        "movq          %0, %%mm2 \n\t"
356
        "movq          %1, %%mm3 \n\t"
357
        "movq          %2, %%mm4 \n\t"
358
        "movq          %3, %%mm5 \n\t"
359
        "paddusb    %%mm0, %%mm2 \n\t"
360
        "paddusb    %%mm0, %%mm3 \n\t"
361
        "paddusb    %%mm0, %%mm4 \n\t"
362
        "paddusb    %%mm0, %%mm5 \n\t"
363
        "psubusb    %%mm1, %%mm2 \n\t"
364
        "psubusb    %%mm1, %%mm3 \n\t"
365
        "psubusb    %%mm1, %%mm4 \n\t"
366
        "psubusb    %%mm1, %%mm5 \n\t"
367
        "movq       %%mm2, %0    \n\t"
368
        "movq       %%mm3, %1    \n\t"
369
        "movq       %%mm4, %2    \n\t"
370
        "movq       %%mm5, %3    \n\t"
371
        :"+m"(*(uint64_t*)(dst+0*stride)),
372
         "+m"(*(uint64_t*)(dst+1*stride)),
373
         "+m"(*(uint64_t*)(dst+2*stride)),
374
         "+m"(*(uint64_t*)(dst+3*stride))
375
    );
376
    }
377
}
378
379 ac223859 Michael Niedermayer
//FIXME this table is a duplicate from h264data.h, and will be removed once the tables from, h264 have been split
380
static const uint8_t scan8[16 + 2*4]={
381
 4+1*8, 5+1*8, 4+2*8, 5+2*8,
382
 6+1*8, 7+1*8, 6+2*8, 7+2*8,
383
 4+3*8, 5+3*8, 4+4*8, 5+4*8,
384
 6+3*8, 7+3*8, 6+4*8, 7+4*8,
385
 1+1*8, 2+1*8,
386
 1+2*8, 2+2*8,
387
 1+4*8, 2+4*8,
388
 1+5*8, 2+5*8,
389
};
390
391
static void ff_h264_idct_add16_mmx(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
392
    int i;
393
    for(i=0; i<16; i++){
394
        if(nnzc[ scan8[i] ])
395
            ff_h264_idct_add_mmx(dst + block_offset[i], block + i*16, stride);
396
    }
397
}
398
399
static void ff_h264_idct8_add4_mmx(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
400
    int i;
401
    for(i=0; i<16; i+=4){
402
        if(nnzc[ scan8[i] ])
403
            ff_h264_idct8_add_mmx(dst + block_offset[i], block + i*16, stride);
404
    }
405
}
406
407
408
static void ff_h264_idct_add16_mmx2(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
409
    int i;
410
    for(i=0; i<16; i++){
411
        int nnz = nnzc[ scan8[i] ];
412
        if(nnz){
413
            if(nnz==1 && block[i*16]) ff_h264_idct_dc_add_mmx2(dst + block_offset[i], block + i*16, stride);
414
            else                      ff_h264_idct_add_mmx    (dst + block_offset[i], block + i*16, stride);
415
        }
416
    }
417
}
418
419
static void ff_h264_idct_add16intra_mmx(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
420
    int i;
421
    for(i=0; i<16; i++){
422
        if(nnzc[ scan8[i] ] || block[i*16])
423
            ff_h264_idct_add_mmx(dst + block_offset[i], block + i*16, stride);
424
    }
425
}
426
427
static void ff_h264_idct_add16intra_mmx2(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
428
    int i;
429
    for(i=0; i<16; i++){
430
        if(nnzc[ scan8[i] ]) ff_h264_idct_add_mmx    (dst + block_offset[i], block + i*16, stride);
431
        else if(block[i*16]) ff_h264_idct_dc_add_mmx2(dst + block_offset[i], block + i*16, stride);
432
    }
433
}
434
435
static void ff_h264_idct8_add4_mmx2(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
436
    int i;
437
    for(i=0; i<16; i+=4){
438
        int nnz = nnzc[ scan8[i] ];
439
        if(nnz){
440
            if(nnz==1 && block[i*16]) ff_h264_idct8_dc_add_mmx2(dst + block_offset[i], block + i*16, stride);
441
            else                      ff_h264_idct8_add_mmx    (dst + block_offset[i], block + i*16, stride);
442
        }
443
    }
444
}
445
446
static void ff_h264_idct8_add4_sse2(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
447
    int i;
448
    for(i=0; i<16; i+=4){
449
        int nnz = nnzc[ scan8[i] ];
450
        if(nnz){
451
            if(nnz==1 && block[i*16]) ff_h264_idct8_dc_add_mmx2(dst + block_offset[i], block + i*16, stride);
452
            else                      ff_h264_idct8_add_sse2   (dst + block_offset[i], block + i*16, stride);
453
        }
454
    }
455
}
456
457
static void ff_h264_idct_add8_mmx(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
458
    int i;
459
    for(i=16; i<16+8; i++){
460
        if(nnzc[ scan8[i] ] || block[i*16])
461
            ff_h264_idct_add_mmx    (dest[(i&4)>>2] + block_offset[i], block + i*16, stride);
462
    }
463
}
464
465
static void ff_h264_idct_add8_mmx2(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
466
    int i;
467
    for(i=16; i<16+8; i++){
468
        if(nnzc[ scan8[i] ])
469
            ff_h264_idct_add_mmx    (dest[(i&4)>>2] + block_offset[i], block + i*16, stride);
470
        else if(block[i*16])
471
            ff_h264_idct_dc_add_mmx2(dest[(i&4)>>2] + block_offset[i], block + i*16, stride);
472
    }
473
}
474 d2bb7db1 Loren Merritt
475 b250f9c6 Aurelien Jacobs
#if CONFIG_GPL && HAVE_YASM
476 37fed100 Jason Garrett-Glaser
static void ff_h264_idct_dc_add8_mmx2(uint8_t *dst, int16_t *block, int stride)
477
{
478
    __asm__ volatile(
479
        "movd             %0, %%mm0 \n\t"   //  0 0 X D
480
        "punpcklwd        %1, %%mm0 \n\t"   //  x X d D
481
        "paddsw           %2, %%mm0 \n\t"
482
        "psraw            $6, %%mm0 \n\t"
483
        "punpcklwd     %%mm0, %%mm0 \n\t"   //  d d D D
484
        "pxor          %%mm1, %%mm1 \n\t"   //  0 0 0 0
485
        "psubw         %%mm0, %%mm1 \n\t"   // -d-d-D-D
486
        "packuswb      %%mm1, %%mm0 \n\t"   // -d-d-D-D d d D D
487
        "pshufw $0xFA, %%mm0, %%mm1 \n\t"   // -d-d-d-d-D-D-D-D
488
        "punpcklwd     %%mm0, %%mm0 \n\t"   //  d d d d D D D D
489
        ::"m"(block[ 0]),
490
          "m"(block[16]),
491
          "m"(ff_pw_32)
492
    );
493
    __asm__ volatile(
494
        "movq          %0, %%mm2 \n\t"
495
        "movq          %1, %%mm3 \n\t"
496
        "movq          %2, %%mm4 \n\t"
497
        "movq          %3, %%mm5 \n\t"
498
        "paddusb    %%mm0, %%mm2 \n\t"
499
        "paddusb    %%mm0, %%mm3 \n\t"
500
        "paddusb    %%mm0, %%mm4 \n\t"
501
        "paddusb    %%mm0, %%mm5 \n\t"
502
        "psubusb    %%mm1, %%mm2 \n\t"
503
        "psubusb    %%mm1, %%mm3 \n\t"
504
        "psubusb    %%mm1, %%mm4 \n\t"
505
        "psubusb    %%mm1, %%mm5 \n\t"
506
        "movq       %%mm2, %0    \n\t"
507
        "movq       %%mm3, %1    \n\t"
508
        "movq       %%mm4, %2    \n\t"
509
        "movq       %%mm5, %3    \n\t"
510
        :"+m"(*(uint64_t*)(dst+0*stride)),
511
         "+m"(*(uint64_t*)(dst+1*stride)),
512
         "+m"(*(uint64_t*)(dst+2*stride)),
513
         "+m"(*(uint64_t*)(dst+3*stride))
514
    );
515
}
516
517
extern void ff_x264_add8x4_idct_sse2(uint8_t *dst, int16_t *block, int stride);
518
519
static void ff_h264_idct_add16_sse2(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
520
    int i;
521
    for(i=0; i<16; i+=2)
522
        if(nnzc[ scan8[i+0] ]|nnzc[ scan8[i+1] ])
523
            ff_x264_add8x4_idct_sse2 (dst + block_offset[i], block + i*16, stride);
524
}
525
526
static void ff_h264_idct_add16intra_sse2(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
527
    int i;
528
    for(i=0; i<16; i+=2){
529
        if(nnzc[ scan8[i+0] ]|nnzc[ scan8[i+1] ])
530
            ff_x264_add8x4_idct_sse2 (dst + block_offset[i], block + i*16, stride);
531
        else if(block[i*16]|block[i*16+16])
532
            ff_h264_idct_dc_add8_mmx2(dst + block_offset[i], block + i*16, stride);
533
    }
534
}
535
536
static void ff_h264_idct_add8_sse2(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
537
    int i;
538 353f87b8 Baptiste Coudurier
    for(i=16; i<16+8; i+=2){
539 37fed100 Jason Garrett-Glaser
        if(nnzc[ scan8[i+0] ]|nnzc[ scan8[i+1] ])
540
            ff_x264_add8x4_idct_sse2 (dest[(i&4)>>2] + block_offset[i], block + i*16, stride);
541
        else if(block[i*16]|block[i*16+16])
542
            ff_h264_idct_dc_add8_mmx2(dest[(i&4)>>2] + block_offset[i], block + i*16, stride);
543
    }
544
}
545
#endif
546
547 d2bb7db1 Loren Merritt
/***********************************/
548
/* deblocking */
549
550
// out: o = |x-y|>a
551
// clobbers: t
552
#define DIFF_GT_MMX(x,y,a,o,t)\
553
    "movq     "#y", "#t"  \n\t"\
554
    "movq     "#x", "#o"  \n\t"\
555
    "psubusb  "#x", "#t"  \n\t"\
556
    "psubusb  "#y", "#o"  \n\t"\
557
    "por      "#t", "#o"  \n\t"\
558
    "psubusb  "#a", "#o"  \n\t"
559
560 e80cf125 Michael Niedermayer
// out: o = |x-y|>a
561
// clobbers: t
562
#define DIFF_GT2_MMX(x,y,a,o,t)\
563
    "movq     "#y", "#t"  \n\t"\
564
    "movq     "#x", "#o"  \n\t"\
565
    "psubusb  "#x", "#t"  \n\t"\
566
    "psubusb  "#y", "#o"  \n\t"\
567
    "psubusb  "#a", "#t"  \n\t"\
568
    "psubusb  "#a", "#o"  \n\t"\
569
    "pcmpeqb  "#t", "#o"  \n\t"\
570
571 d2bb7db1 Loren Merritt
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1
572
// out: mm5=beta-1, mm7=mask
573
// clobbers: mm4,mm6
574
#define H264_DEBLOCK_MASK(alpha1, beta1) \
575
    "pshufw $0, "#alpha1", %%mm4 \n\t"\
576
    "pshufw $0, "#beta1 ", %%mm5 \n\t"\
577
    "packuswb  %%mm4, %%mm4      \n\t"\
578
    "packuswb  %%mm5, %%mm5      \n\t"\
579
    DIFF_GT_MMX(%%mm1, %%mm2, %%mm4, %%mm7, %%mm6) /* |p0-q0| > alpha-1 */\
580
    DIFF_GT_MMX(%%mm0, %%mm1, %%mm5, %%mm4, %%mm6) /* |p1-p0| > beta-1 */\
581
    "por       %%mm4, %%mm7      \n\t"\
582
    DIFF_GT_MMX(%%mm3, %%mm2, %%mm5, %%mm4, %%mm6) /* |q1-q0| > beta-1 */\
583
    "por       %%mm4, %%mm7      \n\t"\
584
    "pxor      %%mm6, %%mm6      \n\t"\
585
    "pcmpeqb   %%mm6, %%mm7      \n\t"
586
587
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask)
588
// out: mm1=p0' mm2=q0'
589
// clobbers: mm0,3-6
590
#define H264_DEBLOCK_P0_Q0(pb_01, pb_3f)\
591 e9f1885c Michael Niedermayer
        "movq    %%mm1              , %%mm5 \n\t"\
592
        "pxor    %%mm2              , %%mm5 \n\t" /* p0^q0*/\
593
        "pand    "#pb_01"           , %%mm5 \n\t" /* (p0^q0)&1*/\
594
        "pcmpeqb %%mm4              , %%mm4 \n\t"\
595
        "pxor    %%mm4              , %%mm3 \n\t"\
596
        "pavgb   %%mm0              , %%mm3 \n\t" /* (p1 - q1 + 256)>>1*/\
597
        "pavgb   "MANGLE(ff_pb_3)"  , %%mm3 \n\t" /*(((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2*/\
598
        "pxor    %%mm1              , %%mm4 \n\t"\
599
        "pavgb   %%mm2              , %%mm4 \n\t" /* (q0 - p0 + 256)>>1*/\
600
        "pavgb   %%mm5              , %%mm3 \n\t"\
601 bda2203d Michael Niedermayer
        "paddusb %%mm4              , %%mm3 \n\t" /* d+128+33*/\
602 5a1553de Michael Niedermayer
        "movq    "MANGLE(ff_pb_A1)" , %%mm6 \n\t"\
603
        "psubusb %%mm3              , %%mm6 \n\t"\
604 e9f1885c Michael Niedermayer
        "psubusb "MANGLE(ff_pb_A1)" , %%mm3 \n\t"\
605
        "pminub  %%mm7              , %%mm6 \n\t"\
606 5a1553de Michael Niedermayer
        "pminub  %%mm7              , %%mm3 \n\t"\
607 e9f1885c Michael Niedermayer
        "psubusb %%mm6              , %%mm1 \n\t"\
608 5a1553de Michael Niedermayer
        "psubusb %%mm3              , %%mm2 \n\t"\
609
        "paddusb %%mm3              , %%mm1 \n\t"\
610
        "paddusb %%mm6              , %%mm2 \n\t"
611 d2bb7db1 Loren Merritt
612 43de5065 Aurelien Jacobs
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask) %8=ff_bone
613 a1ce6110 Reimar Döffinger
// out: (q1addr) = av_clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 )
614 d2bb7db1 Loren Merritt
// clobbers: q2, tmp, tc0
615
#define H264_DEBLOCK_Q1(p1, q2, q2addr, q1addr, tc0, tmp)\
616
        "movq     %%mm1,  "#tmp"   \n\t"\
617
        "pavgb    %%mm2,  "#tmp"   \n\t"\
618
        "pavgb    "#tmp", "#q2"    \n\t" /* avg(p2,avg(p0,q0)) */\
619
        "pxor   "q2addr", "#tmp"   \n\t"\
620
        "pand     %8,     "#tmp"   \n\t" /* (p2^avg(p0,q0))&1 */\
621
        "psubusb  "#tmp", "#q2"    \n\t" /* (p2+((p0+q0+1)>>1))>>1 */\
622
        "movq     "#p1",  "#tmp"   \n\t"\
623
        "psubusb  "#tc0", "#tmp"   \n\t"\
624
        "paddusb  "#p1",  "#tc0"   \n\t"\
625
        "pmaxub   "#tmp", "#q2"    \n\t"\
626
        "pminub   "#tc0", "#q2"    \n\t"\
627
        "movq     "#q2",  "q1addr" \n\t"
628
629
static inline void h264_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)
630
{
631 079e61db Michael Niedermayer
    DECLARE_ALIGNED_8(uint64_t, tmp0[2]);
632 d2bb7db1 Loren Merritt
633 be449fca Diego Pettenò
    __asm__ volatile(
634 d2bb7db1 Loren Merritt
        "movq    (%1,%3), %%mm0    \n\t" //p1
635
        "movq    (%1,%3,2), %%mm1  \n\t" //p0
636
        "movq    (%2),    %%mm2    \n\t" //q0
637
        "movq    (%2,%3), %%mm3    \n\t" //q1
638
        H264_DEBLOCK_MASK(%6, %7)
639 38cfdc83 Michael Niedermayer
640
        "movd      %5,    %%mm4    \n\t"
641
        "punpcklbw %%mm4, %%mm4    \n\t"
642
        "punpcklwd %%mm4, %%mm4    \n\t"
643
        "pcmpeqb   %%mm3, %%mm3    \n\t"
644
        "movq      %%mm4, %%mm6    \n\t"
645
        "pcmpgtb   %%mm3, %%mm4    \n\t"
646
        "movq      %%mm6, 8+%0     \n\t"
647
        "pand      %%mm4, %%mm7    \n\t"
648
        "movq      %%mm7, %0       \n\t"
649 d2bb7db1 Loren Merritt
650
        /* filter p1 */
651
        "movq     (%1),   %%mm3    \n\t" //p2
652 e80cf125 Michael Niedermayer
        DIFF_GT2_MMX(%%mm1, %%mm3, %%mm5, %%mm6, %%mm4) // |p2-p0|>beta-1
653 d2bb7db1 Loren Merritt
        "pand     %%mm7,  %%mm6    \n\t" // mask & |p2-p0|<beta
654 f5a9e8f3 Michael Niedermayer
        "pand     8+%0,   %%mm7    \n\t" // mask & tc0
655
        "movq     %%mm7,  %%mm4    \n\t"
656 25225c37 Michael Niedermayer
        "psubb    %%mm6,  %%mm7    \n\t"
657 d2bb7db1 Loren Merritt
        "pand     %%mm4,  %%mm6    \n\t" // mask & |p2-p0|<beta & tc0
658
        H264_DEBLOCK_Q1(%%mm0, %%mm3, "(%1)", "(%1,%3)", %%mm6, %%mm4)
659
660
        /* filter q1 */
661
        "movq    (%2,%3,2), %%mm4  \n\t" //q2
662 e80cf125 Michael Niedermayer
        DIFF_GT2_MMX(%%mm2, %%mm4, %%mm5, %%mm6, %%mm3) // |q2-q0|>beta-1
663 d2bb7db1 Loren Merritt
        "pand     %0,     %%mm6    \n\t"
664 93471182 Michael Niedermayer
        "movq     8+%0,   %%mm5    \n\t" // can be merged with the and below but is slower then
665 d2bb7db1 Loren Merritt
        "pand     %%mm6,  %%mm5    \n\t"
666 25225c37 Michael Niedermayer
        "psubb    %%mm6,  %%mm7    \n\t"
667 d2bb7db1 Loren Merritt
        "movq    (%2,%3), %%mm3    \n\t"
668
        H264_DEBLOCK_Q1(%%mm3, %%mm4, "(%2,%3,2)", "(%2,%3)", %%mm5, %%mm6)
669
670
        /* filter p0, q0 */
671 38cfdc83 Michael Niedermayer
        H264_DEBLOCK_P0_Q0(%8, unused)
672 d2bb7db1 Loren Merritt
        "movq      %%mm1, (%1,%3,2) \n\t"
673
        "movq      %%mm2, (%2)      \n\t"
674
675 38cfdc83 Michael Niedermayer
        : "=m"(*tmp0)
676 40d0e665 Ramiro Polla
        : "r"(pix-3*stride), "r"(pix), "r"((x86_reg)stride),
677 38cfdc83 Michael Niedermayer
          "m"(*tmp0/*unused*/), "m"(*(uint32_t*)tc0), "m"(alpha1), "m"(beta1),
678 43de5065 Aurelien Jacobs
          "m"(ff_bone)
679 d2bb7db1 Loren Merritt
    );
680
}
681
682
static void h264_v_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
683
{
684
    if((tc0[0] & tc0[1]) >= 0)
685
        h264_loop_filter_luma_mmx2(pix, stride, alpha-1, beta-1, tc0);
686
    if((tc0[2] & tc0[3]) >= 0)
687
        h264_loop_filter_luma_mmx2(pix+8, stride, alpha-1, beta-1, tc0+2);
688
}
689
static void h264_h_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
690
{
691
    //FIXME: could cut some load/stores by merging transpose with filter
692
    // also, it only needs to transpose 6x8
693 079e61db Michael Niedermayer
    DECLARE_ALIGNED_8(uint8_t, trans[8*8]);
694 d2bb7db1 Loren Merritt
    int i;
695
    for(i=0; i<2; i++, pix+=8*stride, tc0+=2) {
696
        if((tc0[0] & tc0[1]) < 0)
697
            continue;
698
        transpose4x4(trans,       pix-4,          8, stride);
699
        transpose4x4(trans  +4*8, pix,            8, stride);
700
        transpose4x4(trans+4,     pix-4+4*stride, 8, stride);
701
        transpose4x4(trans+4+4*8, pix  +4*stride, 8, stride);
702
        h264_loop_filter_luma_mmx2(trans+4*8, 8, alpha-1, beta-1, tc0);
703
        transpose4x4(pix-2,          trans  +2*8, stride, 8);
704
        transpose4x4(pix-2+4*stride, trans+4+2*8, stride, 8);
705
    }
706
}
707
708
static inline void h264_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)
709
{
710 be449fca Diego Pettenò
    __asm__ volatile(
711 d2bb7db1 Loren Merritt
        "movq    (%0),    %%mm0     \n\t" //p1
712
        "movq    (%0,%2), %%mm1     \n\t" //p0
713
        "movq    (%1),    %%mm2     \n\t" //q0
714
        "movq    (%1,%2), %%mm3     \n\t" //q1
715
        H264_DEBLOCK_MASK(%4, %5)
716
        "movd      %3,    %%mm6     \n\t"
717
        "punpcklbw %%mm6, %%mm6     \n\t"
718
        "pand      %%mm6, %%mm7     \n\t" // mm7 = tc&mask
719
        H264_DEBLOCK_P0_Q0(%6, %7)
720
        "movq      %%mm1, (%0,%2)   \n\t"
721
        "movq      %%mm2, (%1)      \n\t"
722
723 40d0e665 Ramiro Polla
        :: "r"(pix-2*stride), "r"(pix), "r"((x86_reg)stride),
724 d2bb7db1 Loren Merritt
           "r"(*(uint32_t*)tc0),
725 43de5065 Aurelien Jacobs
           "m"(alpha1), "m"(beta1), "m"(ff_bone), "m"(ff_pb_3F)
726 d2bb7db1 Loren Merritt
    );
727
}
728
729
static void h264_v_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
730
{
731
    h264_loop_filter_chroma_mmx2(pix, stride, alpha-1, beta-1, tc0);
732
}
733
734
static void h264_h_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
735
{
736
    //FIXME: could cut some load/stores by merging transpose with filter
737 079e61db Michael Niedermayer
    DECLARE_ALIGNED_8(uint8_t, trans[8*4]);
738 d2bb7db1 Loren Merritt
    transpose4x4(trans, pix-2, 8, stride);
739
    transpose4x4(trans+4, pix-2+4*stride, 8, stride);
740
    h264_loop_filter_chroma_mmx2(trans+2*8, 8, alpha-1, beta-1, tc0);
741
    transpose4x4(pix-2, trans, stride, 8);
742
    transpose4x4(pix-2+4*stride, trans+4, stride, 8);
743
}
744
745
// p0 = (p0 + q1 + 2*p1 + 2) >> 2
746
#define H264_FILTER_CHROMA4(p0, p1, q1, one) \
747
    "movq    "#p0", %%mm4  \n\t"\
748
    "pxor    "#q1", %%mm4  \n\t"\
749
    "pand   "#one", %%mm4  \n\t" /* mm4 = (p0^q1)&1 */\
750
    "pavgb   "#q1", "#p0"  \n\t"\
751
    "psubusb %%mm4, "#p0"  \n\t"\
752
    "pavgb   "#p1", "#p0"  \n\t" /* dst = avg(p1, avg(p0,q1) - ((p0^q1)&1)) */\
753
754
static inline void h264_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha1, int beta1)
755
{
756 be449fca Diego Pettenò
    __asm__ volatile(
757 d2bb7db1 Loren Merritt
        "movq    (%0),    %%mm0     \n\t"
758
        "movq    (%0,%2), %%mm1     \n\t"
759
        "movq    (%1),    %%mm2     \n\t"
760
        "movq    (%1,%2), %%mm3     \n\t"
761
        H264_DEBLOCK_MASK(%3, %4)
762
        "movq    %%mm1,   %%mm5     \n\t"
763
        "movq    %%mm2,   %%mm6     \n\t"
764
        H264_FILTER_CHROMA4(%%mm1, %%mm0, %%mm3, %5) //p0'
765
        H264_FILTER_CHROMA4(%%mm2, %%mm3, %%mm0, %5) //q0'
766
        "psubb   %%mm5,   %%mm1     \n\t"
767
        "psubb   %%mm6,   %%mm2     \n\t"
768
        "pand    %%mm7,   %%mm1     \n\t"
769
        "pand    %%mm7,   %%mm2     \n\t"
770
        "paddb   %%mm5,   %%mm1     \n\t"
771
        "paddb   %%mm6,   %%mm2     \n\t"
772
        "movq    %%mm1,   (%0,%2)   \n\t"
773
        "movq    %%mm2,   (%1)      \n\t"
774 40d0e665 Ramiro Polla
        :: "r"(pix-2*stride), "r"(pix), "r"((x86_reg)stride),
775 43de5065 Aurelien Jacobs
           "m"(alpha1), "m"(beta1), "m"(ff_bone)
776 d2bb7db1 Loren Merritt
    );
777
}
778
779
static void h264_v_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta)
780
{
781
    h264_loop_filter_chroma_intra_mmx2(pix, stride, alpha-1, beta-1);
782
}
783
784
static void h264_h_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta)
785
{
786
    //FIXME: could cut some load/stores by merging transpose with filter
787 079e61db Michael Niedermayer
    DECLARE_ALIGNED_8(uint8_t, trans[8*4]);
788 d2bb7db1 Loren Merritt
    transpose4x4(trans, pix-2, 8, stride);
789
    transpose4x4(trans+4, pix-2+4*stride, 8, stride);
790
    h264_loop_filter_chroma_intra_mmx2(trans+2*8, 8, alpha-1, beta-1);
791
    transpose4x4(pix-2, trans, stride, 8);
792
    transpose4x4(pix-2+4*stride, trans+4, stride, 8);
793
}
794
795 3e20143e Loren Merritt
static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2],
796 4f20b45f Michael Niedermayer
                                            int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field ) {
797 3e20143e Loren Merritt
    int dir;
798 be449fca Diego Pettenò
    __asm__ volatile(
799 3e20143e Loren Merritt
        "pxor %%mm7, %%mm7 \n\t"
800
        "movq %0, %%mm6 \n\t"
801
        "movq %1, %%mm5 \n\t"
802
        "movq %2, %%mm4 \n\t"
803
        ::"m"(ff_pb_1), "m"(ff_pb_3), "m"(ff_pb_7)
804
    );
805 4f20b45f Michael Niedermayer
    if(field)
806 be449fca Diego Pettenò
        __asm__ volatile(
807 4f20b45f Michael Niedermayer
            "movq %0, %%mm5 \n\t"
808
            "movq %1, %%mm4 \n\t"
809
            ::"m"(ff_pb_3_1), "m"(ff_pb_7_3)
810
        );
811
812 3e20143e Loren Merritt
    // could do a special case for dir==0 && edges==1, but it only reduces the
813
    // average filter time by 1.2%
814
    for( dir=1; dir>=0; dir-- ) {
815
        const int d_idx = dir ? -8 : -1;
816
        const int mask_mv = dir ? mask_mv1 : mask_mv0;
817 079e61db Michael Niedermayer
        DECLARE_ALIGNED_8(const uint64_t, mask_dir) = dir ? 0 : 0xffffffffffffffffULL;
818 3e20143e Loren Merritt
        int b_idx, edge, l;
819
        for( b_idx=12, edge=0; edge<edges; edge+=step, b_idx+=8*step ) {
820 be449fca Diego Pettenò
            __asm__ volatile(
821 3e20143e Loren Merritt
                "pand %0, %%mm0 \n\t"
822
                ::"m"(mask_dir)
823
            );
824
            if(!(mask_mv & edge)) {
825 be449fca Diego Pettenò
                __asm__ volatile("pxor %%mm0, %%mm0 \n\t":);
826 3e20143e Loren Merritt
                for( l = bidir; l >= 0; l-- ) {
827 be449fca Diego Pettenò
                    __asm__ volatile(
828 3e20143e Loren Merritt
                        "movd %0, %%mm1 \n\t"
829
                        "punpckldq %1, %%mm1 \n\t"
830
                        "punpckldq %%mm1, %%mm2 \n\t"
831
                        "pcmpeqb %%mm2, %%mm1 \n\t"
832
                        "paddb %%mm6, %%mm1 \n\t"
833
                        "punpckhbw %%mm7, %%mm1 \n\t" // ref[b] != ref[bn]
834
                        "por %%mm1, %%mm0 \n\t"
835
836
                        "movq %2, %%mm1 \n\t"
837
                        "movq %3, %%mm2 \n\t"
838
                        "psubw %4, %%mm1 \n\t"
839
                        "psubw %5, %%mm2 \n\t"
840
                        "packsswb %%mm2, %%mm1 \n\t"
841
                        "paddb %%mm5, %%mm1 \n\t"
842
                        "pminub %%mm4, %%mm1 \n\t"
843
                        "pcmpeqb %%mm4, %%mm1 \n\t" // abs(mv[b] - mv[bn]) >= limit
844
                        "por %%mm1, %%mm0 \n\t"
845
                        ::"m"(ref[l][b_idx]),
846
                          "m"(ref[l][b_idx+d_idx]),
847
                          "m"(mv[l][b_idx][0]),
848
                          "m"(mv[l][b_idx+2][0]),
849
                          "m"(mv[l][b_idx+d_idx][0]),
850
                          "m"(mv[l][b_idx+d_idx+2][0])
851
                    );
852
                }
853 9ac4548f Michael Niedermayer
                if(bidir==1){
854
                    __asm__ volatile("pxor %%mm3, %%mm3 \n\t":);
855
                    for( l = bidir; l >= 0; l-- ) {
856
                    __asm__ volatile(
857
                        "movd %0, %%mm1 \n\t"
858
                        "punpckldq %1, %%mm1 \n\t"
859
                        "punpckldq %%mm1, %%mm2 \n\t"
860
                        "pcmpeqb %%mm2, %%mm1 \n\t"
861
                        "paddb %%mm6, %%mm1 \n\t"
862
                        "punpckhbw %%mm7, %%mm1 \n\t" // ref[b] != ref[bn]
863
                        "por %%mm1, %%mm3 \n\t"
864
865
                        "movq %2, %%mm1 \n\t"
866
                        "movq %3, %%mm2 \n\t"
867
                        "psubw %4, %%mm1 \n\t"
868
                        "psubw %5, %%mm2 \n\t"
869
                        "packsswb %%mm2, %%mm1 \n\t"
870
                        "paddb %%mm5, %%mm1 \n\t"
871
                        "pminub %%mm4, %%mm1 \n\t"
872
                        "pcmpeqb %%mm4, %%mm1 \n\t" // abs(mv[b] - mv[bn]) >= limit
873
                        "por %%mm1, %%mm3 \n\t"
874
                        ::"m"(ref[l][b_idx]),
875
                          "m"(ref[1-l][b_idx+d_idx]),
876
                          "m"(mv[l][b_idx][0]),
877
                          "m"(mv[l][b_idx+2][0]),
878
                          "m"(mv[1-l][b_idx+d_idx][0]),
879
                          "m"(mv[1-l][b_idx+d_idx+2][0])
880
                    );
881
                    }
882
                    __asm__ volatile(
883
                        "pcmpeqw %%mm7, %%mm3 \n\t"
884
                        "psubusw %%mm3, %%mm0 \n\t"
885
                    :);
886
                }
887 3e20143e Loren Merritt
            }
888 be449fca Diego Pettenò
            __asm__ volatile(
889 3e20143e Loren Merritt
                "movd %0, %%mm1 \n\t"
890
                "por  %1, %%mm1 \n\t"
891
                "punpcklbw %%mm7, %%mm1 \n\t"
892
                "pcmpgtw %%mm7, %%mm1 \n\t" // nnz[b] || nnz[bn]
893
                ::"m"(nnz[b_idx]),
894
                  "m"(nnz[b_idx+d_idx])
895
            );
896 be449fca Diego Pettenò
            __asm__ volatile(
897 3e20143e Loren Merritt
                "pcmpeqw %%mm7, %%mm0 \n\t"
898
                "pcmpeqw %%mm7, %%mm0 \n\t"
899
                "psrlw $15, %%mm0 \n\t" // nonzero -> 1
900
                "psrlw $14, %%mm1 \n\t"
901
                "movq %%mm0, %%mm2 \n\t"
902
                "por %%mm1, %%mm2 \n\t"
903
                "psrlw $1, %%mm1 \n\t"
904
                "pandn %%mm2, %%mm1 \n\t"
905
                "movq %%mm1, %0 \n\t"
906
                :"=m"(*bS[dir][edge])
907
                ::"memory"
908
            );
909
        }
910
        edges = 4;
911
        step = 1;
912
    }
913 be449fca Diego Pettenò
    __asm__ volatile(
914 3e20143e Loren Merritt
        "movq   (%0), %%mm0 \n\t"
915
        "movq  8(%0), %%mm1 \n\t"
916
        "movq 16(%0), %%mm2 \n\t"
917
        "movq 24(%0), %%mm3 \n\t"
918
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4)
919
        "movq %%mm0,   (%0) \n\t"
920
        "movq %%mm3,  8(%0) \n\t"
921
        "movq %%mm4, 16(%0) \n\t"
922
        "movq %%mm2, 24(%0) \n\t"
923
        ::"r"(bS[0])
924
        :"memory"
925
    );
926
}
927 d2bb7db1 Loren Merritt
928
/***********************************/
929
/* motion compensation */
930
931 ddf96970 Loren Merritt
#define QPEL_H264V_MM(A,B,C,D,E,F,OP,T,Z,d,q)\
932
        "mov"#q" "#C", "#T"         \n\t"\
933
        "mov"#d" (%0), "#F"         \n\t"\
934
        "paddw "#D", "#T"           \n\t"\
935
        "psllw $2, "#T"             \n\t"\
936
        "psubw "#B", "#T"           \n\t"\
937
        "psubw "#E", "#T"           \n\t"\
938
        "punpcklbw "#Z", "#F"       \n\t"\
939
        "pmullw %4, "#T"            \n\t"\
940 bb270c08 Diego Biurrun
        "paddw %5, "#A"             \n\t"\
941 ddf96970 Loren Merritt
        "add %2, %0                 \n\t"\
942 bb270c08 Diego Biurrun
        "paddw "#F", "#A"           \n\t"\
943 ddf96970 Loren Merritt
        "paddw "#A", "#T"           \n\t"\
944
        "psraw $5, "#T"             \n\t"\
945
        "packuswb "#T", "#T"        \n\t"\
946
        OP(T, (%1), A, d)\
947 bb270c08 Diego Biurrun
        "add %3, %1                 \n\t"
948 d2bb7db1 Loren Merritt
949 ddf96970 Loren Merritt
#define QPEL_H264HV_MM(A,B,C,D,E,F,OF,T,Z,d,q)\
950
        "mov"#q" "#C", "#T"         \n\t"\
951
        "mov"#d" (%0), "#F"         \n\t"\
952
        "paddw "#D", "#T"           \n\t"\
953
        "psllw $2, "#T"             \n\t"\
954 b64dfbb8 Loren Merritt
        "paddw %4, "#A"             \n\t"\
955 ddf96970 Loren Merritt
        "psubw "#B", "#T"           \n\t"\
956
        "psubw "#E", "#T"           \n\t"\
957
        "punpcklbw "#Z", "#F"       \n\t"\
958
        "pmullw %3, "#T"            \n\t"\
959 bb270c08 Diego Biurrun
        "paddw "#F", "#A"           \n\t"\
960 ddf96970 Loren Merritt
        "add %2, %0                 \n\t"\
961
        "paddw "#A", "#T"           \n\t"\
962
        "mov"#q" "#T", "#OF"(%1)    \n\t"
963
964
#define QPEL_H264V(A,B,C,D,E,F,OP) QPEL_H264V_MM(A,B,C,D,E,F,OP,%%mm6,%%mm7,d,q)
965
#define QPEL_H264HV(A,B,C,D,E,F,OF) QPEL_H264HV_MM(A,B,C,D,E,F,OF,%%mm6,%%mm7,d,q)
966
#define QPEL_H264V_XMM(A,B,C,D,E,F,OP) QPEL_H264V_MM(A,B,C,D,E,F,OP,%%xmm6,%%xmm7,q,dqa)
967
#define QPEL_H264HV_XMM(A,B,C,D,E,F,OF) QPEL_H264HV_MM(A,B,C,D,E,F,OF,%%xmm6,%%xmm7,q,dqa)
968
969 115329f1 Diego Biurrun
970 d2bb7db1 Loren Merritt
#define QPEL_H264(OPNAME, OP, MMX)\
971 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
972 d2bb7db1 Loren Merritt
    int h=4;\
973
\
974 be449fca Diego Pettenò
    __asm__ volatile(\
975 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7          \n\t"\
976
        "movq %5, %%mm4             \n\t"\
977
        "movq %6, %%mm5             \n\t"\
978
        "1:                         \n\t"\
979
        "movd  -1(%0), %%mm1        \n\t"\
980
        "movd    (%0), %%mm2        \n\t"\
981
        "movd   1(%0), %%mm3        \n\t"\
982
        "movd   2(%0), %%mm0        \n\t"\
983
        "punpcklbw %%mm7, %%mm1     \n\t"\
984
        "punpcklbw %%mm7, %%mm2     \n\t"\
985
        "punpcklbw %%mm7, %%mm3     \n\t"\
986
        "punpcklbw %%mm7, %%mm0     \n\t"\
987
        "paddw %%mm0, %%mm1         \n\t"\
988
        "paddw %%mm3, %%mm2         \n\t"\
989
        "movd  -2(%0), %%mm0        \n\t"\
990
        "movd   3(%0), %%mm3        \n\t"\
991
        "punpcklbw %%mm7, %%mm0     \n\t"\
992
        "punpcklbw %%mm7, %%mm3     \n\t"\
993
        "paddw %%mm3, %%mm0         \n\t"\
994
        "psllw $2, %%mm2            \n\t"\
995
        "psubw %%mm1, %%mm2         \n\t"\
996
        "pmullw %%mm4, %%mm2        \n\t"\
997
        "paddw %%mm5, %%mm0         \n\t"\
998
        "paddw %%mm2, %%mm0         \n\t"\
999
        "psraw $5, %%mm0            \n\t"\
1000
        "packuswb %%mm0, %%mm0      \n\t"\
1001 d2bb7db1 Loren Merritt
        OP(%%mm0, (%1),%%mm6, d)\
1002 bb270c08 Diego Biurrun
        "add %3, %0                 \n\t"\
1003
        "add %4, %1                 \n\t"\
1004
        "decl %2                    \n\t"\
1005
        " jnz 1b                    \n\t"\
1006 20d565be Loren Merritt
        : "+a"(src), "+c"(dst), "+g"(h)\
1007 40d0e665 Ramiro Polla
        : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1008 d2bb7db1 Loren Merritt
        : "memory"\
1009
    );\
1010
}\
1011 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel4_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
1012 6a8eb0f4 Loren Merritt
    int h=4;\
1013 be449fca Diego Pettenò
    __asm__ volatile(\
1014 6a8eb0f4 Loren Merritt
        "pxor %%mm7, %%mm7          \n\t"\
1015 d84f7c61 Loren Merritt
        "movq %0, %%mm4             \n\t"\
1016
        "movq %1, %%mm5             \n\t"\
1017
        :: "m"(ff_pw_5), "m"(ff_pw_16)\
1018
    );\
1019
    do{\
1020 be449fca Diego Pettenò
    __asm__ volatile(\
1021 6a8eb0f4 Loren Merritt
        "movd  -1(%0), %%mm1        \n\t"\
1022
        "movd    (%0), %%mm2        \n\t"\
1023
        "movd   1(%0), %%mm3        \n\t"\
1024
        "movd   2(%0), %%mm0        \n\t"\
1025
        "punpcklbw %%mm7, %%mm1     \n\t"\
1026
        "punpcklbw %%mm7, %%mm2     \n\t"\
1027
        "punpcklbw %%mm7, %%mm3     \n\t"\
1028
        "punpcklbw %%mm7, %%mm0     \n\t"\
1029
        "paddw %%mm0, %%mm1         \n\t"\
1030
        "paddw %%mm3, %%mm2         \n\t"\
1031
        "movd  -2(%0), %%mm0        \n\t"\
1032
        "movd   3(%0), %%mm3        \n\t"\
1033
        "punpcklbw %%mm7, %%mm0     \n\t"\
1034
        "punpcklbw %%mm7, %%mm3     \n\t"\
1035
        "paddw %%mm3, %%mm0         \n\t"\
1036
        "psllw $2, %%mm2            \n\t"\
1037
        "psubw %%mm1, %%mm2         \n\t"\
1038
        "pmullw %%mm4, %%mm2        \n\t"\
1039
        "paddw %%mm5, %%mm0         \n\t"\
1040
        "paddw %%mm2, %%mm0         \n\t"\
1041
        "movd   (%2), %%mm3         \n\t"\
1042
        "psraw $5, %%mm0            \n\t"\
1043
        "packuswb %%mm0, %%mm0      \n\t"\
1044
        PAVGB" %%mm3, %%mm0         \n\t"\
1045
        OP(%%mm0, (%1),%%mm6, d)\
1046 d84f7c61 Loren Merritt
        "add %4, %0                 \n\t"\
1047
        "add %4, %1                 \n\t"\
1048
        "add %3, %2                 \n\t"\
1049
        : "+a"(src), "+c"(dst), "+d"(src2)\
1050 40d0e665 Ramiro Polla
        : "D"((x86_reg)src2Stride), "S"((x86_reg)dstStride)\
1051 6a8eb0f4 Loren Merritt
        : "memory"\
1052
    );\
1053 d84f7c61 Loren Merritt
    }while(--h);\
1054 6a8eb0f4 Loren Merritt
}\
1055 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel4_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1056 d2bb7db1 Loren Merritt
    src -= 2*srcStride;\
1057 be449fca Diego Pettenò
    __asm__ volatile(\
1058 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7          \n\t"\
1059
        "movd (%0), %%mm0           \n\t"\
1060
        "add %2, %0                 \n\t"\
1061
        "movd (%0), %%mm1           \n\t"\
1062
        "add %2, %0                 \n\t"\
1063
        "movd (%0), %%mm2           \n\t"\
1064
        "add %2, %0                 \n\t"\
1065
        "movd (%0), %%mm3           \n\t"\
1066
        "add %2, %0                 \n\t"\
1067
        "movd (%0), %%mm4           \n\t"\
1068
        "add %2, %0                 \n\t"\
1069
        "punpcklbw %%mm7, %%mm0     \n\t"\
1070
        "punpcklbw %%mm7, %%mm1     \n\t"\
1071
        "punpcklbw %%mm7, %%mm2     \n\t"\
1072
        "punpcklbw %%mm7, %%mm3     \n\t"\
1073
        "punpcklbw %%mm7, %%mm4     \n\t"\
1074 d2bb7db1 Loren Merritt
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
1075
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
1076
        QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
1077
        QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
1078
         \
1079
        : "+a"(src), "+c"(dst)\
1080 40d0e665 Ramiro Polla
        : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1081 d2bb7db1 Loren Merritt
        : "memory"\
1082
    );\
1083
}\
1084 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1085 d2bb7db1 Loren Merritt
    int h=4;\
1086
    int w=3;\
1087
    src -= 2*srcStride+2;\
1088
    while(w--){\
1089 be449fca Diego Pettenò
        __asm__ volatile(\
1090 bb270c08 Diego Biurrun
            "pxor %%mm7, %%mm7      \n\t"\
1091
            "movd (%0), %%mm0       \n\t"\
1092
            "add %2, %0             \n\t"\
1093
            "movd (%0), %%mm1       \n\t"\
1094
            "add %2, %0             \n\t"\
1095
            "movd (%0), %%mm2       \n\t"\
1096
            "add %2, %0             \n\t"\
1097
            "movd (%0), %%mm3       \n\t"\
1098
            "add %2, %0             \n\t"\
1099
            "movd (%0), %%mm4       \n\t"\
1100
            "add %2, %0             \n\t"\
1101
            "punpcklbw %%mm7, %%mm0 \n\t"\
1102
            "punpcklbw %%mm7, %%mm1 \n\t"\
1103
            "punpcklbw %%mm7, %%mm2 \n\t"\
1104
            "punpcklbw %%mm7, %%mm3 \n\t"\
1105
            "punpcklbw %%mm7, %%mm4 \n\t"\
1106 d2bb7db1 Loren Merritt
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*8*3)\
1107
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*8*3)\
1108
            QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*8*3)\
1109
            QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*8*3)\
1110
             \
1111
            : "+a"(src)\
1112 40d0e665 Ramiro Polla
            : "c"(tmp), "S"((x86_reg)srcStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1113 d2bb7db1 Loren Merritt
            : "memory"\
1114
        );\
1115
        tmp += 4;\
1116
        src += 4 - 9*srcStride;\
1117
    }\
1118
    tmp -= 3*4;\
1119 be449fca Diego Pettenò
    __asm__ volatile(\
1120 bb270c08 Diego Biurrun
        "1:                         \n\t"\
1121
        "movq     (%0), %%mm0       \n\t"\
1122
        "paddw  10(%0), %%mm0       \n\t"\
1123
        "movq    2(%0), %%mm1       \n\t"\
1124
        "paddw   8(%0), %%mm1       \n\t"\
1125
        "movq    4(%0), %%mm2       \n\t"\
1126
        "paddw   6(%0), %%mm2       \n\t"\
1127
        "psubw %%mm1, %%mm0         \n\t"/*a-b   (abccba)*/\
1128
        "psraw $2, %%mm0            \n\t"/*(a-b)/4 */\
1129
        "psubw %%mm1, %%mm0         \n\t"/*(a-b)/4-b */\
1130
        "paddsw %%mm2, %%mm0        \n\t"\
1131 cec93959 Loren Merritt
        "psraw $2, %%mm0            \n\t"/*((a-b)/4-b+c)/4 */\
1132 b64dfbb8 Loren Merritt
        "paddw %%mm2, %%mm0         \n\t"/*(a-5*b+20*c)/16 */\
1133 bb270c08 Diego Biurrun
        "psraw $6, %%mm0            \n\t"\
1134
        "packuswb %%mm0, %%mm0      \n\t"\
1135 d2bb7db1 Loren Merritt
        OP(%%mm0, (%1),%%mm7, d)\
1136 bb270c08 Diego Biurrun
        "add $24, %0                \n\t"\
1137
        "add %3, %1                 \n\t"\
1138
        "decl %2                    \n\t"\
1139
        " jnz 1b                    \n\t"\
1140 20d565be Loren Merritt
        : "+a"(tmp), "+c"(dst), "+g"(h)\
1141 40d0e665 Ramiro Polla
        : "S"((x86_reg)dstStride)\
1142 d2bb7db1 Loren Merritt
        : "memory"\
1143
    );\
1144
}\
1145
\
1146 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1147 d2bb7db1 Loren Merritt
    int h=8;\
1148 be449fca Diego Pettenò
    __asm__ volatile(\
1149 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7          \n\t"\
1150
        "movq %5, %%mm6             \n\t"\
1151
        "1:                         \n\t"\
1152
        "movq    (%0), %%mm0        \n\t"\
1153
        "movq   1(%0), %%mm2        \n\t"\
1154
        "movq %%mm0, %%mm1          \n\t"\
1155
        "movq %%mm2, %%mm3          \n\t"\
1156
        "punpcklbw %%mm7, %%mm0     \n\t"\
1157
        "punpckhbw %%mm7, %%mm1     \n\t"\
1158
        "punpcklbw %%mm7, %%mm2     \n\t"\
1159
        "punpckhbw %%mm7, %%mm3     \n\t"\
1160
        "paddw %%mm2, %%mm0         \n\t"\
1161
        "paddw %%mm3, %%mm1         \n\t"\
1162
        "psllw $2, %%mm0            \n\t"\
1163
        "psllw $2, %%mm1            \n\t"\
1164
        "movq   -1(%0), %%mm2       \n\t"\
1165
        "movq    2(%0), %%mm4       \n\t"\
1166
        "movq %%mm2, %%mm3          \n\t"\
1167
        "movq %%mm4, %%mm5          \n\t"\
1168
        "punpcklbw %%mm7, %%mm2     \n\t"\
1169
        "punpckhbw %%mm7, %%mm3     \n\t"\
1170
        "punpcklbw %%mm7, %%mm4     \n\t"\
1171
        "punpckhbw %%mm7, %%mm5     \n\t"\
1172
        "paddw %%mm4, %%mm2         \n\t"\
1173
        "paddw %%mm3, %%mm5         \n\t"\
1174
        "psubw %%mm2, %%mm0         \n\t"\
1175
        "psubw %%mm5, %%mm1         \n\t"\
1176
        "pmullw %%mm6, %%mm0        \n\t"\
1177
        "pmullw %%mm6, %%mm1        \n\t"\
1178
        "movd   -2(%0), %%mm2       \n\t"\
1179
        "movd    7(%0), %%mm5       \n\t"\
1180
        "punpcklbw %%mm7, %%mm2     \n\t"\
1181
        "punpcklbw %%mm7, %%mm5     \n\t"\
1182
        "paddw %%mm3, %%mm2         \n\t"\
1183
        "paddw %%mm5, %%mm4         \n\t"\
1184
        "movq %6, %%mm5             \n\t"\
1185
        "paddw %%mm5, %%mm2         \n\t"\
1186
        "paddw %%mm5, %%mm4         \n\t"\
1187
        "paddw %%mm2, %%mm0         \n\t"\
1188
        "paddw %%mm4, %%mm1         \n\t"\
1189
        "psraw $5, %%mm0            \n\t"\
1190
        "psraw $5, %%mm1            \n\t"\
1191
        "packuswb %%mm1, %%mm0      \n\t"\
1192 d2bb7db1 Loren Merritt
        OP(%%mm0, (%1),%%mm5, q)\
1193 bb270c08 Diego Biurrun
        "add %3, %0                 \n\t"\
1194
        "add %4, %1                 \n\t"\
1195
        "decl %2                    \n\t"\
1196
        " jnz 1b                    \n\t"\
1197 20d565be Loren Merritt
        : "+a"(src), "+c"(dst), "+g"(h)\
1198 40d0e665 Ramiro Polla
        : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1199 d2bb7db1 Loren Merritt
        : "memory"\
1200
    );\
1201
}\
1202
\
1203 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
1204 6a8eb0f4 Loren Merritt
    int h=8;\
1205 be449fca Diego Pettenò
    __asm__ volatile(\
1206 6a8eb0f4 Loren Merritt
        "pxor %%mm7, %%mm7          \n\t"\
1207 d84f7c61 Loren Merritt
        "movq %0, %%mm6             \n\t"\
1208
        :: "m"(ff_pw_5)\
1209
    );\
1210
    do{\
1211 be449fca Diego Pettenò
    __asm__ volatile(\
1212 6a8eb0f4 Loren Merritt
        "movq    (%0), %%mm0        \n\t"\
1213
        "movq   1(%0), %%mm2        \n\t"\
1214
        "movq %%mm0, %%mm1          \n\t"\
1215
        "movq %%mm2, %%mm3          \n\t"\
1216
        "punpcklbw %%mm7, %%mm0     \n\t"\
1217
        "punpckhbw %%mm7, %%mm1     \n\t"\
1218
        "punpcklbw %%mm7, %%mm2     \n\t"\
1219
        "punpckhbw %%mm7, %%mm3     \n\t"\
1220
        "paddw %%mm2, %%mm0         \n\t"\
1221
        "paddw %%mm3, %%mm1         \n\t"\
1222
        "psllw $2, %%mm0            \n\t"\
1223
        "psllw $2, %%mm1            \n\t"\
1224
        "movq   -1(%0), %%mm2       \n\t"\
1225
        "movq    2(%0), %%mm4       \n\t"\
1226
        "movq %%mm2, %%mm3          \n\t"\
1227
        "movq %%mm4, %%mm5          \n\t"\
1228
        "punpcklbw %%mm7, %%mm2     \n\t"\
1229
        "punpckhbw %%mm7, %%mm3     \n\t"\
1230
        "punpcklbw %%mm7, %%mm4     \n\t"\
1231
        "punpckhbw %%mm7, %%mm5     \n\t"\
1232
        "paddw %%mm4, %%mm2         \n\t"\
1233
        "paddw %%mm3, %%mm5         \n\t"\
1234
        "psubw %%mm2, %%mm0         \n\t"\
1235
        "psubw %%mm5, %%mm1         \n\t"\
1236
        "pmullw %%mm6, %%mm0        \n\t"\
1237
        "pmullw %%mm6, %%mm1        \n\t"\
1238
        "movd   -2(%0), %%mm2       \n\t"\
1239
        "movd    7(%0), %%mm5       \n\t"\
1240
        "punpcklbw %%mm7, %%mm2     \n\t"\
1241
        "punpcklbw %%mm7, %%mm5     \n\t"\
1242
        "paddw %%mm3, %%mm2         \n\t"\
1243
        "paddw %%mm5, %%mm4         \n\t"\
1244 d84f7c61 Loren Merritt
        "movq %5, %%mm5             \n\t"\
1245 6a8eb0f4 Loren Merritt
        "paddw %%mm5, %%mm2         \n\t"\
1246
        "paddw %%mm5, %%mm4         \n\t"\
1247
        "paddw %%mm2, %%mm0         \n\t"\
1248
        "paddw %%mm4, %%mm1         \n\t"\
1249
        "psraw $5, %%mm0            \n\t"\
1250
        "psraw $5, %%mm1            \n\t"\
1251
        "movq (%2), %%mm4           \n\t"\
1252
        "packuswb %%mm1, %%mm0      \n\t"\
1253
        PAVGB" %%mm4, %%mm0         \n\t"\
1254
        OP(%%mm0, (%1),%%mm5, q)\
1255 d84f7c61 Loren Merritt
        "add %4, %0                 \n\t"\
1256
        "add %4, %1                 \n\t"\
1257
        "add %3, %2                 \n\t"\
1258
        : "+a"(src), "+c"(dst), "+d"(src2)\
1259 40d0e665 Ramiro Polla
        : "D"((x86_reg)src2Stride), "S"((x86_reg)dstStride),\
1260 d84f7c61 Loren Merritt
          "m"(ff_pw_16)\
1261 6a8eb0f4 Loren Merritt
        : "memory"\
1262
    );\
1263 d84f7c61 Loren Merritt
    }while(--h);\
1264 6a8eb0f4 Loren Merritt
}\
1265
\
1266 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1267 c03ce51d Loren Merritt
    int w= 2;\
1268 d2bb7db1 Loren Merritt
    src -= 2*srcStride;\
1269
    \
1270 c03ce51d Loren Merritt
    while(w--){\
1271 be449fca Diego Pettenò
      __asm__ volatile(\
1272 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7          \n\t"\
1273
        "movd (%0), %%mm0           \n\t"\
1274
        "add %2, %0                 \n\t"\
1275
        "movd (%0), %%mm1           \n\t"\
1276
        "add %2, %0                 \n\t"\
1277
        "movd (%0), %%mm2           \n\t"\
1278
        "add %2, %0                 \n\t"\
1279
        "movd (%0), %%mm3           \n\t"\
1280
        "add %2, %0                 \n\t"\
1281
        "movd (%0), %%mm4           \n\t"\
1282
        "add %2, %0                 \n\t"\
1283
        "punpcklbw %%mm7, %%mm0     \n\t"\
1284
        "punpcklbw %%mm7, %%mm1     \n\t"\
1285
        "punpcklbw %%mm7, %%mm2     \n\t"\
1286
        "punpcklbw %%mm7, %%mm3     \n\t"\
1287
        "punpcklbw %%mm7, %%mm4     \n\t"\
1288 d2bb7db1 Loren Merritt
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
1289
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
1290
        QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
1291
        QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
1292
        QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
1293
        QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
1294
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
1295
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
1296
         \
1297
        : "+a"(src), "+c"(dst)\
1298 40d0e665 Ramiro Polla
        : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1299 d2bb7db1 Loren Merritt
        : "memory"\
1300
     );\
1301 c03ce51d Loren Merritt
     if(h==16){\
1302 be449fca Diego Pettenò
        __asm__ volatile(\
1303 c03ce51d Loren Merritt
            QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
1304
            QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
1305
            QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
1306
            QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
1307
            QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
1308
            QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
1309
            QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
1310
            QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
1311
            \
1312
           : "+a"(src), "+c"(dst)\
1313 40d0e665 Ramiro Polla
           : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1314 c03ce51d Loren Merritt
           : "memory"\
1315
        );\
1316
     }\
1317
     src += 4-(h+5)*srcStride;\
1318
     dst += 4-h*dstStride;\
1319 d2bb7db1 Loren Merritt
   }\
1320
}\
1321 1d67b037 Loren Merritt
static av_always_inline void OPNAME ## h264_qpel8or16_hv1_lowpass_ ## MMX(int16_t *tmp, uint8_t *src, int tmpStride, int srcStride, int size){\
1322 0331f092 Loren Merritt
    int w = (size+8)>>2;\
1323 d2bb7db1 Loren Merritt
    src -= 2*srcStride+2;\
1324
    while(w--){\
1325 be449fca Diego Pettenò
        __asm__ volatile(\
1326 bb270c08 Diego Biurrun
            "pxor %%mm7, %%mm7      \n\t"\
1327
            "movd (%0), %%mm0       \n\t"\
1328
            "add %2, %0             \n\t"\
1329
            "movd (%0), %%mm1       \n\t"\
1330
            "add %2, %0             \n\t"\
1331
            "movd (%0), %%mm2       \n\t"\
1332
            "add %2, %0             \n\t"\
1333
            "movd (%0), %%mm3       \n\t"\
1334
            "add %2, %0             \n\t"\
1335
            "movd (%0), %%mm4       \n\t"\
1336
            "add %2, %0             \n\t"\
1337
            "punpcklbw %%mm7, %%mm0 \n\t"\
1338
            "punpcklbw %%mm7, %%mm1 \n\t"\
1339
            "punpcklbw %%mm7, %%mm2 \n\t"\
1340
            "punpcklbw %%mm7, %%mm3 \n\t"\
1341
            "punpcklbw %%mm7, %%mm4 \n\t"\
1342 0331f092 Loren Merritt
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*48)\
1343
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*48)\
1344
            QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*48)\
1345
            QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*48)\
1346
            QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 4*48)\
1347
            QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 5*48)\
1348
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 6*48)\
1349
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 7*48)\
1350 d2bb7db1 Loren Merritt
            : "+a"(src)\
1351 40d0e665 Ramiro Polla
            : "c"(tmp), "S"((x86_reg)srcStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1352 d2bb7db1 Loren Merritt
            : "memory"\
1353
        );\
1354 0331f092 Loren Merritt
        if(size==16){\
1355 be449fca Diego Pettenò
            __asm__ volatile(\
1356 0331f092 Loren Merritt
                QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1,  8*48)\
1357
                QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2,  9*48)\
1358
                QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 10*48)\
1359
                QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 11*48)\
1360
                QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 12*48)\
1361
                QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 13*48)\
1362
                QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 14*48)\
1363
                QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\
1364
                : "+a"(src)\
1365 40d0e665 Ramiro Polla
                : "c"(tmp), "S"((x86_reg)srcStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1366 0331f092 Loren Merritt
                : "memory"\
1367
            );\
1368
        }\
1369 d2bb7db1 Loren Merritt
        tmp += 4;\
1370 0331f092 Loren Merritt
        src += 4 - (size+5)*srcStride;\
1371 d2bb7db1 Loren Merritt
    }\
1372 1d67b037 Loren Merritt
}\
1373
static av_always_inline void OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size){\
1374
    int w = size>>4;\
1375 0331f092 Loren Merritt
    do{\
1376 1d67b037 Loren Merritt
    int h = size;\
1377 be449fca Diego Pettenò
    __asm__ volatile(\
1378 bb270c08 Diego Biurrun
        "1:                         \n\t"\
1379
        "movq     (%0), %%mm0       \n\t"\
1380
        "movq    8(%0), %%mm3       \n\t"\
1381
        "movq    2(%0), %%mm1       \n\t"\
1382
        "movq   10(%0), %%mm4       \n\t"\
1383
        "paddw   %%mm4, %%mm0       \n\t"\
1384
        "paddw   %%mm3, %%mm1       \n\t"\
1385
        "paddw  18(%0), %%mm3       \n\t"\
1386
        "paddw  16(%0), %%mm4       \n\t"\
1387
        "movq    4(%0), %%mm2       \n\t"\
1388
        "movq   12(%0), %%mm5       \n\t"\
1389
        "paddw   6(%0), %%mm2       \n\t"\
1390
        "paddw  14(%0), %%mm5       \n\t"\
1391
        "psubw %%mm1, %%mm0         \n\t"\
1392
        "psubw %%mm4, %%mm3         \n\t"\
1393
        "psraw $2, %%mm0            \n\t"\
1394
        "psraw $2, %%mm3            \n\t"\
1395
        "psubw %%mm1, %%mm0         \n\t"\
1396
        "psubw %%mm4, %%mm3         \n\t"\
1397
        "paddsw %%mm2, %%mm0        \n\t"\
1398
        "paddsw %%mm5, %%mm3        \n\t"\
1399
        "psraw $2, %%mm0            \n\t"\
1400
        "psraw $2, %%mm3            \n\t"\
1401
        "paddw %%mm2, %%mm0         \n\t"\
1402
        "paddw %%mm5, %%mm3         \n\t"\
1403
        "psraw $6, %%mm0            \n\t"\
1404
        "psraw $6, %%mm3            \n\t"\
1405
        "packuswb %%mm3, %%mm0      \n\t"\
1406 d2bb7db1 Loren Merritt
        OP(%%mm0, (%1),%%mm7, q)\
1407 0331f092 Loren Merritt
        "add $48, %0                \n\t"\
1408 bb270c08 Diego Biurrun
        "add %3, %1                 \n\t"\
1409
        "decl %2                    \n\t"\
1410
        " jnz 1b                    \n\t"\
1411 20d565be Loren Merritt
        : "+a"(tmp), "+c"(dst), "+g"(h)\
1412 40d0e665 Ramiro Polla
        : "S"((x86_reg)dstStride)\
1413 d2bb7db1 Loren Merritt
        : "memory"\
1414
    );\
1415 0331f092 Loren Merritt
    tmp += 8 - size*24;\
1416
    dst += 8 - size*dstStride;\
1417
    }while(w--);\
1418 d2bb7db1 Loren Merritt
}\
1419 c03ce51d Loren Merritt
\
1420
static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1421
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst  , src  , dstStride, srcStride, 8);\
1422
}\
1423 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1424 c03ce51d Loren Merritt
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst  , src  , dstStride, srcStride, 16);\
1425
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
1426 d2bb7db1 Loren Merritt
}\
1427
\
1428 1d67b037 Loren Merritt
static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1429 d2bb7db1 Loren Merritt
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst  , src  , dstStride, srcStride);\
1430
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
1431
    src += 8*srcStride;\
1432
    dst += 8*dstStride;\
1433
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst  , src  , dstStride, srcStride);\
1434
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
1435
}\
1436
\
1437 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
1438 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst  , src  , src2  , dstStride, src2Stride);\
1439
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
1440
    src += 8*dstStride;\
1441
    dst += 8*dstStride;\
1442
    src2 += 8*src2Stride;\
1443
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst  , src  , src2  , dstStride, src2Stride);\
1444
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
1445
}\
1446
\
1447 1d67b037 Loren Merritt
static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
1448
          put_h264_qpel8or16_hv1_lowpass_ ## MMX(tmp, src, tmpStride, srcStride, size);\
1449
    OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\
1450
}\
1451 0331f092 Loren Merritt
static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1452
    OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst  , tmp  , src  , dstStride, tmpStride, srcStride, 8);\
1453
}\
1454
\
1455 d2bb7db1 Loren Merritt
static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1456 0331f092 Loren Merritt
    OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst  , tmp  , src  , dstStride, tmpStride, srcStride, 16);\
1457 d2bb7db1 Loren Merritt
}\
1458 e545f375 Loren Merritt
\
1459 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
1460 e545f375 Loren Merritt
{\
1461 be449fca Diego Pettenò
    __asm__ volatile(\
1462 e545f375 Loren Merritt
        "movq      (%1), %%mm0          \n\t"\
1463
        "movq    24(%1), %%mm1          \n\t"\
1464 4e295993 Loren Merritt
        "psraw      $5,  %%mm0          \n\t"\
1465
        "psraw      $5,  %%mm1          \n\t"\
1466 7a5b2fa8 Loren Merritt
        "packuswb %%mm0, %%mm0          \n\t"\
1467
        "packuswb %%mm1, %%mm1          \n\t"\
1468 e545f375 Loren Merritt
        PAVGB"     (%0), %%mm0          \n\t"\
1469
        PAVGB"  (%0,%3), %%mm1          \n\t"\
1470
        OP(%%mm0, (%2),    %%mm4, d)\
1471
        OP(%%mm1, (%2,%4), %%mm5, d)\
1472
        "lea  (%0,%3,2), %0             \n\t"\
1473
        "lea  (%2,%4,2), %2             \n\t"\
1474
        "movq    48(%1), %%mm0          \n\t"\
1475
        "movq    72(%1), %%mm1          \n\t"\
1476 4e295993 Loren Merritt
        "psraw      $5,  %%mm0          \n\t"\
1477
        "psraw      $5,  %%mm1          \n\t"\
1478 7a5b2fa8 Loren Merritt
        "packuswb %%mm0, %%mm0          \n\t"\
1479
        "packuswb %%mm1, %%mm1          \n\t"\
1480 e545f375 Loren Merritt
        PAVGB"     (%0), %%mm0          \n\t"\
1481
        PAVGB"  (%0,%3), %%mm1          \n\t"\
1482
        OP(%%mm0, (%2),    %%mm4, d)\
1483
        OP(%%mm1, (%2,%4), %%mm5, d)\
1484
        :"+a"(src8), "+c"(src16), "+d"(dst)\
1485 40d0e665 Ramiro Polla
        :"S"((x86_reg)src8Stride), "D"((x86_reg)dstStride)\
1486 e545f375 Loren Merritt
        :"memory");\
1487
}\
1488 00e210dd Michael Niedermayer
static av_noinline void OPNAME ## pixels8_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
1489 e545f375 Loren Merritt
{\
1490 ddf96970 Loren Merritt
    do{\
1491 be449fca Diego Pettenò
    __asm__ volatile(\
1492 e545f375 Loren Merritt
        "movq      (%1), %%mm0          \n\t"\
1493
        "movq     8(%1), %%mm1          \n\t"\
1494 ddf96970 Loren Merritt
        "movq    48(%1), %%mm2          \n\t"\
1495
        "movq  8+48(%1), %%mm3          \n\t"\
1496 4e295993 Loren Merritt
        "psraw      $5,  %%mm0          \n\t"\
1497
        "psraw      $5,  %%mm1          \n\t"\
1498 ddf96970 Loren Merritt
        "psraw      $5,  %%mm2          \n\t"\
1499
        "psraw      $5,  %%mm3          \n\t"\
1500 e545f375 Loren Merritt
        "packuswb %%mm1, %%mm0          \n\t"\
1501 ddf96970 Loren Merritt
        "packuswb %%mm3, %%mm2          \n\t"\
1502 e545f375 Loren Merritt
        PAVGB"     (%0), %%mm0          \n\t"\
1503 ddf96970 Loren Merritt
        PAVGB"  (%0,%3), %%mm2          \n\t"\
1504 e545f375 Loren Merritt
        OP(%%mm0, (%2), %%mm5, q)\
1505 ddf96970 Loren Merritt
        OP(%%mm2, (%2,%4), %%mm5, q)\
1506
        ::"a"(src8), "c"(src16), "d"(dst),\
1507 40d0e665 Ramiro Polla
          "r"((x86_reg)src8Stride), "r"((x86_reg)dstStride)\
1508 e545f375 Loren Merritt
        :"memory");\
1509 ddf96970 Loren Merritt
        src8 += 2L*src8Stride;\
1510
        src16 += 48;\
1511
        dst += 2L*dstStride;\
1512
    }while(h-=2);\
1513 e545f375 Loren Merritt
}\
1514
static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
1515
{\
1516
    OPNAME ## pixels8_l2_shift5_ ## MMX(dst  , src16  , src8  , dstStride, src8Stride, h);\
1517
    OPNAME ## pixels8_l2_shift5_ ## MMX(dst+8, src16+8, src8+8, dstStride, src8Stride, h);\
1518
}\
1519
1520 1d67b037 Loren Merritt
1521 b250f9c6 Aurelien Jacobs
#if ARCH_X86_64
1522 1d67b037 Loren Merritt
#define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
1523 ddf96970 Loren Merritt
static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
1524
    int h=16;\
1525 be449fca Diego Pettenò
    __asm__ volatile(\
1526 ddf96970 Loren Merritt
        "pxor %%xmm15, %%xmm15      \n\t"\
1527
        "movdqa %6, %%xmm14         \n\t"\
1528
        "movdqa %7, %%xmm13         \n\t"\
1529
        "1:                         \n\t"\
1530 2b9969a9 Alexander Strange
        "lddqu    6(%0), %%xmm1     \n\t"\
1531
        "lddqu   -2(%0), %%xmm7     \n\t"\
1532 ddf96970 Loren Merritt
        "movdqa  %%xmm1, %%xmm0     \n\t"\
1533
        "punpckhbw %%xmm15, %%xmm1  \n\t"\
1534
        "punpcklbw %%xmm15, %%xmm0  \n\t"\
1535
        "punpcklbw %%xmm15, %%xmm7  \n\t"\
1536
        "movdqa  %%xmm1, %%xmm2     \n\t"\
1537
        "movdqa  %%xmm0, %%xmm6     \n\t"\
1538
        "movdqa  %%xmm1, %%xmm3     \n\t"\
1539
        "movdqa  %%xmm0, %%xmm8     \n\t"\
1540
        "movdqa  %%xmm1, %%xmm4     \n\t"\
1541
        "movdqa  %%xmm0, %%xmm9     \n\t"\
1542 2b9969a9 Alexander Strange
        "movdqa  %%xmm0, %%xmm12    \n\t"\
1543
        "movdqa  %%xmm1, %%xmm11    \n\t"\
1544
        "palignr $10,%%xmm0, %%xmm11\n\t"\
1545
        "palignr $10,%%xmm7, %%xmm12\n\t"\
1546
        "palignr $2, %%xmm0, %%xmm4 \n\t"\
1547
        "palignr $2, %%xmm7, %%xmm9 \n\t"\
1548
        "palignr $4, %%xmm0, %%xmm3 \n\t"\
1549
        "palignr $4, %%xmm7, %%xmm8 \n\t"\
1550
        "palignr $6, %%xmm0, %%xmm2 \n\t"\
1551
        "palignr $6, %%xmm7, %%xmm6 \n\t"\
1552
        "paddw   %%xmm0 ,%%xmm11    \n\t"\
1553
        "palignr $8, %%xmm0, %%xmm1 \n\t"\
1554
        "palignr $8, %%xmm7, %%xmm0 \n\t"\
1555
        "paddw   %%xmm12,%%xmm7     \n\t"\
1556 ddf96970 Loren Merritt
        "paddw   %%xmm3, %%xmm2     \n\t"\
1557
        "paddw   %%xmm8, %%xmm6     \n\t"\
1558
        "paddw   %%xmm4, %%xmm1     \n\t"\
1559
        "paddw   %%xmm9, %%xmm0     \n\t"\
1560
        "psllw   $2,     %%xmm2     \n\t"\
1561
        "psllw   $2,     %%xmm6     \n\t"\
1562
        "psubw   %%xmm1, %%xmm2     \n\t"\
1563
        "psubw   %%xmm0, %%xmm6     \n\t"\
1564 2b9969a9 Alexander Strange
        "paddw   %%xmm13,%%xmm11    \n\t"\
1565
        "paddw   %%xmm13,%%xmm7     \n\t"\
1566 ddf96970 Loren Merritt
        "pmullw  %%xmm14,%%xmm2     \n\t"\
1567
        "pmullw  %%xmm14,%%xmm6     \n\t"\
1568
        "lddqu   (%2),   %%xmm3     \n\t"\
1569 2b9969a9 Alexander Strange
        "paddw   %%xmm11,%%xmm2     \n\t"\
1570
        "paddw   %%xmm7, %%xmm6     \n\t"\
1571 ddf96970 Loren Merritt
        "psraw   $5,     %%xmm2     \n\t"\
1572
        "psraw   $5,     %%xmm6     \n\t"\
1573
        "packuswb %%xmm2,%%xmm6     \n\t"\
1574
        "pavgb   %%xmm3, %%xmm6     \n\t"\
1575
        OP(%%xmm6, (%1), %%xmm4, dqa)\
1576
        "add %5, %0                 \n\t"\
1577
        "add %5, %1                 \n\t"\
1578
        "add %4, %2                 \n\t"\
1579 ec199cc9 Loren Merritt
        "decl %3                    \n\t"\
1580 ddf96970 Loren Merritt
        "jg 1b                      \n\t"\
1581
        : "+a"(src), "+c"(dst), "+d"(src2), "+g"(h)\
1582 40d0e665 Ramiro Polla
        : "D"((x86_reg)src2Stride), "S"((x86_reg)dstStride),\
1583 ddf96970 Loren Merritt
          "m"(ff_pw_5), "m"(ff_pw_16)\
1584
        : "memory"\
1585
    );\
1586
}
1587
#else // ARCH_X86_64
1588 1d67b037 Loren Merritt
#define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
1589 ddf96970 Loren Merritt
static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
1590
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst  , src  , src2  , dstStride, src2Stride);\
1591
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
1592
    src += 8*dstStride;\
1593
    dst += 8*dstStride;\
1594
    src2 += 8*src2Stride;\
1595
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst  , src  , src2  , dstStride, src2Stride);\
1596
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
1597
}
1598
#endif // ARCH_X86_64
1599
1600 1d67b037 Loren Merritt
#define QPEL_H264_H_XMM(OPNAME, OP, MMX)\
1601 ddf96970 Loren Merritt
static av_noinline void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
1602
    int h=8;\
1603 be449fca Diego Pettenò
    __asm__ volatile(\
1604 ddf96970 Loren Merritt
        "pxor %%xmm7, %%xmm7        \n\t"\
1605
        "movdqa %0, %%xmm6          \n\t"\
1606
        :: "m"(ff_pw_5)\
1607
    );\
1608
    do{\
1609 be449fca Diego Pettenò
    __asm__ volatile(\
1610 2b9969a9 Alexander Strange
        "lddqu   -2(%0), %%xmm1     \n\t"\
1611 ddf96970 Loren Merritt
        "movdqa  %%xmm1, %%xmm0     \n\t"\
1612
        "punpckhbw %%xmm7, %%xmm1   \n\t"\
1613
        "punpcklbw %%xmm7, %%xmm0   \n\t"\
1614
        "movdqa  %%xmm1, %%xmm2     \n\t"\
1615
        "movdqa  %%xmm1, %%xmm3     \n\t"\
1616
        "movdqa  %%xmm1, %%xmm4     \n\t"\
1617
        "movdqa  %%xmm1, %%xmm5     \n\t"\
1618 2b9969a9 Alexander Strange
        "palignr $2, %%xmm0, %%xmm4 \n\t"\
1619
        "palignr $4, %%xmm0, %%xmm3 \n\t"\
1620
        "palignr $6, %%xmm0, %%xmm2 \n\t"\
1621
        "palignr $8, %%xmm0, %%xmm1 \n\t"\
1622
        "palignr $10,%%xmm0, %%xmm5 \n\t"\
1623
        "paddw   %%xmm5, %%xmm0     \n\t"\
1624 ddf96970 Loren Merritt
        "paddw   %%xmm3, %%xmm2     \n\t"\
1625
        "paddw   %%xmm4, %%xmm1     \n\t"\
1626
        "psllw   $2,     %%xmm2     \n\t"\
1627
        "movq    (%2),   %%xmm3     \n\t"\
1628
        "psubw   %%xmm1, %%xmm2     \n\t"\
1629 2b9969a9 Alexander Strange
        "paddw   %5,     %%xmm0     \n\t"\
1630 ddf96970 Loren Merritt
        "pmullw  %%xmm6, %%xmm2     \n\t"\
1631 2b9969a9 Alexander Strange
        "paddw   %%xmm0, %%xmm2     \n\t"\
1632 ddf96970 Loren Merritt
        "psraw   $5,     %%xmm2     \n\t"\
1633
        "packuswb %%xmm2, %%xmm2    \n\t"\
1634
        "pavgb   %%xmm3, %%xmm2     \n\t"\
1635
        OP(%%xmm2, (%1), %%xmm4, q)\
1636
        "add %4, %0                 \n\t"\
1637
        "add %4, %1                 \n\t"\
1638
        "add %3, %2                 \n\t"\
1639
        : "+a"(src), "+c"(dst), "+d"(src2)\
1640 40d0e665 Ramiro Polla
        : "D"((x86_reg)src2Stride), "S"((x86_reg)dstStride),\
1641 ddf96970 Loren Merritt
          "m"(ff_pw_16)\
1642
        : "memory"\
1643
    );\
1644
    }while(--h);\
1645
}\
1646 1d67b037 Loren Merritt
QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
1647 ddf96970 Loren Merritt
\
1648 1d67b037 Loren Merritt
static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1649
    int h=8;\
1650 be449fca Diego Pettenò
    __asm__ volatile(\
1651 1d67b037 Loren Merritt
        "pxor %%xmm7, %%xmm7        \n\t"\
1652
        "movdqa %5, %%xmm6          \n\t"\
1653
        "1:                         \n\t"\
1654 2b9969a9 Alexander Strange
        "lddqu   -2(%0), %%xmm1     \n\t"\
1655 1d67b037 Loren Merritt
        "movdqa  %%xmm1, %%xmm0     \n\t"\
1656
        "punpckhbw %%xmm7, %%xmm1   \n\t"\
1657
        "punpcklbw %%xmm7, %%xmm0   \n\t"\
1658
        "movdqa  %%xmm1, %%xmm2     \n\t"\
1659
        "movdqa  %%xmm1, %%xmm3     \n\t"\
1660
        "movdqa  %%xmm1, %%xmm4     \n\t"\
1661
        "movdqa  %%xmm1, %%xmm5     \n\t"\
1662 2b9969a9 Alexander Strange
        "palignr $2, %%xmm0, %%xmm4 \n\t"\
1663
        "palignr $4, %%xmm0, %%xmm3 \n\t"\
1664
        "palignr $6, %%xmm0, %%xmm2 \n\t"\
1665
        "palignr $8, %%xmm0, %%xmm1 \n\t"\
1666
        "palignr $10,%%xmm0, %%xmm5 \n\t"\
1667
        "paddw   %%xmm5, %%xmm0     \n\t"\
1668 1d67b037 Loren Merritt
        "paddw   %%xmm3, %%xmm2     \n\t"\
1669
        "paddw   %%xmm4, %%xmm1     \n\t"\
1670
        "psllw   $2,     %%xmm2     \n\t"\
1671
        "psubw   %%xmm1, %%xmm2     \n\t"\
1672 2b9969a9 Alexander Strange
        "paddw   %6,     %%xmm0     \n\t"\
1673 1d67b037 Loren Merritt
        "pmullw  %%xmm6, %%xmm2     \n\t"\
1674 2b9969a9 Alexander Strange
        "paddw   %%xmm0, %%xmm2     \n\t"\
1675 1d67b037 Loren Merritt
        "psraw   $5,     %%xmm2     \n\t"\
1676
        "packuswb %%xmm2, %%xmm2    \n\t"\
1677
        OP(%%xmm2, (%1), %%xmm4, q)\
1678
        "add %3, %0                 \n\t"\
1679
        "add %4, %1                 \n\t"\
1680
        "decl %2                    \n\t"\
1681
        " jnz 1b                    \n\t"\
1682
        : "+a"(src), "+c"(dst), "+g"(h)\
1683 40d0e665 Ramiro Polla
        : "D"((x86_reg)srcStride), "S"((x86_reg)dstStride),\
1684 1d67b037 Loren Merritt
          "m"(ff_pw_5), "m"(ff_pw_16)\
1685
        : "memory"\
1686
    );\
1687
}\
1688
static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1689
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst  , src  , dstStride, srcStride);\
1690
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
1691
    src += 8*srcStride;\
1692
    dst += 8*dstStride;\
1693
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst  , src  , dstStride, srcStride);\
1694
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
1695
}\
1696
1697
#define QPEL_H264_V_XMM(OPNAME, OP, MMX)\
1698 ddf96970 Loren Merritt
static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1699
    src -= 2*srcStride;\
1700
    \
1701 be449fca Diego Pettenò
    __asm__ volatile(\
1702 ddf96970 Loren Merritt
        "pxor %%xmm7, %%xmm7        \n\t"\
1703
        "movq (%0), %%xmm0          \n\t"\
1704
        "add %2, %0                 \n\t"\
1705
        "movq (%0), %%xmm1          \n\t"\
1706
        "add %2, %0                 \n\t"\
1707
        "movq (%0), %%xmm2          \n\t"\
1708
        "add %2, %0                 \n\t"\
1709
        "movq (%0), %%xmm3          \n\t"\
1710
        "add %2, %0                 \n\t"\
1711
        "movq (%0), %%xmm4          \n\t"\
1712
        "add %2, %0                 \n\t"\
1713
        "punpcklbw %%xmm7, %%xmm0   \n\t"\
1714
        "punpcklbw %%xmm7, %%xmm1   \n\t"\
1715
        "punpcklbw %%xmm7, %%xmm2   \n\t"\
1716
        "punpcklbw %%xmm7, %%xmm3   \n\t"\
1717
        "punpcklbw %%xmm7, %%xmm4   \n\t"\
1718
        QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\
1719
        QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\
1720
        QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\
1721
        QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\
1722
        QPEL_H264V_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, OP)\
1723
        QPEL_H264V_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, OP)\
1724
        QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\
1725
        QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\
1726
         \
1727
        : "+a"(src), "+c"(dst)\
1728 40d0e665 Ramiro Polla
        : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1729 ddf96970 Loren Merritt
        : "memory"\
1730
    );\
1731
    if(h==16){\
1732 be449fca Diego Pettenò
        __asm__ volatile(\
1733 ddf96970 Loren Merritt
            QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\
1734
            QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\
1735
            QPEL_H264V_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, OP)\
1736
            QPEL_H264V_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, OP)\
1737
            QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\
1738
            QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\
1739
            QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\
1740
            QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\
1741
            \
1742
            : "+a"(src), "+c"(dst)\
1743 40d0e665 Ramiro Polla
            : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1744 ddf96970 Loren Merritt
            : "memory"\
1745
        );\
1746
    }\
1747
}\
1748 1d67b037 Loren Merritt
static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1749
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst  , src  , dstStride, srcStride, 8);\
1750
}\
1751
static av_noinline void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1752
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst  , src  , dstStride, srcStride, 16);\
1753
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
1754
}
1755
1756
static av_always_inline void put_h264_qpel8or16_hv1_lowpass_sse2(int16_t *tmp, uint8_t *src, int tmpStride, int srcStride, int size){
1757
    int w = (size+8)>>3;
1758
    src -= 2*srcStride+2;
1759
    while(w--){
1760 be449fca Diego Pettenò
        __asm__ volatile(
1761 1d67b037 Loren Merritt
            "pxor %%xmm7, %%xmm7        \n\t"
1762
            "movq (%0), %%xmm0          \n\t"
1763
            "add %2, %0                 \n\t"
1764
            "movq (%0), %%xmm1          \n\t"
1765
            "add %2, %0                 \n\t"
1766
            "movq (%0), %%xmm2          \n\t"
1767
            "add %2, %0                 \n\t"
1768
            "movq (%0), %%xmm3          \n\t"
1769
            "add %2, %0                 \n\t"
1770
            "movq (%0), %%xmm4          \n\t"
1771
            "add %2, %0                 \n\t"
1772
            "punpcklbw %%xmm7, %%xmm0   \n\t"
1773
            "punpcklbw %%xmm7, %%xmm1   \n\t"
1774
            "punpcklbw %%xmm7, %%xmm2   \n\t"
1775
            "punpcklbw %%xmm7, %%xmm3   \n\t"
1776
            "punpcklbw %%xmm7, %%xmm4   \n\t"
1777
            QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 0*48)
1778
            QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 1*48)
1779
            QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, 2*48)
1780
            QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 3*48)
1781
            QPEL_H264HV_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, 4*48)
1782
            QPEL_H264HV_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, 5*48)
1783
            QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 6*48)
1784
            QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 7*48)
1785
            : "+a"(src)
1786 40d0e665 Ramiro Polla
            : "c"(tmp), "S"((x86_reg)srcStride), "m"(ff_pw_5), "m"(ff_pw_16)
1787 1d67b037 Loren Merritt
            : "memory"
1788
        );
1789
        if(size==16){
1790 be449fca Diego Pettenò
            __asm__ volatile(
1791 1d67b037 Loren Merritt
                QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1,  8*48)
1792
                QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2,  9*48)
1793
                QPEL_H264HV_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, 10*48)
1794
                QPEL_H264HV_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, 11*48)
1795
                QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 12*48)
1796
                QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 13*48)
1797
                QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, 14*48)
1798
                QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 15*48)
1799
                : "+a"(src)
1800 40d0e665 Ramiro Polla
                : "c"(tmp), "S"((x86_reg)srcStride), "m"(ff_pw_5), "m"(ff_pw_16)
1801 1d67b037 Loren Merritt
                : "memory"
1802
            );
1803
        }
1804
        tmp += 8;
1805
        src += 8 - (size+5)*srcStride;
1806
    }
1807
}
1808
1809
#define QPEL_H264_HV2_XMM(OPNAME, OP, MMX)\
1810
static av_always_inline void OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size){\
1811 ddf96970 Loren Merritt
    int h = size;\
1812 1d67b037 Loren Merritt
    if(size == 16){\
1813 be449fca Diego Pettenò
        __asm__ volatile(\
1814 ddf96970 Loren Merritt
            "1:                         \n\t"\
1815
            "movdqa 32(%0), %%xmm4      \n\t"\
1816
            "movdqa 16(%0), %%xmm5      \n\t"\
1817
            "movdqa   (%0), %%xmm7      \n\t"\
1818
            "movdqa %%xmm4, %%xmm3      \n\t"\
1819
            "movdqa %%xmm4, %%xmm2      \n\t"\
1820
            "movdqa %%xmm4, %%xmm1      \n\t"\
1821
            "movdqa %%xmm4, %%xmm0      \n\t"\
1822
            "palignr $10, %%xmm5, %%xmm0 \n\t"\
1823
            "palignr  $8, %%xmm5, %%xmm1 \n\t"\
1824
            "palignr  $6, %%xmm5, %%xmm2 \n\t"\
1825
            "palignr  $4, %%xmm5, %%xmm3 \n\t"\
1826
            "palignr  $2, %%xmm5, %%xmm4 \n\t"\
1827
            "paddw  %%xmm5, %%xmm0      \n\t"\
1828
            "paddw  %%xmm4, %%xmm1      \n\t"\
1829
            "paddw  %%xmm3, %%xmm2      \n\t"\
1830
            "movdqa %%xmm5, %%xmm6      \n\t"\
1831
            "movdqa %%xmm5, %%xmm4      \n\t"\
1832
            "movdqa %%xmm5, %%xmm3      \n\t"\
1833
            "palignr  $8, %%xmm7, %%xmm4 \n\t"\
1834
            "palignr  $2, %%xmm7, %%xmm6 \n\t"\
1835
            "palignr $10, %%xmm7, %%xmm3 \n\t"\
1836
            "paddw  %%xmm6, %%xmm4      \n\t"\
1837
            "movdqa %%xmm5, %%xmm6      \n\t"\
1838
            "palignr  $6, %%xmm7, %%xmm5 \n\t"\
1839
            "palignr  $4, %%xmm7, %%xmm6 \n\t"\
1840
            "paddw  %%xmm7, %%xmm3      \n\t"\
1841
            "paddw  %%xmm6, %%xmm5      \n\t"\
1842
            \
1843
            "psubw  %%xmm1, %%xmm0      \n\t"\
1844
            "psubw  %%xmm4, %%xmm3      \n\t"\
1845
            "psraw      $2, %%xmm0      \n\t"\
1846
            "psraw      $2, %%xmm3      \n\t"\
1847
            "psubw  %%xmm1, %%xmm0      \n\t"\
1848
            "psubw  %%xmm4, %%xmm3      \n\t"\
1849
            "paddw  %%xmm2, %%xmm0      \n\t"\
1850
            "paddw  %%xmm5, %%xmm3      \n\t"\
1851
            "psraw      $2, %%xmm0      \n\t"\
1852
            "psraw      $2, %%xmm3      \n\t"\
1853
            "paddw  %%xmm2, %%xmm0      \n\t"\
1854
            "paddw  %%xmm5, %%xmm3      \n\t"\
1855
            "psraw      $6, %%xmm0      \n\t"\
1856
            "psraw      $6, %%xmm3      \n\t"\
1857
            "packuswb %%xmm0, %%xmm3    \n\t"\
1858
            OP(%%xmm3, (%1), %%xmm7, dqa)\
1859
            "add $48, %0                \n\t"\
1860
            "add %3, %1                 \n\t"\
1861
            "decl %2                    \n\t"\
1862
            " jnz 1b                    \n\t"\
1863
            : "+a"(tmp), "+c"(dst), "+g"(h)\
1864 40d0e665 Ramiro Polla
            : "S"((x86_reg)dstStride)\
1865 ddf96970 Loren Merritt
            : "memory"\
1866
        );\
1867
    }else{\
1868 be449fca Diego Pettenò
        __asm__ volatile(\
1869 ddf96970 Loren Merritt
            "1:                         \n\t"\
1870
            "movdqa 16(%0), %%xmm1      \n\t"\
1871
            "movdqa   (%0), %%xmm0      \n\t"\
1872
            "movdqa %%xmm1, %%xmm2      \n\t"\
1873
            "movdqa %%xmm1, %%xmm3      \n\t"\
1874
            "movdqa %%xmm1, %%xmm4      \n\t"\
1875
            "movdqa %%xmm1, %%xmm5      \n\t"\
1876
            "palignr $10, %%xmm0, %%xmm5 \n\t"\
1877
            "palignr  $8, %%xmm0, %%xmm4 \n\t"\
1878
            "palignr  $6, %%xmm0, %%xmm3 \n\t"\
1879
            "palignr  $4, %%xmm0, %%xmm2 \n\t"\
1880
            "palignr  $2, %%xmm0, %%xmm1 \n\t"\
1881
            "paddw  %%xmm5, %%xmm0      \n\t"\
1882
            "paddw  %%xmm4, %%xmm1      \n\t"\
1883
            "paddw  %%xmm3, %%xmm2      \n\t"\
1884
            "psubw  %%xmm1, %%xmm0      \n\t"\
1885
            "psraw      $2, %%xmm0      \n\t"\
1886
            "psubw  %%xmm1, %%xmm0      \n\t"\
1887
            "paddw  %%xmm2, %%xmm0      \n\t"\
1888
            "psraw      $2, %%xmm0      \n\t"\
1889
            "paddw  %%xmm2, %%xmm0      \n\t"\
1890
            "psraw      $6, %%xmm0      \n\t"\
1891
            "packuswb %%xmm0, %%xmm0    \n\t"\
1892
            OP(%%xmm0, (%1), %%xmm7, q)\
1893
            "add $48, %0                \n\t"\
1894
            "add %3, %1                 \n\t"\
1895
            "decl %2                    \n\t"\
1896
            " jnz 1b                    \n\t"\
1897
            : "+a"(tmp), "+c"(dst), "+g"(h)\
1898 40d0e665 Ramiro Polla
            : "S"((x86_reg)dstStride)\
1899 ddf96970 Loren Merritt
            : "memory"\
1900
        );\
1901
    }\
1902 1d67b037 Loren Merritt
}
1903
1904
#define QPEL_H264_HV_XMM(OPNAME, OP, MMX)\
1905
static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
1906
          put_h264_qpel8or16_hv1_lowpass_sse2(tmp, src, tmpStride, srcStride, size);\
1907
    OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\
1908 ddf96970 Loren Merritt
}\
1909
static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1910 1d67b037 Loren Merritt
    OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 8);\
1911 ddf96970 Loren Merritt
}\
1912
static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1913 1d67b037 Loren Merritt
    OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 16);\
1914 ddf96970 Loren Merritt
}\
1915
1916 1d67b037 Loren Merritt
#define put_pixels8_l2_sse2 put_pixels8_l2_mmx2
1917
#define avg_pixels8_l2_sse2 avg_pixels8_l2_mmx2
1918
#define put_pixels16_l2_sse2 put_pixels16_l2_mmx2
1919
#define avg_pixels16_l2_sse2 avg_pixels16_l2_mmx2
1920 ddf96970 Loren Merritt
#define put_pixels8_l2_ssse3 put_pixels8_l2_mmx2
1921
#define avg_pixels8_l2_ssse3 avg_pixels8_l2_mmx2
1922 1d67b037 Loren Merritt
#define put_pixels16_l2_ssse3 put_pixels16_l2_mmx2
1923 ddf96970 Loren Merritt
#define avg_pixels16_l2_ssse3 avg_pixels16_l2_mmx2
1924
1925 1d67b037 Loren Merritt
#define put_pixels8_l2_shift5_sse2 put_pixels8_l2_shift5_mmx2
1926
#define avg_pixels8_l2_shift5_sse2 avg_pixels8_l2_shift5_mmx2
1927
#define put_pixels16_l2_shift5_sse2 put_pixels16_l2_shift5_mmx2
1928
#define avg_pixels16_l2_shift5_sse2 avg_pixels16_l2_shift5_mmx2
1929 ddf96970 Loren Merritt
#define put_pixels8_l2_shift5_ssse3 put_pixels8_l2_shift5_mmx2
1930
#define avg_pixels8_l2_shift5_ssse3 avg_pixels8_l2_shift5_mmx2
1931 1d67b037 Loren Merritt
#define put_pixels16_l2_shift5_ssse3 put_pixels16_l2_shift5_mmx2
1932 ddf96970 Loren Merritt
#define avg_pixels16_l2_shift5_ssse3 avg_pixels16_l2_shift5_mmx2
1933
1934 1d67b037 Loren Merritt
#define put_h264_qpel8_h_lowpass_l2_sse2 put_h264_qpel8_h_lowpass_l2_mmx2
1935
#define avg_h264_qpel8_h_lowpass_l2_sse2 avg_h264_qpel8_h_lowpass_l2_mmx2
1936
#define put_h264_qpel16_h_lowpass_l2_sse2 put_h264_qpel16_h_lowpass_l2_mmx2
1937
#define avg_h264_qpel16_h_lowpass_l2_sse2 avg_h264_qpel16_h_lowpass_l2_mmx2
1938
1939
#define put_h264_qpel8_v_lowpass_ssse3 put_h264_qpel8_v_lowpass_sse2
1940
#define avg_h264_qpel8_v_lowpass_ssse3 avg_h264_qpel8_v_lowpass_sse2
1941
#define put_h264_qpel16_v_lowpass_ssse3 put_h264_qpel16_v_lowpass_sse2
1942
#define avg_h264_qpel16_v_lowpass_ssse3 avg_h264_qpel16_v_lowpass_sse2
1943
1944
#define put_h264_qpel8or16_hv2_lowpass_sse2 put_h264_qpel8or16_hv2_lowpass_mmx2
1945
#define avg_h264_qpel8or16_hv2_lowpass_sse2 avg_h264_qpel8or16_hv2_lowpass_mmx2
1946 d2bb7db1 Loren Merritt
1947 ddf96970 Loren Merritt
#define H264_MC(OPNAME, SIZE, MMX, ALIGN) \
1948 1d67b037 Loren Merritt
H264_MC_C(OPNAME, SIZE, MMX, ALIGN)\
1949
H264_MC_V(OPNAME, SIZE, MMX, ALIGN)\
1950
H264_MC_H(OPNAME, SIZE, MMX, ALIGN)\
1951
H264_MC_HV(OPNAME, SIZE, MMX, ALIGN)\
1952
1953
static void put_h264_qpel16_mc00_sse2 (uint8_t *dst, uint8_t *src, int stride){
1954
    put_pixels16_sse2(dst, src, stride, 16);
1955
}
1956
static void avg_h264_qpel16_mc00_sse2 (uint8_t *dst, uint8_t *src, int stride){
1957
    avg_pixels16_sse2(dst, src, stride, 16);
1958
}
1959
#define put_h264_qpel8_mc00_sse2 put_h264_qpel8_mc00_mmx2
1960
#define avg_h264_qpel8_mc00_sse2 avg_h264_qpel8_mc00_mmx2
1961
1962
#define H264_MC_C(OPNAME, SIZE, MMX, ALIGN) \
1963 d2bb7db1 Loren Merritt
static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
1964 6c01d006 Loren Merritt
    OPNAME ## pixels ## SIZE ## _ ## MMX(dst, src, stride, SIZE);\
1965 d2bb7db1 Loren Merritt
}\
1966 1d67b037 Loren Merritt
1967
#define H264_MC_H(OPNAME, SIZE, MMX, ALIGN) \
1968 d2bb7db1 Loren Merritt
static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1969 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\
1970 d2bb7db1 Loren Merritt
}\
1971
\
1972
static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1973
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## MMX(dst, src, stride, stride);\
1974
}\
1975
\
1976
static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1977 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\
1978 d2bb7db1 Loren Merritt
}\
1979 1d67b037 Loren Merritt
1980
#define H264_MC_V(OPNAME, SIZE, MMX, ALIGN) \
1981 d2bb7db1 Loren Merritt
static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1982 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\
1983
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
1984
    OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, temp, stride, stride, SIZE);\
1985 d2bb7db1 Loren Merritt
}\
1986
\
1987
static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1988
    OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## MMX(dst, src, stride, stride);\
1989
}\
1990
\
1991
static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1992 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\
1993
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
1994
    OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, temp, stride, stride, SIZE);\
1995 d2bb7db1 Loren Merritt
}\
1996 1d67b037 Loren Merritt
1997
#define H264_MC_HV(OPNAME, SIZE, MMX, ALIGN) \
1998 d2bb7db1 Loren Merritt
static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1999 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\
2000
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
2001
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\
2002 d2bb7db1 Loren Merritt
}\
2003
\
2004
static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2005 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\
2006
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\
2007
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\
2008 d2bb7db1 Loren Merritt
}\
2009
\
2010
static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2011 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\
2012
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
2013
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\
2014 d2bb7db1 Loren Merritt
}\
2015
\
2016
static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2017 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\
2018
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\
2019
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\
2020 d2bb7db1 Loren Merritt
}\
2021
\
2022
static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2023 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint16_t, temp[SIZE*(SIZE<8?12:24)]);\
2024
    OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, temp, src, stride, SIZE, stride);\
2025 d2bb7db1 Loren Merritt
}\
2026
\
2027
static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2028 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\
2029
    uint8_t * const halfHV= temp;\
2030
    int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
2031 bdb27356 Shane
    assert(((int)temp & 7) == 0);\
2032 7080ec29 Loren Merritt
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
2033 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\
2034 d2bb7db1 Loren Merritt
}\
2035
\
2036
static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2037 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\
2038
    uint8_t * const halfHV= temp;\
2039
    int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
2040 bdb27356 Shane
    assert(((int)temp & 7) == 0);\
2041 7080ec29 Loren Merritt
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
2042 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\
2043 d2bb7db1 Loren Merritt
}\
2044
\
2045
static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2046 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\
2047
    uint8_t * const halfHV= temp;\
2048
    int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
2049 bdb27356 Shane
    assert(((int)temp & 7) == 0);\
2050 e545f375 Loren Merritt
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
2051
    OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+2, halfHV, stride, SIZE, SIZE);\
2052 d2bb7db1 Loren Merritt
}\
2053
\
2054
static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2055 7080ec29 Loren Merritt
    DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\
2056
    uint8_t * const halfHV= temp;\
2057
    int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
2058 bdb27356 Shane
    assert(((int)temp & 7) == 0);\
2059 e545f375 Loren Merritt
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
2060
    OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+3, halfHV, stride, SIZE, SIZE);\
2061 d2bb7db1 Loren Merritt
}\
2062
2063 1d67b037 Loren Merritt
#define H264_MC_4816(MMX)\
2064
H264_MC(put_, 4, MMX, 8)\
2065
H264_MC(put_, 8, MMX, 8)\
2066
H264_MC(put_, 16,MMX, 8)\
2067
H264_MC(avg_, 4, MMX, 8)\
2068
H264_MC(avg_, 8, MMX, 8)\
2069
H264_MC(avg_, 16,MMX, 8)\
2070
2071
#define H264_MC_816(QPEL, XMM)\
2072
QPEL(put_, 8, XMM, 16)\
2073
QPEL(put_, 16,XMM, 16)\
2074
QPEL(avg_, 8, XMM, 16)\
2075
QPEL(avg_, 16,XMM, 16)\
2076
2077 d2bb7db1 Loren Merritt
2078
#define AVG_3DNOW_OP(a,b,temp, size) \
2079 bb270c08 Diego Biurrun
"mov" #size " " #b ", " #temp "   \n\t"\
2080
"pavgusb " #temp ", " #a "        \n\t"\
2081
"mov" #size " " #a ", " #b "      \n\t"
2082 d2bb7db1 Loren Merritt
#define AVG_MMX2_OP(a,b,temp, size) \
2083 bb270c08 Diego Biurrun
"mov" #size " " #b ", " #temp "   \n\t"\
2084
"pavgb " #temp ", " #a "          \n\t"\
2085
"mov" #size " " #a ", " #b "      \n\t"
2086 d2bb7db1 Loren Merritt
2087 e545f375 Loren Merritt
#define PAVGB "pavgusb"
2088 d2bb7db1 Loren Merritt
QPEL_H264(put_,       PUT_OP, 3dnow)
2089
QPEL_H264(avg_, AVG_3DNOW_OP, 3dnow)
2090 e545f375 Loren Merritt
#undef PAVGB
2091
#define PAVGB "pavgb"
2092 d2bb7db1 Loren Merritt
QPEL_H264(put_,       PUT_OP, mmx2)
2093
QPEL_H264(avg_,  AVG_MMX2_OP, mmx2)
2094 1d67b037 Loren Merritt
QPEL_H264_V_XMM(put_,       PUT_OP, sse2)
2095
QPEL_H264_V_XMM(avg_,  AVG_MMX2_OP, sse2)
2096
QPEL_H264_HV_XMM(put_,       PUT_OP, sse2)
2097
QPEL_H264_HV_XMM(avg_,  AVG_MMX2_OP, sse2)
2098 b250f9c6 Aurelien Jacobs
#if HAVE_SSSE3
2099 1d67b037 Loren Merritt
QPEL_H264_H_XMM(put_,       PUT_OP, ssse3)
2100
QPEL_H264_H_XMM(avg_,  AVG_MMX2_OP, ssse3)
2101
QPEL_H264_HV2_XMM(put_,       PUT_OP, ssse3)
2102
QPEL_H264_HV2_XMM(avg_,  AVG_MMX2_OP, ssse3)
2103
QPEL_H264_HV_XMM(put_,       PUT_OP, ssse3)
2104
QPEL_H264_HV_XMM(avg_,  AVG_MMX2_OP, ssse3)
2105 ddf96970 Loren Merritt
#endif
2106 e545f375 Loren Merritt
#undef PAVGB
2107 d2bb7db1 Loren Merritt
2108 1d67b037 Loren Merritt
H264_MC_4816(3dnow)
2109
H264_MC_4816(mmx2)
2110
H264_MC_816(H264_MC_V, sse2)
2111
H264_MC_816(H264_MC_HV, sse2)
2112 b250f9c6 Aurelien Jacobs
#if HAVE_SSSE3
2113 1d67b037 Loren Merritt
H264_MC_816(H264_MC_H, ssse3)
2114
H264_MC_816(H264_MC_HV, ssse3)
2115 ddf96970 Loren Merritt
#endif
2116
2117 21ff7689 Mathieu Velten
/* rnd interleaved with rnd div 8, use p+1 to access rnd div 8 */
2118
DECLARE_ALIGNED_8(static const uint64_t, h264_rnd_reg[4]) = {
2119
    0x0020002000200020ULL, 0x0004000400040004ULL, 0x001C001C001C001CULL, 0x0003000300030003ULL
2120
};
2121 d2bb7db1 Loren Merritt
2122
#define H264_CHROMA_OP(S,D)
2123 a6624e21 Loren Merritt
#define H264_CHROMA_OP4(S,D,T)
2124 21ff7689 Mathieu Velten
#define H264_CHROMA_MC8_TMPL put_h264_chroma_generic_mc8_mmx
2125
#define H264_CHROMA_MC4_TMPL put_h264_chroma_generic_mc4_mmx
2126 fdd30579 Loren Merritt
#define H264_CHROMA_MC2_TMPL put_h264_chroma_mc2_mmx2
2127 a6624e21 Loren Merritt
#define H264_CHROMA_MC8_MV0 put_pixels8_mmx
2128 d2bb7db1 Loren Merritt
#include "dsputil_h264_template_mmx.c"
2129 9fa35729 Christophe Gisquet
2130
static void put_h264_chroma_mc8_mmx_rnd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2131
{
2132 21ff7689 Mathieu Velten
    put_h264_chroma_generic_mc8_mmx(dst, src, stride, h, x, y, h264_rnd_reg);
2133 9fa35729 Christophe Gisquet
}
2134 c374691b David Conrad
static void put_vc1_chroma_mc8_mmx_nornd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2135 9fa35729 Christophe Gisquet
{
2136 21ff7689 Mathieu Velten
    put_h264_chroma_generic_mc8_mmx(dst, src, stride, h, x, y, h264_rnd_reg+2);
2137
}
2138
static void put_h264_chroma_mc4_mmx(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2139
{
2140
    put_h264_chroma_generic_mc4_mmx(dst, src, stride, h, x, y, h264_rnd_reg);
2141 9fa35729 Christophe Gisquet
}
2142
2143 d2bb7db1 Loren Merritt
#undef H264_CHROMA_OP
2144 a6624e21 Loren Merritt
#undef H264_CHROMA_OP4
2145 d2bb7db1 Loren Merritt
#undef H264_CHROMA_MC8_TMPL
2146 a6624e21 Loren Merritt
#undef H264_CHROMA_MC4_TMPL
2147 fdd30579 Loren Merritt
#undef H264_CHROMA_MC2_TMPL
2148 a6624e21 Loren Merritt
#undef H264_CHROMA_MC8_MV0
2149 d2bb7db1 Loren Merritt
2150
#define H264_CHROMA_OP(S,D) "pavgb " #S ", " #D " \n\t"
2151 a6624e21 Loren Merritt
#define H264_CHROMA_OP4(S,D,T) "movd  " #S ", " #T " \n\t"\
2152
                               "pavgb " #T ", " #D " \n\t"
2153 21ff7689 Mathieu Velten
#define H264_CHROMA_MC8_TMPL avg_h264_chroma_generic_mc8_mmx2
2154
#define H264_CHROMA_MC4_TMPL avg_h264_chroma_generic_mc4_mmx2
2155 fdd30579 Loren Merritt
#define H264_CHROMA_MC2_TMPL avg_h264_chroma_mc2_mmx2
2156 a6624e21 Loren Merritt
#define H264_CHROMA_MC8_MV0 avg_pixels8_mmx2
2157 d2bb7db1 Loren Merritt
#include "dsputil_h264_template_mmx.c"
2158 9fa35729 Christophe Gisquet
static void avg_h264_chroma_mc8_mmx2_rnd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2159
{
2160 21ff7689 Mathieu Velten
    avg_h264_chroma_generic_mc8_mmx2(dst, src, stride, h, x, y, h264_rnd_reg);
2161
}
2162 8013da73 David Conrad
static void avg_vc1_chroma_mc8_mmx2_nornd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2163
{
2164
    avg_h264_chroma_generic_mc8_mmx2(dst, src, stride, h, x, y, h264_rnd_reg+2);
2165
}
2166 21ff7689 Mathieu Velten
static void avg_h264_chroma_mc4_mmx2(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2167
{
2168
    avg_h264_chroma_generic_mc4_mmx2(dst, src, stride, h, x, y, h264_rnd_reg);
2169 9fa35729 Christophe Gisquet
}
2170 d2bb7db1 Loren Merritt
#undef H264_CHROMA_OP
2171 a6624e21 Loren Merritt
#undef H264_CHROMA_OP4
2172 d2bb7db1 Loren Merritt
#undef H264_CHROMA_MC8_TMPL
2173 a6624e21 Loren Merritt
#undef H264_CHROMA_MC4_TMPL
2174 fdd30579 Loren Merritt
#undef H264_CHROMA_MC2_TMPL
2175 a6624e21 Loren Merritt
#undef H264_CHROMA_MC8_MV0
2176 d2bb7db1 Loren Merritt
2177
#define H264_CHROMA_OP(S,D) "pavgusb " #S ", " #D " \n\t"
2178 a6624e21 Loren Merritt
#define H264_CHROMA_OP4(S,D,T) "movd " #S ", " #T " \n\t"\
2179
                               "pavgusb " #T ", " #D " \n\t"
2180 21ff7689 Mathieu Velten
#define H264_CHROMA_MC8_TMPL avg_h264_chroma_generic_mc8_3dnow
2181
#define H264_CHROMA_MC4_TMPL avg_h264_chroma_generic_mc4_3dnow
2182 a6624e21 Loren Merritt
#define H264_CHROMA_MC8_MV0 avg_pixels8_3dnow
2183 d2bb7db1 Loren Merritt
#include "dsputil_h264_template_mmx.c"
2184 9fa35729 Christophe Gisquet
static void avg_h264_chroma_mc8_3dnow_rnd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2185
{
2186 21ff7689 Mathieu Velten
    avg_h264_chroma_generic_mc8_3dnow(dst, src, stride, h, x, y, h264_rnd_reg);
2187
}
2188
static void avg_h264_chroma_mc4_3dnow(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2189
{
2190
    avg_h264_chroma_generic_mc4_3dnow(dst, src, stride, h, x, y, h264_rnd_reg);
2191 9fa35729 Christophe Gisquet
}
2192 d2bb7db1 Loren Merritt
#undef H264_CHROMA_OP
2193 a6624e21 Loren Merritt
#undef H264_CHROMA_OP4
2194 d2bb7db1 Loren Merritt
#undef H264_CHROMA_MC8_TMPL
2195 a6624e21 Loren Merritt
#undef H264_CHROMA_MC4_TMPL
2196
#undef H264_CHROMA_MC8_MV0
2197 d2bb7db1 Loren Merritt
2198 b250f9c6 Aurelien Jacobs
#if HAVE_SSSE3
2199 ce53144b Loren Merritt
#define AVG_OP(X)
2200
#undef H264_CHROMA_MC8_TMPL
2201
#undef H264_CHROMA_MC4_TMPL
2202
#define H264_CHROMA_MC8_TMPL put_h264_chroma_mc8_ssse3
2203
#define H264_CHROMA_MC4_TMPL put_h264_chroma_mc4_ssse3
2204
#define H264_CHROMA_MC8_MV0 put_pixels8_mmx
2205
#include "dsputil_h264_template_ssse3.c"
2206
static void put_h264_chroma_mc8_ssse3_rnd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2207
{
2208
    put_h264_chroma_mc8_ssse3(dst, src, stride, h, x, y, 1);
2209
}
2210 c374691b David Conrad
static void put_vc1_chroma_mc8_ssse3_nornd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2211 ce53144b Loren Merritt
{
2212
    put_h264_chroma_mc8_ssse3(dst, src, stride, h, x, y, 0);
2213
}
2214
2215
#undef AVG_OP
2216
#undef H264_CHROMA_MC8_TMPL
2217
#undef H264_CHROMA_MC4_TMPL
2218
#undef H264_CHROMA_MC8_MV0
2219
#define AVG_OP(X) X
2220
#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_ssse3
2221
#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_ssse3
2222
#define H264_CHROMA_MC8_MV0 avg_pixels8_mmx2
2223
#include "dsputil_h264_template_ssse3.c"
2224
static void avg_h264_chroma_mc8_ssse3_rnd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2225
{
2226
    avg_h264_chroma_mc8_ssse3(dst, src, stride, h, x, y, 1);
2227
}
2228 8013da73 David Conrad
static void avg_vc1_chroma_mc8_ssse3_nornd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y)
2229
{
2230
    avg_h264_chroma_mc8_ssse3(dst, src, stride, h, x, y, 0);
2231
}
2232 ce53144b Loren Merritt
#undef AVG_OP
2233
#undef H264_CHROMA_MC8_TMPL
2234
#undef H264_CHROMA_MC4_TMPL
2235
#undef H264_CHROMA_MC8_MV0
2236
#endif
2237
2238 b926572a Loren Merritt
/***********************************/
2239
/* weighted prediction */
2240
2241
static inline void ff_h264_weight_WxH_mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset, int w, int h)
2242