Blame thirdparty/libjpeg-turbo/libjpeg-turbo-2.0.6/simd/i386/jdmrgext-sse2.asm

shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; jdmrgext.asm - merged upsampling/color conversion (SSE2)
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB</ossman@cendio.se>
shun-iwasawa 82a8f5
; Copyright (C) 2012, 2016, D. R. Commander.
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Based on the x86 SIMD extension for IJG JPEG library
shun-iwasawa 82a8f5
; Copyright (C) 1999-2006, MIYASAKA Masaru.
shun-iwasawa 82a8f5
; For conditions of distribution and use, see copyright notice in jsimdext.inc
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; This file should be assembled with NASM (Netwide Assembler),
shun-iwasawa 82a8f5
; can *not* be assembled with Microsoft's MASM or any compatible
shun-iwasawa 82a8f5
; assembler (including Borland's Turbo Assembler).
shun-iwasawa 82a8f5
; NASM is available from http://nasm.sourceforge.net/ or
shun-iwasawa 82a8f5
; http://sourceforge.net/project/showfiles.php?group_id=6208
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%include "jcolsamp.inc"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
; --------------------------------------------------------------------------
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; GLOBAL(void)
shun-iwasawa 82a8f5
; jsimd_h2v1_merged_upsample_sse2(JDIMENSION output_width,
shun-iwasawa 82a8f5
;                                 JSAMPIMAGE input_buf,
shun-iwasawa 82a8f5
;                                 JDIMENSION in_row_group_ctr,
shun-iwasawa 82a8f5
;                                 JSAMPARRAY output_buf);
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%define output_width(b)      (b) + 8    ; JDIMENSION output_width
shun-iwasawa 82a8f5
%define input_buf(b)         (b) + 12   ; JSAMPIMAGE input_buf
shun-iwasawa 82a8f5
%define in_row_group_ctr(b)  (b) + 16   ; JDIMENSION in_row_group_ctr
shun-iwasawa 82a8f5
%define output_buf(b)        (b) + 20   ; JSAMPARRAY output_buf
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%define original_ebp  ebp + 0
shun-iwasawa 82a8f5
%define wk(i)         ebp - (WK_NUM - (i)) * SIZEOF_XMMWORD
shun-iwasawa 82a8f5
                                        ; xmmword wk[WK_NUM]
shun-iwasawa 82a8f5
%define WK_NUM        3
shun-iwasawa 82a8f5
%define gotptr        wk(0) - SIZEOF_POINTER  ; void * gotptr
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    align       32
shun-iwasawa 82a8f5
    GLOBAL_FUNCTION(jsimd_h2v1_merged_upsample_sse2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTN(jsimd_h2v1_merged_upsample_sse2):
shun-iwasawa 82a8f5
    push        ebp
shun-iwasawa 82a8f5
    mov         eax, esp                     ; eax = original ebp
shun-iwasawa 82a8f5
    sub         esp, byte 4
shun-iwasawa 82a8f5
    and         esp, byte (-SIZEOF_XMMWORD)  ; align to 128 bits
shun-iwasawa 82a8f5
    mov         [esp], eax
shun-iwasawa 82a8f5
    mov         ebp, esp                     ; ebp = aligned ebp
shun-iwasawa 82a8f5
    lea         esp, [wk(0)]
shun-iwasawa 82a8f5
    pushpic     eax                     ; make a room for GOT address
shun-iwasawa 82a8f5
    push        ebx
shun-iwasawa 82a8f5
;   push        ecx                     ; need not be preserved
shun-iwasawa 82a8f5
;   push        edx                     ; need not be preserved
shun-iwasawa 82a8f5
    push        esi
shun-iwasawa 82a8f5
    push        edi
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    get_GOT     ebx                     ; get GOT address
shun-iwasawa 82a8f5
    movpic      POINTER [gotptr], ebx   ; save GOT address
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         ecx, JDIMENSION [output_width(eax)]  ; col
shun-iwasawa 82a8f5
    test        ecx, ecx
shun-iwasawa 82a8f5
    jz          near .return
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    push        ecx
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         edi, JSAMPIMAGE [input_buf(eax)]
shun-iwasawa 82a8f5
    mov         ecx, JDIMENSION [in_row_group_ctr(eax)]
shun-iwasawa 82a8f5
    mov         esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    mov         ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    mov         edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    mov         edi, JSAMPARRAY [output_buf(eax)]
shun-iwasawa 82a8f5
    mov         esi, JSAMPROW [esi+ecx*SIZEOF_JSAMPROW]  ; inptr0
shun-iwasawa 82a8f5
    mov         ebx, JSAMPROW [ebx+ecx*SIZEOF_JSAMPROW]  ; inptr1
shun-iwasawa 82a8f5
    mov         edx, JSAMPROW [edx+ecx*SIZEOF_JSAMPROW]  ; inptr2
shun-iwasawa 82a8f5
    mov         edi, JSAMPROW [edi]                      ; outptr
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pop         ecx                     ; col
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
.columnloop:
shun-iwasawa 82a8f5
    movpic      eax, POINTER [gotptr]   ; load GOT address (eax)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm6, XMMWORD [ebx]     ; xmm6=Cb(0123456789ABCDEF)
shun-iwasawa 82a8f5
    movdqa      xmm7, XMMWORD [edx]     ; xmm7=Cr(0123456789ABCDEF)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pxor        xmm1, xmm1              ; xmm1=(all 0's)
shun-iwasawa 82a8f5
    pcmpeqw     xmm3, xmm3
shun-iwasawa 82a8f5
    psllw       xmm3, 7                 ; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm4, xmm6
shun-iwasawa 82a8f5
    punpckhbw   xmm6, xmm1              ; xmm6=Cb(89ABCDEF)=CbH
shun-iwasawa 82a8f5
    punpcklbw   xmm4, xmm1              ; xmm4=Cb(01234567)=CbL
shun-iwasawa 82a8f5
    movdqa      xmm0, xmm7
shun-iwasawa 82a8f5
    punpckhbw   xmm7, xmm1              ; xmm7=Cr(89ABCDEF)=CrH
shun-iwasawa 82a8f5
    punpcklbw   xmm0, xmm1              ; xmm0=Cr(01234567)=CrL
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddw       xmm6, xmm3
shun-iwasawa 82a8f5
    paddw       xmm4, xmm3
shun-iwasawa 82a8f5
    paddw       xmm7, xmm3
shun-iwasawa 82a8f5
    paddw       xmm0, xmm3
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    ; (Original)
shun-iwasawa 82a8f5
    ; R = Y                + 1.40200 * Cr
shun-iwasawa 82a8f5
    ; G = Y - 0.34414 * Cb - 0.71414 * Cr
shun-iwasawa 82a8f5
    ; B = Y + 1.77200 * Cb
shun-iwasawa 82a8f5
    ;
shun-iwasawa 82a8f5
    ; (This implementation)
shun-iwasawa 82a8f5
    ; R = Y                + 0.40200 * Cr + Cr
shun-iwasawa 82a8f5
    ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
shun-iwasawa 82a8f5
    ; B = Y - 0.22800 * Cb + Cb + Cb
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm5, xmm6              ; xmm5=CbH
shun-iwasawa 82a8f5
    movdqa      xmm2, xmm4              ; xmm2=CbL
shun-iwasawa 82a8f5
    paddw       xmm6, xmm6              ; xmm6=2*CbH
shun-iwasawa 82a8f5
    paddw       xmm4, xmm4              ; xmm4=2*CbL
shun-iwasawa 82a8f5
    movdqa      xmm1, xmm7              ; xmm1=CrH
shun-iwasawa 82a8f5
    movdqa      xmm3, xmm0              ; xmm3=CrL
shun-iwasawa 82a8f5
    paddw       xmm7, xmm7              ; xmm7=2*CrH
shun-iwasawa 82a8f5
    paddw       xmm0, xmm0              ; xmm0=2*CrL
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pmulhw      xmm6, [GOTOFF(eax,PW_MF0228)]  ; xmm6=(2*CbH * -FIX(0.22800))
shun-iwasawa 82a8f5
    pmulhw      xmm4, [GOTOFF(eax,PW_MF0228)]  ; xmm4=(2*CbL * -FIX(0.22800))
shun-iwasawa 82a8f5
    pmulhw      xmm7, [GOTOFF(eax,PW_F0402)]   ; xmm7=(2*CrH * FIX(0.40200))
shun-iwasawa 82a8f5
    pmulhw      xmm0, [GOTOFF(eax,PW_F0402)]   ; xmm0=(2*CrL * FIX(0.40200))
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddw       xmm6, [GOTOFF(eax,PW_ONE)]
shun-iwasawa 82a8f5
    paddw       xmm4, [GOTOFF(eax,PW_ONE)]
shun-iwasawa 82a8f5
    psraw       xmm6, 1                 ; xmm6=(CbH * -FIX(0.22800))
shun-iwasawa 82a8f5
    psraw       xmm4, 1                 ; xmm4=(CbL * -FIX(0.22800))
shun-iwasawa 82a8f5
    paddw       xmm7, [GOTOFF(eax,PW_ONE)]
shun-iwasawa 82a8f5
    paddw       xmm0, [GOTOFF(eax,PW_ONE)]
shun-iwasawa 82a8f5
    psraw       xmm7, 1                 ; xmm7=(CrH * FIX(0.40200))
shun-iwasawa 82a8f5
    psraw       xmm0, 1                 ; xmm0=(CrL * FIX(0.40200))
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddw       xmm6, xmm5
shun-iwasawa 82a8f5
    paddw       xmm4, xmm2
shun-iwasawa 82a8f5
    paddw       xmm6, xmm5              ; xmm6=(CbH * FIX(1.77200))=(B-Y)H
shun-iwasawa 82a8f5
    paddw       xmm4, xmm2              ; xmm4=(CbL * FIX(1.77200))=(B-Y)L
shun-iwasawa 82a8f5
    paddw       xmm7, xmm1              ; xmm7=(CrH * FIX(1.40200))=(R-Y)H
shun-iwasawa 82a8f5
    paddw       xmm0, xmm3              ; xmm0=(CrL * FIX(1.40200))=(R-Y)L
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(0)], xmm6   ; wk(0)=(B-Y)H
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(1)], xmm7   ; wk(1)=(R-Y)H
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm6, xmm5
shun-iwasawa 82a8f5
    movdqa      xmm7, xmm2
shun-iwasawa 82a8f5
    punpcklwd   xmm5, xmm1
shun-iwasawa 82a8f5
    punpckhwd   xmm6, xmm1
shun-iwasawa 82a8f5
    pmaddwd     xmm5, [GOTOFF(eax,PW_MF0344_F0285)]
shun-iwasawa 82a8f5
    pmaddwd     xmm6, [GOTOFF(eax,PW_MF0344_F0285)]
shun-iwasawa 82a8f5
    punpcklwd   xmm2, xmm3
shun-iwasawa 82a8f5
    punpckhwd   xmm7, xmm3
shun-iwasawa 82a8f5
    pmaddwd     xmm2, [GOTOFF(eax,PW_MF0344_F0285)]
shun-iwasawa 82a8f5
    pmaddwd     xmm7, [GOTOFF(eax,PW_MF0344_F0285)]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddd       xmm5, [GOTOFF(eax,PD_ONEHALF)]
shun-iwasawa 82a8f5
    paddd       xmm6, [GOTOFF(eax,PD_ONEHALF)]
shun-iwasawa 82a8f5
    psrad       xmm5, SCALEBITS
shun-iwasawa 82a8f5
    psrad       xmm6, SCALEBITS
shun-iwasawa 82a8f5
    paddd       xmm2, [GOTOFF(eax,PD_ONEHALF)]
shun-iwasawa 82a8f5
    paddd       xmm7, [GOTOFF(eax,PD_ONEHALF)]
shun-iwasawa 82a8f5
    psrad       xmm2, SCALEBITS
shun-iwasawa 82a8f5
    psrad       xmm7, SCALEBITS
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    packssdw    xmm5, xmm6              ; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285)
shun-iwasawa 82a8f5
    packssdw    xmm2, xmm7              ; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285)
