summaryrefslogtreecommitdiffstats
path: root/libavcodec/x86/hevc_mc.asm
blob: 16e5eefc699509605fc5dcbb99ebd3d27210c808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
;*****************************************************************************
;* x86-optimized HEVC MC
;* Copyright 2015 Anton Khirnov
;*
;* This file is part of Libav.
;*
;* Libav is free software; you can redistribute it and/or
;* modify it under the terms of the GNU Lesser General Public
;* License as published by the Free Software Foundation; either
;* version 2.1 of the License, or (at your option) any later version.
;*
;* Libav is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
;* License along with Libav; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************

%include "libavutil/x86/x86util.asm"

SECTION_RODATA

pw_1023: times 8 dw 1023

cextern hevc_qpel_coeffs
cextern hevc_qpel_coeffs8

cextern hevc_epel_coeffs
cextern hevc_epel_coeffs8

cextern pw_8
cextern pw_16
cextern pw_32
cextern pw_64

SECTION .text

; %1: width
; %2: bit depth
%macro COMMON_DEFS 2
    %assign blocksize            8
    %assign nb_blocks            ((%1 + blocksize - 1) / blocksize)
    %define last_block_truncated (blocksize * nb_blocks > %1)
    %if %2 > 8
        %define LOAD_BLOCK     movu
        %define LOAD_HALFBLOCK movq
        %assign pixelsize      2
    %else
        %define LOAD_BLOCK     movq
        %define LOAD_HALFBLOCK movd
        %assign pixelsize      1
    %endif
    %define STORE_BLOCK        mova
    %define STORE_HALFBLOCK    movq
%endmacro

; %1: block index
%macro BLOCK_DEFS 1
    %if last_block_truncated && %1 == nb_blocks - 1
        %define block_truncated 1
        %define LOAD            LOAD_HALFBLOCK
        %define STORE           STORE_HALFBLOCK
    %else
        %define block_truncated 0
        %define LOAD            LOAD_BLOCK
        %define STORE           STORE_BLOCK
    %endif
%endmacro


; hevc_get_pixels_<w>_<d>(int16_t *dst, ptrdiff_t dststride,
;                         pixel   *src, ptrdiff_t srcstride,
;                         int height, int mx, int my, int *mcbuffer)

; %1: block width
; %2: bit depth
; %3: log2 of height unroll
%macro GET_PIXELS 3
cglobal hevc_get_pixels_ %+ %1 %+ _ %+ %2, 5, 5, 2, dst, dststride, src, srcstride, height ; rest of the args unused

    %assign shift 14 - %2
    COMMON_DEFS %1, %2

%if pixelsize == 1
    pxor      m0, m0
%endif

    shr       heightd, %3

.loop:

%assign i 0
%rep (1 << %3)

%assign j 0
%rep nb_blocks

    BLOCK_DEFS j

    LOAD       m1, [srcq + j * pixelsize * blocksize]
%if pixelsize == 1
    punpcklbw  m1, m0
%endif
    psllw      m1, shift
    STORE      [dstq + j * 2 * blocksize], m1

%assign j (j + 1)
%endrep

    add       dstq, dststrideq
    add       srcq, srcstrideq

%assign i (i + 1)
%endrep

    dec heightd
    jg .loop
    RET
%endmacro

INIT_XMM sse2
GET_PIXELS 4,  8, 1
GET_PIXELS 8,  8, 1
GET_PIXELS 12, 8, 3
GET_PIXELS 16, 8, 2
GET_PIXELS 24, 8, 3
GET_PIXELS 32, 8, 3
GET_PIXELS 48, 8, 3
GET_PIXELS 64, 8, 3

GET_PIXELS 4,  10, 1
GET_PIXELS 8,  10, 1
GET_PIXELS 12, 10, 3
GET_PIXELS 16, 10, 2
GET_PIXELS 24, 10, 3
GET_PIXELS 32, 10, 3
GET_PIXELS 48, 10, 3
GET_PIXELS 64, 10, 3

; hevc_qpel_h/v_<w>_8(int16_t *dst, ptrdiff_t dststride,
;                     uint8_t *src, ptrdiff_t srcstride,
;                     int height, int mx, int my, int *mcbuffer)

