michael@0: ; michael@0: ; jfsseflt.asm - floating-point FDCT (SSE) michael@0: ; michael@0: ; Copyright 2009 Pierre Ossman for Cendio AB 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: ; This file contains a floating-point implementation of the forward DCT michael@0: ; (Discrete Cosine Transform). The following code is based directly on michael@0: ; the IJG's original jfdctflt.c; see the jfdctflt.c for more details. michael@0: ; michael@0: ; [TAB8] michael@0: michael@0: %include "jsimdext.inc" michael@0: %include "jdct.inc" michael@0: michael@0: ; -------------------------------------------------------------------------- michael@0: michael@0: %macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5) michael@0: shufps %1,%2,0x44 michael@0: %endmacro michael@0: michael@0: %macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7) michael@0: shufps %1,%2,0xEE michael@0: %endmacro michael@0: michael@0: ; -------------------------------------------------------------------------- michael@0: SECTION SEG_CONST michael@0: michael@0: alignz 16 michael@0: global EXTN(jconst_fdct_float_sse) michael@0: michael@0: EXTN(jconst_fdct_float_sse): michael@0: michael@0: PD_0_382 times 4 dd 0.382683432365089771728460 michael@0: PD_0_707 times 4 dd 0.707106781186547524400844 michael@0: PD_0_541 times 4 dd 0.541196100146196984399723 michael@0: PD_1_306 times 4 dd 1.306562964876376527856643 michael@0: michael@0: alignz 16 michael@0: michael@0: ; -------------------------------------------------------------------------- michael@0: SECTION SEG_TEXT michael@0: BITS 32 michael@0: ; michael@0: ; Perform the forward DCT on one block of samples. michael@0: ; michael@0: ; GLOBAL(void) michael@0: ; jsimd_fdct_float_sse (FAST_FLOAT * data) michael@0: ; michael@0: michael@0: %define data(b) (b)+8 ; FAST_FLOAT * data 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 2 michael@0: michael@0: align 16 michael@0: global EXTN(jsimd_fdct_float_sse) michael@0: michael@0: EXTN(jsimd_fdct_float_sse): 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 ebx michael@0: ; push ecx ; need not be preserved michael@0: ; push edx ; need not be preserved michael@0: ; push esi ; unused michael@0: ; push edi ; unused michael@0: michael@0: get_GOT ebx ; get GOT address michael@0: michael@0: ; ---- Pass 1: process rows. michael@0: michael@0: mov edx, POINTER [data(eax)] ; (FAST_FLOAT *) michael@0: mov ecx, DCTSIZE/4 michael@0: alignx 16,7 michael@0: .rowloop: michael@0: michael@0: movaps xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm2, XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm3, XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)] michael@0: michael@0: ; xmm0=(20 21 22 23), xmm2=(24 25 26 27) michael@0: ; xmm1=(30 31 32 33), xmm3=(34 35 36 37) michael@0: michael@0: movaps xmm4,xmm0 ; transpose coefficients(phase 1) michael@0: unpcklps xmm0,xmm1 ; xmm0=(20 30 21 31) michael@0: unpckhps xmm4,xmm1 ; xmm4=(22 32 23 33) michael@0: movaps xmm5,xmm2 ; transpose coefficients(phase 1) michael@0: unpcklps xmm2,xmm3 ; xmm2=(24 34 25 35) michael@0: unpckhps xmm5,xmm3 ; xmm5=(26 36 27 37) michael@0: michael@0: movaps xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] michael@0: michael@0: ; xmm6=(00 01 02 03), xmm1=(04 05 06 07) michael@0: ; xmm7=(10 11 12 13), xmm3=(14 15 16 17) michael@0: michael@0: movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 32 23 33) michael@0: movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(24 34 25 35) michael@0: michael@0: movaps xmm4,xmm6 ; transpose coefficients(phase 1) michael@0: unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11) michael@0: unpckhps xmm4,xmm7 ; xmm4=(02 12 03 13) michael@0: movaps xmm2,xmm1 ; transpose coefficients(phase 1) michael@0: unpcklps xmm1,xmm3 ; xmm1=(04 14 05 15) michael@0: unpckhps xmm2,xmm3 ; xmm2=(06 16 07 17) michael@0: michael@0: movaps xmm7,xmm6 ; transpose coefficients(phase 2) michael@0: unpcklps2 xmm6,xmm0 ; xmm6=(00 10 20 30)=data0 michael@0: unpckhps2 xmm7,xmm0 ; xmm7=(01 11 21 31)=data1 michael@0: movaps xmm3,xmm2 ; transpose coefficients(phase 2) michael@0: unpcklps2 xmm2,xmm5 ; xmm2=(06 16 26 36)=data6 michael@0: unpckhps2 xmm3,xmm5 ; xmm3=(07 17 27 37)=data7 michael@0: michael@0: movaps xmm0,xmm7 michael@0: movaps xmm5,xmm6 michael@0: subps xmm7,xmm2 ; xmm7=data1-data6=tmp6 michael@0: subps xmm6,xmm3 ; xmm6=data0-data7=tmp7 michael@0: addps xmm0,xmm2 ; xmm0=data1+data6=tmp1 michael@0: addps xmm5,xmm3 ; xmm5=data0+data7=tmp0 michael@0: michael@0: movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 32 23 33) michael@0: movaps xmm3, XMMWORD [wk(1)] ; xmm3=(24 34 25 35) michael@0: movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6 michael@0: movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 michael@0: michael@0: movaps xmm7,xmm4 ; transpose coefficients(phase 2) michael@0: unpcklps2 xmm4,xmm2 ; xmm4=(02 12 22 32)=data2 michael@0: unpckhps2 xmm7,xmm2 ; xmm7=(03 13 23 33)=data3 michael@0: movaps xmm6,xmm1 ; transpose coefficients(phase 2) michael@0: unpcklps2 xmm1,xmm3 ; xmm1=(04 14 24 34)=data4 michael@0: unpckhps2 xmm6,xmm3 ; xmm6=(05 15 25 35)=data5 michael@0: michael@0: movaps xmm2,xmm7 michael@0: movaps xmm3,xmm4 michael@0: addps xmm7,xmm1 ; xmm7=data3+data4=tmp3 michael@0: addps xmm4,xmm6 ; xmm4=data2+data5=tmp2 michael@0: subps xmm2,xmm1 ; xmm2=data3-data4=tmp4 michael@0: subps xmm3,xmm6 ; xmm3=data2-data5=tmp5 michael@0: michael@0: ; -- Even part michael@0: michael@0: movaps xmm1,xmm5 michael@0: movaps xmm6,xmm0 michael@0: subps xmm5,xmm7 ; xmm5=tmp13 michael@0: subps xmm0,xmm4 ; xmm0=tmp12 michael@0: addps xmm1,xmm7 ; xmm1=tmp10 michael@0: addps xmm6,xmm4 ; xmm6=tmp11 michael@0: michael@0: addps xmm0,xmm5 michael@0: mulps xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1 michael@0: michael@0: movaps xmm7,xmm1 michael@0: movaps xmm4,xmm5 michael@0: subps xmm1,xmm6 ; xmm1=data4 michael@0: subps xmm5,xmm0 ; xmm5=data6 michael@0: addps xmm7,xmm6 ; xmm7=data0 michael@0: addps xmm4,xmm0 ; xmm4=data2 michael@0: michael@0: movaps XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)], xmm1 michael@0: movaps XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)], xmm5 michael@0: movaps XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7 michael@0: movaps XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4 michael@0: michael@0: ; -- Odd part michael@0: michael@0: movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6 michael@0: movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7 michael@0: michael@0: addps xmm2,xmm3 ; xmm2=tmp10 michael@0: addps xmm3,xmm6 ; xmm3=tmp11 michael@0: addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7 michael@0: michael@0: mulps xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3 michael@0: michael@0: movaps xmm1,xmm2 ; xmm1=tmp10 michael@0: subps xmm2,xmm6 michael@0: mulps xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5 michael@0: mulps xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196) michael@0: mulps xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562) michael@0: addps xmm1,xmm2 ; xmm1=z2 michael@0: addps xmm6,xmm2 ; xmm6=z4 michael@0: michael@0: movaps xmm5,xmm0 michael@0: subps xmm0,xmm3 ; xmm0=z13 michael@0: addps xmm5,xmm3 ; xmm5=z11 michael@0: michael@0: movaps xmm7,xmm0 michael@0: movaps xmm4,xmm5 michael@0: subps xmm0,xmm1 ; xmm0=data3 michael@0: subps xmm5,xmm6 ; xmm5=data7 michael@0: addps xmm7,xmm1 ; xmm7=data5 michael@0: addps xmm4,xmm6 ; xmm4=data1 michael@0: michael@0: movaps XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0 michael@0: movaps XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)], xmm5 michael@0: movaps XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)], xmm7 michael@0: movaps XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4 michael@0: michael@0: add edx, 4*DCTSIZE*SIZEOF_FAST_FLOAT michael@0: dec ecx michael@0: jnz near .rowloop michael@0: michael@0: ; ---- Pass 2: process columns. michael@0: michael@0: mov edx, POINTER [data(eax)] ; (FAST_FLOAT *) michael@0: mov ecx, DCTSIZE/4 michael@0: alignx 16,7 michael@0: .columnloop: michael@0: michael@0: movaps xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm2, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)] michael@0: michael@0: ; xmm0=(02 12 22 32), xmm2=(42 52 62 72) michael@0: ; xmm1=(03 13 23 33), xmm3=(43 53 63 73) michael@0: michael@0: movaps xmm4,xmm0 ; transpose coefficients(phase 1) michael@0: unpcklps xmm0,xmm1 ; xmm0=(02 03 12 13) michael@0: unpckhps xmm4,xmm1 ; xmm4=(22 23 32 33) michael@0: movaps xmm5,xmm2 ; transpose coefficients(phase 1) michael@0: unpcklps xmm2,xmm3 ; xmm2=(42 43 52 53) michael@0: unpckhps xmm5,xmm3 ; xmm5=(62 63 72 73) michael@0: michael@0: movaps xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm1, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)] michael@0: movaps xmm3, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)] michael@0: michael@0: ; xmm6=(00 10 20 30), xmm1=(40 50 60 70) michael@0: ; xmm7=(01 11 21 31), xmm3=(41 51 61 71) michael@0: michael@0: movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 23 32 33) michael@0: movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(42 43 52 53) michael@0: michael@0: movaps xmm4,xmm6 ; transpose coefficients(phase 1) michael@0: unpcklps xmm6,xmm7 ; xmm6=(00 01 10 11) michael@0: unpckhps xmm4,xmm7 ; xmm4=(20 21 30 31) michael@0: movaps xmm2,xmm1 ; transpose coefficients(phase 1) michael@0: unpcklps xmm1,xmm3 ; xmm1=(40 41 50 51) michael@0: unpckhps xmm2,xmm3 ; xmm2=(60 61 70 71) michael@0: michael@0: movaps xmm7,xmm6 ; transpose coefficients(phase 2) michael@0: unpcklps2 xmm6,xmm0 ; xmm6=(00 01 02 03)=data0 michael@0: unpckhps2 xmm7,xmm0 ; xmm7=(10 11 12 13)=data1 michael@0: movaps xmm3,xmm2 ; transpose coefficients(phase 2) michael@0: unpcklps2 xmm2,xmm5 ; xmm2=(60 61 62 63)=data6 michael@0: unpckhps2 xmm3,xmm5 ; xmm3=(70 71 72 73)=data7 michael@0: michael@0: movaps xmm0,xmm7 michael@0: movaps xmm5,xmm6 michael@0: subps xmm7,xmm2 ; xmm7=data1-data6=tmp6 michael@0: subps xmm6,xmm3 ; xmm6=data0-data7=tmp7 michael@0: addps xmm0,xmm2 ; xmm0=data1+data6=tmp1 michael@0: addps xmm5,xmm3 ; xmm5=data0+data7=tmp0 michael@0: michael@0: movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 23 32 33) michael@0: movaps xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53) michael@0: movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6 michael@0: movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 michael@0: michael@0: movaps xmm7,xmm4 ; transpose coefficients(phase 2) michael@0: unpcklps2 xmm4,xmm2 ; xmm4=(20 21 22 23)=data2 michael@0: unpckhps2 xmm7,xmm2 ; xmm7=(30 31 32 33)=data3 michael@0: movaps xmm6,xmm1 ; transpose coefficients(phase 2) michael@0: unpcklps2 xmm1,xmm3 ; xmm1=(40 41 42 43)=data4 michael@0: unpckhps2 xmm6,xmm3 ; xmm6=(50 51 52 53)=data5 michael@0: michael@0: movaps xmm2,xmm7 michael@0: movaps xmm3,xmm4 michael@0: addps xmm7,xmm1 ; xmm7=data3+data4=tmp3 michael@0: addps xmm4,xmm6 ; xmm4=data2+data5=tmp2 michael@0: subps xmm2,xmm1 ; xmm2=data3-data4=tmp4 michael@0: subps xmm3,xmm6 ; xmm3=data2-data5=tmp5 michael@0: michael@0: ; -- Even part michael@0: michael@0: movaps xmm1,xmm5 michael@0: movaps xmm6,xmm0 michael@0: subps xmm5,xmm7 ; xmm5=tmp13 michael@0: subps xmm0,xmm4 ; xmm0=tmp12 michael@0: addps xmm1,xmm7 ; xmm1=tmp10 michael@0: addps xmm6,xmm4 ; xmm6=tmp11 michael@0: michael@0: addps xmm0,xmm5 michael@0: mulps xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1 michael@0: michael@0: movaps xmm7,xmm1 michael@0: movaps xmm4,xmm5 michael@0: subps xmm1,xmm6 ; xmm1=data4 michael@0: subps xmm5,xmm0 ; xmm5=data6 michael@0: addps xmm7,xmm6 ; xmm7=data0 michael@0: addps xmm4,xmm0 ; xmm4=data2 michael@0: michael@0: movaps XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)], xmm1 michael@0: movaps XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)], xmm5 michael@0: movaps XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7 michael@0: movaps XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4 michael@0: michael@0: ; -- Odd part michael@0: michael@0: movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6 michael@0: movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7 michael@0: michael@0: addps xmm2,xmm3 ; xmm2=tmp10 michael@0: addps xmm3,xmm6 ; xmm3=tmp11 michael@0: addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7 michael@0: michael@0: mulps xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3 michael@0: michael@0: movaps xmm1,xmm2 ; xmm1=tmp10 michael@0: subps xmm2,xmm6 michael@0: mulps xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5 michael@0: mulps xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196) michael@0: mulps xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562) michael@0: addps xmm1,xmm2 ; xmm1=z2 michael@0: addps xmm6,xmm2 ; xmm6=z4 michael@0: michael@0: movaps xmm5,xmm0 michael@0: subps xmm0,xmm3 ; xmm0=z13 michael@0: addps xmm5,xmm3 ; xmm5=z11 michael@0: michael@0: movaps xmm7,xmm0 michael@0: movaps xmm4,xmm5 michael@0: subps xmm0,xmm1 ; xmm0=data3 michael@0: subps xmm5,xmm6 ; xmm5=data7 michael@0: addps xmm7,xmm1 ; xmm7=data5 michael@0: addps xmm4,xmm6 ; xmm4=data1 michael@0: michael@0: movaps XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0 michael@0: movaps XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)], xmm5 michael@0: movaps XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)], xmm7 michael@0: movaps XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4 michael@0: michael@0: add edx, byte 4*SIZEOF_FAST_FLOAT michael@0: dec ecx michael@0: jnz near .columnloop michael@0: michael@0: ; pop edi ; unused michael@0: ; pop esi ; unused michael@0: ; pop edx ; need not be preserved michael@0: ; pop ecx ; need not be preserved michael@0: poppic 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: ; 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