shun-iwasawa 82a8f5
    psubw       xmm5, xmm1              ; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H
shun-iwasawa 82a8f5
    psubw       xmm2, xmm3              ; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(2)], xmm5   ; wk(2)=(G-Y)H
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         al, 2                   ; Yctr
shun-iwasawa 82a8f5
    jmp         short .Yloop_1st
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.Yloop_2nd:
shun-iwasawa 82a8f5
    movdqa      xmm0, XMMWORD [wk(1)]   ; xmm0=(R-Y)H
shun-iwasawa 82a8f5
    movdqa      xmm2, XMMWORD [wk(2)]   ; xmm2=(G-Y)H
shun-iwasawa 82a8f5
    movdqa      xmm4, XMMWORD [wk(0)]   ; xmm4=(B-Y)H
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.Yloop_1st:
shun-iwasawa 82a8f5
    movdqa      xmm7, XMMWORD [esi]     ; xmm7=Y(0123456789ABCDEF)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pcmpeqw     xmm6, xmm6
shun-iwasawa 82a8f5
    psrlw       xmm6, BYTE_BIT          ; xmm6={0xFF 0x00 0xFF 0x00 ..}
shun-iwasawa 82a8f5
    pand        xmm6, xmm7              ; xmm6=Y(02468ACE)=YE