; 8-bit qpel interpolation
; %1: block width
; %2: 0 - horizontal; 1 - vertical
%macro QPEL_8 2
%if %2
    %define postfix    v
    %define mvfrac     myq
    %define coeffsaddr r5q
    %define pixstride  srcstrideq
    %define pixstride3 r5q
    %define src_m3     r6q
%else
    %define postfix    h
    %define mvfrac     mxq
    %define coeffsaddr r6q
    %define pixstride  1
    %define pixstride3 3
    %define src_m3     (srcq - 3)
%endif

    COMMON_DEFS %1, 8

cglobal hevc_qpel_ %+ postfix %+ _ %+ %1 %+ _8, 7, 7, 7, dst, dststride, src, srcstride, height, mx, my
    and       mvfrac, 0x3
    dec       mvfrac
    shl       mvfrac, 4
    lea       coeffsaddr, [hevc_qpel_coeffs8]
    mova      m0,         [coeffsaddr + mvfrac]

    SPLATW    m1, m0, 1
    SPLATW    m2, m0, 2
    SPLATW    m3, m0, 3
    SPLATW    m0, m0, 0

%if %2
    lea       pixstride3, [srcstrideq + 2 * srcstrideq]
    mov       src_m3, srcq
    sub       src_m3, pixstride3
%endif

.loop:

%assign i 0
%rep nb_blocks

    BLOCK_DEFS i

    LOAD m4, [src_m3 + i * blocksize]
    LOAD m5, [src_m3 + i * blocksize + 1 * pixstride]
    punpcklbw m4, m5
    pmaddubsw m4, m0

    LOAD m5, [src_m3 + i * blocksize + 2 * pixstride]
    LOAD m6, [srcq   + i * blocksize]
    punpcklbw m5, m6
    pmaddubsw m5, m1
    paddsw    m4, m5

    LOAD m5, [srcq + i * blocksize + 1 * pixstride]
    LOAD m6, [srcq + i * blocksize + 2 * pixstride]
    punpcklbw m5, m6
    pmaddubsw m5, m2
    paddsw    m4, m5

    LOAD m5, [srcq + i * blocksize +     pixstride3]
    LOAD m6, [srcq + i * blocksize + 4 * pixstride]
    punpcklbw m5, m6
    pmaddubsw m5, m3
    paddsw    m4, m5

    STORE [dstq + i * 2 * blocksize], m4

%assign i (i + 1)
%endrep

    add       dstq,   dststrideq
    add       srcq,   srcstrideq
%if %2
    add       src_m3, srcstrideq
%endif

    dec heightd
    jg .loop
    RET
%endmacro

INIT_XMM ssse3
QPEL_8 4,  0
QPEL_8 8,  0
QPEL_8 12, 0
QPEL_8 16, 0
QPEL_8 24, 0
QPEL_8 32, 0
QPEL_8 48, 0
QPEL_8 64, 0

QPEL_8 4,  1
QPEL_8 8,  1
QPEL_8 12, 1
QPEL_8 16, 1
QPEL_8 24, 1
QPEL_8 32, 1
QPEL_8 48, 1
QPEL_8 64, 1

; 16-bit qpel interpolation
; %1: block width
; %2: shift applied to the result
; %3: 0 - horizontal; 1 - vertical
%macro QPEL_16 3
%if %3
    %define mvfrac     myq
    %define pixstride  srcstrideq
    %define pixstride3 sstride3q
    %define src_m3     srcm3q
%else
    %define mvfrac     mxq
    %define pixstride  2
    %define pixstride3 6
    %define src_m3     (srcq - 6)
%endif

    COMMON_DEFS %1, 16

    and       mvfrac, 0x3
    dec       mvfrac
    shl       mvfrac, 4
    lea       coeffsregq, [hevc_qpel_coeffs]
    mova      m0,         [coeffsregq + mvfrac]

    pshufd    m1, m0, 0x55
    pshufd    m2, m0, 0xaa
    pshufd    m3, m0, 0xff
    pshufd    m0, m0, 0x00

%if %3
    lea       sstride3q, [srcstrideq + 2 * srcstrideq]
    mov       srcm3q, srcq
    sub       srcm3q, sstride3q
%endif

.loop:

