Coverage Report

Created: 2026-07-16 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/libde265/libde265/x86/sse-motion.cc
Line
Count
Source
1
/*
2
 * H.265 video codec.
3
 * Copyright (c) 2013 openHEVC contributors
4
 * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
5
 *
6
 * This file is part of libde265.
7
 *
8
 * libde265 is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as
10
 * published by the Free Software Foundation, either version 3 of
11
 * the License, or (at your option) any later version.
12
 *
13
 * libde265 is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with libde265.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#ifdef HAVE_CONFIG_H
23
#include "config.h"
24
#endif
25
26
#include <stdio.h>
27
#include <emmintrin.h>
28
#include <tmmintrin.h> // SSSE3
29
#if HAVE_SSE4_1
30
#include <smmintrin.h>
31
#endif
32
33
#include "sse-motion.h"
34
#include "libde265/util.h"
35
36
37
ALIGNED_16(const int8_t) epel_filters[7][16] = {
38
  { -2,  58,  10,  -2,-2,  58,  10,  -2,-2,  58,  10,  -2,-2,  58,  10,  -2 },
39
  { -4,  54,  16,  -2,-4,  54,  16,  -2,-4,  54,  16,  -2,-4,  54,  16,  -2 },
40
  { -6,  46,  28,  -4,-6,  46,  28,  -4,-6,  46,  28,  -4,-6,  46,  28,  -4 },
41
  { -4,  36,  36,  -4,-4,  36,  36,  -4,-4,  36,  36,  -4,-4,  36,  36,  -4 },
42
  { -4,  28,  46,  -6,-4,  28,  46,  -6,-4,  28,  46,  -6,-4,  28,  46,  -6 },
43
  { -2,  16,  54,  -4,-2,  16,  54,  -4,-2,  16,  54,  -4,-2,  16,  54,  -4 },
44
  { -2,  10,  58,  -2,-2,  10,  58,  -2,-2,  10,  58,  -2,-2,  10,  58,  -2 },
45
};
46
47
static const uint8_t qpel_extra_before[4] = { 0, 3, 3, 2 };
48
//static const uint8_t qpel_extra_after[4] = { 0, 3, 4, 4 };
49
static const uint8_t qpel_extra[4] = { 0, 6, 7, 6 };
50
51
static const int epel_extra_before = 1;
52
//static const int epel_extra_after = 2;
53
static const int epel_extra = 3;
54
55
169M
#define MAX_PB_SIZE 64
56
57
#define MASKMOVE 0
58
59
void print128(const char* prefix, __m128i r)
60
0
{
61
0
  unsigned char buf[16];
62
63
0
  *(__m128i*)buf = r;
64
65
0
  printf("%s ",prefix);
66
0
  for (int i=0;i<16;i++)
67
0
    {
68
0
      if (i>0) { printf(":"); }
69
0
      printf("%02x", buf[i]);
70
0
    }
71
72
0
  printf("\n");
73
0
}
74
75
76
void printm32(const char* prefix, unsigned char* p)
77
0
{
78
0
  printf("%s ",prefix);
79
80
0
  for (int i=0;i<4;i++)
81
0
    {
82
0
      if (i>0) { printf(":"); }
83
0
      printf("%02x", p[i]);
84
0
    }
85
86
0
  printf("\n");
87
0
}
88
89
90
4.35M
#define BIT_DEPTH 8
91
92
void ff_hevc_put_unweighted_pred_8_sse(uint8_t *_dst, ptrdiff_t dststride,
93
                                       const int16_t *src, ptrdiff_t srcstride,
94
12.0M
                                       int width, int height) {
95
12.0M
    int x, y;
96
12.0M
    uint8_t *dst = (uint8_t*) _dst;
97
12.0M
    __m128i r0, r1, f0;
98
99
12.0M
    f0 = _mm_set1_epi16(32);
100
101
102
12.0M
    if(!(width & 15))
103
606k
    {
104
9.82M
        for (y = 0; y < height; y++) {
105
20.2M
                    for (x = 0; x < width; x += 16) {
106
11.0M
                        r0 = _mm_load_si128((__m128i *) (src+x));
107
108
11.0M
                        r1 = _mm_load_si128((__m128i *) (src+x + 8));
109
11.0M
                        r0 = _mm_adds_epi16(r0, f0);
110
111
11.0M
                        r1 = _mm_adds_epi16(r1, f0);
112
11.0M
                        r0 = _mm_srai_epi16(r0, 6);
113
11.0M
                        r1 = _mm_srai_epi16(r1, 6);
114
11.0M
                        r0 = _mm_packus_epi16(r0, r1);
115
116
11.0M
                        _mm_storeu_si128((__m128i *) (dst+x), r0);
117
11.0M
                    }
118
9.22M
                    dst += dststride;
119
9.22M
                    src += srcstride;
120
9.22M
                }
121
11.4M
    }else if(!(width & 7))
122
3.45M
    {
123
31.3M
        for (y = 0; y < height; y++) {
124
56.4M
            for (x = 0; x < width; x += 8) {
125
28.4M
                    r0 = _mm_load_si128((__m128i *) (src+x));
126
127
28.4M
                    r0 = _mm_adds_epi16(r0, f0);
128
129
28.4M
                    r0 = _mm_srai_epi16(r0, 6);
130
28.4M
                    r0 = _mm_packus_epi16(r0, r0);
131
132
28.4M
                    _mm_storel_epi64((__m128i *) (dst+x), r0);
133
28.4M
            }
134
27.9M
                    dst += dststride;
135
27.9M
                    src += srcstride;
136
27.9M
                }
137
8.01M
    }else if(!(width & 3)){
138
40.4M
        for (y = 0; y < height; y++) {
139
68.9M
                    for(x = 0;x < width; x+=4){
140
35.0M
                    r0 = _mm_loadl_epi64((__m128i *) (src+x));
141
35.0M
                    r0 = _mm_adds_epi16(r0, f0);
142
143
35.0M
                    r0 = _mm_srai_epi16(r0, 6);
144
35.0M
                    r0 = _mm_packus_epi16(r0, r0);
145
#if MASKMOVE
146
                    _mm_maskmoveu_si128(r0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
147
#else
148
                    //r0 = _mm_shuffle_epi32 (r0, 0x00);
149
35.0M
                    *((uint32_t*)(dst+x)) = _mm_cvtsi128_si32(r0);
150
35.0M
#endif
151
35.0M
                    }
152
33.9M
                    dst += dststride;
153
33.9M
                    src += srcstride;
154
33.9M
                }
155
6.49M
    }else{
156
11.1M
        for (y = 0; y < height; y++) {
157
19.6M
                    for(x = 0;x < width; x+=2){
158
10.1M
                    r0 = _mm_loadl_epi64((__m128i *) (src+x));
159
10.1M
                    r0 = _mm_adds_epi16(r0, f0);
160
161
10.1M
                    r0 = _mm_srai_epi16(r0, 6);
162
10.1M
                    r0 = _mm_packus_epi16(r0, r0);
163
#if MASKMOVE
164
                    _mm_maskmoveu_si128(r0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1),(char *) (dst+x));
165
#else
166
10.1M
                    *((uint16_t*)(dst+x)) = _mm_cvtsi128_si32(r0);
167
10.1M
#endif
168
10.1M
                    }
169
9.58M
                    dst += dststride;
170
9.58M
                    src += srcstride;
171
9.58M
                }
172
1.52M
    }
173
174
12.0M
}
175
176
void ff_hevc_put_unweighted_pred_sse(uint8_t *_dst, ptrdiff_t _dststride,
177
                                     const int16_t *src, ptrdiff_t srcstride,
178
0
                                     int width, int height) {
179
0
    int x, y;
180
0
    uint8_t *dst = (uint8_t*) _dst;
181
0
    ptrdiff_t dststride = _dststride / sizeof(uint8_t);
182
0
    __m128i r0, r1, f0;
183
0
    int shift = 14 - BIT_DEPTH;
184
0
#if BIT_DEPTH < 14
185
0
    int16_t offset = 1 << (shift - 1);
186
#else
187
    int16_t offset = 0;
188
189
#endif
190
0
    f0 = _mm_set1_epi16(offset);
191
192
0
    for (y = 0; y < height; y++) {
193
0
        for (x = 0; x < width; x += 16) {
194
0
            r0 = _mm_load_si128((__m128i *) &src[x]);
195
196
0
            r1 = _mm_load_si128((__m128i *) &src[x + 8]);
197
0
            r0 = _mm_adds_epi16(r0, f0);
198
199
0
            r1 = _mm_adds_epi16(r1, f0);
200
0
            r0 = _mm_srai_epi16(r0, shift);
201
0
            r1 = _mm_srai_epi16(r1, shift);
202
0
            r0 = _mm_packus_epi16(r0, r1);
203
204
0
            _mm_storeu_si128((__m128i *) &dst[x], r0);
205
0
        }
206
0
        dst += dststride;
207
0
        src += srcstride;
208
0
    }
209
0
}
210
211
void ff_hevc_put_weighted_pred_avg_8_sse(uint8_t *_dst, ptrdiff_t dststride,
212
                                         const int16_t *src1, const int16_t *src2,
213
                                         ptrdiff_t srcstride, int width,
214
2.12M
                                         int height) {
215
2.12M
    int x, y;
216
2.12M
    uint8_t *dst = (uint8_t*) _dst;
217
2.12M
    __m128i r0, r1, f0, r2, r3;
218
219
2.12M
    f0 = _mm_set1_epi16(64);
220
2.12M
    if(!(width & 15)){
221
4.39M
        for (y = 0; y < height; y++) {
222
223
9.20M
            for (x = 0; x < width; x += 16) {
224
5.07M
                r0 = _mm_load_si128((__m128i *) &src1[x]);
225
5.07M
                r1 = _mm_load_si128((__m128i *) &src1[x + 8]);
226
5.07M
                r2 = _mm_load_si128((__m128i *) &src2[x]);
227
5.07M
                r3 = _mm_load_si128((__m128i *) &src2[x + 8]);
228
229
5.07M
                r0 = _mm_adds_epi16(r0, f0);
230
5.07M
                r1 = _mm_adds_epi16(r1, f0);
231
5.07M
                r0 = _mm_adds_epi16(r0, r2);
232
5.07M
                r1 = _mm_adds_epi16(r1, r3);
233
5.07M
                r0 = _mm_srai_epi16(r0, 7);
234
5.07M
                r1 = _mm_srai_epi16(r1, 7);
235
5.07M
                r0 = _mm_packus_epi16(r0, r1);
236
237
5.07M
                _mm_storeu_si128((__m128i *) (dst + x), r0);
238
5.07M
            }
239
4.12M
            dst += dststride;
240
4.12M
            src1 += srcstride;
241
4.12M
            src2 += srcstride;
242
4.12M
        }
243
1.84M
    }else if(!(width & 7)){
244
8.55M
        for (y = 0; y < height; y++) {
245
15.6M
            for(x=0;x<width;x+=8){
246
7.92M
                r0 = _mm_load_si128((__m128i *) (src1+x));
247
7.92M
                r2 = _mm_load_si128((__m128i *) (src2+x));
248
249
7.92M
                r0 = _mm_adds_epi16(r0, f0);
250
7.92M
                r0 = _mm_adds_epi16(r0, r2);
251
7.92M
                r0 = _mm_srai_epi16(r0, 7);
252
7.92M
                r0 = _mm_packus_epi16(r0, r0);
253
254
7.92M
                _mm_storel_epi64((__m128i *) (dst+x), r0);
255
7.92M
            }
256
7.73M
            dst += dststride;
257
7.73M
            src1 += srcstride;
258
7.73M
            src2 += srcstride;
259
7.73M
        }
260
1.02M
    }else if(!(width & 3)){
261
#if MASKMOVE
262
      r1= _mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1);
263
#endif
264
7.32M
        for (y = 0; y < height; y++) {
265
266
13.0M
            for(x=0;x<width;x+=4)
267
6.70M
            {
268
6.70M
                r0 = _mm_loadl_epi64((__m128i *) (src1+x));
269
6.70M
                r2 = _mm_loadl_epi64((__m128i *) (src2+x));
270
271
6.70M
                r0 = _mm_adds_epi16(r0, f0);
272
6.70M
                r0 = _mm_adds_epi16(r0, r2);
273
6.70M
                r0 = _mm_srai_epi16(r0, 7);
274
6.70M
                r0 = _mm_packus_epi16(r0, r0);
275
276
#if MASKMOVE
277
                _mm_maskmoveu_si128(r0,r1,(char *) (dst+x));
278
#else
279
6.70M
                *((uint32_t*)(dst+x)) = _mm_cvtsi128_si32(r0);
280
6.70M
#endif
281
6.70M
            }
282
6.32M
            dst += dststride;
283
6.32M
            src1 += srcstride;
284
6.32M
            src2 += srcstride;
285
6.32M
        }
286
1.00M
    }else{
287
#if MASKMOVE
288
      r1= _mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1);
289
#endif
290
282k
        for (y = 0; y < height; y++) {
291
772k
                    for(x=0;x<width;x+=2)
292
514k
                    {
293
514k
                        r0 = _mm_loadl_epi64((__m128i *) (src1+x));
294
514k
                        r2 = _mm_loadl_epi64((__m128i *) (src2+x));
295
296
514k
                        r0 = _mm_adds_epi16(r0, f0);
297
514k
                        r0 = _mm_adds_epi16(r0, r2);
298
514k
                        r0 = _mm_srai_epi16(r0, 7);
299
514k
                        r0 = _mm_packus_epi16(r0, r0);
300
301
#if MASKMOVE
302
                        _mm_maskmoveu_si128(r0,r1,(char *) (dst+x));
303
#else
304
514k
                        *((uint16_t*)(dst+x)) = _mm_cvtsi128_si32(r0);
305
514k
#endif
306
514k
                    }
307
258k
                    dst += dststride;
308
258k
                    src1 += srcstride;
309
258k
                    src2 += srcstride;
310
258k
                }
311
24.6k
    }
312
313
314
2.12M
}
315
316
void ff_hevc_put_weighted_pred_avg_sse(uint8_t *_dst, ptrdiff_t _dststride,
317
                                       const int16_t *src1, const int16_t *src2,
318
                                       ptrdiff_t srcstride, int width,
319
0
                                       int height) {
320
0
    int x, y;
321
0
    uint8_t *dst = (uint8_t*) _dst;
322
0
    ptrdiff_t dststride = _dststride / sizeof(uint8_t);
323
0
    __m128i r0, r1, f0, r2, r3;
324
0
    int shift = 14 + 1 - BIT_DEPTH;
325
0
#if BIT_DEPTH < 14
326
0
    int offset = 1 << (shift - 1);
327
#else
328
    int offset = 0;
329
#endif
330
0
    f0 = _mm_set1_epi16(offset);
331
0
    for (y = 0; y < height; y++) {
332
333
0
        for (x = 0; x < width; x += 16) {
334
0
            r0 = _mm_load_si128((__m128i *) &src1[x]);
335
0
            r1 = _mm_load_si128((__m128i *) &src1[x + 8]);
336
0
            r2 = _mm_load_si128((__m128i *) &src2[x]);
337
0
            r3 = _mm_load_si128((__m128i *) &src2[x + 8]);
338
339
0
            r0 = _mm_adds_epi16(r0, f0);
340
0
            r1 = _mm_adds_epi16(r1, f0);
341
0
            r0 = _mm_adds_epi16(r0, r2);
342
0
            r1 = _mm_adds_epi16(r1, r3);
343
0
            r0 = _mm_srai_epi16(r0, shift);
344
0
            r1 = _mm_srai_epi16(r1, shift);
345
0
            r0 = _mm_packus_epi16(r0, r1);
346
347
0
            _mm_storeu_si128((__m128i *) (dst + x), r0);
348
0
        }
349
0
        dst += dststride;
350
0
        src1 += srcstride;
351
0
        src2 += srcstride;
352
0
    }
353
0
}
354
355
#if 0
356
void ff_hevc_weighted_pred_8_sse4(uint8_t denom, int16_t wlxFlag, int16_t olxFlag,
357
                                  uint8_t *_dst, ptrdiff_t _dststride,
358
                                  const int16_t *src, ptrdiff_t srcstride,
359
                                  int width, int height) {
360
361
    int log2Wd;
362
    int x, y;
363
364
    uint8_t *dst = (uint8_t*) _dst;
365
    ptrdiff_t dststride = _dststride / sizeof(uint8_t);
366
    __m128i x0, x1, x2, x3, c0, add, add2;
367
368
    log2Wd = denom + 14 - BIT_DEPTH;
369
370
    add = _mm_set1_epi32(olxFlag * (1 << (BIT_DEPTH - 8)));
371
    add2 = _mm_set1_epi32(1 << (log2Wd - 1));
372
    c0 = _mm_set1_epi16(wlxFlag);
373
    if (log2Wd >= 1){
374
        if(!(width & 15)){
375
            for (y = 0; y < height; y++) {
376
                for (x = 0; x < width; x += 16) {
377
                    x0 = _mm_load_si128((__m128i *) &src[x]);
378
                    x2 = _mm_load_si128((__m128i *) &src[x + 8]);
379
                    x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
380
                            _mm_mulhi_epi16(x0, c0));
381
                    x3 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c0),
382
                            _mm_mulhi_epi16(x2, c0));
383
                    x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
384
                            _mm_mulhi_epi16(x0, c0));
385
                    x2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c0),
386
                            _mm_mulhi_epi16(x2, c0));
387
                    x0 = _mm_add_epi32(x0, add2);
388
                    x1 = _mm_add_epi32(x1, add2);
389
                    x2 = _mm_add_epi32(x2, add2);
390
                    x3 = _mm_add_epi32(x3, add2);
391
                    x0 = _mm_srai_epi32(x0, log2Wd);
392
                    x1 = _mm_srai_epi32(x1, log2Wd);
393
                    x2 = _mm_srai_epi32(x2, log2Wd);
394
                    x3 = _mm_srai_epi32(x3, log2Wd);
395
                    x0 = _mm_add_epi32(x0, add);
396
                    x1 = _mm_add_epi32(x1, add);
397
                    x2 = _mm_add_epi32(x2, add);
398
                    x3 = _mm_add_epi32(x3, add);
399
                    x0 = _mm_packus_epi32(x0, x1);
400
                    x2 = _mm_packus_epi32(x2, x3);
401
                    x0 = _mm_packus_epi16(x0, x2);
402
403
                    _mm_storeu_si128((__m128i *) (dst + x), x0);
404
405
                }
406
                dst += dststride;
407
                src += srcstride;
408
            }
409
        }else if(!(width & 7)){
410
            for (y = 0; y < height; y++) {
411
                for(x=0;x<width;x+=8){
412
                    x0 = _mm_load_si128((__m128i *) (src+x));
413
                    x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
414
                            _mm_mulhi_epi16(x0, c0));
415
416
                    x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
417
                            _mm_mulhi_epi16(x0, c0));
418
419
                    x0 = _mm_add_epi32(x0, add2);
420
                    x1 = _mm_add_epi32(x1, add2);
421
422
                    x0 = _mm_srai_epi32(x0, log2Wd);
423
                    x1 = _mm_srai_epi32(x1, log2Wd);
424
425
                    x0 = _mm_add_epi32(x0, add);
426
                    x1 = _mm_add_epi32(x1, add);
427
428
                    x0 = _mm_packus_epi32(x0, x1);
429
                    x0 = _mm_packus_epi16(x0, x0);
430
431
                    _mm_storel_epi64((__m128i *) (dst+x), x0);
432
433
                }
434
                dst += dststride;
435
                src += srcstride;
436
            }
437
        }else if(!(width & 3)){
438
            for (y = 0; y < height; y++) {
439
                for(x=0;x<width;x+=4){
440
                    x0 = _mm_loadl_epi64((__m128i *)(src+x));
441
                    x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
442
                            _mm_mulhi_epi16(x0, c0));
443
                    x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
444
                            _mm_mulhi_epi16(x0, c0));
445
446
                    x0 = _mm_add_epi32(x0, add2);
447
                    x1 = _mm_add_epi32(x1, add2);
448
                    x0 = _mm_srai_epi32(x0, log2Wd);
449
                    x1 = _mm_srai_epi32(x1, log2Wd);
450
                    x0 = _mm_add_epi32(x0, add);
451
                    x1 = _mm_add_epi32(x1, add);
452
                    x0 = _mm_packus_epi32(x0, x1);
453
                    x0 = _mm_packus_epi16(x0, x0);
454
455
                    _mm_maskmoveu_si128(x0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
456
                    // _mm_storeu_si128((__m128i *) (dst + x), x0);
457
                }
458
                dst += dststride;
459
                src += srcstride;
460
            }
461
        }else{
462
            for (y = 0; y < height; y++) {
463
                for(x=0;x<width;x+=2){
464
                    x0 = _mm_loadl_epi64((__m128i *)(src+x));
465
                    x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
466
                            _mm_mulhi_epi16(x0, c0));
467
                    x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
468
                            _mm_mulhi_epi16(x0, c0));
469
470
                    x0 = _mm_add_epi32(x0, add2);
471
                    x1 = _mm_add_epi32(x1, add2);
472
                    x0 = _mm_srai_epi32(x0, log2Wd);
473
                    x1 = _mm_srai_epi32(x1, log2Wd);
474
                    x0 = _mm_add_epi32(x0, add);
475
                    x1 = _mm_add_epi32(x1, add);
476
                    x0 = _mm_packus_epi32(x0, x1);
477
                    x0 = _mm_packus_epi16(x0, x0);
478
479
                    _mm_maskmoveu_si128(x0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1),(char *) (dst+x));
480
                    // _mm_storeu_si128((__m128i *) (dst + x), x0);
481
                }
482
                dst += dststride;
483
                src += srcstride;
484
            }
485
        }
486
    }else{
487
        if(!(width & 15)){
488
            for (y = 0; y < height; y++) {
489
                for (x = 0; x < width; x += 16) {
490
491
                    x0 = _mm_load_si128((__m128i *) &src[x]);
492
                    x2 = _mm_load_si128((__m128i *) &src[x + 8]);
493
                    x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
494
                            _mm_mulhi_epi16(x0, c0));
495
                    x3 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c0),
496
                            _mm_mulhi_epi16(x2, c0));
497
                    x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
498
                            _mm_mulhi_epi16(x0, c0));
499
                    x2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c0),
500
                            _mm_mulhi_epi16(x2, c0));
501
502
                    x0 = _mm_add_epi32(x0, add2);
503
                    x1 = _mm_add_epi32(x1, add2);
504
                    x2 = _mm_add_epi32(x2, add2);
505
                    x3 = _mm_add_epi32(x3, add2);
506
507
                    x0 = _mm_packus_epi32(x0, x1);
508
                    x2 = _mm_packus_epi32(x2, x3);
509
                    x0 = _mm_packus_epi16(x0, x2);
510
511
                    _mm_storeu_si128((__m128i *) (dst + x), x0);
512
513
                }
514
                dst += dststride;
515
                src += srcstride;
516
            }
517
        }else if(!(width & 7)){
518
            for (y = 0; y < height; y++) {
519
                for(x=0;x<width;x+=8){
520
                    x0 = _mm_load_si128((__m128i *) (src+x));
521
                    x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
522
                            _mm_mulhi_epi16(x0, c0));
523
524
                    x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
525
                            _mm_mulhi_epi16(x0, c0));
526
527
528
                    x0 = _mm_add_epi32(x0, add2);
529
                    x1 = _mm_add_epi32(x1, add2);
530
531
                    x0 = _mm_packus_epi32(x0, x1);
532
                    x0 = _mm_packus_epi16(x0, x0);
533
534
                    _mm_storeu_si128((__m128i *) (dst+x), x0);
535
                }
536
537
                dst += dststride;
538
                src += srcstride;
539
            }
540
        }else if(!(width & 3)){
541
            for (y = 0; y < height; y++) {
542
                for(x=0;x<width;x+=4){
543
                    x0 = _mm_loadl_epi64((__m128i *) (src+x));
544
                    x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
545
                            _mm_mulhi_epi16(x0, c0));
546
547
                    x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
548
                            _mm_mulhi_epi16(x0, c0));
549
550
551
                    x0 = _mm_add_epi32(x0, add2);
552
                    x1 = _mm_add_epi32(x1, add2);
553
554
555
                    x0 = _mm_packus_epi32(x0, x1);
556
                    x0 = _mm_packus_epi16(x0, x0);
557
558
559
                    _mm_maskmoveu_si128(x0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
560
                }
561
                dst += dststride;
562
                src += srcstride;
563
            }
564
        }else{
565
            for (y = 0; y < height; y++) {
566
                for(x=0;x<width;x+=2){
567
                    x0 = _mm_loadl_epi64((__m128i *) (src+x));
568
                    x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
569
                            _mm_mulhi_epi16(x0, c0));
570
571
                    x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
572
                            _mm_mulhi_epi16(x0, c0));
573
574
575
                    x0 = _mm_add_epi32(x0, add2);
576
                    x1 = _mm_add_epi32(x1, add2);
577
578
579
                    x0 = _mm_packus_epi32(x0, x1);
580
                    x0 = _mm_packus_epi16(x0, x0);
581
582
583
                    _mm_maskmoveu_si128(x0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1),(char *) (dst+x));
584
                }
585
                dst += dststride;
586
                src += srcstride;
587
            }
588
589
        }
590
591
    }
592
593
}
594
#endif
595
596
597
#if 0
598
void ff_hevc_weighted_pred_sse(uint8_t denom, int16_t wlxFlag, int16_t olxFlag,
599
                               uint8_t *_dst, ptrdiff_t _dststride,
600
                               const int16_t *src, ptrdiff_t srcstride,
601
                               int width, int height) {
602
603
    int log2Wd;
604
    int x, y;
605
606
    uint8_t *dst = (uint8_t*) _dst;
607
    ptrdiff_t dststride = _dststride / sizeof(uint8_t);
608
    __m128i x0, x1, x2, x3, c0, add, add2;
609
610
    log2Wd = denom + 14 - BIT_DEPTH;
611
612
    add = _mm_set1_epi32(olxFlag * (1 << (BIT_DEPTH - 8)));
613
    add2 = _mm_set1_epi32(1 << (log2Wd - 1));
614
    c0 = _mm_set1_epi16(wlxFlag);
615
    if (log2Wd >= 1)
616
        for (y = 0; y < height; y++) {
617
            for (x = 0; x < width; x += 16) {
618
                x0 = _mm_load_si128((__m128i *) &src[x]);
619
                x2 = _mm_load_si128((__m128i *) &src[x + 8]);
620
                x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
621
                        _mm_mulhi_epi16(x0, c0));
622
                x3 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c0),
623
                        _mm_mulhi_epi16(x2, c0));
624
                x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
625
                        _mm_mulhi_epi16(x0, c0));
626
                x2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c0),
627
                        _mm_mulhi_epi16(x2, c0));
628
                x0 = _mm_add_epi32(x0, add2);
629
                x1 = _mm_add_epi32(x1, add2);
630
                x2 = _mm_add_epi32(x2, add2);
631
                x3 = _mm_add_epi32(x3, add2);
632
                x0 = _mm_srai_epi32(x0, log2Wd);
633
                x1 = _mm_srai_epi32(x1, log2Wd);
634
                x2 = _mm_srai_epi32(x2, log2Wd);
635
                x3 = _mm_srai_epi32(x3, log2Wd);
636
                x0 = _mm_add_epi32(x0, add);
637
                x1 = _mm_add_epi32(x1, add);
638
                x2 = _mm_add_epi32(x2, add);
639
                x3 = _mm_add_epi32(x3, add);
640
                x0 = _mm_packus_epi32(x0, x1);
641
                x2 = _mm_packus_epi32(x2, x3);
642
                x0 = _mm_packus_epi16(x0, x2);
643
644
                _mm_storeu_si128((__m128i *) (dst + x), x0);
645
646
            }
647
            dst += dststride;
648
            src += srcstride;
649
        }
650
    else
651
        for (y = 0; y < height; y++) {
652
            for (x = 0; x < width; x += 16) {
653
654
                x0 = _mm_load_si128((__m128i *) &src[x]);
655
                x2 = _mm_load_si128((__m128i *) &src[x + 8]);
656
                x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
657
                        _mm_mulhi_epi16(x0, c0));
658
                x3 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c0),
659
                        _mm_mulhi_epi16(x2, c0));
660
                x0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
661
                        _mm_mulhi_epi16(x0, c0));
662
                x2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c0),
663
                        _mm_mulhi_epi16(x2, c0));
664
665
                x0 = _mm_add_epi32(x0, add2);
666
                x1 = _mm_add_epi32(x1, add2);
667
                x2 = _mm_add_epi32(x2, add2);
668
                x3 = _mm_add_epi32(x3, add2);
669
670
                x0 = _mm_packus_epi32(x0, x1);
671
                x2 = _mm_packus_epi32(x2, x3);
672
                x0 = _mm_packus_epi16(x0, x2);
673
674
                _mm_storeu_si128((__m128i *) (dst + x), x0);
675
676
            }
677
            dst += dststride;
678
            src += srcstride;
679
        }
680
}
681
#endif
682
683
#if HAVE_SSE4_1
684
void ff_hevc_weighted_pred_avg_8_sse4(uint8_t denom, int16_t wl0Flag,
685
                                      int16_t wl1Flag, int16_t ol0Flag, int16_t ol1Flag,
686
                                      uint8_t *_dst, ptrdiff_t _dststride,
687
                                      const int16_t *src1, const int16_t *src2, ptrdiff_t srcstride,
688
0
                                      int width, int height) {
689
0
    int shift, shift2;
690
0
    int log2Wd;
691
0
    int o0;
692
0
    int o1;
693
0
    int x, y;
694
0
    uint8_t *dst = (uint8_t*) _dst;
695
0
    ptrdiff_t dststride = _dststride / sizeof(uint8_t);
696
0
    __m128i x0, x1, x2, x3, r0, r1, r2, r3, c0, c1, c2;
697
0
    shift = 14 - BIT_DEPTH;
698
0
    log2Wd = denom + shift;
699
700
0
    o0 = (ol0Flag) * (1 << (BIT_DEPTH - 8));
701
0
    o1 = (ol1Flag) * (1 << (BIT_DEPTH - 8));
702
0
    shift2 = (log2Wd + 1);
703
0
    c0 = _mm_set1_epi16(wl0Flag);
704
0
    c1 = _mm_set1_epi16(wl1Flag);
705
0
    c2 = _mm_set1_epi32((o0 + o1 + 1) << log2Wd);
706
707
0
    if(!(width & 15)){
708
0
        for (y = 0; y < height; y++) {
709
0
                   for (x = 0; x < width; x += 16) {
710
0
                       x0 = _mm_load_si128((__m128i *) &src1[x]);
711
0
                       x1 = _mm_load_si128((__m128i *) &src1[x + 8]);
712
0
                       x2 = _mm_load_si128((__m128i *) &src2[x]);
713
0
                       x3 = _mm_load_si128((__m128i *) &src2[x + 8]);
714
715
0
                       r0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
716
0
                               _mm_mulhi_epi16(x0, c0));
717
0
                       r1 = _mm_unpacklo_epi16(_mm_mullo_epi16(x1, c0),
718
0
                               _mm_mulhi_epi16(x1, c0));
719
0
                       r2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c1),
720
0
                               _mm_mulhi_epi16(x2, c1));
721
0
                       r3 = _mm_unpacklo_epi16(_mm_mullo_epi16(x3, c1),
722
0
                               _mm_mulhi_epi16(x3, c1));
723
0
                       x0 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
724
0
                               _mm_mulhi_epi16(x0, c0));
725
0
                       x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x1, c0),
726
0
                               _mm_mulhi_epi16(x1, c0));
727
0
                       x2 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c1),
728
0
                               _mm_mulhi_epi16(x2, c1));
729
0
                       x3 = _mm_unpackhi_epi16(_mm_mullo_epi16(x3, c1),
730
0
                               _mm_mulhi_epi16(x3, c1));
731
0
                       r0 = _mm_add_epi32(r0, r2);
732
0
                       r1 = _mm_add_epi32(r1, r3);
733
0
                       r2 = _mm_add_epi32(x0, x2);
734
0
                       r3 = _mm_add_epi32(x1, x3);
735
736
0
                       r0 = _mm_add_epi32(r0, c2);
737
0
                       r1 = _mm_add_epi32(r1, c2);
738
0
                       r2 = _mm_add_epi32(r2, c2);
739
0
                       r3 = _mm_add_epi32(r3, c2);
740
741
0
                       r0 = _mm_srai_epi32(r0, shift2);
742
0
                       r1 = _mm_srai_epi32(r1, shift2);
743
0
                       r2 = _mm_srai_epi32(r2, shift2);
744
0
                       r3 = _mm_srai_epi32(r3, shift2);
745
746
0
                       r0 = _mm_packus_epi32(r0, r2);
747
0
                       r1 = _mm_packus_epi32(r1, r3);
748
0
                       r0 = _mm_packus_epi16(r0, r1);
749
750
0
                       _mm_storeu_si128((__m128i *) (dst + x), r0);
751
752
0
                   }
753
0
                   dst += dststride;
754
0
                   src1 += srcstride;
755
0
                   src2 += srcstride;
756
0
               }
757
0
    }else if(!(width & 7)){
758
0
        for (y = 0; y < height; y++) {
759
0
            for(x=0;x<width;x+=8){
760
0
                x0 = _mm_load_si128((__m128i *) (src1+x));
761
0
                x2 = _mm_load_si128((__m128i *) (src2+x));
762
763
0
                r0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
764
0
                        _mm_mulhi_epi16(x0, c0));
765
766
0
                r2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c1),
767
0
                        _mm_mulhi_epi16(x2, c1));
768
769
0
                x0 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
770
0
                        _mm_mulhi_epi16(x0, c0));
771
772
0
                x2 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c1),
773
0
                        _mm_mulhi_epi16(x2, c1));
774
775
0
                r0 = _mm_add_epi32(r0, r2);
776
0
                r2 = _mm_add_epi32(x0, x2);
777
778
779
0
                r0 = _mm_add_epi32(r0, c2);
780
0
                r2 = _mm_add_epi32(r2, c2);
781
782
0
                r0 = _mm_srai_epi32(r0, shift2);
783
0
                r2 = _mm_srai_epi32(r2, shift2);
784
785
0
                r0 = _mm_packus_epi32(r0, r2);
786
0
                r0 = _mm_packus_epi16(r0, r0);
787
788
0
                _mm_storel_epi64((__m128i *) (dst+x), r0);
789
0
            }
790
791
0
            dst += dststride;
792
0
            src1 += srcstride;
793
0
            src2 += srcstride;
794
0
        }
795
0
    }else if(!(width & 3)){
796
0
        for (y = 0; y < height; y++) {
797
0
            for(x=0;x<width;x+=4){
798
0
                x0 = _mm_loadl_epi64((__m128i *) (src1+x));
799
0
                x2 = _mm_loadl_epi64((__m128i *) (src2+x));
800
801
0
                r0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
802
0
                        _mm_mulhi_epi16(x0, c0));
803
804
0
                r2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c1),
805
0
                        _mm_mulhi_epi16(x2, c1));
806
807
0
                x0 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
808
0
                        _mm_mulhi_epi16(x0, c0));
809
810
0
                x2 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c1),
811
0
                        _mm_mulhi_epi16(x2, c1));
812
813
0
                r0 = _mm_add_epi32(r0, r2);
814
0
                r2 = _mm_add_epi32(x0, x2);
815
816
0
                r0 = _mm_add_epi32(r0, c2);
817
0
                r2 = _mm_add_epi32(r2, c2);
818
819
0
                r0 = _mm_srai_epi32(r0, shift2);
820
0
                r2 = _mm_srai_epi32(r2, shift2);
821
822
0
                r0 = _mm_packus_epi32(r0, r2);
823
0
                r0 = _mm_packus_epi16(r0, r0);
824
825
#if MASKMOVE
826
                _mm_maskmoveu_si128(r0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
827
#else
828
0
                *((uint32_t*)(dst+x)) = _mm_cvtsi128_si32(r0);
829
0
#endif
830
0
            }
831
0
            dst += dststride;
832
0
            src1 += srcstride;
833
0
            src2 += srcstride;
834
0
        }
835
0
    }else{
836
0
        for (y = 0; y < height; y++) {
837
0
            for(x=0;x<width;x+=2){
838
0
                x0 = _mm_loadl_epi64((__m128i *) (src1+x));
839
0
                x2 = _mm_loadl_epi64((__m128i *) (src2+x));
840
841
0
                r0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
842
0
                        _mm_mulhi_epi16(x0, c0));
843
844
0
                r2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c1),
845
0
                        _mm_mulhi_epi16(x2, c1));
846
847
0
                x0 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
848
0
                        _mm_mulhi_epi16(x0, c0));
849
850
0
                x2 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c1),
851
0
                        _mm_mulhi_epi16(x2, c1));
852
853
0
                r0 = _mm_add_epi32(r0, r2);
854
0
                r2 = _mm_add_epi32(x0, x2);
855
856
0
                r0 = _mm_add_epi32(r0, c2);
857
0
                r2 = _mm_add_epi32(r2, c2);
858
859
0
                r0 = _mm_srai_epi32(r0, shift2);
860
0
                r2 = _mm_srai_epi32(r2, shift2);
861
862
0
                r0 = _mm_packus_epi32(r0, r2);
863
0
                r0 = _mm_packus_epi16(r0, r0);
864
865
#if MASKMOVE
866
                _mm_maskmoveu_si128(r0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1),(char *) (dst+x));
867
#else
868
0
                *((uint16_t*)(dst+x)) = _mm_cvtsi128_si32(r0);
869
0
#endif
870
0
            }
871
0
            dst += dststride;
872
0
            src1 += srcstride;
873
0
            src2 += srcstride;
874
0
        }
875
0
    }
876
0
}
877
#endif
878
879
880
#if 0
881
void ff_hevc_weighted_pred_avg_sse(uint8_t denom, int16_t wl0Flag,
882
        int16_t wl1Flag, int16_t ol0Flag, int16_t ol1Flag, uint8_t *_dst,
883
                                   ptrdiff_t _dststride, const int16_t *src1, const int16_t *src2, ptrdiff_t srcstride,
884
        int width, int height) {
885
    int shift, shift2;
886
    int log2Wd;
887
    int o0;
888
    int o1;
889
    int x, y;
890
    uint8_t *dst = (uint8_t*) _dst;
891
    ptrdiff_t dststride = _dststride / sizeof(uint8_t);
892
    __m128i x0, x1, x2, x3, r0, r1, r2, r3, c0, c1, c2;
893
    shift = 14 - BIT_DEPTH;
894
    log2Wd = denom + shift;
895
896
    o0 = (ol0Flag) * (1 << (BIT_DEPTH - 8));
897
    o1 = (ol1Flag) * (1 << (BIT_DEPTH - 8));
898
    shift2 = (log2Wd + 1);
899
    c0 = _mm_set1_epi16(wl0Flag);
900
    c1 = _mm_set1_epi16(wl1Flag);
901
    c2 = _mm_set1_epi32((o0 + o1 + 1) << log2Wd);
902
903
    for (y = 0; y < height; y++) {
904
        for (x = 0; x < width; x += 16) {
905
            x0 = _mm_load_si128((__m128i *) &src1[x]);
906
            x1 = _mm_load_si128((__m128i *) &src1[x + 8]);
907
            x2 = _mm_load_si128((__m128i *) &src2[x]);
908
            x3 = _mm_load_si128((__m128i *) &src2[x + 8]);
909
910
            r0 = _mm_unpacklo_epi16(_mm_mullo_epi16(x0, c0),
911
                    _mm_mulhi_epi16(x0, c0));
912
            r1 = _mm_unpacklo_epi16(_mm_mullo_epi16(x1, c0),
913
                    _mm_mulhi_epi16(x1, c0));
914
            r2 = _mm_unpacklo_epi16(_mm_mullo_epi16(x2, c1),
915
                    _mm_mulhi_epi16(x2, c1));
916
            r3 = _mm_unpacklo_epi16(_mm_mullo_epi16(x3, c1),
917
                    _mm_mulhi_epi16(x3, c1));
918
            x0 = _mm_unpackhi_epi16(_mm_mullo_epi16(x0, c0),
919
                    _mm_mulhi_epi16(x0, c0));
920
            x1 = _mm_unpackhi_epi16(_mm_mullo_epi16(x1, c0),
921
                    _mm_mulhi_epi16(x1, c0));
922
            x2 = _mm_unpackhi_epi16(_mm_mullo_epi16(x2, c1),
923
                    _mm_mulhi_epi16(x2, c1));
924
            x3 = _mm_unpackhi_epi16(_mm_mullo_epi16(x3, c1),
925
                    _mm_mulhi_epi16(x3, c1));
926
            r0 = _mm_add_epi32(r0, r2);
927
            r1 = _mm_add_epi32(r1, r3);
928
            r2 = _mm_add_epi32(x0, x2);
929
            r3 = _mm_add_epi32(x1, x3);
930
931
            r0 = _mm_add_epi32(r0, c2);
932
            r1 = _mm_add_epi32(r1, c2);
933
            r2 = _mm_add_epi32(r2, c2);
934
            r3 = _mm_add_epi32(r3, c2);
935
936
            r0 = _mm_srai_epi32(r0, shift2);
937
            r1 = _mm_srai_epi32(r1, shift2);
938
            r2 = _mm_srai_epi32(r2, shift2);
939
            r3 = _mm_srai_epi32(r3, shift2);
940
941
            r0 = _mm_packus_epi32(r0, r2);
942
            r1 = _mm_packus_epi32(r1, r3);
943
            r0 = _mm_packus_epi16(r0, r1);
944
945
            _mm_storeu_si128((__m128i *) (dst + x), r0);
946
947
        }
948
        dst += dststride;
949
        src1 += srcstride;
950
        src2 += srcstride;
951
    }
952
}
953
#endif
954
955
956
void ff_hevc_put_hevc_epel_pixels_8_sse(int16_t *dst, ptrdiff_t dststride,
957
                                        const uint8_t *_src, ptrdiff_t srcstride,
958
                                        int width, int height, int mx,
959
5.76M
                                        int my, int16_t* mcbuffer) {
960
5.76M
    int x, y;
961
5.76M
    __m128i x1, x2,x3;
962
5.76M
    uint8_t *src = (uint8_t*) _src;
963
5.76M
    if(!(width & 15)){
964
172k
        x3= _mm_setzero_si128();
965
2.56M
        for (y = 0; y < height; y++) {
966
4.93M
                    for (x = 0; x < width; x += 16) {
967
968
2.53M
                        x1 = _mm_loadu_si128((__m128i *) &src[x]);
969
2.53M
                        x2 = _mm_unpacklo_epi8(x1, x3);
970
971
2.53M
                        x1 = _mm_unpackhi_epi8(x1, x3);
972
973
2.53M
                        x2 = _mm_slli_epi16(x2, 6);
974
2.53M
                        x1 = _mm_slli_epi16(x1, 6);
975
2.53M
                        _mm_store_si128((__m128i *) &dst[x], x2);
976
2.53M
                        _mm_store_si128((__m128i *) &dst[x + 8], x1);
977
978
2.53M
                    }
979
2.39M
                    src += srcstride;
980
2.39M
                    dst += dststride;
981
2.39M
                }
982
5.59M
    }else  if(!(width & 7)){
983
690k
        x1= _mm_setzero_si128();
984
7.64M
        for (y = 0; y < height; y++) {
985
13.9M
                    for (x = 0; x < width; x += 8) {
986
987
6.97M
                        x2 = _mm_loadl_epi64((__m128i *) &src[x]);
988
6.97M
                        x2 = _mm_unpacklo_epi8(x2, x1);
989
6.97M
                        x2 = _mm_slli_epi16(x2, 6);
990
6.97M
                        _mm_store_si128((__m128i *) &dst[x], x2);
991
992
6.97M
                    }
993
6.95M
                    src += srcstride;
994
6.95M
                    dst += dststride;
995
6.95M
                }
996
4.90M
    }else  if(!(width & 3)){
997
4.21M
        x1= _mm_setzero_si128();
998
24.9M
        for (y = 0; y < height; y++) {
999
41.8M
                    for (x = 0; x < width; x += 4) {
1000
1001
21.0M
                        x2 = _mm_loadl_epi64((__m128i *) &src[x]);
1002
21.0M
                        x2 = _mm_unpacklo_epi8(x2,x1);
1003
1004
21.0M
                        x2 = _mm_slli_epi16(x2, 6);
1005
1006
21.0M
                        _mm_storel_epi64((__m128i *) &dst[x], x2);
1007
1008
21.0M
                    }
1009
20.7M
                    src += srcstride;
1010
20.7M
                    dst += dststride;
1011
20.7M
                }
1012
4.21M
    }else{
1013
689k
        x1= _mm_setzero_si128();
1014
4.75M
        for (y = 0; y < height; y++) {
1015
8.70M
                    for (x = 0; x < width; x += 2) {
1016
1017
4.63M
                        x2 = _mm_loadl_epi64((__m128i *) &src[x]);
1018
4.63M
                        x2 = _mm_unpacklo_epi8(x2, x1);
1019
4.63M
                        x2 = _mm_slli_epi16(x2, 6);
1020
#if MASKMOVE
1021
                        _mm_maskmoveu_si128(x2,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
1022
#else
1023
4.63M
                        *((uint32_t*)(dst+x)) = _mm_cvtsi128_si32(x2);
1024
4.63M
#endif
1025
4.63M
                    }
1026
4.06M
                    src += srcstride;
1027
4.06M
                    dst += dststride;
1028
4.06M
                }
1029
689k
    }
1030
1031
5.76M
}
1032
1033
#ifndef __native_client__
1034
void ff_hevc_put_hevc_epel_pixels_10_sse(int16_t *dst, ptrdiff_t dststride,
1035
                                         const uint8_t *_src, ptrdiff_t _srcstride,
1036
                                         int width, int height, int mx,
1037
0
                                         int my, int16_t* mcbuffer) {
1038
0
    int x, y;
1039
0
    __m128i x2;
1040
0
    uint16_t *src = (uint16_t*) _src;
1041
0
    ptrdiff_t srcstride = _srcstride>>1;
1042
0
    if(!(width & 7)){
1043
      //x1= _mm_setzero_si128();
1044
0
        for (y = 0; y < height; y++) {
1045
0
            for (x = 0; x < width; x += 8) {
1046
1047
0
                x2 = _mm_loadu_si128((__m128i *) &src[x]);
1048
0
                x2 = _mm_slli_epi16(x2, 4);         //shift 14 - BIT LENGTH
1049
0
                _mm_store_si128((__m128i *) &dst[x], x2);
1050
1051
0
            }
1052
0
            src += srcstride;
1053
0
            dst += dststride;
1054
0
        }
1055
0
    }else  if(!(width & 3)){
1056
      //x1= _mm_setzero_si128();
1057
0
        for (y = 0; y < height; y++) {
1058
0
            for (x = 0; x < width; x += 4) {
1059
1060
0
                x2 = _mm_loadl_epi64((__m128i *) &src[x]);
1061
0
                x2 = _mm_slli_epi16(x2, 4);     //shift 14 - BIT LENGTH
1062
1063
0
                _mm_storel_epi64((__m128i *) &dst[x], x2);
1064
1065
0
            }
1066
0
            src += srcstride;
1067
0
            dst += dststride;
1068
0
        }
1069
0
    }else{
1070
      //x1= _mm_setzero_si128();
1071
0
        for (y = 0; y < height; y++) {
1072
0
            for (x = 0; x < width; x += 2) {
1073
1074
0
                x2 = _mm_loadl_epi64((__m128i *) &src[x]);
1075
0
                x2 = _mm_slli_epi16(x2, 4);     //shift 14 - BIT LENGTH
1076
0
                _mm_maskmoveu_si128(x2,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
1077
0
            }
1078
0
            src += srcstride;
1079
0
            dst += dststride;
1080
0
        }
1081
0
    }
1082
1083
0
}
1084
#endif
1085
1086
void ff_hevc_put_hevc_epel_h_8_sse(int16_t *dst, ptrdiff_t dststride,
1087
                                   const uint8_t *_src, ptrdiff_t _srcstride,
1088
                                   int width, int height, int mx,
1089
1.12M
                                   int my, int16_t* mcbuffer, int bit_depth) {
1090
1.12M
    int x, y;
1091
1.12M
    const uint8_t *src = (const uint8_t*) _src;
1092
1.12M
    ptrdiff_t srcstride = _srcstride;
1093
1.12M
    const int8_t *filter = epel_filters[mx - 1];
1094
1.12M
    __m128i r0, bshuffle1, bshuffle2, x1, x2, x3;
1095
1.12M
    int8_t filter_0 = filter[0];
1096
1.12M
    int8_t filter_1 = filter[1];
1097
1.12M
    int8_t filter_2 = filter[2];
1098
1.12M
    int8_t filter_3 = filter[3];
1099
1.12M
    r0 = _mm_set_epi8(filter_3, filter_2, filter_1, filter_0, filter_3,
1100
1.12M
            filter_2, filter_1, filter_0, filter_3, filter_2, filter_1,
1101
1.12M
            filter_0, filter_3, filter_2, filter_1, filter_0);
1102
1.12M
    bshuffle1 = _mm_set_epi8(6, 5, 4, 3, 5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0);
1103
1104
1105
    /*
1106
  printf("---IN---SSE\n");
1107
1108
  int extra_top  = 1;
1109
  int extra_left = 1;
1110
  int extra_right  = 2;
1111
  int extra_bottom = 2;
1112
1113
  for (int y=-extra_top;y<height+extra_bottom;y++) {
1114
    uint8_t* p = &_src[y*_srcstride -extra_left];
1115
1116
    for (int x=-extra_left;x<width+extra_right;x++) {
1117
      printf("%05d ",*p << 6);
1118
      p++;
1119
    }
1120
    printf("\n");
1121
  }
1122
    */