shun-iwasawa 82a8f5
    psrlw       xmm7, BYTE_BIT          ; xmm7=Y(13579BDF)=YO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm1, xmm0              ; xmm1=xmm0=(R-Y)(L/H)
shun-iwasawa 82a8f5
    movdqa      xmm3, xmm2              ; xmm3=xmm2=(G-Y)(L/H)
shun-iwasawa 82a8f5
    movdqa      xmm5, xmm4              ; xmm5=xmm4=(B-Y)(L/H)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddw       xmm0, xmm6              ; xmm0=((R-Y)+YE)=RE=R(02468ACE)
shun-iwasawa 82a8f5
    paddw       xmm1, xmm7              ; xmm1=((R-Y)+YO)=RO=R(13579BDF)
shun-iwasawa 82a8f5
    packuswb    xmm0, xmm0              ; xmm0=R(02468ACE********)
shun-iwasawa 82a8f5
    packuswb    xmm1, xmm1              ; xmm1=R(13579BDF********)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddw       xmm2, xmm6              ; xmm2=((G-Y)+YE)=GE=G(02468ACE)
shun-iwasawa 82a8f5
    paddw       xmm3, xmm7              ; xmm3=((G-Y)+YO)=GO=G(13579BDF)
shun-iwasawa 82a8f5
    packuswb    xmm2, xmm2              ; xmm2=G(02468ACE********)