%assign i 0
%rep nb_blocks

    BLOCK_DEFS i

    LOAD m4,  [src_m3 + i * 2 * blocksize]
    LOAD m5,  [src_m3 + i * 2 * blocksize + 1 * pixstride]
    LOAD m6,  [src_m3 + i * 2 * blocksize + 2 * pixstride]
    LOAD m7,  [srcq   + i * 2 * blocksize + 0 * pixstride]
    LOAD m8,  [srcq   + i * 2 * blocksize + 1 * pixstride]
    LOAD m9,  [srcq   + i * 2 * blocksize + 2 * pixstride]
    LOAD m10, [srcq   + i * 2 * blocksize +     pixstride3]
    LOAD m11, [srcq   + i * 2 * blocksize + 4 * pixstride]

    punpcklwd m12, m4, m5
    pmaddwd   m12, m0

    punpcklwd m13, m6, m7
    pmaddwd   m13, m1
    paddd     m12, m13

    punpcklwd m13, m8, m9
    pmaddwd   m13, m2
    paddd     m12, m13

    punpcklwd m13, m10, m11
    pmaddwd   m13, m3
    paddd     m12, m13
    psrad     m12, %2

    %if block_truncated == 0
        punpckhwd m4, m5
        pmaddwd   m4, m0

        punpckhwd m6, m7
        pmaddwd   m6, m1
        paddd     m4, m6

        punpckhwd m8, m9
        pmaddwd   m8, m2
        paddd     m4, m8

        punpckhwd m10, m11
        pmaddwd   m10, m3
        paddd     m4, m10

        psrad     m4, %2
    %endif
    packssdw  m12, m4
    STORE [dstq + i * 2 * blocksize], m12

%assign i (i + 1)
%endrep

    add       dstq,   dststrideq
    add       srcq,   srcstrideq
%if %3
    add       srcm3q, srcstrideq
%endif

    dec heightd
    jg .loop
    RET
%endmacro

%if ARCH_X86_64

%macro QPEL_H_10 1
cglobal hevc_qpel_h_ %+ %1 %+ _10, 7, 9, 14, dst, dststride, src, srcstride, height, mx, my, mcbuffer, coeffsreg
QPEL_16 %1, 2, 0
%endmacro

INIT_XMM avx
QPEL_H_10 4
QPEL_H_10 8
QPEL_H_10 12
QPEL_H_10 16
QPEL_H_10 24
QPEL_H_10 32
QPEL_H_10 48
QPEL_H_10 64

%macro QPEL_V_10 1
cglobal hevc_qpel_v_ %+ %1 %+ _10, 7, 10, 14, dst, dststride, src, srcstride, height, mx, my, sstride3, srcm3, coeffsreg
QPEL_16 %1, 2, 1
%endmacro

INIT_XMM avx
QPEL_V_10 4
QPEL_V_10 8
QPEL_V_10 12
QPEL_V_10 16
QPEL_V_10 24
QPEL_V_10 32
QPEL_V_10 48
QPEL_V_10 64

; hevc_qpel_hv_<w>(int16_t *dst, ptrdiff_t dststride,
;                  uint8_t *src, ptrdiff_t srcstride,
;                  int height, int mx, int my, int *mcbuffer)

%macro QPEL_HV 1
cglobal hevc_qpel_hv_ %+ %1, 7, 10, 14, dst, dststride, src, srcstride, height, mx, my, sstride3, srcm3, coeffsreg
QPEL_16 %1, 6, 1
%endmacro

INIT_XMM avx
QPEL_HV 4
QPEL_HV 8
QPEL_HV 12
QPEL_HV 16
QPEL_HV 24
QPEL_HV 32
QPEL_HV 48
QPEL_HV 64

%endif ; ARCH_X86_64

; hevc_epel_h/v_<w>_8(int16_t *dst, ptrdiff_t dststride,
;                     uint8_t *src, ptrdiff_t srcstride,
;                     int height, int mx, int my, int *mcbuffer)

; 8-bit epel interpolation
; %1: block width
; %2: 0 - horizontal; 1 - vertical
%macro EPEL_8 2
%if %2
    %define postfix    v
    %define mvfrac     myq
    %define coeffsaddr r5q
    %define pixstride  srcstrideq
    %define pixstride3 r5q
%else
    %define postfix    h
    %define mvfrac     mxq
    %define coeffsaddr r6q
    %define pixstride  1
    %define pixstride3 3
%endif

    COMMON_DEFS %1, 8