1123
1124
1.12M
    if(!(width & 7)){
1125
201k
        bshuffle2 = _mm_set_epi8(10, 9, 8, 7, 9, 8, 7, 6, 8, 7, 6, 5, 7, 6, 5,
1126
201k
                        4);
1127
2.36M
                for (y = 0; y < height; y++) {
1128
4.74M
                    for (x = 0; x < width; x += 8) {
1129
1130
2.58M
                        x1 = _mm_loadu_si128((__m128i *) &src[x - 1]);
1131
2.58M
                        x2 = _mm_shuffle_epi8(x1, bshuffle1);
1132
2.58M
                        x3 = _mm_shuffle_epi8(x1, bshuffle2);
1133
1134
                        /*  PMADDUBSW then PMADDW     */
1135
2.58M
                        x2 = _mm_maddubs_epi16(x2, r0);
1136
2.58M
                        x3 = _mm_maddubs_epi16(x3, r0);
1137
2.58M
                        x2 = _mm_hadd_epi16(x2, x3);
1138
2.58M
                        _mm_store_si128((__m128i *) &dst[x], x2);
1139
2.58M
                    }
1140
2.16M
                    src += srcstride;
1141
2.16M
                    dst += dststride;
1142
2.16M
                }
1143
923k
    }else if(!(width & 3)){
1144
1145
4.89M
        for (y = 0; y < height; y++) {
1146
8.35M
            for (x = 0; x < width; x += 4) {
1147
            /* load data in register     */
1148
4.20M
            x1 = _mm_loadu_si128((__m128i *) &src[x-1]);
1149
4.20M
            x2 = _mm_shuffle_epi8(x1, bshuffle1);
1150
1151
            /*  PMADDUBSW then PMADDW     */
1152
4.20M
            x2 = _mm_maddubs_epi16(x2, r0);
1153
4.20M
            x2 = _mm_hadd_epi16(x2, _mm_setzero_si128());
1154
            /* give results back            */
1155
4.20M
            _mm_storel_epi64((__m128i *) &dst[x], x2);
1156
4.20M
            }
1157
4.15M
            src += srcstride;
1158
4.15M
            dst += dststride;
1159
4.15M
        }
1160
740k
    }else{
1161
1.50M
        for (y = 0; y < height; y++) {
1162
2.75M
            for (x = 0; x < width; x += 2) {
1163
            /* load data in register     */
1164
1.42M
            x1 = _mm_loadu_si128((__m128i *) &src[x-1]);
1165
1.42M
            x2 = _mm_shuffle_epi8(x1, bshuffle1);
1166
1167
            /*  PMADDUBSW then PMADDW     */
1168
1.42M
            x2 = _mm_maddubs_epi16(x2, r0);
1169
1.42M
            x2 = _mm_hadd_epi16(x2, _mm_setzero_si128());
1170
            /* give results back            */
1171
#if MASKMOVE
1172
            _mm_maskmoveu_si128(x2,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
1173
#else
1174
1.42M
            *((uint32_t*)(dst+x)) = _mm_cvtsi128_si32(x2);
1175
1.42M
#endif
1176
1.42M
            }
1177
1.32M
            src += srcstride;
1178
1.32M
            dst += dststride;
1179
1.32M
        }
1180
182k
    }
1181
1.12M
}
1182
1183
#ifndef __native_client__
1184
void ff_hevc_put_hevc_epel_h_10_sse(int16_t *dst, ptrdiff_t dststride,
1185
                                    const uint8_t *_src, ptrdiff_t _srcstride,
1186
                                    int width, int height, int mx,
1187
0
                                    int my, int16_t* mcbuffer) {
1188
0
    int x, y;
1189
0
    uint16_t *src = (uint16_t*) _src;
1190
0
    ptrdiff_t srcstride = _srcstride>>1;
1191
0
    const int8_t *filter = epel_filters[mx - 1];
1192
0
    __m128i r0, bshuffle1, bshuffle2, x1, x2, x3, r1;
1193
0
    int8_t filter_0 = filter[0];
1194
0
    int8_t filter_1 = filter[1];
1195
0
    int8_t filter_2 = filter[2];
1196
0
    int8_t filter_3 = filter[3];
1197
0
    r0 = _mm_set_epi16(filter_3, filter_2, filter_1,
1198
0
            filter_0, filter_3, filter_2, filter_1, filter_0);
1199
0
    bshuffle1 = _mm_set_epi8(9,8,7,6,5,4, 3, 2,7,6,5,4, 3, 2, 1, 0);
1200
1201
0
    if(!(width & 3)){
1202
0
        bshuffle2 = _mm_set_epi8(13,12,11,10,9,8,7,6,11,10, 9,8,7,6,5, 4);
1203
0
        for (y = 0; y < height; y++) {
1204
0
            for (x = 0; x < width; x += 4) {
1205
1206
0
                x1 = _mm_loadu_si128((__m128i *) &src[x-1]);
1207
0
                x2 = _mm_shuffle_epi8(x1, bshuffle1);
1208
0
                x3 = _mm_shuffle_epi8(x1, bshuffle2);
1209
1210
1211
0
                x2 = _mm_madd_epi16(x2, r0);
1212
0
                x3 = _mm_madd_epi16(x3, r0);
1213
0
                x2 = _mm_hadd_epi32(x2, x3);
1214
0
                x2= _mm_srai_epi32(x2,2);   //>> (BIT_DEPTH - 8)
1215
1216
0
                x2 = _mm_packs_epi32(x2,r0);
1217
                //give results back
1218
0
                _mm_storel_epi64((__m128i *) &dst[x], x2);
1219
0
            }
1220
0
            src += srcstride;
1221
0
            dst += dststride;
1222
0
        }
1223
0
    }else{
1224
0
        r1= _mm_setzero_si128();
1225
0
        for (y = 0; y < height; y++) {
1226
0
            for (x = 0; x < width; x += 2) {
1227
                /* load data in register     */
1228
0
                x1 = _mm_loadu_si128((__m128i *) &src[x-1]);
1229
0
                x2 = _mm_shuffle_epi8(x1, bshuffle1);
1230
1231
                /*  PMADDUBSW then PMADDW     */
1232
0
                x2 = _mm_madd_epi16(x2, r0);
1233
0
                x2 = _mm_hadd_epi32(x2, r1);
1234
0
                x2= _mm_srai_epi32(x2,2);   //>> (BIT_DEPTH - 8)
1235
0
                x2 = _mm_packs_epi32(x2, r1);
1236
                /* give results back            */
1237
0
                _mm_maskmoveu_si128(x2,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
1238
0
            }
1239
0
            src += srcstride;
1240
0
            dst += dststride;
1241
0
        }
1242
0
    }
1243
0
}
1244
#endif
1245
1246
1247
void ff_hevc_put_hevc_epel_v_8_sse(int16_t *dst, ptrdiff_t dststride,
1248
                                   const uint8_t *_src, ptrdiff_t _srcstride, int width, int height, int mx,
1249
1.26M
                                   int my, int16_t* mcbuffer, int bit_depth) {
1250
1.26M
    int x, y;
1251
1.26M
    __m128i x0, x1, x2, x3, t0, t1, t2, t3, r0, f0, f1, f2, f3, r1;
1252
1.26M
    uint8_t *src = (uint8_t*) _src;
1253
1.26M
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
1254
1.26M
    const int8_t *filter = epel_filters[my - 1];
1255
1.26M
    int8_t filter_0 = filter[0];
1256
1.26M
    int8_t filter_1 = filter[1];
1257
1.26M
    int8_t filter_2 = filter[2];
1258
1.26M
    int8_t filter_3 = filter[3];
1259
1.26M
    f0 = _mm_set1_epi16(filter_0);
1260
1.26M
    f1 = _mm_set1_epi16(filter_1);
1261
1.26M
    f2 = _mm_set1_epi16(filter_2);
1262
1.26M
    f3 = _mm_set1_epi16(filter_3);
1263
1264
1.26M
    if(!(width & 15)){
1265
910k
        for (y = 0; y < height; y++) {
1266
1.71M
            for (x = 0; x < width; x += 16) {
1267
                /* check if memory needs to be reloaded */
1268
1269
874k
                x0 = _mm_loadu_si128((__m128i *) &src[x - srcstride]);
1270
874k
                x1 = _mm_loadu_si128((__m128i *) &src[x]);
1271
874k
                x2 = _mm_loadu_si128((__m128i *) &src[x + srcstride]);
1272
874k
                x3 = _mm_loadu_si128((__m128i *) &src[x + 2 * srcstride]);
1273
1274
874k
                t0 = _mm_unpacklo_epi8(x0, _mm_setzero_si128());
1275
874k
                t1 = _mm_unpacklo_epi8(x1, _mm_setzero_si128());
1276
874k
                t2 = _mm_unpacklo_epi8(x2, _mm_setzero_si128());
1277
874k
                t3 = _mm_unpacklo_epi8(x3, _mm_setzero_si128());
1278
1279
874k
                x0 = _mm_unpackhi_epi8(x0, _mm_setzero_si128());
1280
874k
                x1 = _mm_unpackhi_epi8(x1, _mm_setzero_si128());
1281
874k
                x2 = _mm_unpackhi_epi8(x2, _mm_setzero_si128());
1282
874k
                x3 = _mm_unpackhi_epi8(x3, _mm_setzero_si128());
1283
1284
                /* multiply by correct value : */
1285
874k
                r0 = _mm_mullo_epi16(t0, f0);
1286
874k
                r1 = _mm_mullo_epi16(x0, f0);
1287
874k
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t1, f1));
1288
874k
                r1 = _mm_adds_epi16(r1, _mm_mullo_epi16(x1, f1));
1289
874k
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t2, f2));
1290
874k
                r1 = _mm_adds_epi16(r1, _mm_mullo_epi16(x2, f2));
1291
874k
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t3, f3));
1292
874k
                r1 = _mm_adds_epi16(r1, _mm_mullo_epi16(x3, f3));
