h264_intrapred.asm 68.2 KB
Newer Older
1 2 3
;******************************************************************************
;* H.264 intra prediction asm optimizations
;* Copyright (c) 2010 Jason Garrett-Glaser
4 5 6
;* Copyright (c) 2010 Holger Lubitz
;* Copyright (c) 2010 Loren Merritt
;* Copyright (c) 2010 Ronald S. Bultje
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg 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.
;*
;* FFmpeg 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 FFmpeg; if not, write to the Free Software
22
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 24
;******************************************************************************

25
%include "libavutil/x86/x86util.asm"
26 27 28 29

SECTION_RODATA

tm_shuf: times 8 db 0x03, 0x80
30
pw_ff00: times 8 dw 0xff00
31 32 33 34 35 36 37 38
plane_shuf:  db -8, -7, -6, -5, -4, -3, -2, -1
             db  1,  2,  3,  4,  5,  6,  7,  8
plane8_shuf: db -4, -3, -2, -1,  0,  0,  0,  0
             db  1,  2,  3,  4,  0,  0,  0,  0
pw_0to7:     dw  0,  1,  2,  3,  4,  5,  6,  7
pw_1to8:     dw  1,  2,  3,  4,  5,  6,  7,  8
pw_m8tom1:   dw -8, -7, -6, -5, -4, -3, -2, -1
pw_m4to4:    dw -4, -3, -2, -1,  1,  2,  3,  4
39 40 41

SECTION .text

42
cextern pb_1
43
cextern pb_3
44
cextern pw_4
45
cextern pw_5
46
cextern pw_8
47 48 49
cextern pw_16
cextern pw_17
cextern pw_32
50 51

;-----------------------------------------------------------------------------
52
; void pred16x16_vertical_8(uint8_t *src, int stride)
53 54
;-----------------------------------------------------------------------------

55 56
INIT_MMX mmx
cglobal pred16x16_vertical_8, 2,3
57 58 59 60 61 62 63 64 65 66 67 68 69 70
    sub   r0, r1
    mov   r2, 8
    movq mm0, [r0+0]
    movq mm1, [r0+8]
.loop:
    movq [r0+r1*1+0], mm0
    movq [r0+r1*1+8], mm1
    movq [r0+r1*2+0], mm0
    movq [r0+r1*2+8], mm1
    lea   r0, [r0+r1*2]
    dec   r2
    jg .loop
    REP_RET

71 72
INIT_XMM sse
cglobal pred16x16_vertical_8, 2,3
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    sub   r0, r1
    mov   r2, 4
    movaps xmm0, [r0]
.loop:
    movaps [r0+r1*1], xmm0
    movaps [r0+r1*2], xmm0
    lea   r0, [r0+r1*2]
    movaps [r0+r1*1], xmm0
    movaps [r0+r1*2], xmm0
    lea   r0, [r0+r1*2]
    dec   r2
    jg .loop
    REP_RET

;-----------------------------------------------------------------------------
88
; void pred16x16_horizontal_8(uint8_t *src, int stride)
89 90
;-----------------------------------------------------------------------------

91
%macro PRED16x16_H 0
92
cglobal pred16x16_horizontal_8, 2,3
93
    mov       r2, 8
94
%if cpuflag(ssse3)
95 96 97 98 99 100
    mova      m2, [pb_3]
%endif
.loop:
    movd      m0, [r0+r1*0-4]
    movd      m1, [r0+r1*1-4]

101
%if cpuflag(ssse3)
102 103 104 105 106
    pshufb    m0, m2
    pshufb    m1, m2
%else
    punpcklbw m0, m0
    punpcklbw m1, m1
107 108
    SPLATW    m0, m0, 3
    SPLATW    m1, m1, 3
109 110 111 112 113 114 115 116 117 118 119 120
    mova [r0+r1*0+8], m0
    mova [r0+r1*1+8], m1
%endif

    mova [r0+r1*0], m0
    mova [r0+r1*1], m1
    lea       r0, [r0+r1*2]
    dec       r2
    jg .loop
    REP_RET
%endmacro

121 122
INIT_MMX mmx
PRED16x16_H
123
INIT_MMX mmxext
124 125 126
PRED16x16_H
INIT_XMM ssse3
PRED16x16_H
127 128

;-----------------------------------------------------------------------------
129
; void pred16x16_dc_8(uint8_t *src, int stride)
130 131
;-----------------------------------------------------------------------------

132
%macro PRED16x16_DC 0
133
cglobal pred16x16_dc_8, 2,7
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    mov       r4, r0
    sub       r0, r1
    pxor      mm0, mm0
    pxor      mm1, mm1
    psadbw    mm0, [r0+0]
    psadbw    mm1, [r0+8]
    dec        r0
    movzx     r5d, byte [r0+r1*1]
    paddw     mm0, mm1
    movd      r6d, mm0
    lea        r0, [r0+r1*2]
%rep 7
    movzx     r2d, byte [r0+r1*0]
    movzx     r3d, byte [r0+r1*1]
    add       r5d, r2d
    add       r6d, r3d
    lea        r0, [r0+r1*2]
%endrep
    movzx     r2d, byte [r0+r1*0]
    add       r5d, r6d
    lea       r2d, [r2+r5+16]
    shr       r2d, 5
156 157
%if cpuflag(ssse3)
    pxor       m1, m1
158
%endif
159
    SPLATB_REG m0, r2, m1
160 161 162 163

%if mmsize==8
    mov       r3d, 8
.loop:
164 165 166 167
    mova [r4+r1*0+0], m0
    mova [r4+r1*0+8], m0
    mova [r4+r1*1+0], m0
    mova [r4+r1*1+8], m0
168 169 170
%else
    mov       r3d, 4
.loop:
171 172
    mova [r4+r1*0], m0
    mova [r4+r1*1], m0
173
    lea   r4, [r4+r1*2]
174 175
    mova [r4+r1*0], m0
    mova [r4+r1*1], m0
176 177 178 179 180 181 182
%endif
    lea   r4, [r4+r1*2]
    dec   r3d
    jg .loop
    REP_RET
%endmacro

183
INIT_MMX mmxext
184 185 186 187 188
PRED16x16_DC
INIT_XMM sse2
PRED16x16_DC
INIT_XMM ssse3
PRED16x16_DC
189 190

;-----------------------------------------------------------------------------
191
; void pred16x16_tm_vp8_8(uint8_t *src, int stride)
192 193
;-----------------------------------------------------------------------------

194
%macro PRED16x16_TM 0
195
cglobal pred16x16_tm_vp8_8, 2,5
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    sub        r0, r1
    pxor      mm7, mm7
    movq      mm0, [r0+0]
    movq      mm2, [r0+8]
    movq      mm1, mm0
    movq      mm3, mm2
    punpcklbw mm0, mm7
    punpckhbw mm1, mm7
    punpcklbw mm2, mm7
    punpckhbw mm3, mm7
    movzx     r3d, byte [r0-1]
    mov       r4d, 16
.loop:
    movzx     r2d, byte [r0+r1-1]
    sub       r2d, r3d
    movd      mm4, r2d
212
    SPLATW    mm4, mm4, 0
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
    movq      mm5, mm4
    movq      mm6, mm4
    movq      mm7, mm4
    paddw     mm4, mm0
    paddw     mm5, mm1
    paddw     mm6, mm2
    paddw     mm7, mm3
    packuswb  mm4, mm5
    packuswb  mm6, mm7
    movq [r0+r1+0], mm4
    movq [r0+r1+8], mm6
    add        r0, r1
    dec       r4d
    jg .loop
    REP_RET
%endmacro

230
INIT_MMX mmx
231
PRED16x16_TM
232
INIT_MMX mmxext
233
PRED16x16_TM
234

235 236
INIT_XMM sse2
cglobal pred16x16_tm_vp8_8, 2,6,6
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
    sub          r0, r1
    pxor       xmm2, xmm2
    movdqa     xmm0, [r0]
    movdqa     xmm1, xmm0
    punpcklbw  xmm0, xmm2
    punpckhbw  xmm1, xmm2
    movzx       r4d, byte [r0-1]
    mov         r5d, 8
.loop:
    movzx       r2d, byte [r0+r1*1-1]
    movzx       r3d, byte [r0+r1*2-1]
    sub         r2d, r4d
    sub         r3d, r4d
    movd       xmm2, r2d
    movd       xmm4, r3d
    pshuflw    xmm2, xmm2, 0
    pshuflw    xmm4, xmm4, 0
    punpcklqdq xmm2, xmm2
    punpcklqdq xmm4, xmm4
    movdqa     xmm3, xmm2
    movdqa     xmm5, xmm4
    paddw      xmm2, xmm0
    paddw      xmm3, xmm1
    paddw      xmm4, xmm0
    paddw      xmm5, xmm1
    packuswb   xmm2, xmm3
    packuswb   xmm4, xmm5
    movdqa [r0+r1*1], xmm2
    movdqa [r0+r1*2], xmm4
    lea          r0, [r0+r1*2]
    dec         r5d
    jg .loop
    REP_RET

271
;-----------------------------------------------------------------------------
272
; void pred16x16_plane_*_8(uint8_t *src, int stride)
273 274
;-----------------------------------------------------------------------------

275
%macro H264_PRED16x16_PLANE 1
276
cglobal pred16x16_plane_%1_8, 2,9,7
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
    mov          r2, r1           ; +stride
    neg          r1               ; -stride

    movh         m0, [r0+r1  -1]
%if mmsize == 8
    pxor         m4, m4
    movh         m1, [r0+r1  +3 ]
    movh         m2, [r0+r1  +8 ]
    movh         m3, [r0+r1  +12]
    punpcklbw    m0, m4
    punpcklbw    m1, m4
    punpcklbw    m2, m4
    punpcklbw    m3, m4
    pmullw       m0, [pw_m8tom1  ]
    pmullw       m1, [pw_m8tom1+8]
    pmullw       m2, [pw_1to8    ]
    pmullw       m3, [pw_1to8  +8]
    paddw        m0, m2
    paddw        m1, m3
%else ; mmsize == 16
297 298 299 300
%if cpuflag(ssse3)
    movhps       m0, [r0+r1  +8]
    pmaddubsw    m0, [plane_shuf] ; H coefficients
%else ; sse2
301 302 303 304 305 306 307 308 309 310 311
    pxor         m2, m2
    movh         m1, [r0+r1  +8]
    punpcklbw    m0, m2
    punpcklbw    m1, m2
    pmullw       m0, [pw_m8tom1]
    pmullw       m1, [pw_1to8]
    paddw        m0, m1