cglobal hevc_epel_ %+ postfix %+ _ %+ %1 %+ _8, 7, 7, 6, dst, dststride, src, srcstride, height, mx, my
    and       mvfrac, 0x7
    dec       mvfrac
    shl       mvfrac, 4
    lea       coeffsaddr, [hevc_epel_coeffs8]
    movq      m0,         [coeffsaddr + mvfrac]

    SPLATW    m1, m0, 1
    SPLATW    m0, m0, 0

%if %2
    lea       pixstride3, [srcstrideq + 2 * srcstrideq]
%endif
    sub       srcq, pixstride

.loop:

%assign i 0
%rep nb_blocks

    BLOCK_DEFS i

    LOAD m2, [srcq + i * blocksize + 0 * pixstride]
    LOAD m3, [srcq + i * blocksize + 1 * pixstride]
    LOAD m4, [srcq + i * blocksize + 2 * pixstride]
    LOAD m5, [srcq + i * blocksize +     pixstride3]

    punpcklbw m2, m3
    punpcklbw m4, m5

    pmaddubsw m2, m0
    pmaddubsw m4, m1

    paddsw    m2, m4

    STORE [dstq + i * 2 * blocksize], m2

%assign i (i + 1)
%endrep

    add       dstq, dststrideq
    add       srcq, srcstrideq

    dec heightd
    jg .loop
    RET
%endmacro

INIT_XMM ssse3
EPEL_8 4,  0
EPEL_8 8,  0
EPEL_8 12, 0
EPEL_8 16, 0
EPEL_8 24, 0
EPEL_8 32, 0

EPEL_8 4,  1
EPEL_8 8,  1
EPEL_8 12, 1
EPEL_8 16, 1
EPEL_8 24, 1
EPEL_8 32, 1

%macro EPEL_16 3
%if %3
    %define mvfrac     myq
    %define pixstride  srcstrideq
    %define pixstride3 sstride3q
%else
    %define mvfrac     mxq
    %define pixstride  2
    %define pixstride3 6
%endif

    COMMON_DEFS %1, 16

    and       mvfrac, 0x7
    dec       mvfrac
    shl       mvfrac, 5
    lea       coeffsregq, [hevc_epel_coeffs]
    mova      m0, [coeffsregq + mvfrac]

    pshufd    m1, m0, 0x55
    pshufd    m0, m0, 0x00

%if %3
    lea       sstride3q, [srcstrideq + 2 * srcstrideq]
%endif
    sub       srcq, pixstride

.loop:

%assign i 0
%rep nb_blocks

    BLOCK_DEFS i

    LOAD m2, [srcq + i * 2 * blocksize + 0 * pixstride]
    LOAD m3, [srcq + i * 2 * blocksize + 1 * pixstride]
    LOAD m4, [srcq + i * 2 * blocksize + 2 * pixstride]
    LOAD m5, [srcq + i * 2 * blocksize +     pixstride3]

    punpcklwd m6, m2, m3
    punpcklwd m7, m4, m5
    pmaddwd   m6, m0
    pmaddwd   m7, m1
    paddd     m6, m7
    psrad     m6, %2

    %if block_truncated == 0
        punpckhwd m2, m3
        punpckhwd m4, m5
        pmaddwd   m2, m0
        pmaddwd   m4, m1
        paddd     m2, m4
        psrad     m2, %2
    %endif
    packssdw  m6, m2
    STORE [dstq + i * 2 * blocksize], m6

%assign i (i + 1)
%endrep

    add       dstq,   dststrideq
    add       srcq,   srcstrideq

    dec heightd
    jg .loop
    RET
%endmacro

%if ARCH_X86_64

%macro EPEL_H_10 1
cglobal hevc_epel_h_ %+ %1 %+ _10, 8, 9, 8, dst, dststride, src, srcstride, height, mx, my, sstride3, coeffsreg
EPEL_16 %1, 2, 0
%endmacro

INIT_XMM avx
EPEL_H_10 4
EPEL_H_10 8
EPEL_H_10 12
EPEL_H_10 16
EPEL_H_10 24
EPEL_H_10 32

%macro EPEL_V_10 1
cglobal hevc_epel_v_ %+ %1 %+ _10, 8, 9, 8, dst, dststride, src, srcstride, height, mx, my, sstride3, coeffsreg
EPEL_16 %1, 2, 1
%endmacro

INIT_XMM avx
EPEL_V_10 4
EPEL_V_10 8
EPEL_V_10 12
EPEL_V_10 16
EPEL_V_10 24
EPEL_V_10 32

