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