Statistics
| Branch: | Revision:

ffmpeg / libavcodec / x86 / h264dsp_mmx.c @ 29e71937

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