%endif
    movhlps      m1, m0
%endif
    paddw        m0, m1
312
%if cpuflag(mmxext)
313
    PSHUFLW      m1, m0, 0xE
314
%elif cpuflag(mmx)
315 316 317 318
    mova         m1, m0
    psrlq        m1, 32
%endif
    paddw        m0, m1
319
%if cpuflag(mmxext)
320
    PSHUFLW      m1, m0, 0x1
321
%elif cpuflag(mmx)
322 323 324 325 326 327 328 329 330
    mova         m1, m0
    psrlq        m1, 16
%endif
    paddw        m0, m1           ; sum of H coefficients

    lea          r4, [r0+r2*8-1]
    lea          r3, [r0+r2*4-1]
    add          r4, r2

331
%if ARCH_X86_64
332
%define e_reg r8
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
%else
%define e_reg r0
%endif

    movzx     e_reg, byte [r3+r2*2   ]
    movzx        r5, byte [r4+r1     ]
    sub          r5, e_reg

    movzx     e_reg, byte [r3+r2     ]
    movzx        r6, byte [r4        ]
    sub          r6, e_reg
    lea          r5, [r5+r6*2]

    movzx     e_reg, byte [r3+r1     ]
    movzx        r6, byte [r4+r2*2   ]
    sub          r6, e_reg
    lea          r5, [r5+r6*4]

    movzx     e_reg, byte [r3        ]
352
%if ARCH_X86_64
353 354
    movzx        r7, byte [r4+r2     ]
    sub          r7, e_reg
355 356 357 358 359 360 361 362 363 364 365 366 367
%else
    movzx        r6, byte [r4+r2     ]
    sub          r6, e_reg
    lea          r5, [r5+r6*4]
    sub          r5, r6
%endif

    lea       e_reg, [r3+r1*4]
    lea          r3, [r4+r2*4]

    movzx        r4, byte [e_reg+r2  ]
    movzx        r6, byte [r3        ]
    sub          r6, r4
368
%if ARCH_X86_64
369
    lea          r6, [r7+r6*2]
370 371 372 373 374 375 376 377
    lea          r5, [r5+r6*2]
    add          r5, r6
%else
    lea          r5, [r5+r6*4]
    lea          r5, [r5+r6*2]
%endif

    movzx        r4, byte [e_reg     ]
378
%if ARCH_X86_64
379 380 381
    movzx        r7, byte [r3   +r2  ]
    sub          r7, r4
    sub          r5, r7
382 383 384 385 386 387 388 389 390 391
%else
    movzx        r6, byte [r3   +r2  ]
    sub          r6, r4
    lea          r5, [r5+r6*8]
    sub          r5, r6
%endif

    movzx        r4, byte [e_reg+r1  ]
    movzx        r6, byte [r3   +r2*2]
    sub          r6, r4
392
%if ARCH_X86_64
393
    add          r6, r7
394 395 396 397 398 399 400 401 402
%endif
    lea          r5, [r5+r6*8]

    movzx        r4, byte [e_reg+r2*2]
    movzx        r6, byte [r3   +r1  ]
    sub          r6, r4
    lea          r5, [r5+r6*4]
    add          r5, r6           ; sum of V coefficients

403
%if ARCH_X86_64 == 0
404 405 406
    mov          r0, r0m
%endif

407
%ifidn %1, h264
408 409
    lea          r5, [r5*5+32]
    sar          r5, 6
410
%elifidn %1, rv40
411 412
    lea          r5, [r5*5]
    sar          r5, 6
413
%elifidn %1, svq3
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
    test         r5, r5
    lea          r6, [r5+3]
    cmovs        r5, r6
    sar          r5, 2            ; V/4
    lea          r5, [r5*5]       ; 5*(V/4)
    test         r5, r5
    lea          r6, [r5+15]
    cmovs        r5, r6
    sar          r5, 4            ; (5*(V/4))/16
%endif

    movzx        r4, byte [r0+r1  +15]
    movzx        r3, byte [r3+r2*2   ]
    lea          r3, [r3+r4+1]
    shl          r3, 4
429

430 431
    movd        r1d, m0
    movsx       r1d, r1w
432 433
%ifnidn %1, svq3
%ifidn %1, h264
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
    lea         r1d, [r1d*5+32]
%else ; rv40
    lea         r1d, [r1d*5]
%endif
    sar         r1d, 6
%else ; svq3
    test        r1d, r1d
    lea         r4d, [r1d+3]
    cmovs       r1d, r4d
    sar         r1d, 2           ; H/4
    lea         r1d, [r1d*5]     ; 5*(H/4)
    test        r1d, r1d
    lea         r4d, [r1d+15]
    cmovs       r1d, r4d
    sar         r1d, 4           ; (5*(H/4))/16
%endif
    movd         m0, r1d

452 453 454 455 456 457 458
    add         r1d, r5d
    add         r3d, r1d
    shl         r1d, 3
    sub         r3d, r1d          ; a

    movd         m1, r5d
    movd         m3, r3d
459 460 461
    SPLATW       m0, m0, 0        ; H
    SPLATW       m1, m1, 0        ; V
    SPLATW       m3, m3, 0        ; a
462
%ifidn %1, svq3
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
    SWAP          0, 1
%endif
    mova         m2, m0
%if mmsize == 8
    mova         m5, m0
%endif
    pmullw       m0, [pw_0to7]    ; 0*H, 1*H, ..., 7*H  (words)
%if mmsize == 16
    psllw        m2, 3
%else
    psllw        m5, 3
    psllw        m2, 2
    mova         m6, m5
    paddw        m6, m2
%endif
    paddw        m0, m3           ; a + {0,1,2,3,4,5,6,7}*H
    paddw        m2, m0           ; a + {8,9,10,11,12,13,14,15}*H
%if mmsize == 8
    paddw        m5, m0           ; a + {8,9,10,11}*H
    paddw        m6, m0           ; a + {12,13,14,15}*H
%endif

    mov          r4, 8
486
.loop:
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
    mova         m3, m0           ; b[0..7]
    mova         m4, m2           ; b[8..15]
    psraw        m3, 5
    psraw        m4, 5
    packuswb     m3, m4
    mova       [r0], m3
%if mmsize == 8
    mova         m3, m5           ; b[8..11]
    mova         m4, m6           ; b[12..15]
    psraw        m3, 5
    psraw        m4, 5
    packuswb     m3, m4
    mova     [r0+8], m3
%endif
    paddw        m0, m1
    paddw        m2, m1
%if mmsize == 8
    paddw        m5, m1
    paddw        m6, m1
%endif

    mova         m3, m0           ; b[0..7]
    mova         m4, m2           ; b[8..15]
    psraw        m3, 5
    psraw        m4, 5
    packuswb     m3, m4
    mova    [r0+r2], m3
%if mmsize == 8
    mova         m3, m5           ; b[8..11]
    mova         m4, m6           ; b[12..15]
    psraw        m3, 5
    psraw        m4, 5
    packuswb     m3, m4
    mova  [r0+r2+8], m3
%endif
    paddw        m0, m1
    paddw        m2, m1
%if mmsize == 8
    paddw        m5, m1
    paddw        m6, m1
%endif

    lea          r0, [r0+r2*2]
    dec          r4
    jg .loop
    REP_RET
%endmacro

535 536 537 538
INIT_MMX mmx
H264_PRED16x16_PLANE h264
H264_PRED16x16_PLANE rv40
H264_PRED16x16_PLANE svq3
539
INIT_MMX mmxext
540 541 542 543 544 545 546 547 548 549 550
H264_PRED16x16_PLANE h264
H264_PRED16x16_PLANE rv40
H264_PRED16x16_PLANE svq3
INIT_XMM sse2
H264_PRED16x16_PLANE h264
H264_PRED16x16_PLANE rv40
H264_PRED16x16_PLANE svq3
INIT_XMM ssse3
H264_PRED16x16_PLANE h264
H264_PRED16x16_PLANE rv40
H264_PRED16x16_PLANE svq3
551 552

;-----------------------------------------------------------------------------
553
; void pred8x8_plane_8(uint8_t *src, int stride)
554 555
;-----------------------------------------------------------------------------

556
%macro H264_PRED8x8_PLANE 0
557
cglobal pred8x8_plane_8, 2,9,7
558 559 560 561 562 563 564 565 566 567 568 569
    mov          r2, r1           ; +stride
    neg          r1               ; -stride

    movd         m0, [r0+r1  -1]
%if mmsize == 8
    pxor         m2, m2
    movh         m1, [r0+r1  +4 ]
    punpcklbw    m0, m2
    punpcklbw    m1, m2
    pmullw       m0, [pw_m4to4]
    pmullw       m1, [pw_m4to4+8]
%else ; mmsize == 16
570 571 572 573
%if cpuflag(ssse3)
    movhps       m0, [r0+r1  +4]   ; this reads 4 bytes more than necessary
    pmaddubsw    m0, [plane8_shuf] ; H coefficients
%else ; sse2
574 575 576 577 578 579 580 581 582 583
    pxor         m2, m2
    movd         m1, [r0+r1  +4]
    punpckldq    m0, m1
    punpcklbw    m0, m2
    pmullw       m0, [pw_m4to4]
%endif
    movhlps      m1, m0
%endif
    paddw        m0, m1

584
%if notcpuflag(ssse3)
585
%if cpuflag(mmxext)
586
    PSHUFLW      m1, m0, 0xE
587
%elif cpuflag(mmx)
588 589 590 591 592 593
    mova         m1, m0
    psrlq        m1, 32
%endif
    paddw        m0, m1
%endif ; !ssse3

594
%if cpuflag(mmxext)
595
    PSHUFLW      m1, m0, 0x1
596
%elif cpuflag(mmx)
597 598 599 600 601 602 603 604 605
    mova         m1, m0
    psrlq        m1, 16
%endif
    paddw        m0, m1           ; sum of H coefficients

    lea          r4, [r0+r2*4-1]
    lea          r3, [r0     -1]
    add          r4, r2

606
%if ARCH_X86_64
607
%define e_reg r8
608 609 610 611 612 613 614 615 616
%else
%define e_reg r0
%endif

    movzx     e_reg, byte [r3+r2*2   ]
    movzx        r5, byte [r4+r1     ]
    sub          r5, e_reg

    movzx     e_reg, byte [r3        ]
617
%if ARCH_X86_64
618 619 620
    movzx        r7, byte [r4+r2     ]
    sub          r7, e_reg
    sub          r5, r7
621 622 623 624 625 626 627 628 629 630
%else
    movzx        r6, byte [r4+r2     ]
    sub          r6, e_reg
    lea          r5, [r5+r6*4]
    sub          r5, r6