1293
                /* give results back            */
1294
874k
                _mm_store_si128((__m128i *) &dst[x], r0);
1295
874k
                _mm_storeu_si128((__m128i *) &dst[x + 8], r1);
1296
874k
            }
1297
842k
            src += srcstride;
1298
842k
            dst += dststride;
1299
842k
        }
1300
1.19M
    }else if(!(width & 7)){
1301
202k
        r1= _mm_setzero_si128();
1302
2.13M
        for (y = 0; y < height; y++) {
1303
3.86M
            for(x=0;x<width;x+=8){
1304
1.93M
                x0 = _mm_loadl_epi64((__m128i *) &src[x - srcstride]);
1305
1.93M
                x1 = _mm_loadl_epi64((__m128i *) &src[x]);
1306
1.93M
                x2 = _mm_loadl_epi64((__m128i *) &src[x + srcstride]);
1307
1.93M
                x3 = _mm_loadl_epi64((__m128i *) &src[x + 2 * srcstride]);
1308
1309
1.93M
                t0 = _mm_unpacklo_epi8(x0, r1);
1310
1.93M
                t1 = _mm_unpacklo_epi8(x1, r1);
1311
1.93M
                t2 = _mm_unpacklo_epi8(x2, r1);
1312
1.93M
                t3 = _mm_unpacklo_epi8(x3, r1);
1313
1314
1315
                /* multiply by correct value : */
1316
1.93M
                r0 = _mm_mullo_epi16(t0, f0);
1317
1.93M
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t1, f1));
1318
1.93M
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t2, f2));
1319
1.93M
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t3, f3));
1320
                /* give results back            */
1321
1.93M
                _mm_storeu_si128((__m128i *) &dst[x], r0);
1322
1.93M
            }
1323
1.93M
            src += srcstride;
1324
1.93M
            dst += dststride;
1325
1.93M
        }
1326
993k
    }else if(!(width & 3)){
1327
870k
        r1= _mm_setzero_si128();
1328
5.13M
        for (y = 0; y < height; y++) {
1329
8.58M
            for(x=0;x<width;x+=4){
1330
4.31M
                x0 = _mm_loadl_epi64((__m128i *) &src[x - srcstride]);
1331
4.31M
                x1 = _mm_loadl_epi64((__m128i *) &src[x]);
1332
4.31M
                x2 = _mm_loadl_epi64((__m128i *) &src[x + srcstride]);
1333
4.31M
                x3 = _mm_loadl_epi64((__m128i *) &src[x + 2 * srcstride]);
1334
1335
4.31M
                t0 = _mm_unpacklo_epi8(x0, r1);
1336
4.31M
                t1 = _mm_unpacklo_epi8(x1, r1);
1337
4.31M
                t2 = _mm_unpacklo_epi8(x2, r1);
1338
4.31M
                t3 = _mm_unpacklo_epi8(x3, r1);
1339
1340
1341
                /* multiply by correct value : */
1342
4.31M
                r0 = _mm_mullo_epi16(t0, f0);
1343
4.31M
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t1, f1));
1344
4.31M
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t2, f2));
1345
4.31M
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t3, f3));
1346
                /* give results back            */
1347
4.31M
                _mm_storel_epi64((__m128i *) &dst[x], r0);
1348
4.31M
            }
1349
4.26M
            src += srcstride;
1350
4.26M
            dst += dststride;
1351
4.26M
        }
1352
870k
    }else{
1353
123k
        r1= _mm_setzero_si128();
1354
935k
        for (y = 0; y < height; y++) {
1355
1.69M
            for(x=0;x<width;x+=2){
1356
884k
                x0 = _mm_loadl_epi64((__m128i *) &src[x - srcstride]);
1357
884k
                x1 = _mm_loadl_epi64((__m128i *) &src[x]);
1358
884k
                x2 = _mm_loadl_epi64((__m128i *) &src[x + srcstride]);
1359
884k
                x3 = _mm_loadl_epi64((__m128i *) &src[x + 2 * srcstride]);
1360
1361
884k
                t0 = _mm_unpacklo_epi8(x0, r1);
1362
884k
                t1 = _mm_unpacklo_epi8(x1, r1);
1363
884k
                t2 = _mm_unpacklo_epi8(x2, r1);
1364
884k
                t3 = _mm_unpacklo_epi8(x3, r1);
1365
1366
1367
                /* multiply by correct value : */
1368
884k
                r0 = _mm_mullo_epi16(t0, f0);
1369
884k
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t1, f1));
1370
884k
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t2, f2));
1371
884k
                r0 = _mm_adds_epi16(r0, _mm_mullo_epi16(t3, f3));
1372
                /* give results back            */
1373
#if MASKMOVE
1374
                _mm_maskmoveu_si128(r0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
1375
#else
1376
884k
                *((uint32_t*)(dst+x)) = _mm_cvtsi128_si32(r0);
1377
884k
#endif
1378
884k
            }
1379
812k
            src += srcstride;
1380
812k
            dst += dststride;
1381
812k
        }
1382
123k
    }
1383
1.26M
}
1384
1385
#ifndef __native_client__
1386
void ff_hevc_put_hevc_epel_v_10_sse(int16_t *dst, ptrdiff_t dststride,
1387
                                    const uint8_t *_src, ptrdiff_t _srcstride, int width, int height, int mx,
1388
0
        int my, int16_t* mcbuffer) {
1389
0
    int x, y;
1390
0
    __m128i x0, x1, x2, x3, t0, t1, t2, t3, r0, f0, f1, f2, f3, r1, r2, r3;
1391
0
    uint16_t *src = (uint16_t*) _src;
1392
0
    ptrdiff_t srcstride = _srcstride >>1;
1393
0
    const int8_t *filter = epel_filters[my - 1];
1394
0
    int8_t filter_0 = filter[0];
1395
0
    int8_t filter_1 = filter[1];
1396
0
    int8_t filter_2 = filter[2];
1397
0
    int8_t filter_3 = filter[3];
1398
0
    f0 = _mm_set1_epi16(filter_0);
1399
0
    f1 = _mm_set1_epi16(filter_1);
1400
0
    f2 = _mm_set1_epi16(filter_2);
1401
0
    f3 = _mm_set1_epi16(filter_3);
1402
1403
0
    if(!(width & 7)){
1404
0
        r1= _mm_setzero_si128();
1405
0
        for (y = 0; y < height; y++) {
1406
0
            for(x=0;x<width;x+=8){
1407
0
                x0 = _mm_loadu_si128((__m128i *) &src[x - srcstride]);
1408
0
                x1 = _mm_loadu_si128((__m128i *) &src[x]);
1409
0
                x2 = _mm_loadu_si128((__m128i *) &src[x + srcstride]);
1410
0
                x3 = _mm_loadu_si128((__m128i *) &src[x + 2 * srcstride]);
1411
1412
                // multiply by correct value :
1413
0
                r0 = _mm_mullo_epi16(x0, f0);
1414
0
                t0 = _mm_mulhi_epi16(x0, f0);
1415
1416
0
                x0= _mm_unpacklo_epi16(r0,t0);
1417
0
                t0= _mm_unpackhi_epi16(r0,t0);
1418
1419
0
                r1 = _mm_mullo_epi16(x1, f1);
1420
0
                t1 = _mm_mulhi_epi16(x1, f1);
1421
1422
0
                x1= _mm_unpacklo_epi16(r1,t1);
1423
0
                t1= _mm_unpackhi_epi16(r1,t1);
1424
1425
1426
0
                r2 = _mm_mullo_epi16(x2, f2);
1427
0
                t2 = _mm_mulhi_epi16(x2, f2);
1428
1429
0
                x2= _mm_unpacklo_epi16(r2,t2);
1430
0
                t2= _mm_unpackhi_epi16(r2,t2);
1431
1432
1433
0
                r3 = _mm_mullo_epi16(x3, f3);
1434
0
                t3 = _mm_mulhi_epi16(x3, f3);
1435
1436
0
                x3= _mm_unpacklo_epi16(r3,t3);
1437
0
                t3= _mm_unpackhi_epi16(r3,t3);
1438
1439
1440
0
                r0= _mm_add_epi32(x0,x1);
1441
0
                r1= _mm_add_epi32(x2,x3);
1442
1443
0
                t0= _mm_add_epi32(t0,t1);
1444
0
                t1= _mm_add_epi32(t2,t3);
1445
1446
0
                r0= _mm_add_epi32(r0,r1);
1447
0
                t0= _mm_add_epi32(t0,t1);
1448
1449
0
                r0= _mm_srai_epi32(r0,2);//>> (BIT_DEPTH - 8)
1450
0
                t0= _mm_srai_epi32(t0,2);//>> (BIT_DEPTH - 8)
1451
1452
0
                r0= _mm_packs_epi32(r0, t0);
1453
                // give results back
1454
0
                _mm_storeu_si128((__m128i *) &dst[x], r0);
1455
0
            }
1456
0
            src += srcstride;
1457
0
            dst += dststride;
1458
0
        }
1459
0
    }else if(!(width & 3)){
1460
0
        r1= _mm_setzero_si128();
1461
0
        for (y = 0; y < height; y++) {
1462
0
            for(x=0;x<width;x+=4){
1463
0
                x0 = _mm_loadl_epi64((__m128i *) &src[x - srcstride]);
1464
0
                x1 = _mm_loadl_epi64((__m128i *) &src[x]);
1465
0
                x2 = _mm_loadl_epi64((__m128i *) &src[x + srcstride]);
1466
0
                x3 = _mm_loadl_epi64((__m128i *) &src[x + 2 * srcstride]);
1467
1468
                /* multiply by correct value : */
1469
0
                r0 = _mm_mullo_epi16(x0, f0);
1470
0
                t0 = _mm_mulhi_epi16(x0, f0);
1471
1472
0
                x0= _mm_unpacklo_epi16(r0,t0);
1473
1474
0
                r1 = _mm_mullo_epi16(x1, f1);
1475
0
                t1 = _mm_mulhi_epi16(x1, f1);
1476
1477
0
                x1= _mm_unpacklo_epi16(r1,t1);
1478
1479
1480
0
                r2 = _mm_mullo_epi16(x2, f2);
1481
0
                t2 = _mm_mulhi_epi16(x2, f2);
1482
1483
0
                x2= _mm_unpacklo_epi16(r2,t2);
1484
1485
1486
0
                r3 = _mm_mullo_epi16(x3, f3);
1487
0
                t3 = _mm_mulhi_epi16(x3, f3);
1488
1489
0
                x3= _mm_unpacklo_epi16(r3,t3);
1490
1491
1492
0
                r0= _mm_add_epi32(x0,x1);
1493
0
                r1= _mm_add_epi32(x2,x3);
1494
0
                r0= _mm_add_epi32(r0,r1);
1495
0
                r0= _mm_srai_epi32(r0,2);//>> (BIT_DEPTH - 8)
1496
1497
0
                r0= _mm_packs_epi32(r0, r0);
1498
1499
                // give results back
1500
0
                _mm_storel_epi64((__m128i *) &dst[x], r0);
1501
0
            }
1502
0
            src += srcstride;
1503
0
            dst += dststride;
1504
0
        }
1505
0
    }else{
1506
0
        r1= _mm_setzero_si128();
1507
0
        for (y = 0; y < height; y++) {
1508
0
            for(x=0;x<width;x+=2){
1509
0
                x0 = _mm_loadl_epi64((__m128i *) &src[x - srcstride]);
1510
0
                x1 = _mm_loadl_epi64((__m128i *) &src[x]);
1511
0
                x2 = _mm_loadl_epi64((__m128i *) &src[x + srcstride]);
1512
0
                x3 = _mm_loadl_epi64((__m128i *) &src[x + 2 * srcstride]);
1513
1514
                /* multiply by correct value : */
1515
0
                r0 = _mm_mullo_epi16(x0, f0);
1516
0
                t0 = _mm_mulhi_epi16(x0, f0);
1517
1518
0
                x0= _mm_unpacklo_epi16(r0,t0);
1519
1520
0
                r1 = _mm_mullo_epi16(x1, f1);
1521
0
                t1 = _mm_mulhi_epi16(x1, f1);
1522
1523
0
                x1= _mm_unpacklo_epi16(r1,t1);
1524
1525
0
                r2 = _mm_mullo_epi16(x2, f2);
1526
0
                t2 = _mm_mulhi_epi16(x2, f2);
1527
1528
0
                x2= _mm_unpacklo_epi16(r2,t2);
1529
1530
0
                r3 = _mm_mullo_epi16(x3, f3);
1531
0
                t3 = _mm_mulhi_epi16(x3, f3);
1532
1533
0
                x3= _mm_unpacklo_epi16(r3,t3);
1534
1535
0
                r0= _mm_add_epi32(x0,x1);
1536
0
                r1= _mm_add_epi32(x2,x3);
1537
0
                r0= _mm_add_epi32(r0,r1);
1538
0
                r0= _mm_srai_epi32(r0,2);//>> (BIT_DEPTH - 8)
1539
1540
0
                r0= _mm_packs_epi32(r0, r0);
1541
1542
                /* give results back            */
1543
0
                _mm_maskmoveu_si128(r0,_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1),(char *) (dst+x));
1544
1545
0
            }
1546
0
            src += srcstride;
1547
0
            dst += dststride;
1548
0
        }
1549
0
    }
1550
0
}
1551
#endif
1552
1553
void ff_hevc_put_hevc_epel_hv_8_sse(int16_t *dst, ptrdiff_t dststride,
1554
                                    const uint8_t *_src, ptrdiff_t _srcstride, int width, int height, int mx,
1555
3.42M
                                    int my, int16_t* mcbuffer, int bit_depth) {
1556
3.42M
  int x, y;
1557
3.42M
  uint8_t *src = (uint8_t*) _src;
1558
3.42M
  ptrdiff_t srcstride = _srcstride;
1559
3.42M
  const int8_t *filter_h = epel_filters[mx - 1];
1560
3.42M
  const int8_t *filter_v = epel_filters[my - 1];
1561
3.42M
  __m128i r0, bshuffle1, bshuffle2, x0, x1, x2, x3, t0, t1, t2, t3, f0, f1,
1562
3.42M
  f2, f3, r1, r2;
1563
3.42M
  int8_t filter_0 = filter_h[0];
1564
3.42M
  int8_t filter_1 = filter_h[1];
1565
3.42M
  int8_t filter_2 = filter_h[2];
1566
3.42M
  int8_t filter_3 = filter_h[3];
1567
3.42M
  int16_t *tmp = mcbuffer;
1568
3.42M
  r0 = _mm_set_epi8(filter_3, filter_2, filter_1, filter_0, filter_3,
1569
3.42M
      filter_2, filter_1, filter_0, filter_3, filter_2, filter_1,
1570
3.42M
      filter_0, filter_3, filter_2, filter_1, filter_0);
1571
3.42M
  bshuffle1 = _mm_set_epi8(6, 5, 4, 3, 5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0);
1572
1573
3.42M
  src -= epel_extra_before * srcstride;
1574
1575
3.42M
  f3 = _mm_set1_epi16(filter_v[3]);
1576
3.42M
  f1 = _mm_set1_epi16(filter_v[1]);
1577
3.42M
  f2 = _mm_set1_epi16(filter_v[2]);
1578
3.42M
  f0 = _mm_set1_epi16(filter_v[0]);
1579
1580
  /* horizontal treatment */
1581
3.42M
  if(!(width & 7)){
1582
552k
    bshuffle2 = _mm_set_epi8(10, 9, 8, 7, 9, 8, 7, 6, 8, 7, 6, 5, 7, 6, 5,
1583
552k
        4);
1584
8.03M
    for (y = 0; y < height + epel_extra; y++) {
1585
16.8M
      for (x = 0; x < width; x += 8) {
1586
1587
9.33M
        x1 = _mm_loadu_si128((__m128i *) &src[x - 1]);
1588
9.33M
        x2 = _mm_shuffle_epi8(x1, bshuffle1);
1589
9.33M
        x3 = _mm_shuffle_epi8(x1, bshuffle2);
1590
1591
        /*  PMADDUBSW then PMADDW     */
1592
9.33M
        x2 = _mm_maddubs_epi16(x2, r0);
1593
9.33M
        x3 = _mm_maddubs_epi16(x3, r0);
1594
9.33M
        x2 = _mm_hadd_epi16(x2, x3);
1595
9.33M
        _mm_store_si128((__m128i *) &tmp[x], x2);
1596
9.33M
      }
1597
7.48M
      src += srcstride;
1598
7.48M
      tmp += MAX_PB_SIZE;
1599
7.48M
    }
1600
552k
    tmp = mcbuffer + epel_extra_before * MAX_PB_SIZE;
1601
1602
    /* vertical treatment */
1603
1604
6.37M
    for (y = 0; y < height; y++) {
1605
13.1M
      for (x = 0; x < width; x += 8) {
1606
        /* check if memory needs to be reloaded */
1607
7.32M
        x0 = _mm_load_si128((__m128i *) &tmp[x - MAX_PB_SIZE]);
1608
7.32M
        x1 = _mm_load_si128((__m128i *) &tmp[x]);
1609
7.32M
        x2 = _mm_load_si128((__m128i *) &tmp[x + MAX_PB_SIZE]);
1610
7.32M
        x3 = _mm_load_si128((__m128i *) &tmp[x + 2 * MAX_PB_SIZE]);
1611
1612
7.32M
        r0 = _mm_mullo_epi16(x0, f0);
1613
7.32M
        r1 = _mm_mulhi_epi16(x0, f0);
1614
7.32M
        r2 = _mm_mullo_epi16(x1, f1);
1615
7.32M
        t0 = _mm_unpacklo_epi16(r0, r1);
1616
7.32M
        x0 = _mm_unpackhi_epi16(r0, r1);
1617
7.32M
        r0 = _mm_mulhi_epi16(x1, f1);
1618
7.32M
        r1 = _mm_mullo_epi16(x2, f2);
1619
7.32M
        t1 = _mm_unpacklo_epi16(r2, r0);
1620
7.32M
        x1 = _mm_unpackhi_epi16(r2, r0);
1621
7.32M
        r2 = _mm_mulhi_epi16(x2, f2);
1622
7.32M
        r0 = _mm_mullo_epi16(x3, f3);
1623
7.32M
        t2 = _mm_unpacklo_epi16(r1, r2);
1624
7.32M
        x2 = _mm_unpackhi_epi16(r1, r2);
1625
7.32M
        r1 = _mm_mulhi_epi16(x3, f3);
1626
7.32M
        t3 = _mm_unpacklo_epi16(r0, r1);
1627
7.32M
        x3 = _mm_unpackhi_epi16(r0, r1);
1628
1629
        /* multiply by correct value : */
1630
7.32M
        r0 = _mm_add_epi32(t0, t1);
1631
7.32M
        r1 = _mm_add_epi32(x0, x1);
1632
7.32M
        r0 = _mm_add_epi32(r0, t2);
1633
7.32M
        r1 = _mm_add_epi32(r1, x2);
1634
7.32M
        r0 = _mm_add_epi32(r0, t3);
1635
7.32M
        r1 = _mm_add_epi32(r1, x3);
1636
7.32M
        r0 = _mm_srai_epi32(r0, 6);
1637
7.32M
        r1 = _mm_srai_epi32(r1, 6);
1638
1639
        /* give results back            */
1640
7.32M
        r0 = _mm_packs_epi32(r0, r1);
1641
7.32M
        _mm_store_si128((__m128i *) &dst[x], r0);
1642
7.32M
      }
1643
5.82M
      tmp += MAX_PB_SIZE;
1644
5.82M
      dst += dststride;
1645
5.82M
    }
1646
2.86M
  }else if(!(width & 3)){
1647
20.9M
    for (y = 0; y < height + epel_extra; y ++) {
1648
37.8M
      for(x=0;x<width;x+=4){
1649
        /* load data in register     */
1650
19.2M
        x1 = _mm_loadl_epi64((__m128i *) &src[x-1]);
1651
1652
19.2M
        x1 = _mm_shuffle_epi8(x1, bshuffle1);
1653
1654
        /*  PMADDUBSW then PMADDW     */
1655
19.2M
        x1 = _mm_maddubs_epi16(x1, r0);
1656
19.2M
        x1 = _mm_hadd_epi16(x1, _mm_setzero_si128());
1657
1658
        /* give results back            */
1659
19.2M
        _mm_storel_epi64((__m128i *) &tmp[x], x1);
1660
1661
19.2M
      }
1662
18.6M
      src += srcstride;
1663
18.6M
      tmp += MAX_PB_SIZE;
1664
18.6M
    }
1665
2.26M
    tmp = mcbuffer + epel_extra_before * MAX_PB_SIZE;
1666
1667
    /* vertical treatment */
1668
1669
1670
14.1M
    for (y = 0; y < height; y++) {
1671
24.2M
      for (x = 0; x < width; x += 4) {
1672
        /* check if memory needs to be reloaded */
1673
12.3M
        x0 = _mm_loadl_epi64((__m128i *) &tmp[x - MAX_PB_SIZE]);
1674
12.3M
        x1 = _mm_loadl_epi64((__m128i *) &tmp[x]);
1675
12.3M
        x2 = _mm_loadl_epi64((__m128i *) &tmp[x + MAX_PB_SIZE]);
1676
12.3M
        x3 = _mm_loadl_epi64((__m128i *) &tmp[x + 2 * MAX_PB_SIZE]);
1677
1678
12.3M
        r0 = _mm_mullo_epi16(x0, f0);
1679
12.3M
        r1 = _mm_mulhi_epi16(x0, f0);
1680
12.3M
        r2 = _mm_mullo_epi16(x1, f1);
1681
12.3M
        t0 = _mm_unpacklo_epi16(r0, r1);
1682
1683
12.3M
        r0 = _mm_mulhi_epi16(x1, f1);
1684
12.3M
        r1 = _mm_mullo_epi16(x2, f2);
1685
12.3M
        t1 = _mm_unpacklo_epi16(r2, r0);
1686
1687
12.3M
        r2 = _mm_mulhi_epi16(x2, f2);
1688
12.3M
        r0 = _mm_mullo_epi16(x3, f3);
1689
12.3M
        t2 = _mm_unpacklo_epi16(r1, r2);
1690
1691
12.3M
        r1 = _mm_mulhi_epi16(x3, f3);
1692
12.3M
        t3 = _mm_unpacklo_epi16(r0, r1);
1693
1694
1695
        /* multiply by correct value : */
1696
12.3M
        r0 = _mm_add_epi32(t0, t1);
1697
12.3M
        r0 = _mm_add_epi32(r0, t2);
1698
12.3M
        r0 = _mm_add_epi32(r0, t3);
1699
12.3M
        r0 = _mm_srai_epi32(r0, 6);
1700
1701
        /* give results back            */
1702
12.3M
        r0 = _mm_packs_epi32(r0, r0);
1703
12.3M
        _mm_storel_epi64((__m128i *) &dst[x], r0);
1704
12.3M
      }
1705
11.8M
      tmp += MAX_PB_SIZE;
1706
11.8M
      dst += dststride;
1707
11.8M
    }
1708
2.26M
  }else{
1709
#if MASKMOVE
1710
    bshuffle2=_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1);
1711
#endif
1712
6.41M
    for (y = 0; y < height + epel_extra; y ++) {
1713
11.9M
      for(x=0;x<width;x+=2){
1714
        /* load data in register     */
1715
6.18M
        x1 = _mm_loadl_epi64((__m128i *) &src[x-1]);
1716
6.18M
        x1 = _mm_shuffle_epi8(x1, bshuffle1);
1717
1718
        /*  PMADDUBSW then PMADDW     */
1719
6.18M
        x1 = _mm_maddubs_epi16(x1, r0);
1720
6.18M
        x1 = _mm_hadd_epi16(x1, _mm_setzero_si128());
1721
1722
        /* give results back            */
1723
#if MASKMOVE
1724
        _mm_maskmoveu_si128(x1,bshuffle2,(char *) (tmp+x));
1725
#else
1726
6.18M
                                *((uint32_t*)(tmp+x)) = _mm_cvtsi128_si32(x1);
1727
6.18M
#endif
1728
6.18M
      }
1729
5.80M
      src += srcstride;
1730
5.80M
      tmp += MAX_PB_SIZE;
1731
5.80M
    }
1732
1733
607k
    tmp = mcbuffer + epel_extra_before * MAX_PB_SIZE;
1734
1735
    /* vertical treatment */
1736
1737
4.59M
    for (y = 0; y < height; y++) {
1738
8.25M
      for (x = 0; x < width; x += 2) {
1739
        /* check if memory needs to be reloaded */
1740
4.27M
        x0 = _mm_loadl_epi64((__m128i *) &tmp[x - MAX_PB_SIZE]);
1741
4.27M
        x1 = _mm_loadl_epi64((__m128i *) &tmp[x]);
1742
4.27M
        x2 = _mm_loadl_epi64((__m128i *) &tmp[x + MAX_PB_SIZE]);
1743
4.27M
        x3 = _mm_loadl_epi64((__m128i *) &tmp[x + 2 * MAX_PB_SIZE]);
1744
1745
4.27M
        r0 = _mm_mullo_epi16(x0, f0);
1746
4.27M
        r1 = _mm_mulhi_epi16(x0, f0);
1747
4.27M
        r2 = _mm_mullo_epi16(x1, f1);
1748
4.27M
        t0 = _mm_unpacklo_epi16(r0, r1);
1749
4.27M
        r0 = _mm_mulhi_epi16(x1, f1);
1750
4.27M
        r1 = _mm_mullo_epi16(x2, f2);
1751
4.27M
        t1 = _mm_unpacklo_epi16(r2, r0);
1752
4.27M
        r2 = _mm_mulhi_epi16(x2, f2);
1753
4.27M
        r0 = _mm_mullo_epi16(x3, f3);
1754
4.27M
        t2 = _mm_unpacklo_epi16(r1, r2);
1755
4.27M
        r1 = _mm_mulhi_epi16(x3, f3);
1756
4.27M
        t3 = _mm_unpacklo_epi16(r0, r1);
1757
1758
        /* multiply by correct value : */
1759
4.27M
        r0 = _mm_add_epi32(t0, t1);
1760
4.27M
        r0 = _mm_add_epi32(r0, t2);
1761
4.27M
        r0 = _mm_add_epi32(r0, t3);
1762
4.27M
        r0 = _mm_srai_epi32(r0, 6);
1763
        /* give results back            */
1764
4.27M
        r0 = _mm_packs_epi32(r0, r0);
1765
#if MASKMOVE
1766
        _mm_maskmoveu_si128(r0,bshuffle2,(char *) (dst+x));
1767
#else
1768
4.27M
                                *((uint32_t*)(dst+x)) = _mm_cvtsi128_si32(r0);
1769
4.27M
#endif
1770
4.27M
      }
1771
3.98M
      tmp += MAX_PB_SIZE;
1772
3.98M
      dst += dststride;
1773
3.98M
    }
1774
607k
  }