shun-iwasawa 82a8f5
    packuswb    xmm3, xmm3              ; xmm3=G(13579BDF********)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddw       xmm4, xmm6              ; xmm4=((B-Y)+YE)=BE=B(02468ACE)
shun-iwasawa 82a8f5
    paddw       xmm5, xmm7              ; xmm5=((B-Y)+YO)=BO=B(13579BDF)
shun-iwasawa 82a8f5
    packuswb    xmm4, xmm4              ; xmm4=B(02468ACE********)
shun-iwasawa 82a8f5
    packuswb    xmm5, xmm5              ; xmm5=B(13579BDF********)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%if RGB_PIXELSIZE == 3  ; ---------------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
shun-iwasawa 82a8f5
    ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
shun-iwasawa 82a8f5
    ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
shun-iwasawa 82a8f5
    ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklbw   xmmA, xmmC        ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
shun-iwasawa 82a8f5
    punpcklbw   xmmE, xmmB        ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
shun-iwasawa 82a8f5
    punpcklbw   xmmD, xmmF        ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmG, xmmA
shun-iwasawa 82a8f5
    movdqa      xmmH, xmmA
shun-iwasawa 82a8f5
    punpcklwd   xmmA, xmmE        ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
shun-iwasawa 82a8f5
    punpckhwd   xmmG, xmmE        ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psrldq      xmmH, 2           ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