%endif

    movzx     e_reg, byte [r3+r1     ]
    movzx        r6, byte [r4+r2*2   ]
    sub          r6, e_reg
631
%if ARCH_X86_64
632
    add          r6, r7
633 634 635 636 637 638 639 640 641 642 643 644
%endif
    lea          r5, [r5+r6*4]

    movzx     e_reg, byte [r3+r2     ]
    movzx        r6, byte [r4        ]
    sub          r6, e_reg
    lea          r6, [r5+r6*2]

    lea          r5, [r6*9+16]
    lea          r5, [r5+r6*8]
    sar          r5, 5

645
%if ARCH_X86_64 == 0
646 647 648 649 650 651 652 653 654
    mov          r0, r0m
%endif

    movzx        r3, byte [r4+r2*2  ]
    movzx        r4, byte [r0+r1  +7]
    lea          r3, [r3+r4+1]
    shl          r3, 4
    movd        r1d, m0
    movsx       r1d, r1w
655 656 657 658
    imul        r1d, 17
    add         r1d, 16
    sar         r1d, 5
    movd         m0, r1d
659 660 661 662 663 664 665
    add         r1d, r5d
    sub         r3d, r1d
    add         r1d, r1d
    sub         r3d, r1d          ; a

    movd         m1, r5d
    movd         m3, r3d
666 667 668
    SPLATW       m0, m0, 0        ; H
    SPLATW       m1, m1, 0        ; V
    SPLATW       m3, m3, 0        ; a
669 670 671 672 673 674 675 676 677 678 679 680
%if mmsize == 8
    mova         m2, m0
%endif
    pmullw       m0, [pw_0to7]    ; 0*H, 1*H, ..., 7*H  (words)
    paddw        m0, m3           ; a + {0,1,2,3,4,5,6,7}*H
%if mmsize == 8
    psllw        m2, 2
    paddw        m2, m0           ; a + {4,5,6,7}*H
%endif

    mov          r4, 4
ALIGN 16
681
.loop:
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
%if mmsize == 16
    mova         m3, m0           ; b[0..7]
    paddw        m0, m1
    psraw        m3, 5
    mova         m4, m0           ; V+b[0..7]
    paddw        m0, m1
    psraw        m4, 5
    packuswb     m3, m4
    movh       [r0], m3
    movhps  [r0+r2], m3
%else ; mmsize == 8
    mova         m3, m0           ; b[0..3]
    mova         m4, m2           ; b[4..7]
    paddw        m0, m1
    paddw        m2, m1
    psraw        m3, 5
    psraw        m4, 5
    mova         m5, m0           ; V+b[0..3]
    mova         m6, m2           ; V+b[4..7]
    paddw        m0, m1
    paddw        m2, m1
    psraw        m5, 5
    psraw        m6, 5
    packuswb     m3, m4
    packuswb     m5, m6
    mova       [r0], m3
    mova    [r0+r2], m5
%endif

    lea          r0, [r0+r2*2]
    dec          r4
    jg .loop
    REP_RET
%endmacro

717 718
INIT_MMX mmx
H264_PRED8x8_PLANE
719
INIT_MMX mmxext
720 721 722 723 724
H264_PRED8x8_PLANE
INIT_XMM sse2
H264_PRED8x8_PLANE
INIT_XMM ssse3
H264_PRED8x8_PLANE
725

726
;-----------------------------------------------------------------------------
727
; void pred8x8_vertical_8(uint8_t *src, int stride)
728 729
;-----------------------------------------------------------------------------

730 731
INIT_MMX mmx
cglobal pred8x8_vertical_8, 2,2
732 733 734 735 736 737 738 739 740 741 742 743
    sub    r0, r1
    movq  mm0, [r0]
%rep 3
    movq [r0+r1*1], mm0
    movq [r0+r1*2], mm0
    lea    r0, [r0+r1*2]
%endrep
    movq [r0+r1*1], mm0
    movq [r0+r1*2], mm0
    RET

;-----------------------------------------------------------------------------
744
; void pred8x8_horizontal_8(uint8_t *src, int stride)
745 746
;-----------------------------------------------------------------------------

747
%macro PRED8x8_H 0
748
cglobal pred8x8_horizontal_8, 2,3
749
    mov       r2, 4
750
%if cpuflag(ssse3)
751 752 753
    mova      m2, [pb_3]
%endif
.loop:
754 755
    SPLATB_LOAD m0, r0+r1*0-1, m2
    SPLATB_LOAD m1, r0+r1*1-1, m2
756 757 758 759 760 761 762 763
    mova [r0+r1*0], m0
    mova [r0+r1*1], m1
    lea       r0, [r0+r1*2]
    dec       r2
    jg .loop
    REP_RET
%endmacro

764 765
INIT_MMX mmx
PRED8x8_H
766
INIT_MMX mmxext
767 768 769
PRED8x8_H
INIT_MMX ssse3
PRED8x8_H
770

771
;-----------------------------------------------------------------------------
772
; void pred8x8_top_dc_8_mmxext(uint8_t *src, int stride)
773
;-----------------------------------------------------------------------------
774 775
INIT_MMX mmxext
cglobal pred8x8_top_dc_8, 2,5
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
    sub         r0, r1
    movq       mm0, [r0]
    pxor       mm1, mm1
    pxor       mm2, mm2
    lea         r2, [r0+r1*2]
    punpckhbw  mm1, mm0
    punpcklbw  mm0, mm2
    psadbw     mm1, mm2        ; s1
    lea         r3, [r2+r1*2]
    psadbw     mm0, mm2        ; s0
    psrlw      mm1, 1
    psrlw      mm0, 1
    pavgw      mm1, mm2
    lea         r4, [r3+r1*2]
    pavgw      mm0, mm2
    pshufw     mm1, mm1, 0
    pshufw     mm0, mm0, 0     ; dc0 (w)
    packuswb   mm0, mm1        ; dc0,dc1 (b)
    movq [r0+r1*1], mm0
    movq [r0+r1*2], mm0
    lea         r0, [r3+r1*2]
    movq [r2+r1*1], mm0
    movq [r2+r1*2], mm0
    movq [r3+r1*1], mm0
    movq [r3+r1*2], mm0
    movq [r0+r1*1], mm0
    movq [r0+r1*2], mm0
    RET

805
;-----------------------------------------------------------------------------
806
; void pred8x8_dc_8_mmxext(uint8_t *src, int stride)
807
;-----------------------------------------------------------------------------
808

809 810
INIT_MMX mmxext
cglobal pred8x8_dc_8, 2,5
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 852 853 854 855 856 857 858 859 860 861 862 863 864 865
    sub       r0, r1
    pxor      m7, m7
    movd      m0, [r0+0]
    movd      m1, [r0+4]
    psadbw    m0, m7            ; s0
    mov       r4, r0
    psadbw    m1, m7            ; s1

    movzx    r2d, byte [r0+r1*1-1]
    movzx    r3d, byte [r0+r1*2-1]
    lea       r0, [r0+r1*2]
    add      r2d, r3d
    movzx    r3d, byte [r0+r1*1-1]
    add      r2d, r3d
    movzx    r3d, byte [r0+r1*2-1]
    add      r2d, r3d
    lea       r0, [r0+r1*2]
    movd      m2, r2d            ; s2
    movzx    r2d, byte [r0+r1*1-1]
    movzx    r3d, byte [r0+r1*2-1]
    lea       r0, [r0+r1*2]
    add      r2d, r3d
    movzx    r3d, byte [r0+r1*1-1]
    add      r2d, r3d
    movzx    r3d, byte [r0+r1*2-1]
    add      r2d, r3d
    movd      m3, r2d            ; s3

    punpcklwd m0, m1
    mov       r0, r4
    punpcklwd m2, m3
    punpckldq m0, m2            ; s0, s1, s2, s3
    pshufw    m3, m0, 11110110b ; s2, s1, s3, s3
    lea       r2, [r0+r1*2]
    pshufw    m0, m0, 01110100b ; s0, s1, s3, s1
    paddw     m0, m3
    lea       r3, [r2+r1*2]
    psrlw     m0, 2
    pavgw     m0, m7            ; s0+s2, s1, s3, s1+s3
    lea       r4, [r3+r1*2]
    packuswb  m0, m0
    punpcklbw m0, m0
    movq      m1, m0
    punpcklbw m0, m0
    punpckhbw m1, m1
    movq [r0+r1*1], m0
    movq [r0+r1*2], m0
    movq [r2+r1*1], m0
    movq [r2+r1*2], m0
    movq [r3+r1*1], m1
    movq [r3+r1*2], m1
    movq [r4+r1*1], m1
    movq [r4+r1*2], m1
    RET

866
;-----------------------------------------------------------------------------
867
; void pred8x8_dc_rv40_8(uint8_t *src, int stride)
868 869
;-----------------------------------------------------------------------------

870 871
INIT_MMX mmxext
cglobal pred8x8_dc_rv40_8, 2,7
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
    mov       r4, r0
    sub       r0, r1
    pxor      mm0, mm0
    psadbw    mm0, [r0]
    dec        r0
    movzx     r5d, byte [r0+r1*1]
    movd      r6d, mm0
    lea        r0, [r0+r1*2]
%rep 3
    movzx     r2d, byte [r0+r1*0]
    movzx     r3d, byte [r0+r1*1]
    add       r5d, r2d
    add       r6d, r3d
    lea        r0, [r0+r1*2]
%endrep
    movzx     r2d, byte [r0+r1*0]
    add       r5d, r6d
    lea       r2d, [r2+r5+8]
    shr       r2d, 4
    movd      mm0, r2d
    punpcklbw mm0, mm0
    pshufw    mm0, mm0, 0
    mov       r3d, 4
.loop:
    movq [r4+r1*0], mm0
    movq [r4+r1*1], mm0
    lea   r4, [r4+r1*2]
    dec   r3d
    jg .loop
    REP_RET

;-----------------------------------------------------------------------------
904
; void pred8x8_tm_vp8_8(uint8_t *src, int stride)
905 906
;-----------------------------------------------------------------------------

907
%macro PRED8x8_TM 0
908
cglobal pred8x8_tm_vp8_8, 2,6
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
    sub        r0, r1
    pxor      mm7, mm7
    movq      mm0, [r0]
    movq      mm1, mm0
    punpcklbw mm0, mm7
    punpckhbw mm1, mm7
    movzx     r4d, byte [r0-1]
    mov       r5d, 4
