1; 2; jquantf.asm - sample data conversion and quantization (SSE & SSE2) 3; 4; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB 5; 6; Based on the x86 SIMD extension for IJG JPEG library 7; Copyright (C) 1999-2006, MIYASAKA Masaru. 8; For conditions of distribution and use, see copyright notice in jsimdext.inc 9; 10; This file should be assembled with NASM (Netwide Assembler), 11; can *not* be assembled with Microsoft's MASM or any compatible 12; assembler (including Borland's Turbo Assembler). 13; NASM is available from http://nasm.sourceforge.net/ or 14; http://sourceforge.net/project/showfiles.php?group_id=6208 15; 16; [TAB8] 17 18%include "jsimdext.inc" 19%include "jdct.inc" 20 21; -------------------------------------------------------------------------- 22 SECTION SEG_TEXT 23 BITS 32 24; 25; Load data into workspace, applying unsigned->signed conversion 26; 27; GLOBAL(void) 28; jsimd_convsamp_float_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col, 29; FAST_FLOAT *workspace); 30; 31 32%define sample_data ebp+8 ; JSAMPARRAY sample_data 33%define start_col ebp+12 ; JDIMENSION start_col 34%define workspace ebp+16 ; FAST_FLOAT *workspace 35 36 align 16 37 global EXTN(jsimd_convsamp_float_sse2) 38 39EXTN(jsimd_convsamp_float_sse2): 40 push ebp 41 mov ebp,esp 42 push ebx 43; push ecx ; need not be preserved 44; push edx ; need not be preserved 45 push esi 46 push edi 47 48 pcmpeqw xmm7,xmm7 49 psllw xmm7,7 50 packsswb xmm7,xmm7 ; xmm7 = PB_CENTERJSAMPLE (0x808080..) 51 52 mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) 53 mov eax, JDIMENSION [start_col] 54 mov edi, POINTER [workspace] ; (DCTELEM *) 55 mov ecx, DCTSIZE/2 56 alignx 16,7 57.convloop: 58 mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) 59 mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) 60 61 movq xmm0, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE] 62 movq xmm1, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE] 63 64 psubb xmm0,xmm7 ; xmm0=(01234567) 65 psubb xmm1,xmm7 ; xmm1=(89ABCDEF) 66 67 punpcklbw xmm0,xmm0 ; xmm0=(*0*1*2*3*4*5*6*7) 68 punpcklbw xmm1,xmm1 ; xmm1=(*8*9*A*B*C*D*E*F) 69 70 punpcklwd xmm2,xmm0 ; xmm2=(***0***1***2***3) 71 punpckhwd xmm0,xmm0 ; xmm0=(***4***5***6***7) 72 punpcklwd xmm3,xmm1 ; xmm3=(***8***9***A***B) 73 punpckhwd xmm1,xmm1 ; xmm1=(***C***D***E***F) 74 75 psrad xmm2,(DWORD_BIT-BYTE_BIT) ; xmm2=(0123) 76 psrad xmm0,(DWORD_BIT-BYTE_BIT) ; xmm0=(4567) 77 cvtdq2ps xmm2,xmm2 ; xmm2=(0123) 78 cvtdq2ps xmm0,xmm0 ; xmm0=(4567) 79 psrad xmm3,(DWORD_BIT-BYTE_BIT) ; xmm3=(89AB) 80 psrad xmm1,(DWORD_BIT-BYTE_BIT) ; xmm1=(CDEF) 81 cvtdq2ps xmm3,xmm3 ; xmm3=(89AB) 82 cvtdq2ps xmm1,xmm1 ; xmm1=(CDEF) 83 84 movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm2 85 movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0 86 movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3 87 movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1 88 89 add esi, byte 2*SIZEOF_JSAMPROW 90 add edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT 91 dec ecx 92 jnz short .convloop 93 94 pop edi 95 pop esi 96; pop edx ; need not be preserved 97; pop ecx ; need not be preserved 98 pop ebx 99 pop ebp 100 ret 101 102 103; -------------------------------------------------------------------------- 104; 105; Quantize/descale the coefficients, and store into coef_block 106; 107; GLOBAL(void) 108; jsimd_quantize_float_sse2 (JCOEFPTR coef_block, FAST_FLOAT *divisors, 109; FAST_FLOAT *workspace); 110; 111 112%define coef_block ebp+8 ; JCOEFPTR coef_block 113%define divisors ebp+12 ; FAST_FLOAT *divisors 114%define workspace ebp+16 ; FAST_FLOAT *workspace 115 116 align 16 117 global EXTN(jsimd_quantize_float_sse2) 118 119EXTN(jsimd_quantize_float_sse2): 120 push ebp 121 mov ebp,esp 122; push ebx ; unused 123; push ecx ; unused 124; push edx ; need not be preserved 125 push esi 126 push edi 127 128 mov esi, POINTER [workspace] 129 mov edx, POINTER [divisors] 130 mov edi, JCOEFPTR [coef_block] 131 mov eax, DCTSIZE2/16 132 alignx 16,7 133.quantloop: 134 movaps xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)] 135 movaps xmm1, XMMWORD [XMMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)] 136 mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] 137 mulps xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] 138 movaps xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)] 139 movaps xmm3, XMMWORD [XMMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)] 140 mulps xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] 141 mulps xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] 142 143 cvtps2dq xmm0,xmm0 144 cvtps2dq xmm1,xmm1 145 cvtps2dq xmm2,xmm2 146 cvtps2dq xmm3,xmm3 147 148 packssdw xmm0,xmm1 149 packssdw xmm2,xmm3 150 151 movdqa XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_JCOEF)], xmm0 152 movdqa XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_JCOEF)], xmm2 153 154 add esi, byte 16*SIZEOF_FAST_FLOAT 155 add edx, byte 16*SIZEOF_FAST_FLOAT 156 add edi, byte 16*SIZEOF_JCOEF 157 dec eax 158 jnz short .quantloop 159 160 pop edi 161 pop esi 162; pop edx ; need not be preserved 163; pop ecx ; unused 164; pop ebx ; unused 165 pop ebp 166 ret 167 168; For some reason, the OS X linker does not honor the request to align the 169; segment unless we do this. 170 align 16 171