1775
1776
3.42M
}
1777
1778
1779
#ifndef __native_client__
1780
void ff_hevc_put_hevc_epel_hv_10_sse(int16_t *dst, ptrdiff_t dststride,
1781
                                     const uint8_t *_src, ptrdiff_t _srcstride, int width, int height, int mx,
1782
0
        int my, int16_t* mcbuffer) {
1783
0
    int x, y;
1784
0
    uint16_t *src = (uint16_t*) _src;
1785
0
    ptrdiff_t srcstride = _srcstride>>1;
1786
0
    const int8_t *filter_h = epel_filters[mx - 1];
1787
0
    const int8_t *filter_v = epel_filters[my - 1];
1788
0
    __m128i r0, bshuffle1, bshuffle2, x0, x1, x2, x3, t0, t1, t2, t3, f0, f1,
1789
0
    f2, f3, r1, r2, r3;
1790
0
    int8_t filter_0 = filter_h[0];
1791
0
    int8_t filter_1 = filter_h[1];
1792
0
    int8_t filter_2 = filter_h[2];
1793
0
    int8_t filter_3 = filter_h[3];
1794
0
    int16_t *tmp = mcbuffer;
1795
1796
0
    r0 = _mm_set_epi16(filter_3, filter_2, filter_1,
1797
0
                filter_0, filter_3, filter_2, filter_1, filter_0);
1798
0
        bshuffle1 = _mm_set_epi8(9,8,7,6,5,4, 3, 2,7,6,5,4, 3, 2, 1, 0);
1799
1800
0
    src -= epel_extra_before * srcstride;
1801
1802
0
    f0 = _mm_set1_epi16(filter_v[0]);
1803
0
    f1 = _mm_set1_epi16(filter_v[1]);
1804
0
    f2 = _mm_set1_epi16(filter_v[2]);
1805
0
    f3 = _mm_set1_epi16(filter_v[3]);
1806
1807
1808
    /* horizontal treatment */
1809
0
    if(!(width & 3)){
1810
0
        bshuffle2 = _mm_set_epi8(13,12,11,10,9,8,7,6,11,10, 9,8,7,6,5, 4);
1811
0
        for (y = 0; y < height + epel_extra; y ++) {
1812
0
            for(x=0;x<width;x+=4){
1813
1814
0
                x1 = _mm_loadu_si128((__m128i *) &src[x-1]);
1815
0
                x2 = _mm_shuffle_epi8(x1, bshuffle1);
1816
0
                x3 = _mm_shuffle_epi8(x1, bshuffle2);
1817
1818
1819
0
                x2 = _mm_madd_epi16(x2, r0);
1820
0
                x3 = _mm_madd_epi16(x3, r0);
1821
0
                x2 = _mm_hadd_epi32(x2, x3);
1822
0
                x2= _mm_srai_epi32(x2,2);   //>> (BIT_DEPTH - 8)
1823
1824
0
                x2 = _mm_packs_epi32(x2,r0);
1825
                //give results back
1826
0
                _mm_storel_epi64((__m128i *) &tmp[x], x2);
1827
1828
0
            }
1829
0
            src += srcstride;
1830
0
            tmp += MAX_PB_SIZE;
1831
0
        }
1832
0
        tmp = mcbuffer + epel_extra_before * MAX_PB_SIZE;
1833
1834
        // vertical treatment
1835
1836
1837
0
        for (y = 0; y < height; y++) {
1838
0
            for (x = 0; x < width; x += 4) {
1839
0
                x0 = _mm_loadl_epi64((__m128i *) &tmp[x - MAX_PB_SIZE]);
1840
0
                x1 = _mm_loadl_epi64((__m128i *) &tmp[x]);
1841
0
                x2 = _mm_loadl_epi64((__m128i *) &tmp[x + MAX_PB_SIZE]);
1842
0
                x3 = _mm_loadl_epi64((__m128i *) &tmp[x + 2 * MAX_PB_SIZE]);
1843
1844
0
                r0 = _mm_mullo_epi16(x0, f0);
1845
0
                r1 = _mm_mulhi_epi16(x0, f0);
1846
0
                r2 = _mm_mullo_epi16(x1, f1);
1847
0
                t0 = _mm_unpacklo_epi16(r0, r1);
1848
1849
0
                r0 = _mm_mulhi_epi16(x1, f1);
1850
0
                r1 = _mm_mullo_epi16(x2, f2);
1851
0
                t1 = _mm_unpacklo_epi16(r2, r0);
1852
1853
0
                r2 = _mm_mulhi_epi16(x2, f2);
1854
0
                r0 = _mm_mullo_epi16(x3, f3);
1855
0
                t2 = _mm_unpacklo_epi16(r1, r2);
1856
1857
0
                r1 = _mm_mulhi_epi16(x3, f3);
1858
0
                t3 = _mm_unpacklo_epi16(r0, r1);
1859
1860
1861
1862
0
                r0 = _mm_add_epi32(t0, t1);
1863
0
                r0 = _mm_add_epi32(r0, t2);
1864
0
                r0 = _mm_add_epi32(r0, t3);
1865
0
                r0 = _mm_srai_epi32(r0, 6);
1866
1867
                // give results back
1868
0
                r0 = _mm_packs_epi32(r0, r0);
1869
0
                _mm_storel_epi64((__m128i *) &dst[x], r0);
1870
0
            }
1871
0
            tmp += MAX_PB_SIZE;
1872
0
            dst += dststride;
1873
0
        }
1874
0
    }else{
1875
0
        bshuffle2=_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1);
1876
0
        r1= _mm_setzero_si128();
1877
0
        for (y = 0; y < height + epel_extra; y ++) {
1878
0
            for(x=0;x<width;x+=2){
1879
                /* load data in register     */
1880
0
                x1 = _mm_loadu_si128((__m128i *) &src[x-1]);
1881
0
                x2 = _mm_shuffle_epi8(x1, bshuffle1);
1882
1883
                /*  PMADDUBSW then PMADDW     */
1884
0
                x2 = _mm_madd_epi16(x2, r0);
1885
0
                x2 = _mm_hadd_epi32(x2, r1);
1886
0
                x2= _mm_srai_epi32(x2,2);   //>> (BIT_DEPTH - 8)
1887
0
                x2 = _mm_packs_epi32(x2, r1);
1888
                /* give results back            */
1889
0
                _mm_maskmoveu_si128(x2,bshuffle2,(char *) (tmp+x));
1890
0
            }
1891
0
            src += srcstride;
1892
0
            tmp += MAX_PB_SIZE;
1893
0
        }
1894
1895
0
        tmp = mcbuffer + epel_extra_before * MAX_PB_SIZE;
1896
1897
        /* vertical treatment */
1898
1899
0
        for (y = 0; y < height; y++) {
1900
0
            for (x = 0; x < width; x += 2) {
1901
                /* check if memory needs to be reloaded */
1902
0
                x0 = _mm_loadl_epi64((__m128i *) &tmp[x - MAX_PB_SIZE]);
1903
0
                x1 = _mm_loadl_epi64((__m128i *) &tmp[x]);
1904
0
                x2 = _mm_loadl_epi64((__m128i *) &tmp[x + MAX_PB_SIZE]);
1905
0
                x3 = _mm_loadl_epi64((__m128i *) &tmp[x + 2 * MAX_PB_SIZE]);
1906
1907
0
                r0 = _mm_mullo_epi16(x0, f0);
1908
0
                t0 = _mm_mulhi_epi16(x0, f0);
1909
1910
0
                x0= _mm_unpacklo_epi16(r0,t0);
1911
1912
0
                r1 = _mm_mullo_epi16(x1, f1);
1913
0
                t1 = _mm_mulhi_epi16(x1, f1);
1914
1915
0
                x1= _mm_unpacklo_epi16(r1,t1);
1916
1917
0
                r2 = _mm_mullo_epi16(x2, f2);
1918
0
                t2 = _mm_mulhi_epi16(x2, f2);
1919
1920
0
                x2= _mm_unpacklo_epi16(r2,t2);
1921
1922
0
                r3 = _mm_mullo_epi16(x3, f3);
1923
0
                t3 = _mm_mulhi_epi16(x3, f3);
1924
1925
0
                x3= _mm_unpacklo_epi16(r3,t3);
1926
1927
0
                r0= _mm_add_epi32(x0,x1);
1928
0
                r1= _mm_add_epi32(x2,x3);
1929
0
                r0= _mm_add_epi32(r0,r1);
1930
0
                r0 = _mm_srai_epi32(r0, 6);
1931
                /* give results back            */
1932
0
                r0 = _mm_packs_epi32(r0, r0);
1933
0
                _mm_maskmoveu_si128(r0,bshuffle2,(char *) (dst+x));
1934
0
            }
1935
0
            tmp += MAX_PB_SIZE;
1936
0
            dst += dststride;
1937
0
        }
1938
0
    }
1939
0
}
1940
#endif
1941
1942
void ff_hevc_put_hevc_qpel_pixels_8_sse(int16_t *dst, ptrdiff_t dststride,
1943
                                        const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
1944
3.32M
        int16_t* mcbuffer) {
1945
3.32M
    int x, y;
1946
3.32M
    __m128i x1, x2, x3, x0;
1947
3.32M
    uint8_t *src = (uint8_t*) _src;
1948
3.32M
    ptrdiff_t srcstride = _srcstride;
1949
3.32M
    x0= _mm_setzero_si128();
1950
3.32M
    if(!(width & 15)){
1951
10.5M
        for (y = 0; y < height; y++) {
1952
24.2M
            for (x = 0; x < width; x += 16) {
1953
1954
14.2M
                x1 = _mm_loadu_si128((__m128i *) &src[x]);
1955
14.2M
                x2 = _mm_unpacklo_epi8(x1, x0);
1956
1957
14.2M
                x3 = _mm_unpackhi_epi8(x1, x0);
1958
1959
14.2M
                x2 = _mm_slli_epi16(x2, 6);
1960
14.2M
                x3 = _mm_slli_epi16(x3, 6);
1961
14.2M
                _mm_storeu_si128((__m128i *) &dst[x], x2);
1962
14.2M
                _mm_storeu_si128((__m128i *) &dst[x + 8], x3);
1963
1964
14.2M
            }
1965
9.96M
            src += srcstride;
1966
9.96M
            dst += dststride;
1967
9.96M
        }
1968
2.78M
    }else if(!(width & 7)){
1969
21.1M
        for (y = 0; y < height; y++) {
1970
37.9M
            for (x = 0; x < width; x += 8) {
1971
1972
19.1M
                x1 = _mm_loadu_si128((__m128i *) &src[x]);
1973
19.1M
                x2 = _mm_unpacklo_epi8(x1, x0);
1974
19.1M
                x2 = _mm_slli_epi16(x2, 6);
1975
19.1M
                _mm_storeu_si128((__m128i *) &dst[x], x2);
1976
1977
19.1M
            }
1978
18.7M
            src += srcstride;
1979
18.7M
            dst += dststride;
1980
18.7M
        }
1981
2.40M
    }else if(!(width & 3)){
1982
3.62M
        for (y = 0; y < height; y++) {
1983
7.01M
            for(x=0;x<width;x+=4){
1984
3.75M
                x1 = _mm_loadu_si128((__m128i *) &src[x]);
1985
3.75M
                x2 = _mm_unpacklo_epi8(x1, x0);
1986
3.75M
                x2 = _mm_slli_epi16(x2, 6);
1987
3.75M
                _mm_storel_epi64((__m128i *) &dst[x], x2);
1988
3.75M
            }
1989
3.25M
            src += srcstride;
1990
3.25M
            dst += dststride;
1991
3.25M
        }
1992
375k
    }else{
1993
#if MASKMOVE
1994
        x4= _mm_set_epi32(0,0,0,-1); //mask to store
1995
#endif
1996
0
        for (y = 0; y < height; y++) {
1997
0
                    for(x=0;x<width;x+=2){
1998
0
                        x1 = _mm_loadl_epi64((__m128i *) &src[x]);
1999
0
                        x2 = _mm_unpacklo_epi8(x1, x0);
2000
0
                        x2 = _mm_slli_epi16(x2, 6);
2001
#if MASKMOVE
2002
                        _mm_maskmoveu_si128(x2,x4,(char *) (dst+x));
2003
#else
2004
0
                        *((uint16_t*)(dst+x)) = _mm_cvtsi128_si32(x2);
2005
0
#endif
2006
0
                    }
2007
0
                    src += srcstride;
2008
0
                    dst += dststride;
2009
0
                }
2010
0
    }
2011
2012
2013
3.32M
}
2014
2015
#ifndef __native_client__
2016
void ff_hevc_put_hevc_qpel_pixels_10_sse(int16_t *dst, ptrdiff_t dststride,
2017
                                         const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2018
0
        int16_t* mcbuffer) {
2019
0
    int x, y;
2020
0
    __m128i x1, x2, x4;
2021
0
    uint16_t *src = (uint16_t*) _src;
2022
0
    ptrdiff_t srcstride = _srcstride>>1;
2023
0
    if(!(width & 7)){
2024
0
        for (y = 0; y < height; y++) {
2025
0
            for (x = 0; x < width; x += 8) {
2026
2027
0
                x1 = _mm_loadu_si128((__m128i *) &src[x]);
2028
0
                x2 = _mm_slli_epi16(x1, 4); //14-BIT DEPTH
2029
0
                _mm_storeu_si128((__m128i *) &dst[x], x2);
2030
2031
0
            }
2032
0
            src += srcstride;
2033
0
            dst += dststride;
2034
0
        }
2035
0
    }else if(!(width & 3)){
2036
0
        for (y = 0; y < height; y++) {
2037
0
            for(x=0;x<width;x+=4){
2038
0
                x1 = _mm_loadl_epi64((__m128i *) &src[x]);
2039
0
                x2 = _mm_slli_epi16(x1, 4);//14-BIT DEPTH
2040
0
                _mm_storel_epi64((__m128i *) &dst[x], x2);
2041
0
            }
2042
0
            src += srcstride;
2043
0
            dst += dststride;
2044
0
        }
2045
0
    }else{
2046
0
        x4= _mm_set_epi32(0,0,0,-1); //mask to store
2047
0
        for (y = 0; y < height; y++) {
2048
0
                    for(x=0;x<width;x+=2){
2049
0
                        x1 = _mm_loadl_epi64((__m128i *) &src[x]);
2050
0
                        x2 = _mm_slli_epi16(x1, 4);//14-BIT DEPTH
2051
0
                        _mm_maskmoveu_si128(x2,x4,(char *) (dst+x));
2052
0
                    }
2053
0
                    src += srcstride;
2054
0
                    dst += dststride;
2055
0
                }
2056
0
    }
2057
2058
2059
0
}
2060
#endif
2061
2062
2063
void ff_hevc_put_hevc_qpel_h_1_8_sse(int16_t *dst, ptrdiff_t dststride,
2064
                                     const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2065
217k
        int16_t* mcbuffer) {
2066
217k
    int x, y;
2067
217k
    const uint8_t *src = _src;
2068
217k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
2069
217k
    __m128i x1, r0, x2, x3, x4, x5;
2070
2071
217k
    r0 = _mm_set_epi8(0, 1, -5, 17, 58, -10, 4, -1, 0, 1, -5, 17, 58, -10, 4,
2072
217k
            -1);
2073
2074
217k
    if(!(width & 7)){
2075
1.97M
        for (y = 0; y < height; y++) {
2076
4.54M
            for (x = 0; x < width; x += 8) {
2077
                /* load data in register     */
2078
2.75M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
2079
2.75M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2080
2.75M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2081
2.75M
                        _mm_srli_si128(x1, 3));
2082
2.75M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
2083
2.75M
                        _mm_srli_si128(x1, 5));
2084
2.75M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
2085
2.75M
                        _mm_srli_si128(x1, 7));
2086
2087
                /*  PMADDUBSW then PMADDW     */
2088
2.75M
                x2 = _mm_maddubs_epi16(x2, r0);
2089
2.75M
                x3 = _mm_maddubs_epi16(x3, r0);
2090
2.75M
                x4 = _mm_maddubs_epi16(x4, r0);
2091
2.75M
                x5 = _mm_maddubs_epi16(x5, r0);
2092
2.75M
                x2 = _mm_hadd_epi16(x2, x3);
2093
2.75M
                x4 = _mm_hadd_epi16(x4, x5);
2094
2.75M
                x2 = _mm_hadd_epi16(x2, x4);
2095
                /* give results back            */
2096
2.75M
                _mm_store_si128((__m128i *) &dst[x],x2);
2097
2098
2.75M
            }
2099
1.78M
            src += srcstride;
2100
1.78M
            dst += dststride;
2101
1.78M
        }
2102
187k
    }else if(!(width &3)){
2103
2104
290k
        for (y = 0; y < height; y ++) {
2105
552k
            for(x=0;x<width;x+=4){
2106
            /* load data in register     */
2107
293k
            x1 = _mm_loadu_si128((__m128i *) &src[x-3]);
2108
293k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2109
293k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2110
293k
                    _mm_srli_si128(x1, 3));
2111
2112
            /*  PMADDUBSW then PMADDW     */
2113
293k
            x2 = _mm_maddubs_epi16(x2, r0);
2114
293k
            x3 = _mm_maddubs_epi16(x3, r0);
2115
293k
            x2 = _mm_hadd_epi16(x2, x3);
2116
293k
            x2 = _mm_hadd_epi16(x2, x2);
2117
2118
            /* give results back            */
2119
293k
            _mm_storel_epi64((__m128i *) &dst[x], x2);
2120
293k
            }
2121
2122
259k
            src += srcstride;
2123
259k
            dst += dststride;
2124
259k
        }
2125
30.5k
    }else{
2126
0
        x5= _mm_setzero_si128();
2127
#if MASKMOVE
2128
        x3= _mm_set_epi32(0,0,0,-1);
2129
#endif
2130
0
        for (y = 0; y < height; y ++) {
2131
0
            for(x=0;x<width;x+=4){
2132
            /* load data in register     */
2133
0
            x1 = _mm_loadu_si128((__m128i *) &src[x-3]);
2134
0
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2135
2136
2137
2138
            /*  PMADDUBSW then PMADDW     */
2139
0
            x2 = _mm_maddubs_epi16(x2, r0);
2140
0
            x2 = _mm_hadd_epi16(x2,x5 );
2141
0
            x2 = _mm_hadd_epi16(x2,x5 );
2142
2143
            /* give results back            */
2144
            //_mm_storel_epi64((__m128i *) &dst[x], x2);
2145
#if MASKMOVE
2146
            _mm_maskmoveu_si128(x2,x3,(char *) (dst+x));
2147
#else
2148
0
            *((uint16_t*)(dst+x)) = _mm_cvtsi128_si32(x2);
2149
0
#endif
2150
0
            }
2151
2152
0
            src += srcstride;
2153
0
            dst += dststride;
2154
0
        }
2155
0
    }
2156
2157
217k
}
2158
#ifndef __native_client__
2159
/*
2160
 * @TODO : Valgrind to see if it's useful to use SSE or wait for AVX2 implementation
2161
 */
2162
void ff_hevc_put_hevc_qpel_h_1_10_sse(int16_t *dst, ptrdiff_t dststride,
2163
                                      const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2164
0
        int16_t* mcbuffer) {
2165
0
    int x, y;
2166
0
    uint16_t *src = (uint16_t*)_src;
2167
0
    ptrdiff_t srcstride = _srcstride>>1;
2168
0
    __m128i x0, x1, x2, x3, r0;
2169
2170
0
    r0 = _mm_set_epi16(0, 1, -5, 17, 58, -10, 4, -1);
2171
0
    x0= _mm_setzero_si128();
2172
0
    x3= _mm_set_epi32(0,0,0,-1);
2173
0
    for (y = 0; y < height; y ++) {
2174
0
        for(x=0;x<width;x+=2){
2175
0
            x1 = _mm_loadu_si128((__m128i *) &src[x-3]);
2176
0
            x2 = _mm_srli_si128(x1,2); //last 16bit not used so 1 load can be used for 2 dst
2177
2178
0
            x1 = _mm_madd_epi16(x1,r0);
2179
0
            x2 = _mm_madd_epi16(x2,r0);
2180
2181
0
            x1 = _mm_hadd_epi32(x1,x2);
2182
0
            x1 = _mm_hadd_epi32(x1,x0);
2183
0
            x1= _mm_srai_epi32(x1,2); //>>BIT_DEPTH-8
2184
0
            x1= _mm_packs_epi32(x1,x0);
2185
         //   dst[x]= _mm_extract_epi16(x1,0);
2186
0
            _mm_maskmoveu_si128(x1,x3,(char *) (dst+x));
2187
0
        }
2188
0
        src += srcstride;
2189
0
        dst += dststride;
2190
0
    }
2191
2192
0
}
2193
#endif
2194
2195
2196
void ff_hevc_put_hevc_qpel_h_2_8_sse(int16_t *dst, ptrdiff_t dststride,
2197
                                     const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2198
120k
        int16_t* mcbuffer) {
2199
120k
    int x, y;
2200
120k
    const uint8_t *src = _src;
2201
120k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
2202
120k
    __m128i x1, r0, x2, x3, x4, x5;
2203
2204
120k
    r0 = _mm_set_epi8(-1, 4, -11, 40, 40, -11, 4, -1, -1, 4, -11, 40, 40, -11,
2205
120k
            4, -1);
2206
2207
    /* LOAD src from memory to registers to limit memory bandwidth */
2208
120k
    if(!(width - 15)){
2209
0
        for (y = 0; y < height; y++) {
2210
0
                    for (x = 0; x < width; x += 8) {
2211
                        /* load data in register     */
2212
0
                        x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
2213
0
                        x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2214
0
                        x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2215
0
                                _mm_srli_si128(x1, 3));
2216
0
                        x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
2217
0
                                _mm_srli_si128(x1, 5));
2218
0
                        x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
2219
0
                                _mm_srli_si128(x1, 7));
2220
2221
                        /*  PMADDUBSW then PMADDW     */
2222
0
                        x2 = _mm_maddubs_epi16(x2, r0);
2223
0
                        x3 = _mm_maddubs_epi16(x3, r0);
2224
0
                        x4 = _mm_maddubs_epi16(x4, r0);
2225
0
                        x5 = _mm_maddubs_epi16(x5, r0);
2226
0
                        x2 = _mm_hadd_epi16(x2, x3);
2227
0
                        x4 = _mm_hadd_epi16(x4, x5);
2228
0
                        x2 = _mm_hadd_epi16(x2, x4);
2229
                        /* give results back            */
2230
0
                        _mm_store_si128((__m128i *) &dst[x],x2);
2231
0
                    }
2232
0
                    src += srcstride;
2233
0
                    dst += dststride;
2234
0
                }
2235
2236
120k
    }else{
2237
2238
1.27M
        for (y = 0; y < height; y ++) {
2239
4.61M
            for(x=0;x<width;x+=4){
2240
            /* load data in register     */
2241
3.46M
            x1 = _mm_loadu_si128((__m128i *) &src[x-3]);
2242
2243
3.46M
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2244
3.46M
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2245
3.46M
                    _mm_srli_si128(x1, 3));
2246
2247
2248
            /*  PMADDUBSW then PMADDW     */
2249
3.46M
            x2 = _mm_maddubs_epi16(x2, r0);
2250
3.46M
            x3 = _mm_maddubs_epi16(x3, r0);
2251
3.46M
            x2 = _mm_hadd_epi16(x2, x3);
2252
3.46M
            x2 = _mm_hadd_epi16(x2, _mm_setzero_si128());
2253
2254
            /* give results back            */
2255
3.46M
            _mm_storel_epi64((__m128i *) &dst[x], x2);
2256
2257
3.46M
            }
2258
1.15M
            src += srcstride;
2259
1.15M
            dst += dststride;
2260
1.15M
        }
2261
120k
    }
2262
2263
120k
}
2264
2265
#if 0
2266
static void ff_hevc_put_hevc_qpel_h_2_sse(int16_t *dst, ptrdiff_t dststride,
2267
                                          const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2268
        int16_t* mcbuffer) {
2269
    int x, y;
2270
    uint8_t *src = _src;
2271
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
2272
    __m128i x1, r0, x2, x3, x4, x5;
2273
2274
    r0 = _mm_set_epi8(-1, 4, -11, 40, 40, -11, 4, -1, -1, 4, -11, 40, 40, -11,
2275
            4, -1);
2276
2277
    /* LOAD src from memory to registers to limit memory bandwidth */
2278
    if(!(width & 7)){
2279
        for (y = 0; y < height; y++) {
2280
                    for (x = 0; x < width; x += 8) {
2281
                        /* load data in register     */
2282
                        x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
2283
                        x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2284
                        x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2285
                                _mm_srli_si128(x1, 3));
2286
                        x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
2287
                                _mm_srli_si128(x1, 5));
2288
                        x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
2289
                                _mm_srli_si128(x1, 7));
2290
2291
                        /*  PMADDUBSW then PMADDW     */
2292
                        x2 = _mm_maddubs_epi16(x2, r0);
2293
                        x3 = _mm_maddubs_epi16(x3, r0);
2294
                        x4 = _mm_maddubs_epi16(x4, r0);
2295
                        x5 = _mm_maddubs_epi16(x5, r0);
2296
                        x2 = _mm_hadd_epi16(x2, x3);
2297
                        x4 = _mm_hadd_epi16(x4, x5);
2298
                        x2 = _mm_hadd_epi16(x2, x4);
2299
                        /* give results back            */
2300
                        _mm_store_si128((__m128i *) &dst[x],x2);
2301
                    }
2302
                    src += srcstride;
2303
                    dst += dststride;
2304
                }
2305
2306
    }else{
2307
2308
        for (y = 0; y < height; y ++) {
2309
            for(x=0;x<width;x+=4){
2310
            /* load data in register     */
2311
            x1 = _mm_loadu_si128((__m128i *) &src[x-3]);
2312
2313
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2314
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2315
                    _mm_srli_si128(x1, 3));
2316
2317
2318
            /*  PMADDUBSW then PMADDW     */
2319
            x2 = _mm_maddubs_epi16(x2, r0);
2320
            x3 = _mm_maddubs_epi16(x3, r0);
2321
            x2 = _mm_hadd_epi16(x2, x3);
2322
            x2 = _mm_hadd_epi16(x2, _mm_setzero_si128());
2323
2324
            /* give results back            */
2325
            _mm_storel_epi64((__m128i *) &dst[x], x2);
2326
2327
            }
2328
            src += srcstride;
2329
            dst += dststride;
2330
        }
2331
    }
2332
2333
}
2334
static void ff_hevc_put_hevc_qpel_h_3_sse(int16_t *dst, ptrdiff_t dststride,
2335
                                          const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2336
        int16_t* mcbuffer) {
2337
    int x, y;
2338
    uint8_t *src = _src;
2339
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
2340
    __m128i x1, r0, x2, x3, x4, x5;
2341
2342
    r0 = _mm_set_epi8(-1, 4, -10, 58, 17, -5, 1, 0, -1, 4, -10, 58, 17, -5, 1,
2343
            0);
2344
2345
    if(!(width & 7)){
2346
        for (y = 0; y < height; y++) {
2347
            for (x = 0; x < width; x += 8) {
2348
                /* load data in register     */
2349
                x1 = _mm_loadu_si128((__m128i *) &src[x - 2]);
2350
                x1 = _mm_slli_si128(x1, 1);
2351
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2352
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2353
                        _mm_srli_si128(x1, 3));
2354
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
2355
                        _mm_srli_si128(x1, 5));
2356
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
2357
                        _mm_srli_si128(x1, 7));
2358
2359
                /*  PMADDUBSW then PMADDW     */
2360
                x2 = _mm_maddubs_epi16(x2, r0);
2361
                x3 = _mm_maddubs_epi16(x3, r0);
2362
                x4 = _mm_maddubs_epi16(x4, r0);
2363
                x5 = _mm_maddubs_epi16(x5, r0);
2364
                x2 = _mm_hadd_epi16(x2, x3);
2365
                x4 = _mm_hadd_epi16(x4, x5);
2366
                x2 = _mm_hadd_epi16(x2, x4);
2367
                /* give results back            */
2368
                _mm_store_si128((__m128i *) &dst[x],
2369
                        _mm_srli_si128(x2, BIT_DEPTH - 8));
2370
            }
2371
            src += srcstride;
2372
            dst += dststride;
2373
        }
2374
    }else{
2375
        for (y = 0; y < height; y ++) {
2376
            for(x=0;x<width;x+=4){
2377
                /* load data in register     */
2378
                x1 = _mm_loadu_si128((__m128i *) &src[x-2]);
2379
                x1 = _mm_slli_si128(x1, 1);
2380
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2381
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2382
                        _mm_srli_si128(x1, 3));
2383
2384
                /*  PMADDUBSW then PMADDW     */
2385
                x2 = _mm_maddubs_epi16(x2, r0);
2386
                x3 = _mm_maddubs_epi16(x3, r0);
2387
                x2 = _mm_hadd_epi16(x2, x3);
2388
                x2 = _mm_hadd_epi16(x2, _mm_setzero_si128());
2389
                x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
2390
                /* give results back            */
2391
                _mm_storel_epi64((__m128i *) &dst[x], x2);
2392
2393
            }
2394
            src += srcstride;
2395
            dst += dststride;
2396
        }
2397
    }
2398
}
2399
#endif
2400
2401
void ff_hevc_put_hevc_qpel_h_3_8_sse(int16_t *dst, ptrdiff_t dststride,
2402
                                     const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2403
254k
        int16_t* mcbuffer) {
2404
254k
    int x, y;
2405
254k
    const uint8_t *src = _src;
2406
254k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
2407
254k
    __m128i x1, r0, x2, x3, x4, x5;
2408
2409
254k
    r0 = _mm_set_epi8(-1, 4, -10, 58, 17, -5, 1, 0, -1, 4, -10, 58, 17, -5, 1,
2410
254k
            0);
2411
2412
254k
    if(!(width & 7)){
2413
2.33M
        for (y = 0; y < height; y++) {
2414
5.60M
            for (x = 0; x < width; x += 8) {
2415
                /* load data in register     */
2416
3.48M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 2]);
2417
3.48M
                x1 = _mm_slli_si128(x1, 1);
2418
3.48M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2419
3.48M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2420
3.48M
                        _mm_srli_si128(x1, 3));
2421
3.48M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
2422
3.48M
                        _mm_srli_si128(x1, 5));
2423
3.48M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
2424
3.48M
                        _mm_srli_si128(x1, 7));
2425
2426
                /*  PMADDUBSW then PMADDW     */
2427
3.48M
                x2 = _mm_maddubs_epi16(x2, r0);
2428
3.48M
                x3 = _mm_maddubs_epi16(x3, r0);
2429
3.48M
                x4 = _mm_maddubs_epi16(x4, r0);
2430
3.48M
                x5 = _mm_maddubs_epi16(x5, r0);
2431
3.48M
                x2 = _mm_hadd_epi16(x2, x3);
2432
3.48M
                x4 = _mm_hadd_epi16(x4, x5);
2433
3.48M
                x2 = _mm_hadd_epi16(x2, x4);
2434
                /* give results back            */
2435
3.48M
                _mm_store_si128((__m128i *) &dst[x],x2);
2436
3.48M
            }
2437
2.11M
            src += srcstride;
2438
2.11M
            dst += dststride;
2439
2.11M
        }
2440
217k
    }else{
2441
361k
        for (y = 0; y < height; y ++) {
2442
712k
            for(x=0;x<width;x+=4){
2443
                /* load data in register     */
2444
388k
                x1 = _mm_loadu_si128((__m128i *) &src[x-2]);
2445
388k
                x1 = _mm_slli_si128(x1, 1);
2446
388k
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
2447
388k
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
2448
388k
                        _mm_srli_si128(x1, 3));
2449
2450
                /*  PMADDUBSW then PMADDW     */
2451
388k
                x2 = _mm_maddubs_epi16(x2, r0);
2452
388k
                x3 = _mm_maddubs_epi16(x3, r0);
2453
388k
                x2 = _mm_hadd_epi16(x2, x3);
2454
388k
                x2 = _mm_hadd_epi16(x2, _mm_setzero_si128());
2455
                /* give results back            */
2456
388k
                _mm_storel_epi64((__m128i *) &dst[x], x2);
2457
2458
388k
            }
2459
324k
            src += srcstride;
2460
324k
            dst += dststride;
2461
324k
        }
2462
37.3k
    }
2463
254k
}
2464
/**
2465
 for column MC treatment, we will calculate 8 pixels at the same time by multiplying the values
2466
 of each row.
2467
2468
 */