.loop:
    movzx     r2d, byte [r0+r1*1-1]
    movzx     r3d, byte [r0+r1*2-1]
    sub       r2d, r4d
    sub       r3d, r4d
    movd      mm2, r2d
    movd      mm4, r3d
924 925
    SPLATW    mm2, mm2, 0
    SPLATW    mm4, mm4, 0
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
    movq      mm3, mm2
    movq      mm5, mm4
    paddw     mm2, mm0
    paddw     mm3, mm1
    paddw     mm4, mm0
    paddw     mm5, mm1
    packuswb  mm2, mm3
    packuswb  mm4, mm5
    movq [r0+r1*1], mm2
    movq [r0+r1*2], mm4
    lea        r0, [r0+r1*2]
    dec       r5d
    jg .loop
    REP_RET
%endmacro

942
INIT_MMX mmx
943
PRED8x8_TM
944
INIT_MMX mmxext
945
PRED8x8_TM
946

947 948
INIT_XMM sse2
cglobal pred8x8_tm_vp8_8, 2,6,4
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
    sub          r0, r1
    pxor       xmm1, xmm1
    movq       xmm0, [r0]
    punpcklbw  xmm0, xmm1
    movzx       r4d, byte [r0-1]
    mov         r5d, 4
.loop:
    movzx       r2d, byte [r0+r1*1-1]
    movzx       r3d, byte [r0+r1*2-1]
    sub         r2d, r4d
    sub         r3d, r4d
    movd       xmm2, r2d
    movd       xmm3, r3d
    pshuflw    xmm2, xmm2, 0
    pshuflw    xmm3, xmm3, 0
    punpcklqdq xmm2, xmm2
    punpcklqdq xmm3, xmm3
    paddw      xmm2, xmm0
    paddw      xmm3, xmm0
    packuswb   xmm2, xmm3
    movq   [r0+r1*1], xmm2
    movhps [r0+r1*2], xmm2
    lea          r0, [r0+r1*2]
    dec         r5d
    jg .loop
    REP_RET

976 977
INIT_XMM ssse3
cglobal pred8x8_tm_vp8_8, 2,3,6
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
    sub          r0, r1
    movdqa     xmm4, [tm_shuf]
    pxor       xmm1, xmm1
    movq       xmm0, [r0]
    punpcklbw  xmm0, xmm1
    movd       xmm5, [r0-4]
    pshufb     xmm5, xmm4
    mov         r2d, 4
.loop:
    movd       xmm2, [r0+r1*1-4]
    movd       xmm3, [r0+r1*2-4]
    pshufb     xmm2, xmm4
    pshufb     xmm3, xmm4
    psubw      xmm2, xmm5
    psubw      xmm3, xmm5
    paddw      xmm2, xmm0
    paddw      xmm3, xmm0
    packuswb   xmm2, xmm3
    movq   [r0+r1*1], xmm2
    movhps [r0+r1*2], xmm2
    lea          r0, [r0+r1*2]
    dec         r2d
    jg .loop
    REP_RET
1002

1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
; dest, left, right, src, tmp
; output: %1 = (t[n-1] + t[n]*2 + t[n+1] + 2) >> 2
%macro PRED4x4_LOWPASS 5
    mova    %5, %2
    pavgb   %2, %3
    pxor    %3, %5
    mova    %1, %4
    pand    %3, [pb_1]
    psubusb %2, %3
    pavgb   %1, %2
%endmacro

1015
;-----------------------------------------------------------------------------
1016
; void pred8x8l_top_dc_8(uint8_t *src, int has_topleft, int has_topright, int stride)
1017
;-----------------------------------------------------------------------------
1018 1019
%macro PRED8x8L_TOP_DC 0
cglobal pred8x8l_top_dc_8, 4,4
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
    sub          r0, r3
    pxor        mm7, mm7
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1 ; top_left
    jz .fix_lt_2
    test         r2, r2 ; top_right
    jz .fix_tr_1
    jmp .body
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2 ; top_right
    jnz .body
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
1048
.body:
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
    PRED4x4_LOWPASS mm0, mm2, mm1, mm3, mm5
    psadbw   mm7, mm0
    paddw    mm7, [pw_4]
    psrlw    mm7, 3
    pshufw   mm7, mm7, 0
    packuswb mm7, mm7
%rep 3
    movq [r0+r3*1], mm7
    movq [r0+r3*2], mm7
    lea    r0, [r0+r3*2]
%endrep
    movq [r0+r3*1], mm7
    movq [r0+r3*2], mm7
    RET
%endmacro

1065 1066 1067 1068
INIT_MMX mmxext
PRED8x8L_TOP_DC
INIT_MMX ssse3
PRED8x8L_TOP_DC
1069 1070

;-----------------------------------------------------------------------------
1071
;void pred8x8l_dc_8(uint8_t *src, int has_topleft, int has_topright, int stride)
1072
;-----------------------------------------------------------------------------
1073