; hevc_epel_hv_<w>_8(int16_t *dst, ptrdiff_t dststride,
;                    int16_t *src, ptrdiff_t srcstride,
;                    int height, int mx, int my, int *mcbuffer)

%macro EPEL_HV 1
cglobal hevc_epel_hv_ %+ %1, 8, 9, 8, dst, dststride, src, srcstride, height, mx, my, sstride3, coeffsreg
EPEL_16 %1, 6, 1
%endmacro

INIT_XMM avx
EPEL_HV 4
EPEL_HV 8
EPEL_HV 12
EPEL_HV 16
EPEL_HV 24
EPEL_HV 32

%endif ; ARCH_X86_64

; hevc_put_unweighted_pred_<w>_<d>(pixel   *dst, ptrdiff_t dststride,
;                                  int16_t *src, ptrdiff_t srcstride,
;                                  int height)

%macro AVG 5
    %if %3
        %if %4 == 4
            movq %5, %2
            paddsw %1, %5
        %else
            paddsw %1, %2
        %endif
    %endif
%endmacro

; %1: 0 - one source; 1 - two sources
; %2: width
; %3: bit depth
%macro PUT_PRED 3
%if %1
cglobal hevc_put_unweighted_pred_avg_ %+ %2 %+ _ %+ %3, 6, 6, 4, dst, dststride, src, src2, srcstride, height
%else
cglobal hevc_put_unweighted_pred_ %+ %2 %+ _ %+ %3, 5, 5, 4, dst, dststride, src, srcstride, height
%endif

%assign shift       14 + %1 - %3
%assign offset      (1 << (shift - 1))
%define offset_data pw_ %+ offset

    mova        m0, [offset_data]

%if %3 > 8
    %define STORE_BLOCK movu
    %define STORE_HALF  movq

    %assign pixel_max ((1 << %3) - 1)
    %define pw_pixel_max pw_ %+ pixel_max
    pxor    m1, m1
    mova    m2, [pw_pixel_max]
%else
    %define STORE_BLOCK movq
    %define STORE_HALF  movd
%endif

.loop:
%assign i 0
%rep (%2 + 7) / 8

    %if (i + 1) * 8 > %2
        %define LOAD movq
        %define STORE STORE_HALF
    %else
        %define LOAD mova
        %define STORE STORE_BLOCK
    %endif

    LOAD m3, [srcq  + 16 * i]
    AVG  m3, [src2q + 16 * i], %1, %3 - i * 8, m4

    paddsw m3, m0
    psraw  m3, shift

    %if %3 == 8
        packuswb m3, m3
        STORE [dstq + 8 * i], m3
    %else
        CLIPW m3, m1, m2
        STORE [dstq + 16 * i], m3
    %endif
%assign i (i + 1)
%endrep

    add dstq,  dststrideq
    add srcq,  srcstrideq
%if %1
    add src2q, srcstrideq
%endif

    dec         heightd
    jg          .loop
    RET
%endmacro

INIT_XMM sse2
PUT_PRED 0, 4,  8
PUT_PRED 1, 4,  8
PUT_PRED 0, 8,  8
PUT_PRED 1, 8,  8
PUT_PRED 0, 12, 8
PUT_PRED 1, 12, 8
PUT_PRED 0, 16, 8
PUT_PRED 1, 16, 8
PUT_PRED 0, 24, 8
PUT_PRED 1, 24, 8
PUT_PRED 0, 32, 8
PUT_PRED 1, 32, 8
PUT_PRED 0, 48, 8
PUT_PRED 1, 48, 8
PUT_PRED 0, 64, 8
PUT_PRED 1, 64, 8

PUT_PRED 0, 4,  10
PUT_PRED 1, 4,  10
PUT_PRED 0, 8,  10
PUT_PRED 1, 8,  10
PUT_PRED 0, 12, 10
PUT_PRED 1, 12, 10
PUT_PRED 0, 16, 10
PUT_PRED 1, 16, 10
PUT_PRED 0, 24, 10
PUT_PRED 1, 24, 10
PUT_PRED 0, 32, 10
PUT_PRED 1, 32, 10
PUT_PRED 0, 48, 10
PUT_PRED 1, 48, 10
PUT_PRED 0, 64, 10
PUT_PRED 1, 64, 10