shun-iwasawa 82a8f5
    psrldq      xmmE, 2           ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmC, xmmD
shun-iwasawa 82a8f5
    movdqa      xmmB, xmmD
shun-iwasawa 82a8f5
    punpcklwd   xmmD, xmmH        ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
shun-iwasawa 82a8f5
    punpckhwd   xmmC, xmmH        ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psrldq      xmmB, 2           ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmF, xmmE
shun-iwasawa 82a8f5
    punpcklwd   xmmE, xmmB        ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
shun-iwasawa 82a8f5
    punpckhwd   xmmF, xmmB        ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pshufd      xmmH, xmmA, 0x4E  ; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
shun-iwasawa 82a8f5
    movdqa      xmmB, xmmE
shun-iwasawa 82a8f5
    punpckldq   xmmA, xmmD        ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
shun-iwasawa 82a8f5
    punpckldq   xmmE, xmmH        ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
shun-iwasawa 82a8f5
    punpckhdq   xmmD, xmmB        ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pshufd      xmmH, xmmG, 0x4E  ; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
shun-iwasawa 82a8f5
    movdqa      xmmB, xmmF
shun-iwasawa 82a8f5
    punpckldq   xmmG, xmmC        ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
shun-iwasawa 82a8f5
    punpckldq   xmmF, xmmH        ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
shun-iwasawa 82a8f5
    punpckhdq   xmmC, xmmB        ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklqdq  xmmA, xmmE        ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
shun-iwasawa 82a8f5
    punpcklqdq  xmmD, xmmG        ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
shun-iwasawa 82a8f5
    punpcklqdq  xmmF, xmmC        ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jb          short .column_st32
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    test        edi, SIZEOF_XMMWORD-1
shun-iwasawa 82a8f5
    jnz         short .out1
shun-iwasawa 82a8f5
    ; --(aligned)-------------------
shun-iwasawa 82a8f5
    movntdq     XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
shun-iwasawa 82a8f5
    movntdq     XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
shun-iwasawa 82a8f5
    movntdq     XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF
shun-iwasawa 82a8f5
    jmp         short .out0
shun-iwasawa 82a8f5
.out1:  ; --(unaligned)-----------------
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF
shun-iwasawa 82a8f5
.out0:
shun-iwasawa 82a8f5
    add         edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD  ; outptr
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jz          near .endcolumn
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         esi, byte SIZEOF_XMMWORD  ; inptr0
shun-iwasawa 82a8f5
    dec         al                        ; Yctr
shun-iwasawa 82a8f5
    jnz         near .Yloop_2nd
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         ebx, byte SIZEOF_XMMWORD  ; inptr1
shun-iwasawa 82a8f5
    add         edx, byte SIZEOF_XMMWORD  ; inptr2
shun-iwasawa 82a8f5
    jmp         near .columnloop
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.column_st32:
shun-iwasawa 82a8f5
    lea         ecx, [ecx+ecx*2]            ; imul ecx, RGB_PIXELSIZE
shun-iwasawa 82a8f5
    cmp         ecx, byte 2*SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jb          short .column_st16
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
shun-iwasawa 82a8f5
    add         edi, byte 2*SIZEOF_XMMWORD  ; outptr
shun-iwasawa 82a8f5
    movdqa      xmmA, xmmF
shun-iwasawa 82a8f5
    sub         ecx, byte 2*SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jmp         short .column_st15