1074 1075
%macro PRED8x8L_DC 0
cglobal pred8x8l_dc_8, 4,5
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
    sub          r0, r3
    lea          r4, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
    punpckhbw   mm0, [r0+r3*0-8]
    movq        mm1, [r4+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r4, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
    movq        mm1, [r4]
    mov          r0, r4
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    test        r1, r1
    jnz .do_left
.fix_lt_1:
    movq        mm5, mm3
    pxor        mm5, mm4
    psrlq       mm5, 56
    psllq       mm5, 48
    pxor        mm1, mm5
    jmp .do_left
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2
    jnz .body
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .body
.do_left:
    movq        mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq        mm4, mm0
    movq        mm7, mm2
    PRED4x4_LOWPASS mm1, mm3, mm0, mm4, mm5
    psllq       mm1, 56
    PALIGNR     mm7, mm1, 7, mm3
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1
    jz .fix_lt_2
    test         r2, r2
    jz .fix_tr_1
1143
.body:
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
    lea          r1, [r0+r3*2]
    PRED4x4_LOWPASS mm6, mm2, mm1, mm3, mm5
    pxor        mm0, mm0
    pxor        mm1, mm1
    lea          r2, [r1+r3*2]
    psadbw      mm0, mm7
    psadbw      mm1, mm6
    paddw       mm0, [pw_8]
    paddw       mm0, mm1
    lea          r4, [r2+r3*2]
    psrlw       mm0, 4
    pshufw      mm0, mm0, 0
    packuswb    mm0, mm0
    movq [r0+r3*1], mm0
    movq [r0+r3*2], mm0
    movq [r1+r3*1], mm0
    movq [r1+r3*2], mm0
    movq [r2+r3*1], mm0
    movq [r2+r3*2], mm0
    movq [r4+r3*1], mm0
    movq [r4+r3*2], mm0
    RET
%endmacro
1167 1168 1169 1170 1171

INIT_MMX mmxext
PRED8x8L_DC
INIT_MMX ssse3
PRED8x8L_DC
1172 1173

;-----------------------------------------------------------------------------
1174
; void pred8x8l_horizontal_8(uint8_t *src, int has_topleft, int has_topright, int stride)
1175
;-----------------------------------------------------------------------------
1176

1177 1178
%macro PRED8x8L_HORIZONTAL 0
cglobal pred8x8l_horizontal_8, 4,4
1179 1180 1181
    sub          r0, r3
    lea          r2, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
1182 1183 1184 1185
    test         r1, r1
    lea          r1, [r0+r3]
    cmovnz       r1, r0
    punpckhbw   mm0, [r1+r3*0-8]
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
    movq        mm1, [r2+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r2, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
1200
    movq        mm1, [r1+r3*0-8]
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238
    mov          r0, r2
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    movq        mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq        mm4, mm0
    movq        mm7, mm2
    PRED4x4_LOWPASS mm1, mm3, mm0, mm4, mm5
    psllq       mm1, 56
    PALIGNR     mm7, mm1, 7, mm3
    movq        mm3, mm7
    lea         r1, [r0+r3*2]
    movq       mm7, mm3
    punpckhbw  mm3, mm3
    punpcklbw  mm7, mm7
    pshufw     mm0, mm3, 0xff
    pshufw     mm1, mm3, 0xaa
    lea         r2, [r1+r3*2]
    pshufw     mm2, mm3, 0x55
    pshufw     mm3, mm3, 0x00
    pshufw     mm4, mm7, 0xff
    pshufw     mm5, mm7, 0xaa
    pshufw     mm6, mm7, 0x55
    pshufw     mm7, mm7, 0x00
    movq [r0+r3*1], mm0
    movq [r0+r3*2], mm1
    movq [r1+r3*1], mm2
    movq [r1+r3*2], mm3
    movq [r2+r3*1], mm4
    movq [r2+r3*2], mm5
    lea         r0, [r2+r3*2]
    movq [r0+r3*1], mm6
    movq [r0+r3*2], mm7
    RET
%endmacro

1239 1240 1241 1242
INIT_MMX mmxext
PRED8x8L_HORIZONTAL
INIT_MMX ssse3
PRED8x8L_HORIZONTAL
1243 1244

;-----------------------------------------------------------------------------
1245
; void pred8x8l_vertical_8(uint8_t *src, int has_topleft, int has_topright, int stride)
1246
;-----------------------------------------------------------------------------
1247

1248 1249
%macro PRED8x8L_VERTICAL 0
cglobal pred8x8l_vertical_8, 4,4
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
    sub          r0, r3
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1 ; top_left
    jz .fix_lt_2
    test         r2, r2 ; top_right
    jz .fix_tr_1
    jmp .body
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2 ; top_right
    jnz .body
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
1277
.body:
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
    PRED4x4_LOWPASS mm0, mm2, mm1, mm3, mm5
%rep 3
    movq [r0+r3*1], mm0
    movq [r0+r3*2], mm0
    lea    r0, [r0+r3*2]
%endrep
    movq [r0+r3*1], mm0
    movq [r0+r3*2], mm0
    RET
%endmacro

1289 1290 1291 1292
INIT_MMX mmxext
PRED8x8L_VERTICAL
INIT_MMX ssse3
PRED8x8L_VERTICAL
1293 1294

;-----------------------------------------------------------------------------
1295
;void pred8x8l_down_left_8(uint8_t *src, int has_topleft, int has_topright, int stride)
1296
;-----------------------------------------------------------------------------
1297

1298 1299
INIT_MMX mmxext
cglobal pred8x8l_down_left_8, 4,5
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
    sub          r0, r3
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1
    jz .fix_lt_2
    test         r2, r2
    jz .fix_tr_1
    jmp .do_top
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
.fix_tr_2:
    punpckhbw   mm3, mm3
    pshufw      mm1, mm3, 0xFF
    jmp .do_topright
.do_top:
    PRED4x4_LOWPASS mm4, mm2, mm1, mm3, mm5
    movq        mm7, mm4
    test         r2, r2
    jz .fix_tr_2
    movq        mm0, [r0+8]
    movq        mm5, mm0
    movq        mm2, mm0
    movq        mm4, mm0
    psrlq       mm5, 56
    PALIGNR     mm2, mm3, 7, mm3
    PALIGNR     mm5, mm4, 1, mm4
    PRED4x4_LOWPASS mm1, mm2, mm5, mm0, mm4
.do_topright:
    lea          r1, [r0+r3*2]
    movq        mm6, mm1
    psrlq       mm1, 56
    movq        mm4, mm1
    lea          r2, [r1+r3*2]
    movq        mm2, mm6
    PALIGNR     mm2, mm7, 1, mm0
    movq        mm3, mm6
    PALIGNR     mm3, mm7, 7, mm0
    PALIGNR     mm4, mm6, 1, mm0
    movq        mm5, mm7
    movq        mm1, mm7
    movq        mm7, mm6
    lea          r4, [r2+r3*2]
    psllq       mm1, 8
    PRED4x4_LOWPASS mm0, mm1, mm2, mm5, mm6
    PRED4x4_LOWPASS mm1, mm3, mm4, mm7, mm6
    movq  [r4+r3*2], mm1
    movq        mm2, mm0
    psllq       mm1, 8
    psrlq       mm2, 56
    psllq       mm0, 8
    por         mm1, mm2
    movq  [r4+r3*1], mm1
    movq        mm2, mm0
    psllq       mm1, 8
    psrlq       mm2, 56
    psllq       mm0, 8
    por         mm1, mm2
    movq  [r2+r3*2], mm1
    movq        mm2, mm0
    psllq       mm1, 8
    psrlq       mm2, 56
    psllq       mm0, 8
    por         mm1, mm2
    movq  [r2+r3*1], mm1
    movq        mm2, mm0
    psllq       mm1, 8
    psrlq       mm2, 56
    psllq       mm0, 8
    por         mm1, mm2
    movq  [r1+r3*2], mm1
    movq        mm2, mm0
    psllq       mm1, 8
    psrlq       mm2, 56
    psllq       mm0, 8
    por         mm1, mm2
    movq  [r1+r3*1], mm1
    movq        mm2, mm0
    psllq       mm1, 8
    psrlq       mm2, 56
    psllq       mm0, 8
    por         mm1, mm2
    movq  [r0+r3*2], mm1
    psllq       mm1, 8
    psrlq       mm0, 56
    por         mm1, mm0
    movq  [r0+r3*1], mm1
    RET

1406 1407
%macro PRED8x8L_DOWN_LEFT 0
cglobal pred8x8l_down_left_8, 4,4
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
    sub          r0, r3
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1 ; top_left
    jz .fix_lt_2
    test         r2, r2 ; top_right
    jz .fix_tr_1
    jmp .do_top
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2 ; top_right
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
.fix_tr_2:
    punpckhbw   mm3, mm3
    pshufw      mm1, mm3, 0xFF
    jmp .do_topright
.do_top:
    PRED4x4_LOWPASS mm4, mm2, mm1, mm3, mm5
    movq2dq    xmm3, mm4
    test         r2, r2 ; top_right
    jz .fix_tr_2
    movq        mm0, [r0+8]
    movq        mm5, mm0
    movq        mm2, mm0
    movq        mm4, mm0
    psrlq       mm5, 56
    PALIGNR     mm2, mm3, 7, mm3
    PALIGNR     mm5, mm4, 1, mm4
    PRED4x4_LOWPASS mm1, mm2, mm5, mm0, mm4
.do_topright:
    movq2dq    xmm4, mm1
    psrlq       mm1, 56
    movq2dq    xmm5, mm1
    lea         r1, [r0+r3*2]
    pslldq    xmm4, 8
    por       xmm3, xmm4
    movdqa    xmm2, xmm3
    psrldq    xmm2, 1
    pslldq    xmm5, 15
    por       xmm2, xmm5
    lea         r2, [r1+r3*2]
    movdqa    xmm1, xmm3
    pslldq    xmm1, 1
1467
INIT_XMM cpuname
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
    PRED4x4_LOWPASS xmm0, xmm1, xmm2, xmm3, xmm4
    psrldq    xmm0, 1
    movq [r0+r3*1], xmm0
    psrldq    xmm0, 1
    movq [r0+r3*2], xmm0
    psrldq    xmm0, 1
    lea         r0, [r2+r3*2]
    movq [r1+r3*1], xmm0
    psrldq    xmm0, 1
    movq [r1+r3*2], xmm0
    psrldq    xmm0, 1
    movq [r2+r3*1], xmm0
    psrldq    xmm0, 1
    movq [r2+r3*2], xmm0
    psrldq    xmm0, 1
    movq [r0+r3*1], xmm0
    psrldq    xmm0, 1
    movq [r0+r3*2], xmm0
    RET
%endmacro

1489 1490 1491 1492
INIT_MMX sse2
PRED8x8L_DOWN_LEFT
INIT_MMX ssse3
PRED8x8L_DOWN_LEFT
1493 1494

;-----------------------------------------------------------------------------
1495
;void pred8x8l_down_right_8_mmxext(uint8_t *src, int has_topleft, int has_topright, int stride)
1496
;-----------------------------------------------------------------------------
1497

1498 1499
INIT_MMX mmxext
cglobal pred8x8l_down_right_8, 4,5
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571
    sub          r0, r3
    lea          r4, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
    punpckhbw   mm0, [r0+r3*0-8]
    movq        mm1, [r4+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r4, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
    movq        mm1, [r4]
    mov          r0, r4
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    test        r1, r1 ; top_left
    jz .fix_lt_1
.do_left:
    movq        mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq        mm4, mm0
    movq        mm7, mm2
    movq        mm6, mm2
    PRED4x4_LOWPASS mm1, mm3, mm0, mm4, mm5
    psllq       mm1, 56
    PALIGNR     mm7, mm1, 7, mm3
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1 ; top_left
    jz .fix_lt_2
    test         r2, r2 ; top_right
    jz .fix_tr_1
.do_top:
    PRED4x4_LOWPASS mm4, mm2, mm1, mm3, mm5
    movq        mm5, mm4
    jmp .body
.fix_lt_1:
    movq        mm5, mm3
    pxor        mm5, mm4
    psrlq       mm5, 56
    psllq       mm5, 48
    pxor        mm1, mm5
    jmp .do_left
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2 ; top_right
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
1572
.body:
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628
    lea         r1, [r0+r3*2]
    movq       mm1, mm7
    movq       mm7, mm5
    movq       mm5, mm6
    movq       mm2, mm7
    lea         r2, [r1+r3*2]
    PALIGNR    mm2, mm6, 1, mm0
    movq       mm3, mm7
    PALIGNR    mm3, mm6, 7, mm0
    movq       mm4, mm7
    lea         r4, [r2+r3*2]
    psrlq      mm4, 8
    PRED4x4_LOWPASS mm0, mm1, mm2, mm5, mm6
    PRED4x4_LOWPASS mm1, mm3, mm4, mm7, mm6
    movq [r4+r3*2], mm0
    movq       mm2, mm1
    psrlq      mm0, 8
    psllq      mm2, 56
    psrlq      mm1, 8
    por        mm0, mm2
    movq [r4+r3*1], mm0
    movq       mm2, mm1
    psrlq      mm0, 8
    psllq      mm2, 56
    psrlq      mm1, 8
    por        mm0, mm2
    movq [r2+r3*2], mm0
    movq       mm2, mm1
    psrlq      mm0, 8
    psllq      mm2, 56
    psrlq      mm1, 8
    por        mm0, mm2
    movq [r2+r3*1], mm0
    movq       mm2, mm1
    psrlq      mm0, 8
    psllq      mm2, 56
    psrlq      mm1, 8
    por        mm0, mm2
    movq [r1+r3*2], mm0
    movq       mm2, mm1
    psrlq      mm0, 8
    psllq      mm2, 56
    psrlq      mm1, 8
    por        mm0, mm2
    movq [r1+r3*1], mm0
    movq       mm2, mm1
    psrlq      mm0, 8
    psllq      mm2, 56
    psrlq      mm1, 8
    por        mm0, mm2
    movq [r0+r3*2], mm0
    psrlq      mm0, 8
    psllq      mm1, 56
    por        mm0, mm1
    movq [r0+r3*1], mm0
    RET
1629

1630 1631
%macro PRED8x8L_DOWN_RIGHT 0
cglobal pred8x8l_down_right_8, 4,5
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
    sub          r0, r3
    lea          r4, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
    punpckhbw   mm0, [r0+r3*0-8]
    movq        mm1, [r4+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r4, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
    movq        mm1, [r4]
    mov          r0, r4
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    test        r1, r1
    jz .fix_lt_1
    jmp .do_left
.fix_lt_1:
    movq        mm5, mm3
    pxor        mm5, mm4
    psrlq       mm5, 56
    psllq       mm5, 48
    pxor        mm1, mm5
    jmp .do_left
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
.do_left:
    movq        mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq        mm4, mm0
    movq        mm7, mm2
    movq2dq    xmm3, mm2
    PRED4x4_LOWPASS mm1, mm3, mm0, mm4, mm5
    psllq       mm1, 56
    PALIGNR     mm7, mm1, 7, mm3
    movq2dq    xmm1, mm7
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1
    jz .fix_lt_2
    test         r2, r2
    jz .fix_tr_1
.do_top:
    PRED4x4_LOWPASS mm4, mm2, mm1, mm3, mm5
    movq2dq   xmm4, mm4
    lea         r1, [r0+r3*2]
    movdqa    xmm0, xmm3
    pslldq    xmm4, 8
    por       xmm3, xmm4
    lea         r2, [r1+r3*2]
    pslldq    xmm4, 1
    por       xmm1, xmm4
    psrldq    xmm0, 7
    pslldq    xmm0, 15
    psrldq    xmm0, 7
    por       xmm1, xmm0
    lea         r0, [r2+r3*2]
    movdqa    xmm2, xmm3
    psrldq    xmm2, 1
1719
INIT_XMM cpuname
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
    PRED4x4_LOWPASS xmm0, xmm1, xmm2, xmm3, xmm4
    movdqa    xmm1, xmm0
    psrldq    xmm1, 1
    movq [r0+r3*2], xmm0
    movq [r0+r3*1], xmm1
    psrldq    xmm0, 2
    psrldq    xmm1, 2
    movq [r2+r3*2], xmm0
    movq [r2+r3*1], xmm1
    psrldq    xmm0, 2
    psrldq    xmm1, 2
    movq [r1+r3*2], xmm0
    movq [r1+r3*1], xmm1
    psrldq    xmm0, 2
    psrldq    xmm1, 2
    movq [r4+r3*2], xmm0
    movq [r4+r3*1], xmm1
    RET
%endmacro

1740 1741 1742 1743
INIT_MMX sse2
PRED8x8L_DOWN_RIGHT
INIT_MMX ssse3
PRED8x8L_DOWN_RIGHT
1744 1745

;-----------------------------------------------------------------------------
1746
; void pred8x8l_vertical_right_8(uint8_t *src, int has_topleft, int has_topright, int stride)
1747
;-----------------------------------------------------------------------------
1748

1749 1750
INIT_MMX mmxext
cglobal pred8x8l_vertical_right_8, 4,5
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
    sub          r0, r3
    lea          r4, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
    punpckhbw   mm0, [r0+r3*0-8]
    movq        mm1, [r4+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r4, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
    movq        mm1, [r4]
    mov          r0, r4
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    test        r1, r1
    jz .fix_lt_1
    jmp .do_left
.fix_lt_1:
    movq        mm5, mm3
    pxor        mm5, mm4
    psrlq       mm5, 56
    psllq       mm5, 48
    pxor        mm1, mm5
    jmp .do_left
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
.do_left:
    movq        mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq        mm7, mm2
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1
    jz .fix_lt_2
    test         r2, r2
    jz .fix_tr_1
1815
.do_top:
1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854
    PRED4x4_LOWPASS mm6, mm2, mm1, mm3, mm5
    lea         r1, [r0+r3*2]
    movq       mm2, mm6
    movq       mm3, mm6
    PALIGNR    mm3, mm7, 7, mm0
    PALIGNR    mm6, mm7, 6, mm1
    movq       mm4, mm3
    pavgb      mm3, mm2
    lea         r2, [r1+r3*2]
    PRED4x4_LOWPASS mm0, mm6, mm2, mm4, mm5
    movq [r0+r3*1], mm3
    movq [r0+r3*2], mm0
    movq       mm5, mm0
    movq       mm6, mm3
    movq       mm1, mm7
    movq       mm2, mm1
    psllq      mm2, 8
    movq       mm3, mm1
    psllq      mm3, 16
    lea         r4, [r2+r3*2]
    PRED4x4_LOWPASS mm0, mm1, mm3, mm2, mm4
    PALIGNR    mm6, mm0, 7, mm2
    movq [r1+r3*1], mm6
    psllq      mm0, 8
    PALIGNR    mm5, mm0, 7, mm1
    movq [r1+r3*2], mm5
    psllq      mm0, 8
    PALIGNR    mm6, mm0, 7, mm2
    movq [r2+r3*1], mm6
    psllq      mm0, 8
    PALIGNR    mm5, mm0, 7, mm1
    movq [r2+r3*2], mm5
    psllq      mm0, 8
    PALIGNR    mm6, mm0, 7, mm2
    movq [r4+r3*1], mm6
    psllq      mm0, 8
    PALIGNR    mm5, mm0, 7, mm1
    movq [r4+r3*2], mm5
    RET
1855

1856 1857
%macro PRED8x8L_VERTICAL_RIGHT 0
cglobal pred8x8l_vertical_right_8, 4,5,7
1858 1859 1860
    ; manually spill XMM registers for Win64 because
    ; the code here is initialized with INIT_MMX
    WIN64_SPILL_XMM 7
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923
    sub          r0, r3
    lea          r4, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
    punpckhbw   mm0, [r0+r3*0-8]
    movq        mm1, [r4+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r4, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
    movq        mm1, [r4]
    mov          r0, r4
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    test        r1, r1
    jnz .do_left
.fix_lt_1:
    movq        mm5, mm3
    pxor        mm5, mm4
    psrlq       mm5, 56
    psllq       mm5, 48
    pxor        mm1, mm5
    jmp .do_left
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
.do_left:
    movq        mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq2dq    xmm0, mm2
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1
    jz .fix_lt_2
    test         r2, r2
    jz .fix_tr_1
1924
.do_top:
1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937
    PRED4x4_LOWPASS mm6, mm2, mm1, mm3, mm5
    lea           r1, [r0+r3*2]
    movq2dq     xmm4, mm6
    pslldq      xmm4, 8
    por         xmm0, xmm4
    movdqa      xmm6, [pw_ff00]
    movdqa      xmm1, xmm0
    lea           r2, [r1+r3*2]
    movdqa      xmm2, xmm0
    movdqa      xmm3, xmm0
    pslldq      xmm0, 1
    pslldq      xmm1, 2
    pavgb       xmm2, xmm0
1938
INIT_XMM cpuname
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
    PRED4x4_LOWPASS xmm4, xmm3, xmm1, xmm0, xmm5
    pandn       xmm6, xmm4
    movdqa      xmm5, xmm4
    psrlw       xmm4, 8
    packuswb    xmm6, xmm4
    movhlps     xmm4, xmm6
    movhps [r0+r3*2], xmm5
    movhps [r0+r3*1], xmm2
    psrldq      xmm5, 4
    movss       xmm5, xmm6
    psrldq      xmm2, 4
    movss       xmm2, xmm4
    lea           r0, [r2+r3*2]
    psrldq      xmm5, 1
    psrldq      xmm2, 1
    movq        [r0+r3*2], xmm5
    movq        [r0+r3*1], xmm2
    psrldq      xmm5, 1
    psrldq      xmm2, 1
    movq        [r2+r3*2], xmm5
    movq        [r2+r3*1], xmm2
    psrldq      xmm5, 1
    psrldq      xmm2, 1
    movq        [r1+r3*2], xmm5
    movq        [r1+r3*1], xmm2
    RET
%endmacro

1967 1968 1969 1970
INIT_MMX sse2
PRED8x8L_VERTICAL_RIGHT
INIT_MMX ssse3
PRED8x8L_VERTICAL_RIGHT
1971 1972

;-----------------------------------------------------------------------------
1973
;void pred8x8l_vertical_left_8(uint8_t *src, int has_topleft, int has_topright, int stride)
1974
;-----------------------------------------------------------------------------
1975

1976 1977
%macro PRED8x8L_VERTICAL_LEFT 0
cglobal pred8x8l_vertical_left_8, 4,4
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
    sub          r0, r3
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1
    jz .fix_lt_2
    test         r2, r2
    jz .fix_tr_1
    jmp .do_top
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
.fix_tr_2:
    punpckhbw   mm3, mm3
    pshufw      mm1, mm3, 0xFF
    jmp .do_topright
.do_top:
    PRED4x4_LOWPASS mm4, mm2, mm1, mm3, mm5
    movq2dq    xmm4, mm4
    test         r2, r2
    jz .fix_tr_2
    movq        mm0, [r0+8]
    movq        mm5, mm0
    movq        mm2, mm0
    movq        mm4, mm0
    psrlq       mm5, 56
    PALIGNR     mm2, mm3, 7, mm3
    PALIGNR     mm5, mm4, 1, mm4
    PRED4x4_LOWPASS mm1, mm2, mm5, mm0, mm4
.do_topright:
    movq2dq   xmm3, mm1
    lea         r1, [r0+r3*2]
    pslldq    xmm3, 8
    por       xmm4, xmm3
    movdqa    xmm2, xmm4
    movdqa    xmm1, xmm4
    movdqa    xmm3, xmm4
    psrldq    xmm2, 1
    pslldq    xmm1, 1
    pavgb     xmm3, xmm2
    lea         r2, [r1+r3*2]
2035
INIT_XMM cpuname
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055
    PRED4x4_LOWPASS xmm0, xmm1, xmm2, xmm4, xmm5
    psrldq    xmm0, 1
    movq [r0+r3*1], xmm3
    movq [r0+r3*2], xmm0
    lea         r0, [r2+r3*2]
    psrldq    xmm3, 1
    psrldq    xmm0, 1
    movq [r1+r3*1], xmm3
    movq [r1+r3*2], xmm0
    psrldq    xmm3, 1
    psrldq    xmm0, 1
    movq [r2+r3*1], xmm3
    movq [r2+r3*2], xmm0
    psrldq    xmm3, 1
    psrldq    xmm0, 1
    movq [r0+r3*1], xmm3
    movq [r0+r3*2], xmm0
    RET
%endmacro

2056 2057 2058 2059
INIT_MMX sse2
PRED8x8L_VERTICAL_LEFT
INIT_MMX ssse3
PRED8x8L_VERTICAL_LEFT
2060 2061

;-----------------------------------------------------------------------------
2062
; void pred8x8l_horizontal_up_8(uint8_t *src, int has_topleft, int has_topright, int stride)
2063
;-----------------------------------------------------------------------------
2064

2065 2066
%macro PRED8x8L_HORIZONTAL_UP 0
cglobal pred8x8l_horizontal_up_8, 4,4
2067 2068 2069
    sub          r0, r3
    lea          r2, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
2070 2071 2072 2073
    test         r1, r1
    lea          r1, [r0+r3]
    cmovnz       r1, r0
    punpckhbw   mm0, [r1+r3*0-8]
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087
    movq        mm1, [r2+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r2, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
2088
    movq        mm1, [r1+r3*0-8]
2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
    mov          r0, r2
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    movq       mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq       mm4, mm0
    movq       mm7, mm2
    PRED4x4_LOWPASS mm1, mm3, mm0, mm4, mm5
    psllq      mm1, 56
    PALIGNR    mm7, mm1, 7, mm3
    lea         r1, [r0+r3*2]
    pshufw     mm0, mm7, 00011011b ; l6 l7 l4 l5 l2 l3 l0 l1
    psllq      mm7, 56             ; l7 .. .. .. .. .. .. ..
    movq       mm2, mm0
    psllw      mm0, 8
    psrlw      mm2, 8
    por        mm2, mm0            ; l7 l6 l5 l4 l3 l2 l1 l0
    movq       mm3, mm2
    movq       mm4, mm2
    movq       mm5, mm2
    psrlq      mm2, 8
    psrlq      mm3, 16
    lea         r2, [r1+r3*2]
    por        mm2, mm7            ; l7 l7 l6 l5 l4 l3 l2 l1
    punpckhbw  mm7, mm7
    por        mm3, mm7            ; l7 l7 l7 l6 l5 l4 l3 l2
    pavgb      mm4, mm2
    PRED4x4_LOWPASS mm1, mm3, mm5, mm2, mm6
    movq       mm5, mm4
    punpcklbw  mm4, mm1            ; p4 p3 p2 p1
    punpckhbw  mm5, mm1            ; p8 p7 p6 p5
    movq       mm6, mm5
    movq       mm7, mm5
    movq       mm0, mm5
    PALIGNR    mm5, mm4, 2, mm1
    pshufw     mm1, mm6, 11111001b
    PALIGNR    mm6, mm4, 4, mm2
    pshufw     mm2, mm7, 11111110b
    PALIGNR    mm7, mm4, 6, mm3
    pshufw     mm3, mm0, 11111111b
    movq [r0+r3*1], mm4
    movq [r0+r3*2], mm5
    lea         r0, [r2+r3*2]
    movq [r1+r3*1], mm6
    movq [r1+r3*2], mm7
    movq [r2+r3*1], mm0
    movq [r2+r3*2], mm1
    movq [r0+r3*1], mm2
    movq [r0+r3*2], mm3
    RET
%endmacro

2143 2144 2145 2146
INIT_MMX mmxext
PRED8x8L_HORIZONTAL_UP
INIT_MMX ssse3
PRED8x8L_HORIZONTAL_UP
2147 2148

;-----------------------------------------------------------------------------
2149
;void pred8x8l_horizontal_down_8(uint8_t *src, int has_topleft, int has_topright, int stride)
2150
;-----------------------------------------------------------------------------
2151

2152 2153
INIT_MMX mmxext
cglobal pred8x8l_horizontal_down_8, 4,5
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265
    sub          r0, r3
    lea          r4, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
    punpckhbw   mm0, [r0+r3*0-8]
    movq        mm1, [r4+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r4, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
    movq        mm1, [r4]
    mov          r0, r4
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    test        r1, r1
    jnz .do_left
.fix_lt_1:
    movq        mm5, mm3
    pxor        mm5, mm4
    psrlq       mm5, 56
    psllq       mm5, 48
    pxor        mm1, mm5
    jmp .do_left
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
.do_left:
    movq        mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq        mm4, mm0
    movq        mm7, mm2
    movq        mm6, mm2
    PRED4x4_LOWPASS mm1, mm3, mm0, mm4, mm5
    psllq       mm1, 56
    PALIGNR     mm7, mm1, 7, mm3
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1
    jz .fix_lt_2
    test         r2, r2
    jz .fix_tr_1
.do_top:
    PRED4x4_LOWPASS mm4, mm2, mm1, mm3, mm5
    movq       mm5, mm4
    lea         r1, [r0+r3*2]
    psllq      mm7, 56
    movq       mm2, mm5
    movq       mm3, mm6
    movq       mm4, mm2
    PALIGNR    mm2, mm6, 7, mm5
    PALIGNR    mm6, mm7, 7, mm0
    lea         r2, [r1+r3*2]
    PALIGNR    mm4, mm3, 1, mm7
    movq       mm5, mm3
    pavgb      mm3, mm6
    PRED4x4_LOWPASS mm0, mm4, mm6, mm5, mm7
    movq       mm4, mm2
    movq       mm1, mm2
    lea         r4, [r2+r3*2]
    psrlq      mm4, 16
    psrlq      mm1, 8
    PRED4x4_LOWPASS mm6, mm4, mm2, mm1, mm5
    movq       mm7, mm3
    punpcklbw  mm3, mm0
    punpckhbw  mm7, mm0
    movq       mm1, mm7
    movq       mm0, mm7
    movq       mm4, mm7
    movq [r4+r3*2], mm3
    PALIGNR    mm7, mm3, 2, mm5
    movq [r4+r3*1], mm7
    PALIGNR    mm1, mm3, 4, mm5
    movq [r2+r3*2], mm1
    PALIGNR    mm0, mm3, 6, mm3
    movq [r2+r3*1], mm0
    movq       mm2, mm6
    movq       mm3, mm6
    movq [r1+r3*2], mm4
    PALIGNR    mm6, mm4, 2, mm5
    movq [r1+r3*1], mm6
    PALIGNR    mm2, mm4, 4, mm5
    movq [r0+r3*2], mm2
    PALIGNR    mm3, mm4, 6, mm4
    movq [r0+r3*1], mm3
    RET
2266

2267 2268
%macro PRED8x8L_HORIZONTAL_DOWN 0
cglobal pred8x8l_horizontal_down_8, 4,5
2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359
    sub          r0, r3
    lea          r4, [r0+r3*2]
    movq        mm0, [r0+r3*1-8]
    punpckhbw   mm0, [r0+r3*0-8]
    movq        mm1, [r4+r3*1-8]
    punpckhbw   mm1, [r0+r3*2-8]
    mov          r4, r0
    punpckhwd   mm1, mm0
    lea          r0, [r0+r3*4]
    movq        mm2, [r0+r3*1-8]
    punpckhbw   mm2, [r0+r3*0-8]
    lea          r0, [r0+r3*2]
    movq        mm3, [r0+r3*1-8]
    punpckhbw   mm3, [r0+r3*0-8]
    punpckhwd   mm3, mm2
    punpckhdq   mm3, mm1
    lea          r0, [r0+r3*2]
    movq        mm0, [r0+r3*0-8]
    movq        mm1, [r4]
    mov          r0, r4
    movq        mm4, mm3
    movq        mm2, mm3
    PALIGNR     mm4, mm0, 7, mm0
    PALIGNR     mm1, mm2, 1, mm2
    test        r1, r1
    jnz .do_left
.fix_lt_1:
    movq        mm5, mm3
    pxor        mm5, mm4
    psrlq       mm5, 56
    psllq       mm5, 48
    pxor        mm1, mm5
    jmp .do_left
.fix_lt_2:
    movq        mm5, mm3
    pxor        mm5, mm2
    psllq       mm5, 56
    psrlq       mm5, 56
    pxor        mm2, mm5
    test         r2, r2
    jnz .do_top
.fix_tr_1:
    movq        mm5, mm3
    pxor        mm5, mm1
    psrlq       mm5, 56
    psllq       mm5, 56
    pxor        mm1, mm5
    jmp .do_top
.fix_tr_2:
    punpckhbw   mm3, mm3
    pshufw      mm1, mm3, 0xFF
    jmp .do_topright
.do_left:
    movq        mm0, mm4
    PRED4x4_LOWPASS mm2, mm1, mm4, mm3, mm5
    movq2dq    xmm0, mm2
    pslldq     xmm0, 8
    movq        mm4, mm0
    PRED4x4_LOWPASS mm1, mm3, mm0, mm4, mm5
    movq2dq    xmm2, mm1
    pslldq     xmm2, 15
    psrldq     xmm2, 8
    por        xmm0, xmm2
    movq        mm0, [r0-8]
    movq        mm3, [r0]
    movq        mm1, [r0+8]
    movq        mm2, mm3
    movq        mm4, mm3
    PALIGNR     mm2, mm0, 7, mm0
    PALIGNR     mm1, mm4, 1, mm4
    test         r1, r1
    jz .fix_lt_2
    test         r2, r2
    jz .fix_tr_1
.do_top:
    PRED4x4_LOWPASS mm4, mm2, mm1, mm3, mm5
    movq2dq    xmm1, mm4
    test         r2, r2
    jz .fix_tr_2
    movq        mm0, [r0+8]
    movq        mm5, mm0
    movq        mm2, mm0
    movq        mm4, mm0
    psrlq       mm5, 56
    PALIGNR     mm2, mm3, 7, mm3
    PALIGNR     mm5, mm4, 1, mm4
    PRED4x4_LOWPASS mm1, mm2, mm5, mm0, mm4
.do_topright:
    movq2dq    xmm5, mm1
    pslldq     xmm5, 8
    por        xmm1, xmm5
2360
INIT_XMM cpuname
2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390
    lea         r2, [r4+r3*2]
    movdqa    xmm2, xmm1
    movdqa    xmm3, xmm1
    PALIGNR   xmm1, xmm0, 7, xmm4
    PALIGNR   xmm2, xmm0, 9, xmm5
    lea         r1, [r2+r3*2]
    PALIGNR   xmm3, xmm0, 8, xmm0
    movdqa    xmm4, xmm1
    pavgb     xmm4, xmm3
    lea         r0, [r1+r3*2]
    PRED4x4_LOWPASS xmm0, xmm1, xmm2, xmm3, xmm5
    punpcklbw xmm4, xmm0
    movhlps   xmm0, xmm4
    movq   [r0+r3*2], xmm4
    movq   [r2+r3*2], xmm0
    psrldq xmm4, 2
    psrldq xmm0, 2
    movq   [r0+r3*1], xmm4
    movq   [r2+r3*1], xmm0
    psrldq xmm4, 2
    psrldq xmm0, 2
    movq   [r1+r3*2], xmm4
    movq   [r4+r3*2], xmm0
    psrldq xmm4, 2
    psrldq xmm0, 2
    movq   [r1+r3*1], xmm4
    movq   [r4+r3*1], xmm0
    RET
%endmacro

2391 2392 2393 2394
INIT_MMX sse2
PRED8x8L_HORIZONTAL_DOWN
INIT_MMX ssse3
PRED8x8L_HORIZONTAL_DOWN
2395 2396

;-----------------------------------------------------------------------------
2397
; void pred4x4_dc_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2398 2399
;-----------------------------------------------------------------------------

2400 2401
INIT_MMX mmxext
cglobal pred4x4_dc_8, 3,5
2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424
    pxor   mm7, mm7
    mov     r4, r0
    sub     r0, r2
    movd   mm0, [r0]
    psadbw mm0, mm7
    movzx  r1d, byte [r0+r2*1-1]
    movd   r3d, mm0
    add    r3d, r1d
    movzx  r1d, byte [r0+r2*2-1]
    lea     r0, [r0+r2*2]
    add    r3d, r1d
    movzx  r1d, byte [r0+r2*1-1]
    add    r3d, r1d
    movzx  r1d, byte [r0+r2*2-1]
    add    r3d, r1d
    add    r3d, 4
    shr    r3d, 3
    imul   r3d, 0x01010101
    mov   [r4+r2*0], r3d
    mov   [r0+r2*0], r3d
    mov   [r0+r2*1], r3d
    mov   [r0+r2*2], r3d
    RET
2425 2426

;-----------------------------------------------------------------------------
2427
; void pred4x4_tm_vp8_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2428 2429
;-----------------------------------------------------------------------------

2430
%macro PRED4x4_TM 0
2431
cglobal pred4x4_tm_vp8_8, 3,6
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444
    sub        r0, r2
    pxor      mm7, mm7
    movd      mm0, [r0]
    punpcklbw mm0, mm7
    movzx     r4d, byte [r0-1]
    mov       r5d, 2
.loop:
    movzx     r1d, byte [r0+r2*1-1]
    movzx     r3d, byte [r0+r2*2-1]
    sub       r1d, r4d
    sub       r3d, r4d
    movd      mm2, r1d
    movd      mm4, r3d
2445
%if cpuflag(mmxext)
2446 2447 2448
    pshufw    mm2, mm2, 0
    pshufw    mm4, mm4, 0
%else
2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465
    punpcklwd mm2, mm2
    punpcklwd mm4, mm4
    punpckldq mm2, mm2
    punpckldq mm4, mm4
%endif
    paddw     mm2, mm0
    paddw     mm4, mm0
    packuswb  mm2, mm2
    packuswb  mm4, mm4
    movd [r0+r2*1], mm2
    movd [r0+r2*2], mm4
    lea        r0, [r0+r2*2]
    dec       r5d
    jg .loop
    REP_RET
%endmacro

2466
INIT_MMX mmx
2467
PRED4x4_TM
2468
INIT_MMX mmxext
2469
PRED4x4_TM
2470

2471 2472
INIT_XMM ssse3
cglobal pred4x4_tm_vp8_8, 3,3
2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488
    sub         r0, r2
    movq       mm6, [tm_shuf]
    pxor       mm1, mm1
    movd       mm0, [r0]
    punpcklbw  mm0, mm1
    movd       mm7, [r0-4]
    pshufb     mm7, mm6
    lea         r1, [r0+r2*2]
    movd       mm2, [r0+r2*1-4]
    movd       mm3, [r0+r2*2-4]
    movd       mm4, [r1+r2*1-4]
    movd       mm5, [r1+r2*2-4]
    pshufb     mm2, mm6
    pshufb     mm3, mm6
    pshufb     mm4, mm6
    pshufb     mm5, mm6
2489
    psubw      mm0, mm7
2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502
    paddw      mm2, mm0
    paddw      mm3, mm0
    paddw      mm4, mm0
    paddw      mm5, mm0
    packuswb   mm2, mm2
    packuswb   mm3, mm3
    packuswb   mm4, mm4
    packuswb   mm5, mm5
    movd [r0+r2*1], mm2
    movd [r0+r2*2], mm3
    movd [r1+r2*1], mm4
    movd [r1+r2*2], mm5
    RET
2503 2504

;-----------------------------------------------------------------------------
2505
; void pred4x4_vertical_vp8_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2506 2507
;-----------------------------------------------------------------------------

2508 2509
INIT_MMX mmxext
cglobal pred4x4_vertical_vp8_8, 3,3
2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522
    sub       r0, r2
    movd      m1, [r0-1]
    movd      m0, [r0]
    mova      m2, m0   ;t0 t1 t2 t3
    punpckldq m0, [r1] ;t0 t1 t2 t3 t4 t5 t6 t7
    lea       r1, [r0+r2*2]
    psrlq     m0, 8    ;t1 t2 t3 t4
    PRED4x4_LOWPASS m3, m1, m0, m2, m4
    movd [r0+r2*1], m3
    movd [r0+r2*2], m3
    movd [r1+r2*1], m3
    movd [r1+r2*2], m3
    RET
2523 2524

;-----------------------------------------------------------------------------
2525
; void pred4x4_down_left_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2526
;-----------------------------------------------------------------------------
2527 2528
INIT_MMX mmxext
cglobal pred4x4_down_left_8, 3,3
2529 2530 2531 2532 2533 2534 2535 2536
    sub       r0, r2
    movq      m1, [r0]
    punpckldq m1, [r1]
    movq      m2, m1
    movq      m3, m1
    psllq     m1, 8
    pxor      m2, m1
    psrlq     m2, 8
2537 2538
    pxor      m2, m3
    PRED4x4_LOWPASS m0, m1, m2, m3, m4
2539 2540 2541 2542 2543 2544 2545 2546 2547 2548
    lea       r1, [r0+r2*2]
    psrlq     m0, 8
    movd      [r0+r2*1], m0
    psrlq     m0, 8
    movd      [r0+r2*2], m0
    psrlq     m0, 8
    movd      [r1+r2*1], m0
    psrlq     m0, 8
    movd      [r1+r2*2], m0
    RET
2549 2550

;-----------------------------------------------------------------------------
2551
; void pred4x4_vertical_left_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2552 2553
;-----------------------------------------------------------------------------

2554 2555
INIT_MMX mmxext
cglobal pred4x4_vertical_left_8, 3,3
2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573
    sub       r0, r2
    movq      m1, [r0]
    punpckldq m1, [r1]
    movq      m3, m1
    movq      m2, m1
    psrlq     m3, 8
    psrlq     m2, 16
    movq      m4, m3
    pavgb     m4, m1
    PRED4x4_LOWPASS m0, m1, m2, m3, m5
    lea       r1, [r0+r2*2]
    movh      [r0+r2*1], m4
    movh      [r0+r2*2], m0
    psrlq     m4, 8
    psrlq     m0, 8
    movh      [r1+r2*1], m4
    movh      [r1+r2*2], m0
    RET
2574 2575

;-----------------------------------------------------------------------------
2576
; void pred4x4_horizontal_up_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2577 2578
;-----------------------------------------------------------------------------

2579 2580
INIT_MMX mmxext
cglobal pred4x4_horizontal_up_8, 3,3
2581 2582
    sub       r0, r2
    lea       r1, [r0+r2*2]
2583 2584 2585 2586
    movd      m0, [r0+r2*1-4]
    punpcklbw m0, [r0+r2*2-4]
    movd      m1, [r1+r2*1-4]
    punpcklbw m1, [r1+r2*2-4]
2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606
    punpckhwd m0, m1
    movq      m1, m0
    punpckhbw m1, m1
    pshufw    m1, m1, 0xFF
    punpckhdq m0, m1
    movq      m2, m0
    movq      m3, m0
    movq      m7, m0
    psrlq     m2, 16
    psrlq     m3, 8
    pavgb     m7, m3
    PRED4x4_LOWPASS m4, m0, m2, m3, m5
    punpcklbw m7, m4
    movd    [r0+r2*1], m7
    psrlq    m7, 16
    movd    [r0+r2*2], m7
    psrlq    m7, 16
    movd    [r1+r2*1], m7
    movd    [r1+r2*2], m1
    RET
2607 2608

;-----------------------------------------------------------------------------
2609
; void pred4x4_horizontal_down_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2610 2611
;-----------------------------------------------------------------------------

2612 2613
INIT_MMX mmxext
cglobal pred4x4_horizontal_down_8, 3,3
2614 2615 2616 2617 2618
    sub       r0, r2
    lea       r1, [r0+r2*2]
    movh      m0, [r0-4]      ; lt ..
    punpckldq m0, [r0]        ; t3 t2 t1 t0 lt .. .. ..
    psllq     m0, 8           ; t2 t1 t0 lt .. .. .. ..
2619 2620 2621 2622
    movd      m1, [r1+r2*2-4] ; l3
    punpcklbw m1, [r1+r2*1-4] ; l2 l3
    movd      m2, [r0+r2*2-4] ; l1
    punpcklbw m2, [r0+r2*1-4] ; l0 l1
2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641
    punpckhwd m1, m2          ; l0 l1 l2 l3
    punpckhdq m1, m0          ; t2 t1 t0 lt l0 l1 l2 l3
    movq      m0, m1
    movq      m2, m1
    movq      m5, m1
    psrlq     m0, 16          ; .. .. t2 t1 t0 lt l0 l1
    psrlq     m2, 8           ; .. t2 t1 t0 lt l0 l1 l2
    pavgb     m5, m2
    PRED4x4_LOWPASS m3, m1, m0, m2, m4
    punpcklbw m5, m3
    psrlq     m3, 32
    PALIGNR   m3, m5, 6, m4
    movh      [r1+r2*2], m5
    psrlq     m5, 16
    movh      [r1+r2*1], m5
    psrlq     m5, 16
    movh      [r0+r2*2], m5
    movh      [r0+r2*1], m3
    RET
2642 2643

;-----------------------------------------------------------------------------
2644
; void pred4x4_vertical_right_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2645 2646
;-----------------------------------------------------------------------------

2647 2648
INIT_MMX mmxext
cglobal pred4x4_vertical_right_8, 3,3
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671
    sub     r0, r2
    lea     r1, [r0+r2*2]
    movh    m0, [r0]                    ; ........t3t2t1t0
    movq    m5, m0
    PALIGNR m0, [r0-8], 7, m1           ; ......t3t2t1t0lt
    pavgb   m5, m0
    PALIGNR m0, [r0+r2*1-8], 7, m1      ; ....t3t2t1t0ltl0
    movq    m1, m0
    PALIGNR m0, [r0+r2*2-8], 7, m2      ; ..t3t2t1t0ltl0l1
    movq    m2, m0
    PALIGNR m0, [r1+r2*1-8], 7, m3      ; t3t2t1t0ltl0l1l2
    PRED4x4_LOWPASS m3, m1, m0, m2, m4
    movq    m1, m3
    psrlq   m3, 16
    psllq   m1, 48
    movh    [r0+r2*1], m5
    movh    [r0+r2*2], m3
    PALIGNR m5, m1, 7, m2
    psllq   m1, 8
    movh    [r1+r2*1], m5
    PALIGNR m3, m1, 7, m1
    movh    [r1+r2*2], m3
    RET
2672 2673

;-----------------------------------------------------------------------------
2674
; void pred4x4_down_right_8_mmxext(uint8_t *src, const uint8_t *topright, int stride)
2675 2676
;-----------------------------------------------------------------------------

2677 2678
INIT_MMX mmxext
cglobal pred4x4_down_right_8, 3,3
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699
    sub       r0, r2
    lea       r1, [r0+r2*2]
    movq      m1, [r1-8]
    movq      m2, [r0+r2*1-8]
    punpckhbw m2, [r0-8]
    movh      m3, [r0]
    punpckhwd m1, m2
    PALIGNR   m3, m1, 5, m1
    movq      m1, m3
    PALIGNR   m3, [r1+r2*1-8], 7, m4
    movq      m2, m3
    PALIGNR   m3, [r1+r2*2-8], 7, m4
    PRED4x4_LOWPASS m0, m3, m1, m2, m4
    movh      [r1+r2*2], m0
    psrlq     m0, 8
    movh      [r1+r2*1], m0
    psrlq     m0, 8
    movh      [r0+r2*2], m0
    psrlq     m0, 8
    movh      [r0+r2*1], m0
    RET