3563 lines · 124.4 KB · Assembly
RawDownload
;*!;* \copy;*     Copyright (c)  2010-2013, Cisco Systems;*     All rights reserved.;*;*     Redistribution and use in source and binary forms, with or without;*     modification, are permitted provided that the following conditions;*     are met:;*;*        * Redistributions of source code must retain the above copyright;*          notice, this list of conditions and the following disclaimer.;*;*        * Redistributions in binary form must reproduce the above copyright;*          notice, this list of conditions and the following disclaimer in;*          the documentation and/or other materials provided with the;*          distribution.;*;*     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS;*     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT;*     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS;*     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE;*     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,;*     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,;*     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;;*     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER;*     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT;*     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN;*     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE;*     POSSIBILITY OF SUCH DAMAGE.;*;*;*      vaa.asm;*;*      Abstract;*      sse2 for pVaa routines;*;*  History;*      04/14/2010      Created;*              06/07/2010      Added AnalysisVaaInfoIntra_sse2(ssse3);*              06/10/2010      Tune rc_sad_frame_sse2 and got about 40% improvement;*              08/11/2010      Added abs_difference_mbrow_sse2 & sum_sqrsum_mbrow_sse2;*;*************************************************************************/%include "asm_inc.asm"  ;***********************************************************************; Macros and other preprocessor constants;***********************************************************************%macro SUM_SQR_SSE2     3       ; dst, pSrc, zero    movdqa %1, %2    punpcklbw %1, %3    punpckhbw %2, %3    pmaddwd %1, %1    pmaddwd %2, %2    paddd %1, %2    pshufd %2, %1, 04Eh   ; 01001110 B    paddd %1, %2    pshufd %2, %1, 0B1h   ; 10110001 B    paddd %1, %2%endmacro       ; END OF SUM_SQR_SSE2 %macro WELS_SAD_16x2_SSE2  3 ;esi :%1 edi:%2 ebx:%3    movdqa        xmm1,   [%1]    movdqa        xmm2,   [%2]    movdqa        xmm3,   [%1+%3]    movdqa        xmm4,   [%2+%3]    psadbw        xmm1,   xmm2    psadbw        xmm3,   xmm4    paddd xmm6,   xmm1    paddd xmm6,   xmm3    lea           %1,     [%1+%3*2]    lea           %2,     [%2+%3*2]%endmacro ; by comparing it outperforms than phaddw(SSSE3) sets%macro SUM_WORD_8x2_SSE2        2       ; dst(pSrc), tmp    ; @sum_8x2 begin    pshufd %2, %1, 04Eh   ; 01001110 B    paddw %1, %2    pshuflw %2, %1, 04Eh  ; 01001110 B    paddw %1, %2    pshuflw %2, %1, 0B1h  ; 10110001 B    paddw %1, %2    ; end of @sum_8x2%endmacro       ; END of SUM_WORD_8x2_SSE2 %macro WELS_SAD_SUM_SQSUM_16x1_SSE2 3 ;esi:%1,edi:%2,ebx:%3    movdqa        xmm1,   [%1]    movdqa        xmm2,   [%2]    movdqa        xmm3,   xmm1    psadbw        xmm3,   xmm2    paddd         xmm6,   xmm3     movdqa        xmm3,   xmm1    psadbw        xmm3,   xmm0    paddd         xmm5,   xmm3     movdqa        xmm2,   xmm1    punpcklbw     xmm1,   xmm0    punpckhbw     xmm2,   xmm0    pmaddwd               xmm1,   xmm1    pmaddwd               xmm2,   xmm2    paddd         xmm4,   xmm1    paddd         xmm4,   xmm2     add           %1,     %3    add           %2,     %3%endmacro %macro WELS_SAD_SUM_SQSUM_SQDIFF_16x1_SSE2 3 ;esi:%1 edi:%2 ebx:%3    movdqa        xmm1,   [%1]    movdqa        xmm2,   [%2]    movdqa        xmm3,   xmm1    psadbw        xmm3,   xmm2    paddd         xmm7,   xmm3    ; sad     movdqa        xmm3,   xmm1    pmaxub        xmm3,   xmm2    pminub        xmm2,   xmm1    psubb xmm3,   xmm2    ; diff     movdqa        xmm2,   xmm1    psadbw        xmm2,   xmm0    paddd xmm6,   xmm2    ; sum     movdqa                xmm2,   xmm1    punpcklbw     xmm1,   xmm0    punpckhbw     xmm2,   xmm0    pmaddwd               xmm1,   xmm1    pmaddwd               xmm2,   xmm2    paddd         xmm5,   xmm1    paddd         xmm5,   xmm2    ; sqsum     movdqa                xmm1,   xmm3    punpcklbw     xmm1,   xmm0    punpckhbw     xmm3,   xmm0    pmaddwd               xmm1,   xmm1    pmaddwd               xmm3,   xmm3    paddd         xmm4,   xmm1    paddd         xmm4,   xmm3    ; sqdiff     add           %1,     %3    add           %2,     %3%endmacro %macro WELS_SAD_SD_MAD_16x1_SSE2       7 ;esi:%5 edi:%6 ebx:%7%define sad_reg                 %1%define sum_cur_reg             %2%define sum_ref_reg             %3%define mad_reg                 %4    movdqa        xmm1,           [%5]    movdqa        xmm2,           [%6]    movdqa        xmm3,           xmm1    psadbw        xmm3,           xmm0    paddd         sum_cur_reg,    xmm3    ; sum_cur    movdqa        xmm3,           xmm2    psadbw        xmm3,           xmm0    paddd sum_ref_reg,                    xmm3    ; sum_ref     movdqa        xmm3,           xmm1    pmaxub        xmm3,           xmm2    pminub        xmm2,           xmm1    psubb xmm3,           xmm2    ; abs diff    pmaxub        mad_reg,        xmm3    ; max abs diff     psadbw        xmm3,           xmm0    paddd sad_reg,        xmm3    ; sad     add                   %5,             %7    add                   %6,             %7%endmacro  %macro WELS_MAX_REG_SSE2       1       ; xmm1, xmm2, xmm3 can be used%define max_reg  %1    movdqa        xmm1,           max_reg    psrldq        xmm1,           4    pmaxub        max_reg,        xmm1    movdqa        xmm1,           max_reg    psrldq        xmm1,           2    pmaxub        max_reg,        xmm1    movdqa        xmm1,           max_reg    psrldq        xmm1,           1    pmaxub        max_reg,        xmm1%endmacro %macro WELS_SAD_BGD_SQDIFF_16x1_SSE2   7 ;esi:%5 edi:%6 ebx:%7%define sad_reg         %1%define sum_reg         %2%define mad_reg         %3%define sqdiff_reg      %4    movdqa                xmm1,           [%5]    movdqa                xmm2,           xmm1    movdqa                xmm3,           xmm1    punpcklbw     xmm2,           xmm0    punpckhbw     xmm3,           xmm0    pmaddwd               xmm2,           xmm2    pmaddwd               xmm3,           xmm3    paddd         xmm2,           xmm3    movdqa                xmm3,           xmm2    psllq         xmm2,           32    psrlq         xmm3,           32    psllq         xmm3,           32    paddd         xmm2,           xmm3    paddd         sad_reg,        xmm2            ; sqsum     movdqa        xmm2,           [%6]    movdqa        xmm3,           xmm1    psadbw        xmm3,           xmm0    paddd sum_reg,                        xmm3    ; sum_cur    movdqa        xmm3,           xmm2    psadbw        xmm3,           xmm0    pslldq        xmm3,           4    paddd sum_reg,                        xmm3    ; sum_ref     movdqa        xmm3,           xmm1    pmaxub        xmm3,           xmm2    pminub        xmm2,           xmm1    psubb xmm3,           xmm2    ; abs diff    pmaxub        mad_reg,        xmm3    ; max abs diff     movdqa        xmm1,           xmm3    psadbw        xmm3,           xmm0    paddd sad_reg,        xmm3    ; sad     movdqa                xmm3,   xmm1    punpcklbw     xmm1,   xmm0    punpckhbw     xmm3,   xmm0    pmaddwd               xmm1,   xmm1    pmaddwd               xmm3,   xmm3    paddd         sqdiff_reg,     xmm1    paddd         sqdiff_reg,     xmm3    ; sqdiff     add           %5,     %7    add           %6,     %7%endmacro  ;***********************************************************************; Code;*********************************************************************** SECTION .text %ifdef X86_32 ;***********************************************************************;   void SampleVariance16x16_sse2(      uint8_t * y_ref, int32_t y_ref_stride, uint8_t * y_src, int32_t y_src_stride,SMotionTextureUnit* pMotionTexture );;***********************************************************************WELS_EXTERN SampleVariance16x16_sse2    push esi    push edi    push ebx     sub esp, 16    %define SUM                   [esp]    %define SUM_CUR               [esp+4]    %define SQR                   [esp+8]    %define SQR_CUR               [esp+12]    %define PUSH_SIZE     28      ; 12 + 16     mov edi, [esp+PUSH_SIZE+4]    ; y_ref    mov edx, [esp+PUSH_SIZE+8]    ; y_ref_stride    mov esi, [esp+PUSH_SIZE+12]   ; y_src    mov eax, [esp+PUSH_SIZE+16]   ; y_src_stride    mov ecx, 010h                         ; height = 16     pxor xmm7, xmm7    movdqu SUM, xmm7 .hloops:    movdqa xmm0, [edi]            ; y_ref    movdqa xmm1, [esi]            ; y_src    movdqa xmm2, xmm0             ; store first for future process    movdqa xmm3, xmm1    ; sum += diff;    movdqa xmm4, xmm0    psadbw xmm4, xmm1             ; 2 parts, [0,..,15], [64,..,79]    ; to be continued for sum    pshufd xmm5, xmm4, 0C6h       ; 11000110 B    paddw xmm4, xmm5    movd ebx, xmm4    add SUM, ebx     ; sqr += diff * diff;    pmaxub xmm0, xmm1    pminub xmm1, xmm2    psubb xmm0, xmm1                              ; diff    SUM_SQR_SSE2 xmm1, xmm0, xmm7 ; dst, pSrc, zero    movd ebx, xmm1    add SQR, ebx     ; sum_cur += y_src[x];    movdqa xmm0, xmm3             ; cur_orig    movdqa xmm1, xmm0    punpcklbw xmm0, xmm7    punpckhbw xmm1, xmm7    paddw xmm0, xmm1              ; 8x2    SUM_WORD_8x2_SSE2 xmm0, xmm1    movd ebx, xmm0    and ebx, 0ffffh    add SUM_CUR, ebx     ; sqr_cur += y_src[x] * y_src[x];    SUM_SQR_SSE2 xmm0, xmm3, xmm7 ; dst, pSrc, zero    movd ebx, xmm0    add SQR_CUR, ebx     lea edi, [edi+edx]    lea esi, [esi+eax]    dec ecx    jnz near .hloops     mov ebx, 0    mov bx, word SUM    sar ebx, 8    imul ebx, ebx    mov ecx, SQR    sar ecx, 8    sub ecx, ebx    mov edi, [esp+PUSH_SIZE+20]   ; pMotionTexture    mov [edi], cx                         ; to store uiMotionIndex    mov ebx, 0    mov bx, word SUM_CUR    sar ebx, 8    imul ebx, ebx    mov ecx, SQR_CUR    sar ecx, 8    sub ecx, ebx    mov [edi+2], cx                               ; to store uiTextureIndex     %undef SUM    %undef SUM_CUR    %undef SQR    %undef SQR_CUR    %undef PUSH_SIZE     add esp, 16    pop ebx    pop edi    pop esi     ret   ;*************************************************************************************************************;void VAACalcSad_sse2( const uint8_t *cur_data, const uint8_t *ref_data, int32_t iPicWidth, int32_t iPicHeight;                                                               int32_t iPicStride, int32_t *psadframe, int32_t *psad8x8);*************************************************************************************************************  WELS_EXTERN VAACalcSad_sse2%define         cur_data                        esp + pushsize + 4%define         ref_data                        esp + pushsize + 8%define         iPicWidth                       esp + pushsize + 12%define         iPicHeight                      esp + pushsize + 16%define         iPicStride                      esp + pushsize + 20%define         psadframe                       esp + pushsize + 24%define         psad8x8                         esp + pushsize + 28%define         pushsize        12    push  esi    push  edi    push  ebx    mov           esi,    [cur_data]    mov           edi,    [ref_data]    mov           ebx,    [iPicStride]    mov           edx,    [psad8x8]    mov           eax,    ebx     shr           dword [iPicWidth],      4                                       ; iPicWidth/16    shr           dword [iPicHeight],     4                                       ; iPicHeight/16    shl           eax,    4                                                               ; iPicStride*16    pxor  xmm0,   xmm0    pxor  xmm7,   xmm7            ; iFrameSadheight_loop:    mov           ecx,    dword [iPicWidth]    push  esi    push  ediwidth_loop:    pxor  xmm6,   xmm6            ;    WELS_SAD_16x2_SSE2 esi,edi,ebx    WELS_SAD_16x2_SSE2 esi,edi,ebx    WELS_SAD_16x2_SSE2 esi,edi,ebx    WELS_SAD_16x2_SSE2 esi,edi,ebx    paddd xmm7,           xmm6    movd  [edx],          xmm6    psrldq        xmm6,           8    movd  [edx+4],        xmm6     pxor  xmm6,   xmm6    WELS_SAD_16x2_SSE2 esi,edi,ebx    WELS_SAD_16x2_SSE2 esi,edi,ebx    WELS_SAD_16x2_SSE2 esi,edi,ebx    WELS_SAD_16x2_SSE2 esi,edi,ebx    paddd xmm7,           xmm6    movd  [edx+8],        xmm6    psrldq        xmm6,           8    movd  [edx+12],       xmm6     add           edx,    16    sub           esi,    eax    sub           edi,    eax    add           esi,    16    add           edi,    16     dec           ecx    jnz           width_loop     pop           edi    pop           esi    add           esi,    eax    add           edi,    eax     dec   dword [iPicHeight]    jnz           height_loop     mov           edx,    [psadframe]    movdqa        xmm5,   xmm7    psrldq        xmm7,   8    paddd xmm7,   xmm5    movd  [edx],  xmm7 %undef          cur_data%undef          ref_data%undef          iPicWidth%undef          iPicHeight%undef          iPicStride%undef          psadframe%undef          psad8x8%undef          pushsize    pop           ebx    pop           edi    pop           esi    ret %else  ;64-bit ;***********************************************************************;   void SampleVariance16x16_sse2(      uint8_t * y_ref, int32_t y_ref_stride, uint8_t * y_src, int32_t y_src_stride,SMotionTextureUnit* pMotionTexture );;***********************************************************************WELS_EXTERN SampleVariance16x16_sse2    %define SUM                   r10;[esp]    %define SUM_CUR               r11;[esp+4]    %define SQR                   r13;[esp+8]    %define SQR_CUR               r15;[esp+12]     push r12    push r13    push r14    push r15    %assign push_num 4    LOAD_5_PARA    PUSH_XMM 8    SIGN_EXTENSION r1,r1d    SIGN_EXTENSION r3,r3d     mov r12,010h    pxor xmm7, xmm7    movq SUM, xmm7    movq SUM_CUR,xmm7    movq SQR,xmm7    movq SQR_CUR,xmm7 .hloops:    mov r14,0    movdqa xmm0, [r0]             ; y_ref    movdqa xmm1, [r2]             ; y_src    movdqa xmm2, xmm0             ; store first for future process    movdqa xmm3, xmm1    ; sum += diff;    movdqa xmm4, xmm0    psadbw xmm4, xmm1             ; 2 parts, [0,..,15], [64,..,79]    ; to be continued for sum    pshufd xmm5, xmm4, 0C6h       ; 11000110 B    paddw xmm4, xmm5    movd r14d, xmm4    add SUM, r14     ; sqr += diff * diff;    pmaxub xmm0, xmm1    pminub xmm1, xmm2    psubb xmm0, xmm1                              ; diff    SUM_SQR_SSE2 xmm1, xmm0, xmm7 ; dst, pSrc, zero    movd r14d, xmm1    add SQR, r14     ; sum_cur += y_src[x];    movdqa xmm0, xmm3             ; cur_orig    movdqa xmm1, xmm0    punpcklbw xmm0, xmm7    punpckhbw xmm1, xmm7    paddw xmm0, xmm1              ; 8x2    SUM_WORD_8x2_SSE2 xmm0, xmm1    movd r14d, xmm0    and r14, 0ffffh    add SUM_CUR, r14     ; sqr_cur += y_src[x] * y_src[x];

Lines 1–500 of 3563.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t