shun-iwasawa 82a8f5
.column_st16:
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jb          short .column_st15
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_XMMWORD    ; outptr
shun-iwasawa 82a8f5
    movdqa      xmmA, xmmD
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD
shun-iwasawa 82a8f5
.column_st15:
shun-iwasawa 82a8f5
    ; Store the lower 8 bytes of xmmA to the output when it has enough
shun-iwasawa 82a8f5
    ; space.
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_MMWORD
shun-iwasawa 82a8f5
    jb          short .column_st7
shun-iwasawa 82a8f5
    movq        XMM_MMWORD [edi], xmmA
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_MMWORD
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_MMWORD
shun-iwasawa 82a8f5
    psrldq      xmmA, SIZEOF_MMWORD
shun-iwasawa 82a8f5
.column_st7:
shun-iwasawa 82a8f5
    ; Store the lower 4 bytes of xmmA to the output when it has enough
shun-iwasawa 82a8f5
    ; space.
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_DWORD
shun-iwasawa 82a8f5
    jb          short .column_st3
shun-iwasawa 82a8f5
    movd        XMM_DWORD [edi], xmmA
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_DWORD
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_DWORD
shun-iwasawa 82a8f5
    psrldq      xmmA, SIZEOF_DWORD
shun-iwasawa 82a8f5
.column_st3:
shun-iwasawa 82a8f5
    ; Store the lower 2 bytes of eax to the output when it has enough
shun-iwasawa 82a8f5
    ; space.
shun-iwasawa 82a8f5
    movd        eax, xmmA
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_WORD
shun-iwasawa 82a8f5
    jb          short .column_st1
shun-iwasawa 82a8f5
    mov         word [edi], ax
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_WORD
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_WORD
shun-iwasawa 82a8f5
    shr         eax, 16
shun-iwasawa 82a8f5
.column_st1:
shun-iwasawa 82a8f5
    ; Store the lower 1 byte of eax to the output when it has enough
shun-iwasawa 82a8f5
    ; space.
shun-iwasawa 82a8f5
    test        ecx, ecx
shun-iwasawa 82a8f5
    jz          short .endcolumn
shun-iwasawa 82a8f5
    mov         byte [edi], al
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%else  ; RGB_PIXELSIZE == 4 ; -----------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%ifdef RGBX_FILLER_0XFF
shun-iwasawa 82a8f5
    pcmpeqb     xmm6, xmm6              ; xmm6=XE=X(02468ACE********)
shun-iwasawa 82a8f5
    pcmpeqb     xmm7, xmm7              ; xmm7=XO=X(13579BDF********)
shun-iwasawa 82a8f5
%else
shun-iwasawa 82a8f5
    pxor        xmm6, xmm6              ; xmm6=XE=X(02468ACE********)
shun-iwasawa 82a8f5
    pxor        xmm7, xmm7              ; xmm7=XO=X(13579BDF********)
shun-iwasawa 82a8f5
%endif
shun-iwasawa 82a8f5
    ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
shun-iwasawa 82a8f5
    ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
shun-iwasawa 82a8f5
    ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
shun-iwasawa 82a8f5
    ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklbw   xmmA, xmmC  ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
shun-iwasawa 82a8f5
    punpcklbw   xmmE, xmmG  ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
shun-iwasawa 82a8f5
    punpcklbw   xmmB, xmmD  ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
shun-iwasawa 82a8f5
    punpcklbw   xmmF, xmmH  ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmC, xmmA
shun-iwasawa 82a8f5
    punpcklwd   xmmA, xmmE  ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
shun-iwasawa 82a8f5
    punpckhwd   xmmC, xmmE  ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
shun-iwasawa 82a8f5
    movdqa      xmmG, xmmB
shun-iwasawa 82a8f5
    punpcklwd   xmmB, xmmF  ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
shun-iwasawa 82a8f5
    punpckhwd   xmmG, xmmF  ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmD, xmmA
shun-iwasawa 82a8f5
    punpckldq   xmmA, xmmB  ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