%macro PUT_WEIGHTED_PRED 3
%if %1
cglobal hevc_put_weighted_pred_avg_ %+ %2 %+ _ %+ %3, 11, 11, 8, denom, weight0, weight1, offset0, offset1, dst, dststride, src0, src1, srcstride, height
%else
cglobal hevc_put_weighted_pred_ %+ %2 %+ _ %+ %3, 8, 8, 8, denom, weight0, offset0, dst, dststride, src0, srcstride, height
%endif

    and         denomd, 0xff
    movsx       weight0d, weight0w
    movsx       offset0d, offset0w
%if %1
    movsx       weight1d, weight1w
    movsx       offset1d, offset1w
%endif

    add         denomd, 14 + %1 - %3
    movd        m0, denomd

%if %3 > 8
    %assign     pixel_max ((1 << %3) - 1)
    %define     pw_pixel_max pw_ %+ pixel_max
    pxor        m4, m4
    mova        m5, [pw_pixel_max]

    shl         offset0d, %3 - 8
%if %1
    shl         offset1d, %3 - 8
%endif
%endif

%if %1
    lea         offset0d, [offset0d + offset1d + 1]
%else
    lea         offset0d, [2 * offset0d + 1]
%endif
    movd        m1, offset0d
    SPLATD      m1
    pslld       m1, m0
    psrad       m1, 1

    movd        m2, weight0d
    SPLATD      m2
%if %1
    movd        m3, weight1d
    SPLATD      m3
%endif

.loop:
%assign i 0
%rep (%2 + 3) / 4

    pmovsxwd   m6, [src0q + 8 * i]
    pmulld     m6, m2

%if %1
    pmovsxwd   m7, [src1q + 8 * i]
    pmulld     m7, m3
    paddd      m6, m7
%endif

    paddd      m6, m1
    psrad      m6, m0

    packssdw   m6, m6

%if %3 > 8
    CLIPW      m6, m4, m5
    movq       [dstq + 8 * i], m6
%else
    packuswb   m6, m6
    movd [dstq + 4 * i], m6
%endif

%assign i (i + 1)
%endrep

    add dstq,  dststrideq
    add src0q, srcstrideq
%if %1
    add src1q, srcstrideq
%endif

    dec         heightd
    jg          .loop
    RET
%endmacro

%if ARCH_X86_64
INIT_XMM sse4
PUT_WEIGHTED_PRED 0, 4,  8
PUT_WEIGHTED_PRED 1, 4,  8
PUT_WEIGHTED_PRED 0, 8,  8
PUT_WEIGHTED_PRED 1, 8,  8
PUT_WEIGHTED_PRED 0, 12, 8
PUT_WEIGHTED_PRED 1, 12, 8
PUT_WEIGHTED_PRED 0, 16, 8
PUT_WEIGHTED_PRED 1, 16, 8
PUT_WEIGHTED_PRED 0, 24, 8
PUT_WEIGHTED_PRED 1, 24, 8
PUT_WEIGHTED_PRED 0, 32, 8
PUT_WEIGHTED_PRED 1, 32, 8
PUT_WEIGHTED_PRED 0, 48, 8
PUT_WEIGHTED_PRED 1, 48, 8
PUT_WEIGHTED_PRED 0, 64, 8
PUT_WEIGHTED_PRED 1, 64, 8

PUT_WEIGHTED_PRED 0, 4,  10
PUT_WEIGHTED_PRED 1, 4,  10
PUT_WEIGHTED_PRED 0, 8,  10
PUT_WEIGHTED_PRED 1, 8,  10
PUT_WEIGHTED_PRED 0, 12, 10
PUT_WEIGHTED_PRED 1, 12, 10
PUT_WEIGHTED_PRED 0, 16, 10
PUT_WEIGHTED_PRED 1, 16, 10
PUT_WEIGHTED_PRED 0, 24, 10
PUT_WEIGHTED_PRED 1, 24, 10
PUT_WEIGHTED_PRED 0, 32, 10
PUT_WEIGHTED_PRED 1, 32, 10
PUT_WEIGHTED_PRED 0, 48, 10
PUT_WEIGHTED_PRED 1, 48, 10
PUT_WEIGHTED_PRED 0, 64, 10
PUT_WEIGHTED_PRED 1, 64, 10

%endif ; ARCH_X86_64
OpenPOWER on IntegriCloud