2469
void ff_hevc_put_hevc_qpel_v_1_8_sse(int16_t *dst, ptrdiff_t dststride,
2470
                                     const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2471
219k
        int16_t* mcbuffer) {
2472
219k
    int x, y;
2473
219k
    uint8_t *src = (uint8_t*) _src;
2474
219k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
2475
219k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, r0, r1, r2;
2476
219k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
2477
219k
    r1 = _mm_set_epi16(0, 1, -5, 17, 58, -10, 4, -1);
2478
2479
219k
    if(!(width & 15)){
2480
46.4k
        x8 = _mm_setzero_si128();
2481
802k
        for (y = 0; y < height; y++) {
2482
1.72M
            for (x = 0; x < width; x += 16) {
2483
                /* check if memory needs to be reloaded */
2484
970k
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3 * srcstride]);
2485
970k
                x2 = _mm_loadu_si128((__m128i *) &src[x - 2 * srcstride]);
2486
970k
                x3 = _mm_loadu_si128((__m128i *) &src[x - srcstride]);
2487
970k
                x4 = _mm_loadu_si128((__m128i *) &src[x]);
2488
970k
                x5 = _mm_loadu_si128((__m128i *) &src[x + srcstride]);
2489
970k
                x6 = _mm_loadu_si128((__m128i *) &src[x + 2 * srcstride]);
2490
970k
                x7 = _mm_loadu_si128((__m128i *) &src[x + 3 * srcstride]);
2491
2492
970k
                t1 = _mm_unpacklo_epi8(x1,x8);
2493
970k
                t2 = _mm_unpacklo_epi8(x2, x8);
2494
970k
                t3 = _mm_unpacklo_epi8(x3, x8);
2495
970k
                t4 = _mm_unpacklo_epi8(x4, x8);
2496
970k
                t5 = _mm_unpacklo_epi8(x5, x8);
2497
970k
                t6 = _mm_unpacklo_epi8(x6, x8);
2498
970k
                t7 = _mm_unpacklo_epi8(x7, x8);
2499
2500
970k
                x1 = _mm_unpackhi_epi8(x1,x8);
2501
970k
                x2 = _mm_unpackhi_epi8(x2, x8);
2502
970k
                x3 = _mm_unpackhi_epi8(x3, x8);
2503
970k
                x4 = _mm_unpackhi_epi8(x4, x8);
2504
970k
                x5 = _mm_unpackhi_epi8(x5, x8);
2505
970k
                x6 = _mm_unpackhi_epi8(x6, x8);
2506
970k
                x7 = _mm_unpackhi_epi8(x7, x8);
2507
2508
                /* multiply by correct value : */
2509
970k
                r0 = _mm_mullo_epi16(t1,
2510
970k
                        _mm_set1_epi16(_mm_extract_epi16(r1, 0)));
2511
970k
                r2 = _mm_mullo_epi16(x1,
2512
970k
                        _mm_set1_epi16(_mm_extract_epi16(r1, 0)));
2513
970k
                r0 = _mm_adds_epi16(r0,
2514
970k
                        _mm_mullo_epi16(t2,
2515
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 1))));
2516
970k
                r2 = _mm_adds_epi16(r2,
2517
970k
                        _mm_mullo_epi16(x2,
2518
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 1))));
2519
970k
                r0 = _mm_adds_epi16(r0,
2520
970k
                        _mm_mullo_epi16(t3,
2521
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
2522
970k
                r2 = _mm_adds_epi16(r2,
2523
970k
                        _mm_mullo_epi16(x3,
2524
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
2525
2526
970k
                r0 = _mm_adds_epi16(r0,
2527
970k
                        _mm_mullo_epi16(t4,
2528
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
2529
970k
                r2 = _mm_adds_epi16(r2,
2530
970k
                        _mm_mullo_epi16(x4,
2531
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
2532
2533
970k
                r0 = _mm_adds_epi16(r0,
2534
970k
                        _mm_mullo_epi16(t5,
2535
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
2536
970k
                r2 = _mm_adds_epi16(r2,
2537
970k
                        _mm_mullo_epi16(x5,
2538
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
2539
2540
970k
                r0 = _mm_adds_epi16(r0,
2541
970k
                        _mm_mullo_epi16(t6,
2542
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
2543
970k
                r2 = _mm_adds_epi16(r2,
2544
970k
                        _mm_mullo_epi16(x6,
2545
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
2546
2547
970k
                r0 = _mm_adds_epi16(r0,
2548
970k
                        _mm_mullo_epi16(t7,
2549
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
2550
970k
                r2 = _mm_adds_epi16(r2,
2551
970k
                        _mm_mullo_epi16(x7,
2552
970k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
2553
2554
2555
                /* give results back            */
2556
970k
                _mm_store_si128((__m128i *) &dst[x],r0);
2557
970k
                _mm_store_si128((__m128i *) &dst[x + 8],r2);
2558
970k
            }
2559
756k
            src += srcstride;
2560
756k
            dst += dststride;
2561
756k
        }
2562
2563
173k
    }else{
2564
173k
        x = 0;
2565
173k
        x8 = _mm_setzero_si128();
2566
173k
        t8 = _mm_setzero_si128();
2567
1.56M
        for (y = 0; y < height; y ++) {
2568
3.94M
            for(x=0;x<width;x+=4){
2569
                /* load data in register  */
2570
2.54M
                x1 = _mm_loadl_epi64((__m128i *) &src[x-(3 * srcstride)]);
2571
2.54M
                x2 = _mm_loadl_epi64((__m128i *) &src[x-(2 * srcstride)]);
2572
2.54M
                x3 = _mm_loadl_epi64((__m128i *) &src[x-srcstride]);
2573
2.54M
                x4 = _mm_loadl_epi64((__m128i *) &src[x]);
2574
2.54M
                x5 = _mm_loadl_epi64((__m128i *) &src[x+srcstride]);
2575
2.54M
                x6 = _mm_loadl_epi64((__m128i *) &src[x+(2 * srcstride)]);
2576
2.54M
                x7 = _mm_loadl_epi64((__m128i *) &src[x+(3 * srcstride)]);
2577
2578
2579
2580
2.54M
                x1 = _mm_unpacklo_epi8(x1, t8);
2581
2.54M
                x2 = _mm_unpacklo_epi8(x2, t8);
2582
2.54M
                x3 = _mm_unpacklo_epi8(x3, t8);
2583
2.54M
                x4 = _mm_unpacklo_epi8(x4, t8);
2584
2.54M
                x5 = _mm_unpacklo_epi8(x5, t8);
2585
2.54M
                x6 = _mm_unpacklo_epi8(x6, t8);
2586
2.54M
                x7 = _mm_unpacklo_epi8(x7, t8);
2587
2588
2589
2.54M
                r0 = _mm_mullo_epi16(x1, _mm_set1_epi16(_mm_extract_epi16(r1, 0)));
2590
2591
2.54M
                r0 = _mm_adds_epi16(r0,
2592
2.54M
                        _mm_mullo_epi16(x2,
2593
2.54M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 1))));
2594
2595
2596
2.54M
                r0 = _mm_adds_epi16(r0,
2597
2.54M
                        _mm_mullo_epi16(x3,
2598
2.54M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
2599
2600
2.54M
                r0 = _mm_adds_epi16(r0,
2601
2.54M
                        _mm_mullo_epi16(x4,
2602
2.54M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
2603
2604
2.54M
                r0 = _mm_adds_epi16(r0,
2605
2.54M
                        _mm_mullo_epi16(x5,
2606
2.54M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
2607
2608
2609
2.54M
                r0 = _mm_adds_epi16(r0,
2610
2.54M
                        _mm_mullo_epi16(x6,
2611
2.54M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
2612
2613
2614
2.54M
                r0 = _mm_adds_epi16(r0,
2615
2.54M
                        _mm_mullo_epi16(x7,
2616
2.54M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
2617
2618
                /* give results back            */
2619
2.54M
                _mm_storel_epi64((__m128i *) &dst[x], r0);
2620
2.54M
            }
2621
1.39M
            src += srcstride;
2622
1.39M
            dst += dststride;
2623
1.39M
        }
2624
173k
    }
2625
219k
}
2626
2627
#if 0
2628
void ff_hevc_put_hevc_qpel_v_1_10_sse4(int16_t *dst, ptrdiff_t dststride,
2629
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2630
        int16_t* mcbuffer) {
2631
    int x, y;
2632
    uint16_t *src = (uint16_t*) _src;
2633
    ptrdiff_t srcstride = _srcstride >> 1;
2634
    __m128i x1, x2, x3, x4, x5, x6, x7, r1;
2635
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
2636
2637
        t7= _mm_set1_epi32(1);
2638
        t6= _mm_set1_epi32(-5);
2639
        t5= _mm_set1_epi32(17);
2640
        t4= _mm_set1_epi32(58);
2641
        t3= _mm_set1_epi32(-10);
2642
        t2= _mm_set1_epi32(4);
2643
        t1= _mm_set1_epi32(-1);
2644
        t8= _mm_setzero_si128();
2645
2646
        for (y = 0; y < height; y ++) {
2647
            for(x=0;x<width;x+=4){
2648
                /* load data in register  */
2649
                x1 = _mm_loadl_epi64((__m128i *) &src[x-(3 * srcstride)]);
2650
                x2 = _mm_loadl_epi64((__m128i *) &src[x-(2 * srcstride)]);
2651
                x3 = _mm_loadl_epi64((__m128i *) &src[x-srcstride]);
2652
                x4 = _mm_loadl_epi64((__m128i *) &src[x]);
2653
                x5 = _mm_loadl_epi64((__m128i *) &src[x+srcstride]);
2654
                x6 = _mm_loadl_epi64((__m128i *) &src[x+(2 * srcstride)]);
2655
                x7 = _mm_loadl_epi64((__m128i *) &src[x+(3 * srcstride)]);
2656
2657
2658
                x1 = _mm_unpacklo_epi16(x1, t8);
2659
                x2 = _mm_unpacklo_epi16(x2, t8);
2660
                x3 = _mm_unpacklo_epi16(x3, t8);
2661
                x4 = _mm_unpacklo_epi16(x4, t8);
2662
                x5 = _mm_unpacklo_epi16(x5, t8);
2663
                x6 = _mm_unpacklo_epi16(x6, t8);
2664
                x7 = _mm_unpacklo_epi16(x7, t8);
2665
2666
2667
                r1 = _mm_mullo_epi32(x1,t1);
2668
2669
                r1 = _mm_add_epi32(r1,
2670
                        _mm_mullo_epi32(x2,t2));
2671
2672
2673
                r1 = _mm_add_epi32(r1,
2674
                        _mm_mullo_epi32(x3,t3));
2675
2676
                r1 = _mm_add_epi32(r1,
2677
                        _mm_mullo_epi32(x4,t4));
2678
2679
                r1 = _mm_add_epi32(r1,
2680
                        _mm_mullo_epi32(x5,t5));
2681
2682
2683
                r1 = _mm_add_epi32(r1,
2684
                        _mm_mullo_epi32(x6,t6));
2685
2686
2687
                r1 = _mm_add_epi32(r1, _mm_mullo_epi32(x7,t7));
2688
                r1 = _mm_srai_epi32(r1,2); //bit depth - 8
2689
2690
2691
                r1 = _mm_packs_epi32(r1,t8);
2692
2693
                // give results back
2694
                _mm_storel_epi64((__m128i *) (dst + x), r1);
2695
            }
2696
            src += srcstride;
2697
            dst += dststride;
2698
        }
2699
2700
}
2701
#endif
2702
2703
2704
2705
void ff_hevc_put_hevc_qpel_v_2_8_sse(int16_t *dst, ptrdiff_t dststride,
2706
                                     const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2707
170k
        int16_t* mcbuffer) {
2708
170k
    int x, y;
2709
170k
    uint8_t *src = (uint8_t*) _src;
2710
170k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
2711
170k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, r0, r1, r2;
2712
170k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
2713
170k
    r1 = _mm_set_epi16(-1, 4, -11, 40, 40, -11, 4, -1);
2714
2715
170k
    if(!(width & 15)){
2716
716k
        for (y = 0; y < height; y++) {
2717
1.64M
            for (x = 0; x < width; x += 16) {
2718
967k
                r0 = _mm_setzero_si128();
2719
                /* check if memory needs to be reloaded */
2720
967k
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3 * srcstride]);
2721
967k
                x2 = _mm_loadu_si128((__m128i *) &src[x - 2 * srcstride]);
2722
967k
                x3 = _mm_loadu_si128((__m128i *) &src[x - srcstride]);
2723
967k
                x4 = _mm_loadu_si128((__m128i *) &src[x]);
2724
967k
                x5 = _mm_loadu_si128((__m128i *) &src[x + srcstride]);
2725
967k
                x6 = _mm_loadu_si128((__m128i *) &src[x + 2 * srcstride]);
2726
967k
                x7 = _mm_loadu_si128((__m128i *) &src[x + 3 * srcstride]);
2727
967k
                x8 = _mm_loadu_si128((__m128i *) &src[x + 4 * srcstride]);
2728
2729
967k
                t1 = _mm_unpacklo_epi8(x1, r0);
2730
967k
                t2 = _mm_unpacklo_epi8(x2, r0);
2731
967k
                t3 = _mm_unpacklo_epi8(x3, r0);
2732
967k
                t4 = _mm_unpacklo_epi8(x4, r0);
2733
967k
                t5 = _mm_unpacklo_epi8(x5, r0);
2734
967k
                t6 = _mm_unpacklo_epi8(x6, r0);
2735
967k
                t7 = _mm_unpacklo_epi8(x7, r0);
2736
967k
                t8 = _mm_unpacklo_epi8(x8, r0);
2737
2738
967k
                x1 = _mm_unpackhi_epi8(x1, r0);
2739
967k
                x2 = _mm_unpackhi_epi8(x2, r0);
2740
967k
                x3 = _mm_unpackhi_epi8(x3, r0);
2741
967k
                x4 = _mm_unpackhi_epi8(x4, r0);
2742
967k
                x5 = _mm_unpackhi_epi8(x5, r0);
2743
967k
                x6 = _mm_unpackhi_epi8(x6, r0);
2744
967k
                x7 = _mm_unpackhi_epi8(x7, r0);
2745
967k
                x8 = _mm_unpackhi_epi8(x8, r0);
2746
2747
                /* multiply by correct value : */
2748
967k
                r0 = _mm_mullo_epi16(t1,
2749
967k
                        _mm_set1_epi16(_mm_extract_epi16(r1, 0)));
2750
967k
                r2 = _mm_mullo_epi16(x1,
2751
967k
                        _mm_set1_epi16(_mm_extract_epi16(r1, 0)));
2752
967k
                r0 = _mm_adds_epi16(r0,
2753
967k
                        _mm_mullo_epi16(t2,
2754
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 1))));
2755
967k
                r2 = _mm_adds_epi16(r2,
2756
967k
                        _mm_mullo_epi16(x2,
2757
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 1))));
2758
967k
                r0 = _mm_adds_epi16(r0,
2759
967k
                        _mm_mullo_epi16(t3,
2760
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
2761
967k
                r2 = _mm_adds_epi16(r2,
2762
967k
                        _mm_mullo_epi16(x3,
2763
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
2764
2765
967k
                r0 = _mm_adds_epi16(r0,
2766
967k
                        _mm_mullo_epi16(t4,
2767
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
2768
967k
                r2 = _mm_adds_epi16(r2,
2769
967k
                        _mm_mullo_epi16(x4,
2770
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
2771
2772
967k
                r0 = _mm_adds_epi16(r0,
2773
967k
                        _mm_mullo_epi16(t5,
2774
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
2775
967k
                r2 = _mm_adds_epi16(r2,
2776
967k
                        _mm_mullo_epi16(x5,
2777
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
2778
2779
967k
                r0 = _mm_adds_epi16(r0,
2780
967k
                        _mm_mullo_epi16(t6,
2781
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
2782
967k
                r2 = _mm_adds_epi16(r2,
2783
967k
                        _mm_mullo_epi16(x6,
2784
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
2785
2786
967k
                r0 = _mm_adds_epi16(r0,
2787
967k
                        _mm_mullo_epi16(t7,
2788
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
2789
967k
                r2 = _mm_adds_epi16(r2,
2790
967k
                        _mm_mullo_epi16(x7,
2791
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
2792
2793
967k
                r0 = _mm_adds_epi16(r0,
2794
967k
                        _mm_mullo_epi16(t8,
2795
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
2796
967k
                r2 = _mm_adds_epi16(r2,
2797
967k
                        _mm_mullo_epi16(x8,
2798
967k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
2799
2800
                /* give results back            */
2801
967k
                _mm_store_si128((__m128i *) &dst[x],r0);
2802
967k
                _mm_store_si128((__m128i *) &dst[x + 8],r2);
2803
967k
            }
2804
679k
            src += srcstride;
2805
679k
            dst += dststride;
2806
679k
        }
2807
133k
    }else{
2808
133k
        x = 0;
2809
1.17M
        for (y = 0; y < height; y ++) {
2810
2.96M
            for(x=0;x<width;x+=4){
2811
1.92M
                r0 = _mm_setzero_si128();
2812
                /* load data in register  */
2813
1.92M
                x1 = _mm_loadl_epi64((__m128i *) &src[x - 3 * srcstride]);
2814
1.92M
                x2 = _mm_loadl_epi64((__m128i *) &src[x-2 * srcstride]);
2815
1.92M
                x3 = _mm_loadl_epi64((__m128i *) &src[x-srcstride]);
2816
1.92M
                x4 = _mm_loadl_epi64((__m128i *) &src[x]);
2817
1.92M
                x5 = _mm_loadl_epi64((__m128i *) &src[x+srcstride]);
2818
1.92M
                x6 = _mm_loadl_epi64((__m128i *) &src[x+2 * srcstride]);
2819
1.92M
                x7 = _mm_loadl_epi64((__m128i *) &src[x+3 * srcstride]);
2820
1.92M
                x8 = _mm_loadl_epi64((__m128i *) &src[x + 4 * srcstride]);
2821
2822
1.92M
                x1 = _mm_unpacklo_epi8(x1,r0);
2823
1.92M
                x2 = _mm_unpacklo_epi8(x2, r0);
2824
1.92M
                x3 = _mm_unpacklo_epi8(x3, r0);
2825
1.92M
                x4 = _mm_unpacklo_epi8(x4, r0);
2826
1.92M
                x5 = _mm_unpacklo_epi8(x5, r0);
2827
1.92M
                x6 = _mm_unpacklo_epi8(x6, r0);
2828
1.92M
                x7 = _mm_unpacklo_epi8(x7, r0);
2829
1.92M
                x8 = _mm_unpacklo_epi8(x8, r0);
2830
2831
2832
1.92M
                r0 = _mm_mullo_epi16(x1, _mm_set1_epi16(_mm_extract_epi16(r1, 0)));
2833
2834
1.92M
                r0 = _mm_adds_epi16(r0,
2835
1.92M
                        _mm_mullo_epi16(x2,
2836
1.92M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 1))));
2837
2838
2839
1.92M
                r0 = _mm_adds_epi16(r0,
2840
1.92M
                        _mm_mullo_epi16(x3,
2841
1.92M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
2842
2843
2844
1.92M
                r0 = _mm_adds_epi16(r0,
2845
1.92M
                        _mm_mullo_epi16(x4,
2846
1.92M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
2847
2848
2849
1.92M
                r0 = _mm_adds_epi16(r0,
2850
1.92M
                        _mm_mullo_epi16(x5,
2851
1.92M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
2852
2853
2854
1.92M
                r0 = _mm_adds_epi16(r0,
2855
1.92M
                        _mm_mullo_epi16(x6,
2856
1.92M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
2857
2858
2859
1.92M
                r0 = _mm_adds_epi16(r0,
2860
1.92M
                        _mm_mullo_epi16(x7,
2861
1.92M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
2862
2863
2864
1.92M
                r0 = _mm_adds_epi16(r0,
2865
1.92M
                        _mm_mullo_epi16(x8,
2866
1.92M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
2867
2868
2869
                /* give results back            */
2870
1.92M
                _mm_storel_epi64((__m128i *) &dst[x], r0);
2871
2872
1.92M
            }
2873
1.03M
            src += srcstride;
2874
1.03M
            dst += dststride;
2875
1.03M
        }
2876
133k
    }
2877
170k
}
2878
2879
#if 0
2880
void ff_hevc_put_hevc_qpel_v_2_10_sse(int16_t *dst, ptrdiff_t dststride,
2881
                                      cosnt uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2882
        int16_t* mcbuffer) {
2883
    int x, y;
2884
    uint16_t *src = (uint16_t*) _src;
2885
    ptrdiff_t srcstride = _srcstride >> 1;
2886
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, r0, r1, r2;
2887
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
2888
    r1 = _mm_set_epi16(-1, 4, -11, 40, 40, -11, 4, -1);
2889
2890
    t1= _mm_set1_epi32(-1);
2891
    t2= _mm_set1_epi32(4);
2892
    t3= _mm_set1_epi32(-11);
2893
    t4= _mm_set1_epi32(40);
2894
    t5= _mm_set1_epi32(40);
2895
    t6= _mm_set1_epi32(-11);
2896
    t7= _mm_set1_epi32(4);
2897
    t8= _mm_set1_epi32(-1);
2898
2899
    {
2900
        x = 0;
2901
        r0 = _mm_setzero_si128();
2902
        for (y = 0; y < height; y ++) {
2903
            for(x=0;x<width;x+=4){
2904
2905
                /* load data in register  */
2906
                x1 = _mm_loadl_epi64((__m128i *) &src[x - 3 * srcstride]);
2907
                x2 = _mm_loadl_epi64((__m128i *) &src[x-2 * srcstride]);
2908
                x3 = _mm_loadl_epi64((__m128i *) &src[x-srcstride]);
2909
                x4 = _mm_loadl_epi64((__m128i *) &src[x]);
2910
                x5 = _mm_loadl_epi64((__m128i *) &src[x+srcstride]);
2911
                x6 = _mm_loadl_epi64((__m128i *) &src[x+2 * srcstride]);
2912
                x7 = _mm_loadl_epi64((__m128i *) &src[x+3 * srcstride]);
2913
                x8 = _mm_loadl_epi64((__m128i *) &src[x + 4 * srcstride]);
2914
2915
                x1 = _mm_unpacklo_epi16(x1, r0);
2916
                x2 = _mm_unpacklo_epi16(x2, r0);
2917
                x3 = _mm_unpacklo_epi16(x3, r0);
2918
                x4 = _mm_unpacklo_epi16(x4, r0);
2919
                x5 = _mm_unpacklo_epi16(x5, r0);
2920
                x6 = _mm_unpacklo_epi16(x6, r0);
2921
                x7 = _mm_unpacklo_epi16(x7, r0);
2922
                x8 = _mm_unpacklo_epi16(x8, r0);
2923
2924
2925
                r1 = _mm_mullo_epi32(x1, t1);
2926
2927
                r1 = _mm_add_epi32(r1,
2928
                        _mm_mullo_epi32(x2,t2));
2929
2930
2931
                r1 = _mm_add_epi32(r1,
2932
                        _mm_mullo_epi32(x3,t3));
2933
2934
2935
                r1 = _mm_add_epi32(r1,
2936
                        _mm_mullo_epi32(x4,t4));
2937
2938
2939
                r1 = _mm_add_epi32(r1,
2940
                        _mm_mullo_epi32(x5,t5));
2941
2942
2943
                r1 = _mm_add_epi32(r1,
2944
                        _mm_mullo_epi32(x6,t6));
2945
2946
2947
                r1 = _mm_add_epi32(r1,
2948
                        _mm_mullo_epi32(x7,t7));
2949
2950
2951
                r1 = _mm_add_epi32(r1,
2952
                        _mm_mullo_epi32(x8,t8));
2953
2954
2955
                r1= _mm_srai_epi32(r1,2); //bit depth - 8
2956
2957
                r1= _mm_packs_epi32(r1,t8);
2958
2959
                /* give results back            */
2960
                _mm_storel_epi64((__m128i *) (dst+x), r1);
2961
2962
            }
2963
            src += srcstride;
2964
            dst += dststride;
2965
        }
2966
    }
2967
}
2968
#endif
2969
2970
#if 0
2971
static  void ff_hevc_put_hevc_qpel_v_3_sse(int16_t *dst, ptrdiff_t dststride,
2972
                                           const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
2973
        int16_t* mcbuffer) {
2974
    int x, y;
2975
    uint8_t *src = (uint8_t*) _src;
2976
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
2977
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, r0, r1, r2;
2978
    __m128i t2, t3, t4, t5, t6, t7, t8;
2979
    r1 = _mm_set_epi16(-1, 4, -10, 58, 17, -5, 1, 0);
2980
2981
    if(!(width & 15)){
2982
        for (y = 0; y < height; y++) {
2983
                    for (x = 0; x < width; x += 16) {
2984
                        /* check if memory needs to be reloaded */
2985
                        x1 = _mm_setzero_si128();
2986
                        x2 = _mm_loadu_si128((__m128i *) &src[x - 2 * srcstride]);
2987
                        x3 = _mm_loadu_si128((__m128i *) &src[x - srcstride]);
2988
                        x4 = _mm_loadu_si128((__m128i *) &src[x]);
2989
                        x5 = _mm_loadu_si128((__m128i *) &src[x + srcstride]);
2990
                        x6 = _mm_loadu_si128((__m128i *) &src[x + 2 * srcstride]);
2991
                        x7 = _mm_loadu_si128((__m128i *) &src[x + 3 * srcstride]);
2992
                        x8 = _mm_loadu_si128((__m128i *) &src[x + 4 * srcstride]);
2993
2994
                        t2 = _mm_unpacklo_epi8(x2, x1);
2995
                        t3 = _mm_unpacklo_epi8(x3, x1);
2996
                        t4 = _mm_unpacklo_epi8(x4, x1);
2997
                        t5 = _mm_unpacklo_epi8(x5, x1);
2998
                        t6 = _mm_unpacklo_epi8(x6, x1);
2999
                        t7 = _mm_unpacklo_epi8(x7, x1);
3000
                        t8 = _mm_unpacklo_epi8(x8, x1);
3001
3002
                        x2 = _mm_unpackhi_epi8(x2, x1);
3003
                        x3 = _mm_unpackhi_epi8(x3, x1);
3004
                        x4 = _mm_unpackhi_epi8(x4, x1);
3005
                        x5 = _mm_unpackhi_epi8(x5, x1);
3006
                        x6 = _mm_unpackhi_epi8(x6, x1);
3007
                        x7 = _mm_unpackhi_epi8(x7, x1);
3008
                        x8 = _mm_unpackhi_epi8(x8, x1);
3009
3010
                        /* multiply by correct value : */
3011
                        r0 = _mm_mullo_epi16(t2,
3012
                                _mm_set1_epi16(_mm_extract_epi16(r1, 1)));
3013
                        r2 = _mm_mullo_epi16(x2,
3014
                                _mm_set1_epi16(_mm_extract_epi16(r1, 1)));
3015
3016
                        r0 = _mm_adds_epi16(r0,
3017
                                _mm_mullo_epi16(t3,
3018
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
3019
                        r2 = _mm_adds_epi16(r2,
3020
                                _mm_mullo_epi16(x3,
3021
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
3022
3023
                        r0 = _mm_adds_epi16(r0,
3024
                                _mm_mullo_epi16(t4,
3025
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
3026
                        r2 = _mm_adds_epi16(r2,
3027
                                _mm_mullo_epi16(x4,
3028
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
3029
3030
                        r0 = _mm_adds_epi16(r0,
3031
                                _mm_mullo_epi16(t5,
3032
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
3033
                        r2 = _mm_adds_epi16(r2,
3034
                                _mm_mullo_epi16(x5,
3035
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
3036
3037
                        r0 = _mm_adds_epi16(r0,
3038
                                _mm_mullo_epi16(t6,
3039
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
3040
                        r2 = _mm_adds_epi16(r2,
3041
                                _mm_mullo_epi16(x6,
3042
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
3043
3044
                        r0 = _mm_adds_epi16(r0,
3045
                                _mm_mullo_epi16(t7,
3046
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
3047
                        r2 = _mm_adds_epi16(r2,
3048
                                _mm_mullo_epi16(x7,
3049
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
3050
3051
                        r0 = _mm_adds_epi16(r0,
3052
                                _mm_mullo_epi16(t8,
3053
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
3054
                        r2 = _mm_adds_epi16(r2,
3055
                                _mm_mullo_epi16(x8,
3056
                                        _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
3057
3058
                        /* give results back            */
3059
                        _mm_store_si128((__m128i *) &dst[x],
3060
                                _mm_srli_epi16(r0, BIT_DEPTH - 8));
3061
                        _mm_store_si128((__m128i *) &dst[x + 8],
3062
                                _mm_srli_epi16(r2, BIT_DEPTH - 8));
3063
                    }
3064
                    src += srcstride;
3065
                    dst += dststride;
3066
                }
3067
    }else{
3068
        x = 0;
3069
                for (y = 0; y < height; y ++) {
3070
                    for(x=0;x<width;x+=4){
3071
                    r0 = _mm_set1_epi16(0);
3072
                    /* load data in register  */
3073
                    //x1 = _mm_setzero_si128();
3074
                    x2 = _mm_loadl_epi64((__m128i *) &src[x-2 * srcstride]);
3075
                    x3 = _mm_loadl_epi64((__m128i *) &src[x-srcstride]);
3076
                    x4 = _mm_loadl_epi64((__m128i *) &src[x]);
3077
                    x5 = _mm_loadl_epi64((__m128i *) &src[x+srcstride]);
3078
                    x6 = _mm_loadl_epi64((__m128i *) &src[x+2 * srcstride]);
3079
                    x7 = _mm_loadl_epi64((__m128i *) &src[x+3 * srcstride]);
3080
                    x8 = _mm_loadl_epi64((__m128i *) &src[x + 4 * srcstride]);
3081
3082
                    x1 = _mm_unpacklo_epi8(x1,r0);
3083
                    x2 = _mm_unpacklo_epi8(x2, r0);
3084
                    x3 = _mm_unpacklo_epi8(x3, r0);
3085
                    x4 = _mm_unpacklo_epi8(x4, r0);
3086
                    x5 = _mm_unpacklo_epi8(x5, r0);
3087
                    x6 = _mm_unpacklo_epi8(x6, r0);
3088
                    x7 = _mm_unpacklo_epi8(x7, r0);
3089
                    x8 = _mm_unpacklo_epi8(x8, r0);
3090
3091
3092
                    r0 = _mm_mullo_epi16(x2, _mm_set1_epi16(_mm_extract_epi16(r1, 1)));
3093
3094
3095
                    r0 = _mm_adds_epi16(r0,
3096
                            _mm_mullo_epi16(x3,
3097
                                    _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
3098
3099
3100
                    r0 = _mm_adds_epi16(r0,
3101
                            _mm_mullo_epi16(x4,
3102
                                    _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
3103
3104
3105
                    r0 = _mm_adds_epi16(r0,
3106
                            _mm_mullo_epi16(x5,
3107
                                    _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
3108
3109
3110
                    r0 = _mm_adds_epi16(r0,
3111
                            _mm_mullo_epi16(x6,
3112
                                    _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
3113
3114
3115
                    r0 = _mm_adds_epi16(r0,
3116
                            _mm_mullo_epi16(x7,
3117
                                    _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
3118
3119
3120
                    r0 = _mm_adds_epi16(r0,
3121
                            _mm_mullo_epi16(x8,
3122
                                    _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
3123
3124
3125
                    r0 = _mm_srli_epi16(r0, BIT_DEPTH - 8);
3126
                    /* give results back            */
3127
                    _mm_storel_epi64((__m128i *) &dst[x], r0);
3128
3129
                    }
3130
                    src += srcstride;
3131
                    dst += dststride;
3132
                }
3133
    }
3134
3135
}
3136
#endif
3137
3138
void ff_hevc_put_hevc_qpel_v_3_8_sse(int16_t *dst, ptrdiff_t dststride,
3139
                                     const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
3140
201k
        int16_t* mcbuffer) {
3141
201k
    int x, y;
3142
201k
    uint8_t *src = (uint8_t*) _src;
3143
201k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
3144
201k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, r0, r1, r2;
3145
201k
    __m128i t2, t3, t4, t5, t6, t7, t8;
3146
201k
    r1 = _mm_set_epi16(-1, 4, -10, 58, 17, -5, 1, 0);
3147
3148
201k
    if(!(width & 15)){
3149
740k
        for (y = 0; y < height; y++) {
3150
1.57M
            for (x = 0; x < width; x += 16) {
3151
                /* check if memory needs to be reloaded */
3152
877k
                x1 = _mm_setzero_si128();
3153
877k
                x2 = _mm_loadu_si128((__m128i *) &src[x - 2 * srcstride]);
3154
877k
                x3 = _mm_loadu_si128((__m128i *) &src[x - srcstride]);
3155
877k
                x4 = _mm_loadu_si128((__m128i *) &src[x]);
3156
877k
                x5 = _mm_loadu_si128((__m128i *) &src[x + srcstride]);
3157
877k
                x6 = _mm_loadu_si128((__m128i *) &src[x + 2 * srcstride]);
3158
877k
                x7 = _mm_loadu_si128((__m128i *) &src[x + 3 * srcstride]);
3159
877k
                x8 = _mm_loadu_si128((__m128i *) &src[x + 4 * srcstride]);
3160
3161
877k
                t2 = _mm_unpacklo_epi8(x2, x1);
3162
877k
                t3 = _mm_unpacklo_epi8(x3, x1);
3163
877k
                t4 = _mm_unpacklo_epi8(x4, x1);
3164
877k
                t5 = _mm_unpacklo_epi8(x5, x1);
3165
877k
                t6 = _mm_unpacklo_epi8(x6, x1);
3166
877k
                t7 = _mm_unpacklo_epi8(x7, x1);
3167
877k
                t8 = _mm_unpacklo_epi8(x8, x1);
3168
3169
877k
                x2 = _mm_unpackhi_epi8(x2, x1);
3170
877k
                x3 = _mm_unpackhi_epi8(x3, x1);
3171
877k
                x4 = _mm_unpackhi_epi8(x4, x1);
3172
877k
                x5 = _mm_unpackhi_epi8(x5, x1);
3173
877k
                x6 = _mm_unpackhi_epi8(x6, x1);
3174
877k
                x7 = _mm_unpackhi_epi8(x7, x1);
3175
877k
                x8 = _mm_unpackhi_epi8(x8, x1);
3176
3177
                /* multiply by correct value : */
3178
877k
                r0 = _mm_mullo_epi16(t2,
3179
877k
                        _mm_set1_epi16(_mm_extract_epi16(r1, 1)));
3180
877k
                r2 = _mm_mullo_epi16(x2,
3181
877k
                        _mm_set1_epi16(_mm_extract_epi16(r1, 1)));
3182
3183
877k
                r0 = _mm_adds_epi16(r0,
3184
877k
                        _mm_mullo_epi16(t3,
3185
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
3186
877k
                r2 = _mm_adds_epi16(r2,
3187
877k
                        _mm_mullo_epi16(x3,
3188
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
3189
3190
877k
                r0 = _mm_adds_epi16(r0,
3191
877k
                        _mm_mullo_epi16(t4,
3192
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
3193
877k
                r2 = _mm_adds_epi16(r2,
3194
877k
                        _mm_mullo_epi16(x4,
3195
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
3196
3197
877k
                r0 = _mm_adds_epi16(r0,
3198
877k
                        _mm_mullo_epi16(t5,
3199
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
3200
877k
                r2 = _mm_adds_epi16(r2,
3201
877k
                        _mm_mullo_epi16(x5,
3202
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
3203
3204
877k
                r0 = _mm_adds_epi16(r0,
3205
877k
                        _mm_mullo_epi16(t6,
3206
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
3207
877k
                r2 = _mm_adds_epi16(r2,
3208
877k
                        _mm_mullo_epi16(x6,
3209
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
3210
3211
877k
                r0 = _mm_adds_epi16(r0,
3212
877k
                        _mm_mullo_epi16(t7,
3213
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
3214
877k
                r2 = _mm_adds_epi16(r2,
3215
877k
                        _mm_mullo_epi16(x7,
3216
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
3217
3218
877k
                r0 = _mm_adds_epi16(r0,
3219
877k
                        _mm_mullo_epi16(t8,
3220
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
3221
877k
                r2 = _mm_adds_epi16(r2,
3222
877k
                        _mm_mullo_epi16(x8,
3223
877k
                                _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
3224
3225
                /* give results back            */
3226
877k
                _mm_store_si128((__m128i *) &dst[x],r0);
3227
877k
                _mm_store_si128((__m128i *) &dst[x + 8],r2);
3228
877k
            }
3229
696k
            src += srcstride;
3230
696k
            dst += dststride;
3231
696k
        }
3232
157k
    }else{
3233
157k
        x = 0;
3234
1.40M
        for (y = 0; y < height; y ++) {
3235
3.57M
            for(x=0;x<width;x+=4){
3236
2.33M
                r0 = _mm_set1_epi16(0);
3237
                /* load data in register  */
3238
2.33M
                x2 = _mm_loadl_epi64((__m128i *) &src[x-2 * srcstride]);
3239
2.33M
                x3 = _mm_loadl_epi64((__m128i *) &src[x-srcstride]);
3240
2.33M
                x4 = _mm_loadl_epi64((__m128i *) &src[x]);
3241
2.33M
                x5 = _mm_loadl_epi64((__m128i *) &src[x+srcstride]);
3242
2.33M
                x6 = _mm_loadl_epi64((__m128i *) &src[x+2 * srcstride]);
3243
2.33M
                x7 = _mm_loadl_epi64((__m128i *) &src[x+3 * srcstride]);
3244
2.33M
                x8 = _mm_loadl_epi64((__m128i *) &src[x + 4 * srcstride]);
3245
3246
2.33M
                x2 = _mm_unpacklo_epi8(x2, r0);
3247
2.33M
                x3 = _mm_unpacklo_epi8(x3, r0);
3248
2.33M
                x4 = _mm_unpacklo_epi8(x4, r0);
3249
2.33M
                x5 = _mm_unpacklo_epi8(x5, r0);
3250
2.33M
                x6 = _mm_unpacklo_epi8(x6, r0);
3251
2.33M
                x7 = _mm_unpacklo_epi8(x7, r0);
3252
2.33M
                x8 = _mm_unpacklo_epi8(x8, r0);
3253
3254
2.33M
                r0 = _mm_mullo_epi16(x2, _mm_set1_epi16(_mm_extract_epi16(r1, 1)));
3255
3256
2.33M
                r0 = _mm_adds_epi16(r0,
3257
2.33M
                        _mm_mullo_epi16(x3,
3258
2.33M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 2))));
3259
3260
2.33M
                r0 = _mm_adds_epi16(r0,
3261
2.33M
                        _mm_mullo_epi16(x4,
3262
2.33M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 3))));
3263
3264
2.33M
                r0 = _mm_adds_epi16(r0,
3265
2.33M
                        _mm_mullo_epi16(x5,
3266
2.33M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 4))));
3267
3268
2.33M
                r0 = _mm_adds_epi16(r0,
3269
2.33M
                        _mm_mullo_epi16(x6,
3270
2.33M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 5))));
3271
3272
2.33M
                r0 = _mm_adds_epi16(r0,
3273
2.33M
                        _mm_mullo_epi16(x7,
3274
2.33M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 6))));
3275
3276
2.33M
                r0 = _mm_adds_epi16(r0,
3277
2.33M
                        _mm_mullo_epi16(x8,
3278
2.33M
                                _mm_set1_epi16(_mm_extract_epi16(r1, 7))));
3279
3280
                /* give results back            */
3281
2.33M
                _mm_storel_epi64((__m128i *) &dst[x], r0);
3282
3283
2.33M
            }
3284
1.24M
            src += srcstride;
3285
1.24M
            dst += dststride;
3286
1.24M
        }
3287
157k
    }
3288
3289
201k
}
3290
3291
3292
#if 0
3293
void ff_hevc_put_hevc_qpel_v_3_10_sse(int16_t *dst, ptrdiff_t dststride,
3294
                                      const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
3295
        int16_t* mcbuffer) {
3296
    int x, y;
3297
    uint16_t *src = (uint16_t*) _src;
3298
    ptrdiff_t srcstride = _srcstride >> 1;
3299
    __m128i x1, x2, x3, x4, x5, x6, x7, r0;
3300
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
3301
3302
    t7 = _mm_set1_epi32(-1);
3303
    t6 = _mm_set1_epi32(4);
3304
    t5 = _mm_set1_epi32(-10);
3305
    t4 = _mm_set1_epi32(58);
3306
    t3 = _mm_set1_epi32(17);
3307
    t2 = _mm_set1_epi32(-5);
3308
    t1 = _mm_set1_epi32(1);
3309
    t8= _mm_setzero_si128();
3310
    {
3311
3312
        for (y = 0; y < height; y ++) {
3313
            for(x=0;x<width;x+=4){
3314
                /* load data in register  */
3315
                x1 = _mm_loadl_epi64((__m128i *) &src[x-2 * srcstride]);
3316
                x2 = _mm_loadl_epi64((__m128i *) &src[x-srcstride]);
3317
                x3 = _mm_loadl_epi64((__m128i *) &src[x]);
3318
                x4 = _mm_loadl_epi64((__m128i *) &src[x+srcstride]);
3319
                x5 = _mm_loadl_epi64((__m128i *) &src[x+2 * srcstride]);
3320
                x6 = _mm_loadl_epi64((__m128i *) &src[x+3 * srcstride]);
3321
                x7 = _mm_loadl_epi64((__m128i *) &src[x + 4 * srcstride]);
3322
3323
                x1 = _mm_unpacklo_epi16(x1, t8);
3324
                x2 = _mm_unpacklo_epi16(x2, t8);
3325
                x3 = _mm_unpacklo_epi16(x3, t8);
3326
                x4 = _mm_unpacklo_epi16(x4, t8);
3327
                x5 = _mm_unpacklo_epi16(x5, t8);
3328
                x6 = _mm_unpacklo_epi16(x6, t8);
3329
                x7 = _mm_unpacklo_epi16(x7, t8);
3330
3331
                r0 = _mm_mullo_epi32(x1, t1);
3332
3333
                r0 = _mm_add_epi32(r0,
3334
                        _mm_mullo_epi32(x2,t2));
3335
3336
                r0 = _mm_add_epi32(r0,
3337
                        _mm_mullo_epi32(x3,t3));
3338
3339
                r0 = _mm_add_epi32(r0,
3340
                        _mm_mullo_epi32(x4,t4));
3341
3342
                r0 = _mm_add_epi32(r0,
3343
                        _mm_mullo_epi32(x5,t5));
3344
3345
                r0 = _mm_add_epi32(r0,
3346
                        _mm_mullo_epi32(x6,t6));
3347
3348
                r0 = _mm_add_epi32(r0,
3349
                        _mm_mullo_epi32(x7,t7));
3350
3351
                r0= _mm_srai_epi32(r0,2);
3352
3353
                r0= _mm_packs_epi32(r0,t8);
3354
3355
                /* give results back            */
3356
                _mm_storel_epi64((__m128i *) &dst[x], r0);
3357
3358
            }
3359
            src += srcstride;
3360
            dst += dststride;
3361
        }
3362
    }
3363
3364
}
3365
#endif
3366
3367
3368
3369
void ff_hevc_put_hevc_qpel_h_1_v_1_sse(int16_t *dst, ptrdiff_t dststride,
3370
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
3371
250k
        int16_t* mcbuffer) {
3372
250k
    int x, y;
3373
250k
    uint8_t* src = (uint8_t*) _src;
3374
250k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
3375
250k
    int16_t *tmp = mcbuffer;
3376
250k
    __m128i x1, x2, x3, x4, x5, x6, x7, rBuffer, rTemp, r0, r1;
3377
250k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
3378
3379
250k
    src -= qpel_extra_before[1] * srcstride;
3380
250k
    r0 = _mm_set_epi8(0, 1, -5, 17, 58, -10, 4, -1, 0, 1, -5, 17, 58, -10, 4,
3381
250k
            -1);
3382
3383
    /* LOAD src from memory to registers to limit memory bandwidth */
3384
250k
    if (width == 4) {
3385
3386
415k
        for (y = 0; y < height + qpel_extra[1]; y += 2) {
3387
            /* load data in register     */
3388
364k
            x1 = _mm_loadu_si128((__m128i *) &src[-3]);
3389
364k
            src += srcstride;
3390
364k
            t1 = _mm_loadu_si128((__m128i *) &src[-3]);
3391
364k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
3392
364k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
3393
364k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
3394
364k
                    _mm_srli_si128(x1, 3));
3395
364k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
3396
364k
                    _mm_srli_si128(t1, 3));
3397
3398
            /*  PMADDUBSW then PMADDW     */
3399
364k
            x2 = _mm_maddubs_epi16(x2, r0);
3400
364k
            t2 = _mm_maddubs_epi16(t2, r0);
3401
364k
            x3 = _mm_maddubs_epi16(x3, r0);
3402
364k
            t3 = _mm_maddubs_epi16(t3, r0);
3403
364k
            x2 = _mm_hadd_epi16(x2, x3);
3404
364k
            t2 = _mm_hadd_epi16(t2, t3);
3405
364k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
3406
364k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
3407
364k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
3408
364k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
3409
            /* give results back            */
3410
364k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
3411
3412
364k
            tmp += MAX_PB_SIZE;
3413
364k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
3414
3415
364k
            src += srcstride;
3416
364k
            tmp += MAX_PB_SIZE;
3417
364k
        }
3418
51.2k
    } else
3419
3.34M
        for (y = 0; y < height + qpel_extra[1]; y++) {
3420
7.91M
            for (x = 0; x < width; x += 8) {
3421
                /* load data in register     */
3422
4.77M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
3423
4.77M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
3424
4.77M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
3425
4.77M
                        _mm_srli_si128(x1, 3));
3426
4.77M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
3427
4.77M
                        _mm_srli_si128(x1, 5));
3428
4.77M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
3429
4.77M
                        _mm_srli_si128(x1, 7));
3430
3431
                /*  PMADDUBSW then PMADDW     */
3432
4.77M
                x2 = _mm_maddubs_epi16(x2, r0);
3433
4.77M
                x3 = _mm_maddubs_epi16(x3, r0);
3434
4.77M
                x4 = _mm_maddubs_epi16(x4, r0);
3435
4.77M
                x5 = _mm_maddubs_epi16(x5, r0);
3436
4.77M
                x2 = _mm_hadd_epi16(x2, x3);
3437
4.77M
                x4 = _mm_hadd_epi16(x4, x5);
3438
4.77M
                x2 = _mm_hadd_epi16(x2, x4);
3439
4.77M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
3440
3441
                /* give results back            */
3442
4.77M
                _mm_store_si128((__m128i *) &tmp[x], x2);
3443
3444
4.77M
            }
3445
3.14M
            src += srcstride;
3446
3.14M
            tmp += MAX_PB_SIZE;
3447
3.14M
        }
3448
3449
250k
    tmp = mcbuffer + qpel_extra_before[1] * MAX_PB_SIZE;
3450
250k
    srcstride = MAX_PB_SIZE;
3451
3452
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
3453
     for register calculations */
3454
250k
    rTemp = _mm_set_epi16(0, 1, -5, 17, 58, -10, 4, -1);
3455
2.61M
    for (y = 0; y < height; y++) {
3456
5.98M
        for (x = 0; x < width; x += 8) {
3457
3458
3.61M
            x1 = _mm_load_si128((__m128i *) &tmp[x - 3 * srcstride]);
3459
3.61M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
3460
3.61M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
3461
3.61M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
3462
3.61M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
3463
3.61M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
3464
3.61M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
3465
3466
3.61M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 0));
3467
3.61M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
3468
3.61M
            t8 = _mm_mullo_epi16(x1, r0);
3469
3.61M
            rBuffer = _mm_mulhi_epi16(x1, r0);
3470
3.61M
            t7 = _mm_mullo_epi16(x2, r1);
3471
3.61M
            t1 = _mm_unpacklo_epi16(t8, rBuffer);
3472
3.61M
            x1 = _mm_unpackhi_epi16(t8, rBuffer);
3473
3474
3.61M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
3475
3.61M
            rBuffer = _mm_mulhi_epi16(x2, r1);
3476
3.61M
            t8 = _mm_mullo_epi16(x3, r0);
3477
3.61M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
3478
3.61M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
3479
3480
3.61M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
3481
3.61M
            rBuffer = _mm_mulhi_epi16(x3, r0);
3482
3.61M
            t7 = _mm_mullo_epi16(x4, r1);
3483
3.61M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
3484
3.61M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
3485
3486
3.61M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
3487
3.61M
            rBuffer = _mm_mulhi_epi16(x4, r1);
3488
3.61M
            t8 = _mm_mullo_epi16(x5, r0);
3489
3.61M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
3490
3.61M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
3491
3492
3.61M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
3493
3.61M
            rBuffer = _mm_mulhi_epi16(x5, r0);
3494
3.61M
            t7 = _mm_mullo_epi16(x6, r1);
3495
3.61M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
3496
3.61M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
3497
3498
3.61M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
3499
3.61M
            rBuffer = _mm_mulhi_epi16(x6, r1);
3500
3.61M
            t8 = _mm_mullo_epi16(x7, r0);
3501
3.61M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
3502
3.61M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
3503
3504
3.61M
            rBuffer = _mm_mulhi_epi16(x7, r0);
3505
3.61M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
3506
3.61M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
3507
3508
3509
3510
            /* add calculus by correct value : */
3511
3512
3.61M
            r1 = _mm_add_epi32(x1, x2);
3513
3.61M
            x3 = _mm_add_epi32(x3, x4);
3514
3.61M
            x5 = _mm_add_epi32(x5, x6);
3515
3.61M
            r1 = _mm_add_epi32(r1, x3);
3516
3517
3.61M
            r1 = _mm_add_epi32(r1, x5);
3518
3519
3.61M
            r0 = _mm_add_epi32(t1, t2);
3520
3.61M
            t3 = _mm_add_epi32(t3, t4);
3521
3.61M
            t5 = _mm_add_epi32(t5, t6);
3522
3.61M
            r0 = _mm_add_epi32(r0, t3);
3523
3.61M
            r0 = _mm_add_epi32(r0, t5);
3524
3.61M
            r1 = _mm_add_epi32(r1, x7);
3525
3.61M
            r0 = _mm_add_epi32(r0, t7);
3526
3.61M
            r1 = _mm_srli_epi32(r1, 6);
3527
3.61M
            r0 = _mm_srli_epi32(r0, 6);
3528
3529
3.61M
            r1 = _mm_and_si128(r1,
3530
3.61M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3531
3.61M
            r0 = _mm_and_si128(r0,
3532
3.61M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3533
3.61M
            r0 = _mm_hadd_epi16(r0, r1);
3534
3.61M
            _mm_store_si128((__m128i *) &dst[x], r0);
3535
3536
3.61M
        }
3537
2.36M
        tmp += MAX_PB_SIZE;
3538
2.36M
        dst += dststride;
3539
2.36M
    }
3540
250k
}
3541
void ff_hevc_put_hevc_qpel_h_1_v_2_sse(int16_t *dst, ptrdiff_t dststride,
3542
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
3543
123k
        int16_t* mcbuffer) {
3544
123k
    int x, y;
3545
123k
    uint8_t *src = (uint8_t*) _src;
3546
123k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
3547
123k
    int16_t *tmp = mcbuffer;
3548
123k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, rBuffer, rTemp, r0, r1;
3549
123k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
3550
3551
123k
    src -= qpel_extra_before[2] * srcstride;
3552
123k
    r0 = _mm_set_epi8(0, 1, -5, 17, 58, -10, 4, -1, 0, 1, -5, 17, 58, -10, 4,
3553
123k
            -1);
3554
3555
    /* LOAD src from memory to registers to limit memory bandwidth */
3556
123k
    if (width == 4) {
3557
3558
244k
        for (y = 0; y < height + qpel_extra[2]; y += 2) {
3559
            /* load data in register     */
3560
217k
            x1 = _mm_loadu_si128((__m128i *) &src[-3]);
3561
217k
            src += srcstride;
3562
217k
            t1 = _mm_loadu_si128((__m128i *) &src[-3]);
3563
217k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
3564
217k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
3565
217k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
3566
217k
                    _mm_srli_si128(x1, 3));
3567
217k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
3568
217k
                    _mm_srli_si128(t1, 3));
3569
3570
            /*  PMADDUBSW then PMADDW     */
3571
217k
            x2 = _mm_maddubs_epi16(x2, r0);
3572
217k
            t2 = _mm_maddubs_epi16(t2, r0);
3573
217k
            x3 = _mm_maddubs_epi16(x3, r0);
3574
217k
            t3 = _mm_maddubs_epi16(t3, r0);
3575
217k
            x2 = _mm_hadd_epi16(x2, x3);
3576
217k
            t2 = _mm_hadd_epi16(t2, t3);
3577
217k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
3578
217k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
3579
217k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
3580
217k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
3581
            /* give results back            */
3582
217k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
3583
3584
217k
            tmp += MAX_PB_SIZE;
3585
217k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
3586
3587
217k
            src += srcstride;
3588
217k
            tmp += MAX_PB_SIZE;
3589
217k
        }
3590
26.9k
    } else
3591
1.74M
        for (y = 0; y < height + qpel_extra[2]; y++) {
3592
4.12M
            for (x = 0; x < width; x += 8) {
3593
                /* load data in register     */
3594
2.47M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
3595
2.47M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
3596
2.47M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
3597
2.47M
                        _mm_srli_si128(x1, 3));
3598
2.47M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
3599
2.47M
                        _mm_srli_si128(x1, 5));
3600
2.47M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
3601
2.47M
                        _mm_srli_si128(x1, 7));
3602
3603
                /*  PMADDUBSW then PMADDW     */
3604
2.47M
                x2 = _mm_maddubs_epi16(x2, r0);
3605
2.47M
                x3 = _mm_maddubs_epi16(x3, r0);
3606
2.47M
                x4 = _mm_maddubs_epi16(x4, r0);
3607
2.47M
                x5 = _mm_maddubs_epi16(x5, r0);
3608
2.47M
                x2 = _mm_hadd_epi16(x2, x3);
3609
2.47M
                x4 = _mm_hadd_epi16(x4, x5);
3610
2.47M
                x2 = _mm_hadd_epi16(x2, x4);
3611
2.47M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
3612
3613
                /* give results back            */
3614
2.47M
                _mm_store_si128((__m128i *) &tmp[x], x2);
3615
3616
2.47M
            }
3617
1.64M
            src += srcstride;
3618
1.64M
            tmp += MAX_PB_SIZE;
3619
1.64M
        }
3620
3621
123k
    tmp = mcbuffer + qpel_extra_before[2] * MAX_PB_SIZE;
3622
123k
    srcstride = MAX_PB_SIZE;
3623
3624
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
3625
     for register calculations */
3626
123k
    rTemp = _mm_set_epi16(-1, 4, -11, 40, 40, -11, 4, -1);
3627
1.31M
    for (y = 0; y < height; y++) {
3628
2.98M
        for (x = 0; x < width; x += 8) {
3629
3630
1.79M
            x1 = _mm_load_si128((__m128i *) &tmp[x - 3 * srcstride]);
3631
1.79M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
3632
1.79M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
3633
1.79M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
3634
1.79M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
3635
1.79M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
3636
1.79M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
3637
1.79M
            x8 = _mm_loadu_si128((__m128i *) &tmp[x + 4 * srcstride]);
3638
3639
1.79M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 0));
3640
1.79M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
3641
1.79M
            t8 = _mm_mullo_epi16(x1, r0);
3642
1.79M
            rBuffer = _mm_mulhi_epi16(x1, r0);
3643
1.79M
            t7 = _mm_mullo_epi16(x2, r1);
3644
1.79M
            t1 = _mm_unpacklo_epi16(t8, rBuffer);
3645
1.79M
            x1 = _mm_unpackhi_epi16(t8, rBuffer);
3646
3647
1.79M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
3648
1.79M
            rBuffer = _mm_mulhi_epi16(x2, r1);
3649
1.79M
            t8 = _mm_mullo_epi16(x3, r0);
3650
1.79M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
3651
1.79M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
3652
3653
1.79M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
3654
1.79M
            rBuffer = _mm_mulhi_epi16(x3, r0);
3655
1.79M
            t7 = _mm_mullo_epi16(x4, r1);
3656
1.79M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
3657
1.79M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
3658
3659
1.79M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
3660
1.79M
            rBuffer = _mm_mulhi_epi16(x4, r1);
3661
1.79M
            t8 = _mm_mullo_epi16(x5, r0);
3662
1.79M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
3663
1.79M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
3664
3665
1.79M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
3666
1.79M
            rBuffer = _mm_mulhi_epi16(x5, r0);
3667
1.79M
            t7 = _mm_mullo_epi16(x6, r1);
3668
1.79M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
3669
1.79M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
3670
3671
1.79M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
3672
1.79M
            rBuffer = _mm_mulhi_epi16(x6, r1);
3673
1.79M
            t8 = _mm_mullo_epi16(x7, r0);
3674
1.79M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
3675
1.79M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
3676
3677
1.79M
            rBuffer = _mm_mulhi_epi16(x7, r0);
3678
1.79M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
3679
1.79M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
3680
3681
1.79M
            t8 = _mm_unpacklo_epi16(
3682
1.79M
                    _mm_mullo_epi16(x8,
3683
1.79M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
3684
1.79M
                            _mm_mulhi_epi16(x8,
3685
1.79M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
3686
1.79M
            x8 = _mm_unpackhi_epi16(
3687
1.79M
                    _mm_mullo_epi16(x8,
3688
1.79M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
3689
1.79M
                            _mm_mulhi_epi16(x8,
3690
1.79M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
3691
3692
            /* add calculus by correct value : */
3693
3694
1.79M
            r1 = _mm_add_epi32(x1, x2);
3695
1.79M
            x3 = _mm_add_epi32(x3, x4);
3696
1.79M
            x5 = _mm_add_epi32(x5, x6);
3697
1.79M
            r1 = _mm_add_epi32(r1, x3);
3698
1.79M
            x7 = _mm_add_epi32(x7, x8);
3699
1.79M
            r1 = _mm_add_epi32(r1, x5);
3700
3701
1.79M
            r0 = _mm_add_epi32(t1, t2);
3702
1.79M
            t3 = _mm_add_epi32(t3, t4);
3703
1.79M
            t5 = _mm_add_epi32(t5, t6);
3704
1.79M
            r0 = _mm_add_epi32(r0, t3);
3705
1.79M
            t7 = _mm_add_epi32(t7, t8);
3706
1.79M
            r0 = _mm_add_epi32(r0, t5);
3707
1.79M
            r1 = _mm_add_epi32(r1, x7);
3708
1.79M
            r0 = _mm_add_epi32(r0, t7);
3709
1.79M
            r1 = _mm_srli_epi32(r1, 6);
3710
1.79M
            r0 = _mm_srli_epi32(r0, 6);
3711
3712
1.79M
            r1 = _mm_and_si128(r1,
3713
1.79M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3714
1.79M
            r0 = _mm_and_si128(r0,
3715
1.79M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3716
1.79M
            r0 = _mm_hadd_epi16(r0, r1);
3717
1.79M
            _mm_store_si128((__m128i *) &dst[x], r0);
3718
3719
1.79M
        }
3720
1.18M
        tmp += MAX_PB_SIZE;
3721
1.18M
        dst += dststride;
3722
1.18M
    }
3723
123k
}
3724
void ff_hevc_put_hevc_qpel_h_1_v_3_sse(int16_t *dst, ptrdiff_t dststride,
3725
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
3726
153k
        int16_t* mcbuffer) {
3727
153k
    int x, y;
3728
153k
    uint8_t *src = (uint8_t*) _src;
3729
153k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
3730
153k
    int16_t *tmp = mcbuffer;
3731
153k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, rBuffer, rTemp, r0, r1;
3732
153k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
3733
3734
153k
    src -= qpel_extra_before[3] * srcstride;
3735
153k
    r0 = _mm_set_epi8(0, 1, -5, 17, 58, -10, 4, -1, 0, 1, -5, 17, 58, -10, 4,
3736
153k
            -1);
3737
3738
    /* LOAD src from memory to registers to limit memory bandwidth */
3739
153k
    if (width == 4) {
3740
3741
197k
        for (y = 0; y < height + qpel_extra[3]; y += 2) {
3742
            /* load data in register     */
3743
173k
            x1 = _mm_loadu_si128((__m128i *) &src[-3]);
3744
173k
            src += srcstride;
3745
173k
            t1 = _mm_loadu_si128((__m128i *) &src[-3]);
3746
173k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
3747
173k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
3748
173k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
3749
173k
                    _mm_srli_si128(x1, 3));
3750
173k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
3751
173k
                    _mm_srli_si128(t1, 3));
3752
3753
            /*  PMADDUBSW then PMADDW     */
3754
173k
            x2 = _mm_maddubs_epi16(x2, r0);
3755
173k
            t2 = _mm_maddubs_epi16(t2, r0);
3756
173k
            x3 = _mm_maddubs_epi16(x3, r0);
3757
173k
            t3 = _mm_maddubs_epi16(t3, r0);
3758
173k
            x2 = _mm_hadd_epi16(x2, x3);
3759
173k
            t2 = _mm_hadd_epi16(t2, t3);
3760
173k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
3761
173k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
3762
173k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
3763
173k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
3764
            /* give results back            */
3765
173k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
3766
3767
173k
            tmp += MAX_PB_SIZE;
3768
173k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
3769
3770
173k
            src += srcstride;
3771
173k
            tmp += MAX_PB_SIZE;
3772
173k
        }
3773
24.5k
    } else
3774
2.19M
        for (y = 0; y < height + qpel_extra[3]; y++) {
3775
5.17M
            for (x = 0; x < width; x += 8) {
3776
                /* load data in register     */
3777
3.10M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
3778
3.10M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
3779
3.10M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
3780
3.10M
                        _mm_srli_si128(x1, 3));
3781
3.10M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
3782
3.10M
                        _mm_srli_si128(x1, 5));
3783
3.10M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
3784
3.10M
                        _mm_srli_si128(x1, 7));
3785
3786
                /*  PMADDUBSW then PMADDW     */
3787
3.10M
                x2 = _mm_maddubs_epi16(x2, r0);
3788
3.10M
                x3 = _mm_maddubs_epi16(x3, r0);
3789
3.10M
                x4 = _mm_maddubs_epi16(x4, r0);
3790
3.10M
                x5 = _mm_maddubs_epi16(x5, r0);
3791
3.10M
                x2 = _mm_hadd_epi16(x2, x3);
3792
3.10M
                x4 = _mm_hadd_epi16(x4, x5);
3793
3.10M
                x2 = _mm_hadd_epi16(x2, x4);
3794
3.10M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
3795
3796
                /* give results back            */
3797
3.10M
                _mm_store_si128((__m128i *) &tmp[x], x2);
3798
3799
3.10M
            }
3800
2.06M
            src += srcstride;
3801
2.06M
            tmp += MAX_PB_SIZE;
3802
2.06M
        }
3803
3804
153k
    tmp = mcbuffer + qpel_extra_before[3] * MAX_PB_SIZE;
3805
153k
    srcstride = MAX_PB_SIZE;
3806
3807
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
3808
     for register calculations */
3809
153k
    rTemp = _mm_set_epi16(-1, 4, -10, 58, 17, -5, 1, 0);
3810
1.64M
    for (y = 0; y < height; y++) {
3811
3.77M
        for (x = 0; x < width; x += 8) {
3812
3813
2.28M
            x1 = _mm_setzero_si128();
3814
2.28M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
3815
2.28M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
3816
2.28M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
3817
2.28M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
3818
2.28M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
3819
2.28M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
3820
2.28M
            x8 = _mm_load_si128((__m128i *) &tmp[x + 4 * srcstride]);
3821
3822
3823
2.28M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
3824
3825
2.28M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
3826
2.28M
            t7 = _mm_mullo_epi16(x2, r1);
3827
2.28M
            rBuffer = _mm_mulhi_epi16(x2, r1);
3828
2.28M
            t8 = _mm_mullo_epi16(x3, r0);
3829
2.28M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
3830
2.28M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
3831
3832
2.28M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
3833
2.28M
            rBuffer = _mm_mulhi_epi16(x3, r0);
3834
2.28M
            t7 = _mm_mullo_epi16(x4, r1);
3835
2.28M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
3836
2.28M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
3837
3838
2.28M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
3839
2.28M
            rBuffer = _mm_mulhi_epi16(x4, r1);
3840
2.28M
            t8 = _mm_mullo_epi16(x5, r0);
3841
2.28M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
3842
2.28M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
3843
3844
2.28M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
3845
2.28M
            rBuffer = _mm_mulhi_epi16(x5, r0);
3846
2.28M
            t7 = _mm_mullo_epi16(x6, r1);
3847
2.28M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
3848
2.28M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
3849
3850
2.28M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
3851
2.28M
            rBuffer = _mm_mulhi_epi16(x6, r1);
3852
2.28M
            t8 = _mm_mullo_epi16(x7, r0);
3853
2.28M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
3854
2.28M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
3855
3856
2.28M
            rBuffer = _mm_mulhi_epi16(x7, r0);
3857
2.28M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
3858
2.28M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
3859
3860
2.28M
            t8 = _mm_unpacklo_epi16(
3861
2.28M
                    _mm_mullo_epi16(x8,
3862
2.28M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
3863
2.28M
                            _mm_mulhi_epi16(x8,
3864
2.28M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
3865
2.28M
            x8 = _mm_unpackhi_epi16(
3866
2.28M
                    _mm_mullo_epi16(x8,
3867
2.28M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
3868
2.28M
                            _mm_mulhi_epi16(x8,
3869
2.28M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
3870
3871
            /* add calculus by correct value : */
3872
3873
2.28M
            x3 = _mm_add_epi32(x3, x4);
3874
2.28M
            x5 = _mm_add_epi32(x5, x6);
3875
2.28M
            r1 = _mm_add_epi32(x2, x3);
3876
2.28M
            x7 = _mm_add_epi32(x7, x8);
3877
2.28M
            r1 = _mm_add_epi32(r1, x5);
3878
3879
2.28M
            t3 = _mm_add_epi32(t3, t4);
3880
2.28M
            t5 = _mm_add_epi32(t5, t6);
3881
2.28M
            r0 = _mm_add_epi32(t2, t3);
3882
2.28M
            t7 = _mm_add_epi32(t7, t8);
3883
2.28M
            r0 = _mm_add_epi32(r0, t5);
3884
2.28M
            r1 = _mm_add_epi32(r1, x7);
3885
2.28M
            r0 = _mm_add_epi32(r0, t7);
3886
2.28M
            r1 = _mm_srli_epi32(r1, 6);
3887
2.28M
            r0 = _mm_srli_epi32(r0, 6);
3888
3889
2.28M
            r1 = _mm_and_si128(r1,
3890
2.28M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3891
2.28M
            r0 = _mm_and_si128(r0,
3892
2.28M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3893
2.28M
            r0 = _mm_hadd_epi16(r0, r1);
3894
2.28M
            _mm_store_si128((__m128i *) &dst[x], r0);
3895
3896
2.28M
        }
3897
1.48M
        tmp += MAX_PB_SIZE;
3898
1.48M
        dst += dststride;
3899
1.48M
    }
3900
153k
}
3901
void ff_hevc_put_hevc_qpel_h_2_v_1_sse(int16_t *dst, ptrdiff_t dststride,
3902
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
3903
120k
        int16_t* mcbuffer) {
3904
120k
    int x, y;
3905
120k
    uint8_t *src = (uint8_t*) _src;
3906
120k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
3907
120k
    int16_t *tmp = mcbuffer;
3908
120k
    __m128i x1, x2, x3, x4, x5, x6, x7, rBuffer, rTemp, r0, r1;
3909
120k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
3910
3911
120k
    src -= qpel_extra_before[1] * srcstride;
3912
120k
    r0 = _mm_set_epi8(-1, 4, -11, 40, 40, -11, 4, -1, -1, 4, -11, 40, 40, -11,
3913
120k
            4, -1);
3914
3915
    /* LOAD src from memory to registers to limit memory bandwidth */
3916
120k
    if (width == 4) {
3917
3918
159k
        for (y = 0; y < height + qpel_extra[1]; y += 2) {
3919
            /* load data in register     */
3920
140k
            x1 = _mm_loadu_si128((__m128i *) &src[-3]);
3921
140k
            src += srcstride;
3922
140k
            t1 = _mm_loadu_si128((__m128i *) &src[-3]);
3923
140k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
3924
140k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
3925
140k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
3926
140k
                    _mm_srli_si128(x1, 3));
3927
140k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
3928
140k
                    _mm_srli_si128(t1, 3));
3929
3930
            /*  PMADDUBSW then PMADDW     */
3931
140k
            x2 = _mm_maddubs_epi16(x2, r0);
3932
140k
            t2 = _mm_maddubs_epi16(t2, r0);
3933
140k
            x3 = _mm_maddubs_epi16(x3, r0);
3934
140k
            t3 = _mm_maddubs_epi16(t3, r0);
3935
140k
            x2 = _mm_hadd_epi16(x2, x3);
3936
140k
            t2 = _mm_hadd_epi16(t2, t3);
3937
140k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
3938
140k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
3939
140k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
3940
140k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
3941
            /* give results back            */
3942
140k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
3943
3944
140k
            tmp += MAX_PB_SIZE;
3945
140k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
3946
3947
140k
            src += srcstride;
3948
140k
            tmp += MAX_PB_SIZE;
3949
140k
        }
3950
19.4k
    } else
3951
1.67M
        for (y = 0; y < height + qpel_extra[1]; y++) {
3952
3.89M
            for (x = 0; x < width; x += 8) {
3953
                /* load data in register     */
3954
2.31M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
3955
2.31M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
3956
2.31M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
3957
2.31M
                        _mm_srli_si128(x1, 3));
3958
2.31M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
3959
2.31M
                        _mm_srli_si128(x1, 5));
3960
2.31M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
3961
2.31M
                        _mm_srli_si128(x1, 7));
3962
3963
                /*  PMADDUBSW then PMADDW     */
3964
2.31M
                x2 = _mm_maddubs_epi16(x2, r0);
3965
2.31M
                x3 = _mm_maddubs_epi16(x3, r0);
3966
2.31M
                x4 = _mm_maddubs_epi16(x4, r0);
3967
2.31M
                x5 = _mm_maddubs_epi16(x5, r0);
3968
2.31M
                x2 = _mm_hadd_epi16(x2, x3);
3969
2.31M
                x4 = _mm_hadd_epi16(x4, x5);
3970
2.31M
                x2 = _mm_hadd_epi16(x2, x4);
3971
2.31M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
3972
3973
                /* give results back            */
3974
2.31M
                _mm_store_si128((__m128i *) &tmp[x], x2);
3975
3976
2.31M
            }
3977
1.57M
            src += srcstride;
3978
1.57M
            tmp += MAX_PB_SIZE;
3979
1.57M
        }
3980
3981
120k
    tmp = mcbuffer + qpel_extra_before[1] * MAX_PB_SIZE;
3982
120k
    srcstride = MAX_PB_SIZE;
3983
3984
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
3985
     for register calculations */
3986
120k
    rTemp = _mm_set_epi16(0, 1, -5, 17, 58, -10, 4, -1);
3987
1.25M
    for (y = 0; y < height; y++) {
3988
2.83M
        for (x = 0; x < width; x += 8) {
3989
3990
1.70M
            x1 = _mm_load_si128((__m128i *) &tmp[x - 3 * srcstride]);
3991
1.70M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
3992
1.70M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
3993
1.70M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
3994
1.70M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
3995
1.70M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
3996
1.70M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
3997
3998
1.70M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 0));
3999
1.70M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
4000
1.70M
            t8 = _mm_mullo_epi16(x1, r0);
4001
1.70M
            rBuffer = _mm_mulhi_epi16(x1, r0);
4002
1.70M
            t7 = _mm_mullo_epi16(x2, r1);
4003
1.70M
            t1 = _mm_unpacklo_epi16(t8, rBuffer);
4004
1.70M
            x1 = _mm_unpackhi_epi16(t8, rBuffer);
4005
4006
1.70M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
4007
1.70M
            rBuffer = _mm_mulhi_epi16(x2, r1);
4008
1.70M
            t8 = _mm_mullo_epi16(x3, r0);
4009
1.70M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
4010
1.70M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
4011
4012
1.70M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
4013
1.70M
            rBuffer = _mm_mulhi_epi16(x3, r0);
4014
1.70M
            t7 = _mm_mullo_epi16(x4, r1);
4015
1.70M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
4016
1.70M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
4017
4018
1.70M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
4019
1.70M
            rBuffer = _mm_mulhi_epi16(x4, r1);
4020
1.70M
            t8 = _mm_mullo_epi16(x5, r0);
4021
1.70M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
4022
1.70M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
4023
4024
1.70M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
4025
1.70M
            rBuffer = _mm_mulhi_epi16(x5, r0);
4026
1.70M
            t7 = _mm_mullo_epi16(x6, r1);
4027
1.70M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
4028
1.70M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
4029
4030
1.70M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
4031
1.70M
            rBuffer = _mm_mulhi_epi16(x6, r1);
4032
1.70M
            t8 = _mm_mullo_epi16(x7, r0);
4033
1.70M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
4034
1.70M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
4035
4036
1.70M
            rBuffer = _mm_mulhi_epi16(x7, r0);
4037
1.70M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
4038
1.70M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
4039
4040
4041
4042
            /* add calculus by correct value : */
4043
4044
1.70M
            r1 = _mm_add_epi32(x1, x2);
4045
1.70M
            x3 = _mm_add_epi32(x3, x4);
4046
1.70M
            x5 = _mm_add_epi32(x5, x6);
4047
1.70M
            r1 = _mm_add_epi32(r1, x3);
4048
1.70M
            r1 = _mm_add_epi32(r1, x5);
4049
4050
1.70M
            r0 = _mm_add_epi32(t1, t2);
4051
1.70M
            t3 = _mm_add_epi32(t3, t4);
4052
1.70M
            t5 = _mm_add_epi32(t5, t6);
4053
1.70M
            r0 = _mm_add_epi32(r0, t3);
4054
1.70M
            r0 = _mm_add_epi32(r0, t5);
4055
1.70M
            r1 = _mm_add_epi32(r1, x7);
4056
1.70M
            r0 = _mm_add_epi32(r0, t7);
4057
1.70M
            r1 = _mm_srli_epi32(r1, 6);
4058
1.70M
            r0 = _mm_srli_epi32(r0, 6);
4059
4060
1.70M
            r1 = _mm_and_si128(r1,
4061
1.70M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4062
1.70M
            r0 = _mm_and_si128(r0,
4063
1.70M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4064
1.70M
            r0 = _mm_hadd_epi16(r0, r1);
4065
1.70M
            _mm_store_si128((__m128i *) &dst[x], r0);
4066
4067
1.70M
        }
4068
1.13M
        tmp += MAX_PB_SIZE;
4069
1.13M
        dst += dststride;
4070
1.13M
    }
4071
120k
}
4072
void ff_hevc_put_hevc_qpel_h_2_v_2_sse(int16_t *dst, ptrdiff_t dststride,
4073
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
4074
240k
        int16_t* mcbuffer) {
4075
240k
    int x, y;
4076
240k
    uint8_t *src = (uint8_t*) _src;
4077
240k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
4078
240k
    int16_t *tmp = mcbuffer;
4079
240k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, rBuffer, rTemp, r0, r1;
4080
240k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
4081
4082
240k
    src -= qpel_extra_before[2] * srcstride;
4083
240k
    r0 = _mm_set_epi8(-1, 4, -11, 40, 40, -11, 4, -1, -1, 4, -11, 40, 40, -11,
4084
240k
            4, -1);
4085
4086
    /* LOAD src from memory to registers to limit memory bandwidth */
4087
240k
    if (width == 4) {
4088
4089
465k
        for (y = 0; y < height + qpel_extra[2]; y += 2) {
4090
            /* load data in register     */
4091
413k
            x1 = _mm_loadu_si128((__m128i *) &src[-3]);
4092
413k
            src += srcstride;
4093
413k
            t1 = _mm_loadu_si128((__m128i *) &src[-3]);
4094
413k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4095
413k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
4096
413k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4097
413k
                    _mm_srli_si128(x1, 3));
4098
413k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
4099
413k
                    _mm_srli_si128(t1, 3));
4100
4101
            /*  PMADDUBSW then PMADDW     */
4102
413k
            x2 = _mm_maddubs_epi16(x2, r0);
4103
413k
            t2 = _mm_maddubs_epi16(t2, r0);
4104
413k
            x3 = _mm_maddubs_epi16(x3, r0);
4105
413k
            t3 = _mm_maddubs_epi16(t3, r0);
4106
413k
            x2 = _mm_hadd_epi16(x2, x3);
4107
413k
            t2 = _mm_hadd_epi16(t2, t3);
4108
413k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
4109
413k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
4110
413k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
4111
413k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
4112
            /* give results back            */
4113
413k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
4114
4115
413k
            tmp += MAX_PB_SIZE;
4116
413k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
4117
4118
413k
            src += srcstride;
4119
413k
            tmp += MAX_PB_SIZE;
4120
413k
        }
4121
51.4k
    } else
4122
3.33M
        for (y = 0; y < height + qpel_extra[2]; y++) {
4123
7.71M
            for (x = 0; x < width; x += 8) {
4124
                /* load data in register     */
4125
4.57M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
4126
4.57M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4127
4.57M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4128
4.57M
                        _mm_srli_si128(x1, 3));
4129
4.57M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
4130
4.57M
                        _mm_srli_si128(x1, 5));
4131
4.57M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
4132
4.57M
                        _mm_srli_si128(x1, 7));
4133
4134
                /*  PMADDUBSW then PMADDW     */
4135
4.57M
                x2 = _mm_maddubs_epi16(x2, r0);
4136
4.57M
                x3 = _mm_maddubs_epi16(x3, r0);
4137
4.57M
                x4 = _mm_maddubs_epi16(x4, r0);
4138
4.57M
                x5 = _mm_maddubs_epi16(x5, r0);
4139
4.57M
                x2 = _mm_hadd_epi16(x2, x3);
4140
4.57M
                x4 = _mm_hadd_epi16(x4, x5);
4141
4.57M
                x2 = _mm_hadd_epi16(x2, x4);
4142
4.57M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
4143
4144
                /* give results back            */
4145
4.57M
                _mm_store_si128((__m128i *) &tmp[x], x2);
4146
4147
4.57M
            }
4148
3.14M
            src += srcstride;
4149
3.14M
            tmp += MAX_PB_SIZE;
4150
3.14M
        }
4151
4152
240k
    tmp = mcbuffer + qpel_extra_before[2] * MAX_PB_SIZE;
4153
240k
    srcstride = MAX_PB_SIZE;
4154
4155
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
4156
     for register calculations */
4157
240k
    rTemp = _mm_set_epi16(-1, 4, -11, 40, 40, -11, 4, -1);
4158
2.47M
    for (y = 0; y < height; y++) {
4159
5.52M
        for (x = 0; x < width; x += 8) {
4160
4161
3.29M
            x1 = _mm_load_si128((__m128i *) &tmp[x - 3 * srcstride]);
4162
3.29M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
4163
3.29M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
4164
3.29M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
4165
3.29M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
4166
3.29M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
4167
3.29M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
4168
3.29M
            x8 = _mm_load_si128((__m128i *) &tmp[x + 4 * srcstride]);
4169
4170
3.29M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 0));
4171
3.29M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
4172
3.29M
            t8 = _mm_mullo_epi16(x1, r0);
4173
3.29M
            rBuffer = _mm_mulhi_epi16(x1, r0);
4174
3.29M
            t7 = _mm_mullo_epi16(x2, r1);
4175
3.29M
            t1 = _mm_unpacklo_epi16(t8, rBuffer);
4176
3.29M
            x1 = _mm_unpackhi_epi16(t8, rBuffer);
4177
4178
3.29M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
4179
3.29M
            rBuffer = _mm_mulhi_epi16(x2, r1);
4180
3.29M
            t8 = _mm_mullo_epi16(x3, r0);
4181
3.29M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
4182
3.29M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
4183
4184
3.29M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
4185
3.29M
            rBuffer = _mm_mulhi_epi16(x3, r0);
4186
3.29M
            t7 = _mm_mullo_epi16(x4, r1);
4187
3.29M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
4188
3.29M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
4189
4190
3.29M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
4191
3.29M
            rBuffer = _mm_mulhi_epi16(x4, r1);
4192
3.29M
            t8 = _mm_mullo_epi16(x5, r0);
4193
3.29M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
4194
3.29M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
4195
4196
3.29M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
4197
3.29M
            rBuffer = _mm_mulhi_epi16(x5, r0);
4198
3.29M
            t7 = _mm_mullo_epi16(x6, r1);
4199
3.29M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
4200
3.29M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
4201
4202
3.29M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
4203
3.29M
            rBuffer = _mm_mulhi_epi16(x6, r1);
4204
3.29M
            t8 = _mm_mullo_epi16(x7, r0);
4205
3.29M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
4206
3.29M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
4207
4208
3.29M
            rBuffer = _mm_mulhi_epi16(x7, r0);
4209
3.29M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
4210
3.29M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
4211
4212
3.29M
            t8 = _mm_unpacklo_epi16(
4213
3.29M
                    _mm_mullo_epi16(x8,
4214
3.29M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
4215
3.29M
                            _mm_mulhi_epi16(x8,
4216
3.29M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
4217
3.29M
            x8 = _mm_unpackhi_epi16(
4218
3.29M
                    _mm_mullo_epi16(x8,
4219
3.29M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
4220
3.29M
                            _mm_mulhi_epi16(x8,
4221
3.29M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
4222
4223
            /* add calculus by correct value : */
4224
4225
3.29M
            r1 = _mm_add_epi32(x1, x2);
4226
3.29M
            x3 = _mm_add_epi32(x3, x4);
4227
3.29M
            x5 = _mm_add_epi32(x5, x6);
4228
3.29M
            r1 = _mm_add_epi32(r1, x3);
4229
3.29M
            x7 = _mm_add_epi32(x7, x8);
4230
3.29M
            r1 = _mm_add_epi32(r1, x5);
4231
4232
3.29M
            r0 = _mm_add_epi32(t1, t2);
4233
3.29M
            t3 = _mm_add_epi32(t3, t4);
4234
3.29M
            t5 = _mm_add_epi32(t5, t6);
4235
3.29M
            r0 = _mm_add_epi32(r0, t3);
4236
3.29M
            t7 = _mm_add_epi32(t7, t8);
4237
3.29M
            r0 = _mm_add_epi32(r0, t5);
4238
3.29M
            r1 = _mm_add_epi32(r1, x7);
4239
3.29M
            r0 = _mm_add_epi32(r0, t7);
4240
3.29M
            r1 = _mm_srli_epi32(r1, 6);
4241
3.29M
            r0 = _mm_srli_epi32(r0, 6);
4242
4243
3.29M
            r1 = _mm_and_si128(r1,
4244
3.29M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4245
3.29M
            r0 = _mm_and_si128(r0,
4246
3.29M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4247
3.29M
            r0 = _mm_hadd_epi16(r0, r1);
4248
3.29M
            _mm_store_si128((__m128i *) &dst[x], r0);
4249
4250
3.29M
        }
4251
2.23M
        tmp += MAX_PB_SIZE;
4252
2.23M
        dst += dststride;
4253
2.23M
    }
4254
240k
}
4255
void ff_hevc_put_hevc_qpel_h_2_v_3_sse(int16_t *dst, ptrdiff_t dststride,
4256
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
4257
129k
        int16_t* mcbuffer) {
4258
129k
    int x, y;
4259
129k
    uint8_t *src = (uint8_t*) _src;
4260
129k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
4261
129k
    int16_t *tmp = mcbuffer;
4262
129k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, rBuffer, rTemp, r0, r1;
4263
129k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
4264
4265
129k
    src -= qpel_extra_before[3] * srcstride;
4266
129k
    r0 = _mm_set_epi8(-1, 4, -11, 40, 40, -11, 4, -1, -1, 4, -11, 40, 40, -11,
4267
129k
            4, -1);
4268
4269
    /* LOAD src from memory to registers to limit memory bandwidth */
4270
129k
    if (width == 4) {
4271
4272
223k
        for (y = 0; y < height + qpel_extra[3]; y += 2) {
4273
            /* load data in register     */
4274
196k
            x1 = _mm_loadu_si128((__m128i *) &src[-3]);
4275
196k
            src += srcstride;
4276
196k
            t1 = _mm_loadu_si128((__m128i *) &src[-3]);
4277
196k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4278
196k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
4279
196k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4280
196k
                    _mm_srli_si128(x1, 3));
4281
196k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
4282
196k
                    _mm_srli_si128(t1, 3));
4283
4284
            /*  PMADDUBSW then PMADDW     */
4285
196k
            x2 = _mm_maddubs_epi16(x2, r0);
4286
196k
            t2 = _mm_maddubs_epi16(t2, r0);
4287
196k
            x3 = _mm_maddubs_epi16(x3, r0);
4288
196k
            t3 = _mm_maddubs_epi16(t3, r0);
4289
196k
            x2 = _mm_hadd_epi16(x2, x3);
4290
196k
            t2 = _mm_hadd_epi16(t2, t3);
4291
196k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
4292
196k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
4293
196k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
4294
196k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
4295
            /* give results back            */
4296
196k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
4297
4298
196k
            tmp += MAX_PB_SIZE;
4299
196k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
4300
4301
196k
            src += srcstride;
4302
196k
            tmp += MAX_PB_SIZE;
4303
196k
        }
4304
27.3k
    } else
4305
1.71M
        for (y = 0; y < height + qpel_extra[3]; y++) {
4306
3.99M
            for (x = 0; x < width; x += 8) {
4307
                /* load data in register     */
4308
2.38M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 3]);
4309
2.38M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4310
2.38M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4311
2.38M
                        _mm_srli_si128(x1, 3));
4312
2.38M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
4313
2.38M
                        _mm_srli_si128(x1, 5));
4314
2.38M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
4315
2.38M
                        _mm_srli_si128(x1, 7));
4316
4317
                /*  PMADDUBSW then PMADDW     */
4318
2.38M
                x2 = _mm_maddubs_epi16(x2, r0);
4319
2.38M
                x3 = _mm_maddubs_epi16(x3, r0);
4320
2.38M
                x4 = _mm_maddubs_epi16(x4, r0);
4321
2.38M
                x5 = _mm_maddubs_epi16(x5, r0);
4322
2.38M
                x2 = _mm_hadd_epi16(x2, x3);
4323
2.38M
                x4 = _mm_hadd_epi16(x4, x5);
4324
2.38M
                x2 = _mm_hadd_epi16(x2, x4);
4325
2.38M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
4326
4327
                /* give results back            */
4328
2.38M
                _mm_store_si128((__m128i *) &tmp[x], x2);
4329
4330
2.38M
            }
4331
1.61M
            src += srcstride;
4332
1.61M
            tmp += MAX_PB_SIZE;
4333
1.61M
        }
4334
4335
129k
    tmp = mcbuffer + qpel_extra_before[3] * MAX_PB_SIZE;
4336
129k
    srcstride = MAX_PB_SIZE;
4337
4338
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
4339
     for register calculations */
4340
129k
    rTemp = _mm_set_epi16(-1, 4, -10, 58, 17, -5, 1, 0);
4341
1.35M
    for (y = 0; y < height; y++) {
4342
3.03M
        for (x = 0; x < width; x += 8) {
4343
4344
1.80M
            x1 = _mm_setzero_si128();
4345
1.80M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
4346
1.80M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
4347
1.80M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
4348
1.80M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
4349
1.80M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
4350
1.80M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
4351
1.80M
            x8 = _mm_load_si128((__m128i *) &tmp[x + 4 * srcstride]);
4352
4353
1.80M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
4354
4355
1.80M
            t7 = _mm_mullo_epi16(x2, r1);
4356
4357
4358
1.80M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
4359
1.80M
            rBuffer = _mm_mulhi_epi16(x2, r1);
4360
1.80M
            t8 = _mm_mullo_epi16(x3, r0);
4361
1.80M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
4362
1.80M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
4363
4364
1.80M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
4365
1.80M
            rBuffer = _mm_mulhi_epi16(x3, r0);
4366
1.80M
            t7 = _mm_mullo_epi16(x4, r1);
4367
1.80M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
4368
1.80M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
4369
4370
1.80M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
4371
1.80M
            rBuffer = _mm_mulhi_epi16(x4, r1);
4372
1.80M
            t8 = _mm_mullo_epi16(x5, r0);
4373
1.80M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
4374
1.80M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
4375
4376
1.80M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
4377
1.80M
            rBuffer = _mm_mulhi_epi16(x5, r0);
4378
1.80M
            t7 = _mm_mullo_epi16(x6, r1);
4379
1.80M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
4380
1.80M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
4381
4382
1.80M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
4383
1.80M
            rBuffer = _mm_mulhi_epi16(x6, r1);
4384
1.80M
            t8 = _mm_mullo_epi16(x7, r0);
4385
1.80M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
4386
1.80M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
4387
4388
1.80M
            rBuffer = _mm_mulhi_epi16(x7, r0);
4389
1.80M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
4390
1.80M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
4391
4392
1.80M
            t8 = _mm_unpacklo_epi16(
4393
1.80M
                    _mm_mullo_epi16(x8,
4394
1.80M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
4395
1.80M
                            _mm_mulhi_epi16(x8,
4396
1.80M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
4397
1.80M
            x8 = _mm_unpackhi_epi16(
4398
1.80M
                    _mm_mullo_epi16(x8,
4399
1.80M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
4400
1.80M
                            _mm_mulhi_epi16(x8,
4401
1.80M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
4402
4403
            /* add calculus by correct value : */
4404
4405
1.80M
            x3 = _mm_add_epi32(x3, x4);
4406
1.80M
            x5 = _mm_add_epi32(x5, x6);
4407
1.80M
            r1 = _mm_add_epi32(x2, x3);
4408
1.80M
            x7 = _mm_add_epi32(x7, x8);
4409
1.80M
            r1 = _mm_add_epi32(r1, x5);
4410
4411
1.80M
            t3 = _mm_add_epi32(t3, t4);
4412
1.80M
            t5 = _mm_add_epi32(t5, t6);
4413
1.80M
            r0 = _mm_add_epi32(t2, t3);
4414
1.80M
            t7 = _mm_add_epi32(t7, t8);
4415
1.80M
            r0 = _mm_add_epi32(r0, t5);
4416
1.80M
            r1 = _mm_add_epi32(r1, x7);
4417
1.80M
            r0 = _mm_add_epi32(r0, t7);
4418
1.80M
            r1 = _mm_srli_epi32(r1, 6);
4419
1.80M
            r0 = _mm_srli_epi32(r0, 6);
4420
4421
1.80M
            r1 = _mm_and_si128(r1,
4422
1.80M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4423
1.80M
            r0 = _mm_and_si128(r0,
4424
1.80M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4425
1.80M
            r0 = _mm_hadd_epi16(r0, r1);
4426
1.80M
            _mm_store_si128((__m128i *) &dst[x], r0);
4427
4428
1.80M
        }
4429
1.22M
        tmp += MAX_PB_SIZE;
4430
1.22M
        dst += dststride;
4431
1.22M
    }
4432
129k
}
4433
void ff_hevc_put_hevc_qpel_h_3_v_1_sse(int16_t *dst, ptrdiff_t dststride,
4434
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
4435
136k
        int16_t* mcbuffer) {
4436
136k
    int x, y;
4437
136k
    uint8_t *src = (uint8_t*) _src;
4438
136k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
4439
136k
    int16_t *tmp = mcbuffer;
4440
136k
    __m128i x1, x2, x3, x4, x5, x6, x7, rBuffer, rTemp, r0, r1;
4441
136k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
4442
4443
136k
    src -= qpel_extra_before[1] * srcstride;
4444
136k
    r0 = _mm_set_epi8(-1, 4, -10, 58, 17, -5, 1, 0, -1, 4, -10, 58, 17, -5, 1,
4445
136k
            0);
4446
4447
    /* LOAD src from memory to registers to limit memory bandwidth */
4448
136k
    if (width == 4) {
4449
4450
191k
        for (y = 0; y < height + qpel_extra[1]; y += 2) {
4451
            /* load data in register     */
4452
168k
            x1 = _mm_loadu_si128((__m128i *) &src[-2]);
4453
168k
            x1 = _mm_slli_si128(x1, 1);
4454
168k
            src += srcstride;
4455
168k
            t1 = _mm_loadu_si128((__m128i *) &src[-2]);
4456
168k
            t1 = _mm_slli_si128(t1, 1);
4457
168k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4458
168k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
4459
168k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4460
168k
                    _mm_srli_si128(x1, 3));
4461
168k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
4462
168k
                    _mm_srli_si128(t1, 3));
4463
4464
            /*  PMADDUBSW then PMADDW     */
4465
168k
            x2 = _mm_maddubs_epi16(x2, r0);
4466
168k
            t2 = _mm_maddubs_epi16(t2, r0);
4467
168k
            x3 = _mm_maddubs_epi16(x3, r0);
4468
168k
            t3 = _mm_maddubs_epi16(t3, r0);
4469
168k
            x2 = _mm_hadd_epi16(x2, x3);
4470
168k
            t2 = _mm_hadd_epi16(t2, t3);
4471
168k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
4472
168k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
4473
168k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
4474
168k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
4475
            /* give results back            */
4476
168k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
4477
4478
168k
            tmp += MAX_PB_SIZE;
4479
168k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
4480
4481
168k
            src += srcstride;
4482
168k
            tmp += MAX_PB_SIZE;
4483
168k
        }
4484
23.8k
    } else
4485
1.96M
        for (y = 0; y < height + qpel_extra[1]; y++) {
4486
4.79M
            for (x = 0; x < width; x += 8) {
4487
                /* load data in register     */
4488
2.94M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 2]);
4489
2.94M
                x1 = _mm_slli_si128(x1, 1);
4490
2.94M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4491
2.94M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4492
2.94M
                        _mm_srli_si128(x1, 3));
4493
2.94M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
4494
2.94M
                        _mm_srli_si128(x1, 5));
4495
2.94M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
4496
2.94M
                        _mm_srli_si128(x1, 7));
4497
4498
                /*  PMADDUBSW then PMADDW     */
4499
2.94M
                x2 = _mm_maddubs_epi16(x2, r0);
4500
2.94M
                x3 = _mm_maddubs_epi16(x3, r0);
4501
2.94M
                x4 = _mm_maddubs_epi16(x4, r0);
4502
2.94M
                x5 = _mm_maddubs_epi16(x5, r0);
4503
2.94M
                x2 = _mm_hadd_epi16(x2, x3);
4504
2.94M
                x4 = _mm_hadd_epi16(x4, x5);
4505
2.94M
                x2 = _mm_hadd_epi16(x2, x4);
4506
2.94M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
4507
4508
                /* give results back            */
4509
2.94M
                _mm_store_si128((__m128i *) &tmp[x], x2);
4510
4511
2.94M
            }
4512
1.85M
            src += srcstride;
4513
1.85M
            tmp += MAX_PB_SIZE;
4514
1.85M
        }
4515
4516
136k
    tmp = mcbuffer + qpel_extra_before[1] * MAX_PB_SIZE;
4517
136k
    srcstride = MAX_PB_SIZE;
4518
4519
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
4520
     for register calculations */
4521
136k
    rTemp = _mm_set_epi16(0, 1, -5, 17, 58, -10, 4, -1);
4522
1.51M
    for (y = 0; y < height; y++) {
4523
3.58M
        for (x = 0; x < width; x += 8) {
4524
4525
2.21M
            x1 = _mm_load_si128((__m128i *) &tmp[x - 3 * srcstride]);
4526
2.21M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
4527
2.21M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
4528
2.21M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
4529
2.21M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
4530
2.21M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
4531
2.21M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
4532
4533
2.21M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 0));
4534
2.21M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
4535
2.21M
            t8 = _mm_mullo_epi16(x1, r0);
4536
2.21M
            rBuffer = _mm_mulhi_epi16(x1, r0);
4537
2.21M
            t7 = _mm_mullo_epi16(x2, r1);
4538
2.21M
            t1 = _mm_unpacklo_epi16(t8, rBuffer);
4539
2.21M
            x1 = _mm_unpackhi_epi16(t8, rBuffer);
4540
4541
2.21M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
4542
2.21M
            rBuffer = _mm_mulhi_epi16(x2, r1);
4543
2.21M
            t8 = _mm_mullo_epi16(x3, r0);
4544
2.21M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
4545
2.21M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
4546
4547
2.21M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
4548
2.21M
            rBuffer = _mm_mulhi_epi16(x3, r0);
4549
2.21M
            t7 = _mm_mullo_epi16(x4, r1);
4550
2.21M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
4551
2.21M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
4552
4553
2.21M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
4554
2.21M
            rBuffer = _mm_mulhi_epi16(x4, r1);
4555
2.21M
            t8 = _mm_mullo_epi16(x5, r0);
4556
2.21M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
4557
2.21M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
4558
4559
2.21M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
4560
2.21M
            rBuffer = _mm_mulhi_epi16(x5, r0);
4561
2.21M
            t7 = _mm_mullo_epi16(x6, r1);
4562
2.21M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
4563
2.21M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
4564
4565
2.21M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
4566
2.21M
            rBuffer = _mm_mulhi_epi16(x6, r1);
4567
2.21M
            t8 = _mm_mullo_epi16(x7, r0);
4568
2.21M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
4569
2.21M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
4570
4571
2.21M
            rBuffer = _mm_mulhi_epi16(x7, r0);
4572
2.21M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
4573
2.21M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
4574
4575
4576
            /* add calculus by correct value : */
4577
4578
2.21M
            r1 = _mm_add_epi32(x1, x2);
4579
2.21M
            x3 = _mm_add_epi32(x3, x4);
4580
2.21M
            x5 = _mm_add_epi32(x5, x6);
4581
2.21M
            r1 = _mm_add_epi32(r1, x3);
4582
2.21M
            r1 = _mm_add_epi32(r1, x5);
4583
4584
2.21M
            r0 = _mm_add_epi32(t1, t2);
4585
2.21M
            t3 = _mm_add_epi32(t3, t4);
4586
2.21M
            t5 = _mm_add_epi32(t5, t6);
4587
2.21M
            r0 = _mm_add_epi32(r0, t3);
4588
2.21M
            r0 = _mm_add_epi32(r0, t5);
4589
2.21M
            r1 = _mm_add_epi32(r1, x7);
4590
2.21M
            r0 = _mm_add_epi32(r0, t7);
4591
2.21M
            r1 = _mm_srli_epi32(r1, 6);
4592
2.21M
            r0 = _mm_srli_epi32(r0, 6);
4593
4594
2.21M
            r1 = _mm_and_si128(r1,
4595
2.21M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4596
2.21M
            r0 = _mm_and_si128(r0,
4597
2.21M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4598
2.21M
            r0 = _mm_hadd_epi16(r0, r1);
4599
2.21M
            _mm_store_si128((__m128i *) &dst[x], r0);
4600
4601
2.21M
        }
4602
1.37M
        tmp += MAX_PB_SIZE;
4603
1.37M
        dst += dststride;
4604
1.37M
    }
4605
136k
}
4606
void ff_hevc_put_hevc_qpel_h_3_v_2_sse(int16_t *dst, ptrdiff_t dststride,
4607
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
4608
114k
        int16_t* mcbuffer) {
4609
114k
    int x, y;
4610
114k
    uint8_t *src = (uint8_t*) _src;
4611
114k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
4612
114k
    int16_t *tmp = mcbuffer;
4613
114k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, rBuffer, rTemp, r0, r1;
4614
114k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
4615
4616
114k
    src -= qpel_extra_before[2] * srcstride;
4617
114k
    r0 = _mm_set_epi8(-1, 4, -10, 58, 17, -5, 1, 0, -1, 4, -10, 58, 17, -5, 1,
4618
114k
            0);
4619
4620
    /* LOAD src from memory to registers to limit memory bandwidth */
4621
114k
    if (width == 4) {
4622
4623
193k
        for (y = 0; y < height + qpel_extra[2]; y += 2) {
4624
            /* load data in register     */
4625
171k
            x1 = _mm_loadu_si128((__m128i *) &src[-2]);
4626
171k
            x1 = _mm_slli_si128(x1, 1);
4627
171k
            src += srcstride;
4628
171k
            t1 = _mm_loadu_si128((__m128i *) &src[-2]);
4629
171k
            t1 = _mm_slli_si128(t1, 1);
4630
171k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4631
171k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
4632
171k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4633
171k
                    _mm_srli_si128(x1, 3));
4634
171k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
4635
171k
                    _mm_srli_si128(t1, 3));
4636
4637
            /*  PMADDUBSW then PMADDW     */
4638
171k
            x2 = _mm_maddubs_epi16(x2, r0);
4639
171k
            t2 = _mm_maddubs_epi16(t2, r0);
4640
171k
            x3 = _mm_maddubs_epi16(x3, r0);
4641
171k
            t3 = _mm_maddubs_epi16(t3, r0);
4642
171k
            x2 = _mm_hadd_epi16(x2, x3);
4643
171k
            t2 = _mm_hadd_epi16(t2, t3);
4644
171k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
4645
171k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
4646
171k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
4647
171k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
4648
            /* give results back            */
4649
171k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
4650
4651
171k
            tmp += MAX_PB_SIZE;
4652
171k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
4653
4654
171k
            src += srcstride;
4655
171k
            tmp += MAX_PB_SIZE;
4656
171k
        }
4657
21.2k
    } else
4658
1.63M
        for (y = 0; y < height + qpel_extra[2]; y++) {
4659
3.77M
            for (x = 0; x < width; x += 8) {
4660
                /* load data in register     */
4661
2.23M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 2]);
4662
2.23M
                x1 = _mm_slli_si128(x1, 1);
4663
2.23M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4664
2.23M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4665
2.23M
                        _mm_srli_si128(x1, 3));
4666
2.23M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
4667
2.23M
                        _mm_srli_si128(x1, 5));
4668
2.23M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
4669
2.23M
                        _mm_srli_si128(x1, 7));
4670
4671
                /*  PMADDUBSW then PMADDW     */
4672
2.23M
                x2 = _mm_maddubs_epi16(x2, r0);
4673
2.23M
                x3 = _mm_maddubs_epi16(x3, r0);
4674
2.23M
                x4 = _mm_maddubs_epi16(x4, r0);
4675
2.23M
                x5 = _mm_maddubs_epi16(x5, r0);
4676
2.23M
                x2 = _mm_hadd_epi16(x2, x3);
4677
2.23M
                x4 = _mm_hadd_epi16(x4, x5);
4678
2.23M
                x2 = _mm_hadd_epi16(x2, x4);
4679
2.23M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
4680
4681
                /* give results back            */
4682
2.23M
                _mm_store_si128((__m128i *) &tmp[x], x2);
4683
4684
2.23M
            }
4685
1.54M
            src += srcstride;
4686
1.54M
            tmp += MAX_PB_SIZE;
4687
1.54M
        }
4688
4689
114k
    tmp = mcbuffer + qpel_extra_before[2] * MAX_PB_SIZE;
4690
114k
    srcstride = MAX_PB_SIZE;
4691
4692
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
4693
     for register calculations */
4694
114k
    rTemp = _mm_set_epi16(-1, 4, -11, 40, 40, -11, 4, -1);
4695
1.17M
    for (y = 0; y < height; y++) {
4696
2.62M
        for (x = 0; x < width; x += 8) {
4697
4698
1.56M
            x1 = _mm_load_si128((__m128i *) &tmp[x - 3 * srcstride]);
4699
1.56M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
4700
1.56M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
4701
1.56M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
4702
1.56M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
4703
1.56M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
4704
1.56M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
4705
1.56M
            x8 = _mm_load_si128((__m128i *) &tmp[x + 4 * srcstride]);
4706
4707
1.56M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 0));
4708
1.56M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
4709
1.56M
            t8 = _mm_mullo_epi16(x1, r0);
4710
1.56M
            rBuffer = _mm_mulhi_epi16(x1, r0);
4711
1.56M
            t7 = _mm_mullo_epi16(x2, r1);
4712
1.56M
            t1 = _mm_unpacklo_epi16(t8, rBuffer);
4713
1.56M
            x1 = _mm_unpackhi_epi16(t8, rBuffer);
4714
4715
1.56M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
4716
1.56M
            rBuffer = _mm_mulhi_epi16(x2, r1);
4717
1.56M
            t8 = _mm_mullo_epi16(x3, r0);
4718
1.56M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
4719
1.56M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
4720
4721
1.56M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
4722
1.56M
            rBuffer = _mm_mulhi_epi16(x3, r0);
4723
1.56M
            t7 = _mm_mullo_epi16(x4, r1);
4724
1.56M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
4725
1.56M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
4726
4727
1.56M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
4728
1.56M
            rBuffer = _mm_mulhi_epi16(x4, r1);
4729
1.56M
            t8 = _mm_mullo_epi16(x5, r0);
4730
1.56M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
4731
1.56M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
4732
4733
1.56M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
4734
1.56M
            rBuffer = _mm_mulhi_epi16(x5, r0);
4735
1.56M
            t7 = _mm_mullo_epi16(x6, r1);
4736
1.56M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
4737
1.56M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
4738
4739
1.56M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
4740
1.56M
            rBuffer = _mm_mulhi_epi16(x6, r1);
4741
1.56M
            t8 = _mm_mullo_epi16(x7, r0);
4742
1.56M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
4743
1.56M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
4744
4745
1.56M
            rBuffer = _mm_mulhi_epi16(x7, r0);
4746
1.56M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
4747
1.56M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
4748
4749
1.56M
            t8 = _mm_unpacklo_epi16(
4750
1.56M
                    _mm_mullo_epi16(x8,
4751
1.56M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
4752
1.56M
                            _mm_mulhi_epi16(x8,
4753
1.56M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
4754
1.56M
            x8 = _mm_unpackhi_epi16(
4755
1.56M
                    _mm_mullo_epi16(x8,
4756
1.56M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
4757
1.56M
                            _mm_mulhi_epi16(x8,
4758
1.56M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
4759
4760
            /* add calculus by correct value : */
4761
4762
1.56M
            r1 = _mm_add_epi32(x1, x2);
4763
1.56M
            x3 = _mm_add_epi32(x3, x4);
4764
1.56M
            x5 = _mm_add_epi32(x5, x6);
4765
1.56M
            r1 = _mm_add_epi32(r1, x3);
4766
1.56M
            x7 = _mm_add_epi32(x7, x8);
4767
1.56M
            r1 = _mm_add_epi32(r1, x5);
4768
4769
1.56M
            r0 = _mm_add_epi32(t1, t2);
4770
1.56M
            t3 = _mm_add_epi32(t3, t4);
4771
1.56M
            t5 = _mm_add_epi32(t5, t6);
4772
1.56M
            r0 = _mm_add_epi32(r0, t3);
4773
1.56M
            t7 = _mm_add_epi32(t7, t8);
4774
1.56M
            r0 = _mm_add_epi32(r0, t5);
4775
1.56M
            r1 = _mm_add_epi32(r1, x7);
4776
1.56M
            r0 = _mm_add_epi32(r0, t7);
4777
1.56M
            r1 = _mm_srli_epi32(r1, 6);
4778
1.56M
            r0 = _mm_srli_epi32(r0, 6);
4779
4780
1.56M
            r1 = _mm_and_si128(r1,
4781
1.56M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4782
1.56M
            r0 = _mm_and_si128(r0,
4783
1.56M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4784
1.56M
            r0 = _mm_hadd_epi16(r0, r1);
4785
1.56M
            _mm_store_si128((__m128i *) &dst[x], r0);
4786
4787
1.56M
        }
4788
1.06M
        tmp += MAX_PB_SIZE;
4789
1.06M
        dst += dststride;
4790
1.06M
    }
4791
114k
}
4792
void ff_hevc_put_hevc_qpel_h_3_v_3_sse(int16_t *dst, ptrdiff_t dststride,
4793
                                       const uint8_t *_src, ptrdiff_t _srcstride, int width, int height,
4794
218k
        int16_t* mcbuffer) {
4795
218k
    int x, y;
4796
218k
    uint8_t *src = (uint8_t*) _src;
4797
218k
    ptrdiff_t srcstride = _srcstride / sizeof(uint8_t);
4798
218k
    int16_t *tmp = mcbuffer;
4799
218k
    __m128i x1, x2, x3, x4, x5, x6, x7, x8, rBuffer, rTemp, r0, r1;
4800
218k
    __m128i t1, t2, t3, t4, t5, t6, t7, t8;
4801
4802
218k
    src -= qpel_extra_before[3] * srcstride;
4803
218k
    r0 = _mm_set_epi8(-1, 4, -10, 58, 17, -5, 1, 0, -1, 4, -10, 58, 17, -5, 1,
4804
218k
            0);
4805
4806
    /* LOAD src from memory to registers to limit memory bandwidth */
4807
218k
    if (width == 4) {
4808
4809
380k
        for (y = 0; y < height + qpel_extra[3]; y += 2) {
4810
            /* load data in register     */
4811
333k
            x1 = _mm_loadu_si128((__m128i *) &src[-2]);
4812
333k
            x1 = _mm_slli_si128(x1, 1);
4813
333k
            src += srcstride;
4814
333k
            t1 = _mm_loadu_si128((__m128i *) &src[-2]);
4815
333k
            t1 = _mm_slli_si128(t1, 1);
4816
333k
            x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4817
333k
            t2 = _mm_unpacklo_epi64(t1, _mm_srli_si128(t1, 1));
4818
333k
            x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4819
333k
                    _mm_srli_si128(x1, 3));
4820
333k
            t3 = _mm_unpacklo_epi64(_mm_srli_si128(t1, 2),
4821
333k
                    _mm_srli_si128(t1, 3));
4822
4823
            /*  PMADDUBSW then PMADDW     */
4824
333k
            x2 = _mm_maddubs_epi16(x2, r0);
4825
333k
            t2 = _mm_maddubs_epi16(t2, r0);
4826
333k
            x3 = _mm_maddubs_epi16(x3, r0);
4827
333k
            t3 = _mm_maddubs_epi16(t3, r0);
4828
333k
            x2 = _mm_hadd_epi16(x2, x3);
4829
333k
            t2 = _mm_hadd_epi16(t2, t3);
4830
333k
            x2 = _mm_hadd_epi16(x2, _mm_set1_epi16(0));
4831
333k
            t2 = _mm_hadd_epi16(t2, _mm_set1_epi16(0));
4832
333k
            x2 = _mm_srli_epi16(x2, BIT_DEPTH - 8);
4833
333k
            t2 = _mm_srli_epi16(t2, BIT_DEPTH - 8);
4834
            /* give results back            */
4835
333k
            _mm_storel_epi64((__m128i *) &tmp[0], x2);
4836
4837
333k
            tmp += MAX_PB_SIZE;
4838
333k
            _mm_storel_epi64((__m128i *) &tmp[0], t2);
4839
4840
333k
            src += srcstride;
4841
333k
            tmp += MAX_PB_SIZE;
4842
333k
        }
4843
46.8k
    } else
4844
2.89M
        for (y = 0; y < height + qpel_extra[3]; y++) {
4845
6.92M
            for (x = 0; x < width; x += 8) {
4846
                /* load data in register     */
4847
4.20M
                x1 = _mm_loadu_si128((__m128i *) &src[x - 2]);
4848
4.20M
                x1 = _mm_slli_si128(x1, 1);
4849
4.20M
                x2 = _mm_unpacklo_epi64(x1, _mm_srli_si128(x1, 1));
4850
4.20M
                x3 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 2),
4851
4.20M
                        _mm_srli_si128(x1, 3));
4852
4.20M
                x4 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 4),
4853
4.20M
                        _mm_srli_si128(x1, 5));
4854
4.20M
                x5 = _mm_unpacklo_epi64(_mm_srli_si128(x1, 6),
4855
4.20M
                        _mm_srli_si128(x1, 7));
4856
4857
                /*  PMADDUBSW then PMADDW     */
4858
4.20M
                x2 = _mm_maddubs_epi16(x2, r0);
4859
4.20M
                x3 = _mm_maddubs_epi16(x3, r0);
4860
4.20M
                x4 = _mm_maddubs_epi16(x4, r0);
4861
4.20M
                x5 = _mm_maddubs_epi16(x5, r0);
4862
4.20M
                x2 = _mm_hadd_epi16(x2, x3);
4863
4.20M
                x4 = _mm_hadd_epi16(x4, x5);
4864
4.20M
                x2 = _mm_hadd_epi16(x2, x4);
4865
4.20M
                x2 = _mm_srli_si128(x2, BIT_DEPTH - 8);
4866
4867
                /* give results back            */
4868
4.20M
                _mm_store_si128((__m128i *) &tmp[x], x2);
4869
4870
4.20M
            }
4871
2.72M
            src += srcstride;
4872
2.72M
            tmp += MAX_PB_SIZE;
4873
2.72M
        }
4874
4875
218k
    tmp = mcbuffer + qpel_extra_before[3] * MAX_PB_SIZE;
4876
218k
    srcstride = MAX_PB_SIZE;
4877
4878
    /* vertical treatment on temp table : tmp contains 16 bit values, so need to use 32 bit  integers
4879
     for register calculations */
4880
218k
    rTemp = _mm_set_epi16(-1, 4, -10, 58, 17, -5, 1, 0);
4881
2.30M
    for (y = 0; y < height; y++) {
4882
5.28M
        for (x = 0; x < width; x += 8) {
4883
4884
3.19M
            x1 = _mm_setzero_si128();
4885
3.19M
            x2 = _mm_load_si128((__m128i *) &tmp[x - 2 * srcstride]);
4886
3.19M
            x3 = _mm_load_si128((__m128i *) &tmp[x - srcstride]);
4887
3.19M
            x4 = _mm_load_si128((__m128i *) &tmp[x]);
4888
3.19M
            x5 = _mm_load_si128((__m128i *) &tmp[x + srcstride]);
4889
3.19M
            x6 = _mm_load_si128((__m128i *) &tmp[x + 2 * srcstride]);
4890
3.19M
            x7 = _mm_load_si128((__m128i *) &tmp[x + 3 * srcstride]);
4891
3.19M
            x8 = _mm_load_si128((__m128i *) &tmp[x + 4 * srcstride]);
4892
4893
3.19M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 1));
4894
3.19M
            t7 = _mm_mullo_epi16(x2, r1);
4895
4896
4897
3.19M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 2));
4898
3.19M
            rBuffer = _mm_mulhi_epi16(x2, r1);
4899
3.19M
            t8 = _mm_mullo_epi16(x3, r0);
4900
3.19M
            t2 = _mm_unpacklo_epi16(t7, rBuffer);
4901
3.19M
            x2 = _mm_unpackhi_epi16(t7, rBuffer);
4902
4903
3.19M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 3));
4904
3.19M
            rBuffer = _mm_mulhi_epi16(x3, r0);
4905
3.19M
            t7 = _mm_mullo_epi16(x4, r1);
4906
3.19M
            t3 = _mm_unpacklo_epi16(t8, rBuffer);
4907
3.19M
            x3 = _mm_unpackhi_epi16(t8, rBuffer);
4908
4909
3.19M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 4));
4910
3.19M
            rBuffer = _mm_mulhi_epi16(x4, r1);
4911
3.19M
            t8 = _mm_mullo_epi16(x5, r0);
4912
3.19M
            t4 = _mm_unpacklo_epi16(t7, rBuffer);
4913
3.19M
            x4 = _mm_unpackhi_epi16(t7, rBuffer);
4914
4915
3.19M
            r1 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 5));
4916
3.19M
            rBuffer = _mm_mulhi_epi16(x5, r0);
4917
3.19M
            t7 = _mm_mullo_epi16(x6, r1);
4918
3.19M
            t5 = _mm_unpacklo_epi16(t8, rBuffer);
4919
3.19M
            x5 = _mm_unpackhi_epi16(t8, rBuffer);
4920
4921
3.19M
            r0 = _mm_set1_epi16(_mm_extract_epi16(rTemp, 6));
4922
3.19M
            rBuffer = _mm_mulhi_epi16(x6, r1);
4923
3.19M
            t8 = _mm_mullo_epi16(x7, r0);
4924
3.19M
            t6 = _mm_unpacklo_epi16(t7, rBuffer);
4925
3.19M
            x6 = _mm_unpackhi_epi16(t7, rBuffer);
4926
4927
3.19M
            rBuffer = _mm_mulhi_epi16(x7, r0);
4928
3.19M
            t7 = _mm_unpacklo_epi16(t8, rBuffer);
4929
3.19M
            x7 = _mm_unpackhi_epi16(t8, rBuffer);
4930
4931
3.19M
            t8 = _mm_unpacklo_epi16(
4932
3.19M
                    _mm_mullo_epi16(x8,
4933
3.19M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
4934
3.19M
                            _mm_mulhi_epi16(x8,
4935
3.19M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
4936
3.19M
            x8 = _mm_unpackhi_epi16(
4937
3.19M
                    _mm_mullo_epi16(x8,
4938
3.19M
                            _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))),
4939
3.19M
                            _mm_mulhi_epi16(x8,
4940
3.19M
                                    _mm_set1_epi16(_mm_extract_epi16(rTemp, 7))));
4941
4942
            /* add calculus by correct value : */
4943
4944
3.19M
            x3 = _mm_add_epi32(x3, x4);
4945
3.19M
            x5 = _mm_add_epi32(x5, x6);
4946
3.19M
            r1 = _mm_add_epi32(x2, x3);
4947
3.19M
            x7 = _mm_add_epi32(x7, x8);
4948
3.19M
            r1 = _mm_add_epi32(r1, x5);
4949
4950
3.19M
            t3 = _mm_add_epi32(t3, t4);
4951
3.19M
            t5 = _mm_add_epi32(t5, t6);
4952
3.19M
            r0 = _mm_add_epi32(t2, t3);
4953
3.19M
            t7 = _mm_add_epi32(t7, t8);
4954
3.19M
            r0 = _mm_add_epi32(r0, t5);
4955
3.19M
            r1 = _mm_add_epi32(r1, x7);
4956
3.19M
            r0 = _mm_add_epi32(r0, t7);
4957
3.19M
            r1 = _mm_srli_epi32(r1, 6);
4958
3.19M
            r0 = _mm_srli_epi32(r0, 6);
4959
4960
3.19M
            r1 = _mm_and_si128(r1,
4961
3.19M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4962
3.19M
            r0 = _mm_and_si128(r0,
4963
3.19M
                    _mm_set_epi16(0, -1, 0, -1, 0, -1, 0, -1));
4964
3.19M
            r0 = _mm_hadd_epi16(r0, r1);
4965
3.19M
            _mm_store_si128((__m128i *) &dst[x], r0);
4966
4967
3.19M
        }
4968
2.08M
        tmp += MAX_PB_SIZE;
4969
2.08M
        dst += dststride;
4970
2.08M
    }
4971
218k
}