shun-iwasawa 82a8f5
    punpckhdq   xmmD, xmmB  ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
shun-iwasawa 82a8f5
    movdqa      xmmH, xmmC
shun-iwasawa 82a8f5
    punpckldq   xmmC, xmmG  ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
shun-iwasawa 82a8f5
    punpckhdq   xmmH, xmmG  ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jb          short .column_st32
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    test        edi, SIZEOF_XMMWORD-1
shun-iwasawa 82a8f5
    jnz         short .out1
shun-iwasawa 82a8f5
    ; --(aligned)-------------------
shun-iwasawa 82a8f5
    movntdq     XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
shun-iwasawa 82a8f5
    movntdq     XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
shun-iwasawa 82a8f5
    movntdq     XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC
shun-iwasawa 82a8f5
    movntdq     XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH
shun-iwasawa 82a8f5
    jmp         short .out0
shun-iwasawa 82a8f5
.out1:  ; --(unaligned)-----------------
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH
shun-iwasawa 82a8f5
.out0:
shun-iwasawa 82a8f5
    add         edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD  ; outptr
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jz          near .endcolumn
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         esi, byte SIZEOF_XMMWORD  ; inptr0
shun-iwasawa 82a8f5
    dec         al                        ; Yctr
shun-iwasawa 82a8f5
    jnz         near .Yloop_2nd
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         ebx, byte SIZEOF_XMMWORD  ; inptr1
shun-iwasawa 82a8f5
    add         edx, byte SIZEOF_XMMWORD  ; inptr2
shun-iwasawa 82a8f5
    jmp         near .columnloop
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.column_st32:
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_XMMWORD/2
shun-iwasawa 82a8f5
    jb          short .column_st16
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
shun-iwasawa 82a8f5
    add         edi, byte 2*SIZEOF_XMMWORD  ; outptr
shun-iwasawa 82a8f5
    movdqa      xmmA, xmmC
shun-iwasawa 82a8f5
    movdqa      xmmD, xmmH
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD/2
shun-iwasawa 82a8f5
.column_st16:
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_XMMWORD/4
shun-iwasawa 82a8f5
    jb          short .column_st15
shun-iwasawa 82a8f5
    movdqu      XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_XMMWORD    ; outptr
shun-iwasawa 82a8f5
    movdqa      xmmA, xmmD
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD/4
shun-iwasawa 82a8f5
.column_st15:
shun-iwasawa 82a8f5
    ; Store two pixels (8 bytes) of xmmA to the output when it has enough
shun-iwasawa 82a8f5
    ; space.
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_XMMWORD/8
shun-iwasawa 82a8f5
    jb          short .column_st7
shun-iwasawa 82a8f5
    movq        XMM_MMWORD [edi], xmmA
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_XMMWORD/8*4
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD/8
shun-iwasawa 82a8f5
    psrldq      xmmA, SIZEOF_XMMWORD/8*4
shun-iwasawa 82a8f5
.column_st7:
shun-iwasawa 82a8f5
    ; Store one pixel (4 bytes) of xmmA to the output when it has enough
shun-iwasawa 82a8f5
    ; space.
shun-iwasawa 82a8f5
    test        ecx, ecx
shun-iwasawa 82a8f5
    jz          short .endcolumn
shun-iwasawa 82a8f5
    movd        XMM_DWORD [edi], xmmA
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%endif  ; RGB_PIXELSIZE ; ---------------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.endcolumn:
shun-iwasawa 82a8f5
    sfence                              ; flush the write buffer
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.return:
shun-iwasawa 82a8f5
    pop         edi
shun-iwasawa 82a8f5
    pop         esi
shun-iwasawa 82a8f5
;   pop         edx                     ; need not be preserved
shun-iwasawa 82a8f5
;   pop         ecx                     ; need not be preserved
shun-iwasawa 82a8f5
    pop         ebx
shun-iwasawa 82a8f5
    mov         esp, ebp                ; esp <- aligned ebp
shun-iwasawa 82a8f5
    pop         esp                     ; esp <- original ebp
shun-iwasawa 82a8f5
    pop         ebp
shun-iwasawa 82a8f5
    ret
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
; --------------------------------------------------------------------------
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; GLOBAL(void)
shun-iwasawa 82a8f5
; jsimd_h2v2_merged_upsample_sse2(JDIMENSION output_width,
shun-iwasawa 82a8f5
;                                 JSAMPIMAGE input_buf,
shun-iwasawa 82a8f5
;                                 JDIMENSION in_row_group_ctr,
shun-iwasawa 82a8f5
;                                 JSAMPARRAY output_buf);
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%define output_width(b)      (b) + 8    ; JDIMENSION output_width
shun-iwasawa 82a8f5
%define input_buf(b)         (b) + 12   ; JSAMPIMAGE input_buf
shun-iwasawa 82a8f5
%define in_row_group_ctr(b)  (b) + 16   ; JDIMENSION in_row_group_ctr
shun-iwasawa 82a8f5
%define output_buf(b)        (b) + 20   ; JSAMPARRAY output_buf
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    align       32
shun-iwasawa 82a8f5
    GLOBAL_FUNCTION(jsimd_h2v2_merged_upsample_sse2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTN(jsimd_h2v2_merged_upsample_sse2):
shun-iwasawa 82a8f5
    push        ebp
shun-iwasawa 82a8f5
    mov         ebp, esp
shun-iwasawa 82a8f5
    push        ebx
shun-iwasawa 82a8f5
;   push        ecx                     ; need not be preserved
shun-iwasawa 82a8f5
;   push        edx                     ; need not be preserved
shun-iwasawa 82a8f5
    push        esi
shun-iwasawa 82a8f5
    push        edi
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         eax, POINTER [output_width(ebp)]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         edi, JSAMPIMAGE [input_buf(ebp)]
shun-iwasawa 82a8f5
    mov         ecx, JDIMENSION [in_row_group_ctr(ebp)]
shun-iwasawa 82a8f5
    mov         esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    mov         ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    mov         edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    mov         edi, JSAMPARRAY [output_buf(ebp)]
shun-iwasawa 82a8f5
    lea         esi, [esi+ecx*SIZEOF_JSAMPROW]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    push        edx                     ; inptr2
shun-iwasawa 82a8f5
    push        ebx                     ; inptr1
shun-iwasawa 82a8f5
    push        esi                     ; inptr00
shun-iwasawa 82a8f5
    mov         ebx, esp
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    push        edi                     ; output_buf (outptr0)
shun-iwasawa 82a8f5
    push        ecx                     ; in_row_group_ctr
shun-iwasawa 82a8f5
    push        ebx                     ; input_buf
shun-iwasawa 82a8f5
    push        eax                     ; output_width
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    call        near EXTN(jsimd_h2v1_merged_upsample_sse2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         esi, byte SIZEOF_JSAMPROW  ; inptr01
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_JSAMPROW  ; outptr1
shun-iwasawa 82a8f5
    mov         POINTER [ebx+0*SIZEOF_POINTER], esi
shun-iwasawa 82a8f5
    mov         POINTER [ebx-1*SIZEOF_POINTER], edi
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    call        near EXTN(jsimd_h2v1_merged_upsample_sse2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         esp, byte 7*SIZEOF_DWORD
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pop         edi
shun-iwasawa 82a8f5
    pop         esi
shun-iwasawa 82a8f5
;   pop         edx                     ; need not be preserved
shun-iwasawa 82a8f5
;   pop         ecx                     ; need not be preserved
shun-iwasawa 82a8f5
    pop         ebx
shun-iwasawa 82a8f5
    pop         ebp
shun-iwasawa 82a8f5
    ret
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
; For some reason, the OS X linker does not honor the request to align the
shun-iwasawa 82a8f5
; segment unless we do this.
shun-iwasawa 82a8f5
    align       32