MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 1 | ; |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 2 | ; jdmerss2.asm - merged upsampling/color conversion (SSE2) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 3 | ; |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 4 | ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
| 5 | ; |
| 6 | ; Based on |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 7 | ; x86 SIMD extension for IJG JPEG library |
| 8 | ; Copyright (C) 1999-2006, MIYASAKA Masaru. |
| 9 | ; For conditions of distribution and use, see copyright notice in jsimdext.inc |
| 10 | ; |
| 11 | ; This file should be assembled with NASM (Netwide Assembler), |
| 12 | ; can *not* be assembled with Microsoft's MASM or any compatible |
| 13 | ; assembler (including Borland's Turbo Assembler). |
| 14 | ; NASM is available from http://nasm.sourceforge.net/ or |
| 15 | ; http://sourceforge.net/project/showfiles.php?group_id=6208 |
| 16 | ; |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 17 | ; [TAB8] |
| 18 | |
Pierre Ossman | 3a65ef4 | 2009-03-16 13:34:18 +0000 | [diff] [blame^] | 19 | %include "jsimdext.inc" |
| 20 | %include "jcolsamp.inc" |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 21 | |
| 22 | ; -------------------------------------------------------------------------- |
| 23 | |
| 24 | %define SCALEBITS 16 |
| 25 | |
| 26 | F_0_344 equ 22554 ; FIX(0.34414) |
| 27 | F_0_714 equ 46802 ; FIX(0.71414) |
| 28 | F_1_402 equ 91881 ; FIX(1.40200) |
| 29 | F_1_772 equ 116130 ; FIX(1.77200) |
| 30 | F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1) |
| 31 | F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414) |
| 32 | F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200) |
| 33 | |
| 34 | ; -------------------------------------------------------------------------- |
| 35 | SECTION SEG_CONST |
| 36 | |
| 37 | alignz 16 |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 38 | global EXTN(jconst_merged_upsample_sse2) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 39 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 40 | EXTN(jconst_merged_upsample_sse2): |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 41 | |
| 42 | PW_F0402 times 8 dw F_0_402 |
| 43 | PW_MF0228 times 8 dw -F_0_228 |
| 44 | PW_MF0344_F0285 times 4 dw -F_0_344, F_0_285 |
| 45 | PW_ONE times 8 dw 1 |
| 46 | PD_ONEHALF times 4 dd 1 << (SCALEBITS-1) |
| 47 | |
| 48 | alignz 16 |
| 49 | |
| 50 | ; -------------------------------------------------------------------------- |
| 51 | SECTION SEG_TEXT |
| 52 | BITS 32 |
| 53 | ; |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 54 | ; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 55 | ; |
| 56 | ; GLOBAL(void) |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 57 | ; jsimd_h2v1_merged_upsample_sse2 (JDIMENSION output_width, |
| 58 | ; JSAMPIMAGE input_buf, |
| 59 | ; JDIMENSION in_row_group_ctr, |
| 60 | ; JSAMPARRAY output_buf); |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 61 | ; |
| 62 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 63 | %define output_width(b) (b)+8 ; JDIMENSION output_width |
| 64 | %define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf |
| 65 | %define in_row_group_ctr(b) (b)+16 ; JDIMENSION in_row_group_ctr |
| 66 | %define output_buf(b) (b)+20 ; JSAMPARRAY output_buf |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 67 | |
| 68 | %define original_ebp ebp+0 |
| 69 | %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 70 | %define WK_NUM 3 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 71 | %define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr |
| 72 | |
| 73 | align 16 |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 74 | global EXTN(jsimd_h2v1_merged_upsample_sse2) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 75 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 76 | EXTN(jsimd_h2v1_merged_upsample_sse2): |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 77 | push ebp |
| 78 | mov eax,esp ; eax = original ebp |
| 79 | sub esp, byte 4 |
| 80 | and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits |
| 81 | mov [esp],eax |
| 82 | mov ebp,esp ; ebp = aligned ebp |
| 83 | lea esp, [wk(0)] |
| 84 | pushpic eax ; make a room for GOT address |
| 85 | push ebx |
| 86 | ; push ecx ; need not be preserved |
| 87 | ; push edx ; need not be preserved |
| 88 | push esi |
| 89 | push edi |
| 90 | |
| 91 | get_GOT ebx ; get GOT address |
| 92 | movpic POINTER [gotptr], ebx ; save GOT address |
| 93 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 94 | mov ecx, JDIMENSION [output_width(eax)] ; col |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 95 | test ecx,ecx |
| 96 | jz near .return |
| 97 | |
| 98 | push ecx |
| 99 | |
| 100 | mov edi, JSAMPIMAGE [input_buf(eax)] |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 101 | mov ecx, JDIMENSION [in_row_group_ctr(eax)] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 102 | mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY] |
| 103 | mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY] |
| 104 | mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 105 | mov edi, JSAMPARRAY [output_buf(eax)] |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 106 | mov esi, JSAMPROW [esi+ecx*SIZEOF_JSAMPROW] ; inptr0 |
| 107 | mov ebx, JSAMPROW [ebx+ecx*SIZEOF_JSAMPROW] ; inptr1 |
| 108 | mov edx, JSAMPROW [edx+ecx*SIZEOF_JSAMPROW] ; inptr2 |
| 109 | mov edi, JSAMPROW [edi] ; outptr |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 110 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 111 | pop ecx ; col |
| 112 | |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 113 | alignx 16,7 |
| 114 | .columnloop: |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 115 | movpic eax, POINTER [gotptr] ; load GOT address (eax) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 116 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 117 | movdqa xmm6, XMMWORD [ebx] ; xmm6=Cb(0123456789ABCDEF) |
| 118 | movdqa xmm7, XMMWORD [edx] ; xmm7=Cr(0123456789ABCDEF) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 119 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 120 | pxor xmm1,xmm1 ; xmm1=(all 0's) |
| 121 | pcmpeqw xmm3,xmm3 |
| 122 | psllw xmm3,7 ; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..} |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 123 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 124 | movdqa xmm4,xmm6 |
| 125 | punpckhbw xmm6,xmm1 ; xmm6=Cb(89ABCDEF)=CbH |
| 126 | punpcklbw xmm4,xmm1 ; xmm4=Cb(01234567)=CbL |
| 127 | movdqa xmm0,xmm7 |
| 128 | punpckhbw xmm7,xmm1 ; xmm7=Cr(89ABCDEF)=CrH |
| 129 | punpcklbw xmm0,xmm1 ; xmm0=Cr(01234567)=CrL |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 130 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 131 | paddw xmm6,xmm3 |
| 132 | paddw xmm4,xmm3 |
| 133 | paddw xmm7,xmm3 |
| 134 | paddw xmm0,xmm3 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 135 | |
| 136 | ; (Original) |
| 137 | ; R = Y + 1.40200 * Cr |
| 138 | ; G = Y - 0.34414 * Cb - 0.71414 * Cr |
| 139 | ; B = Y + 1.77200 * Cb |
| 140 | ; |
| 141 | ; (This implementation) |
| 142 | ; R = Y + 0.40200 * Cr + Cr |
| 143 | ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr |
| 144 | ; B = Y - 0.22800 * Cb + Cb + Cb |
| 145 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 146 | movdqa xmm5,xmm6 ; xmm5=CbH |
| 147 | movdqa xmm2,xmm4 ; xmm2=CbL |
| 148 | paddw xmm6,xmm6 ; xmm6=2*CbH |
| 149 | paddw xmm4,xmm4 ; xmm4=2*CbL |
| 150 | movdqa xmm1,xmm7 ; xmm1=CrH |
| 151 | movdqa xmm3,xmm0 ; xmm3=CrL |
| 152 | paddw xmm7,xmm7 ; xmm7=2*CrH |
| 153 | paddw xmm0,xmm0 ; xmm0=2*CrL |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 154 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 155 | pmulhw xmm6,[GOTOFF(eax,PW_MF0228)] ; xmm6=(2*CbH * -FIX(0.22800)) |
| 156 | pmulhw xmm4,[GOTOFF(eax,PW_MF0228)] ; xmm4=(2*CbL * -FIX(0.22800)) |
| 157 | pmulhw xmm7,[GOTOFF(eax,PW_F0402)] ; xmm7=(2*CrH * FIX(0.40200)) |
| 158 | pmulhw xmm0,[GOTOFF(eax,PW_F0402)] ; xmm0=(2*CrL * FIX(0.40200)) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 159 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 160 | paddw xmm6,[GOTOFF(eax,PW_ONE)] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 161 | paddw xmm4,[GOTOFF(eax,PW_ONE)] |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 162 | psraw xmm6,1 ; xmm6=(CbH * -FIX(0.22800)) |
| 163 | psraw xmm4,1 ; xmm4=(CbL * -FIX(0.22800)) |
| 164 | paddw xmm7,[GOTOFF(eax,PW_ONE)] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 165 | paddw xmm0,[GOTOFF(eax,PW_ONE)] |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 166 | psraw xmm7,1 ; xmm7=(CrH * FIX(0.40200)) |
| 167 | psraw xmm0,1 ; xmm0=(CrL * FIX(0.40200)) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 168 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 169 | paddw xmm6,xmm5 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 170 | paddw xmm4,xmm2 |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 171 | paddw xmm6,xmm5 ; xmm6=(CbH * FIX(1.77200))=(B-Y)H |
| 172 | paddw xmm4,xmm2 ; xmm4=(CbL * FIX(1.77200))=(B-Y)L |
| 173 | paddw xmm7,xmm1 ; xmm7=(CrH * FIX(1.40200))=(R-Y)H |
| 174 | paddw xmm0,xmm3 ; xmm0=(CrL * FIX(1.40200))=(R-Y)L |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 175 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 176 | movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=(B-Y)H |
| 177 | movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(R-Y)H |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 178 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 179 | movdqa xmm6,xmm5 |
| 180 | movdqa xmm7,xmm2 |
| 181 | punpcklwd xmm5,xmm1 |
| 182 | punpckhwd xmm6,xmm1 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 183 | pmaddwd xmm5,[GOTOFF(eax,PW_MF0344_F0285)] |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 184 | pmaddwd xmm6,[GOTOFF(eax,PW_MF0344_F0285)] |
| 185 | punpcklwd xmm2,xmm3 |
| 186 | punpckhwd xmm7,xmm3 |
| 187 | pmaddwd xmm2,[GOTOFF(eax,PW_MF0344_F0285)] |
| 188 | pmaddwd xmm7,[GOTOFF(eax,PW_MF0344_F0285)] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 189 | |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 190 | paddd xmm5,[GOTOFF(eax,PD_ONEHALF)] |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 191 | paddd xmm6,[GOTOFF(eax,PD_ONEHALF)] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 192 | psrad xmm5,SCALEBITS |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 193 | psrad xmm6,SCALEBITS |
| 194 | paddd xmm2,[GOTOFF(eax,PD_ONEHALF)] |
| 195 | paddd xmm7,[GOTOFF(eax,PD_ONEHALF)] |
| 196 | psrad xmm2,SCALEBITS |
| 197 | psrad xmm7,SCALEBITS |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 198 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 199 | packssdw xmm5,xmm6 ; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285) |
| 200 | packssdw xmm2,xmm7 ; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285) |
| 201 | psubw xmm5,xmm1 ; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H |
| 202 | psubw xmm2,xmm3 ; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 203 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 204 | movdqa XMMWORD [wk(2)], xmm5 ; wk(2)=(G-Y)H |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 205 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 206 | mov al,2 ; Yctr |
| 207 | jmp short .Yloop_1st |
| 208 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 209 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 210 | .Yloop_2nd: |
| 211 | movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(R-Y)H |
| 212 | movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(G-Y)H |
| 213 | movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(B-Y)H |
| 214 | alignx 16,7 |
| 215 | |
| 216 | .Yloop_1st: |
| 217 | movdqa xmm7, XMMWORD [esi] ; xmm7=Y(0123456789ABCDEF) |
| 218 | |
| 219 | pcmpeqw xmm6,xmm6 |
| 220 | psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} |
| 221 | pand xmm6,xmm7 ; xmm6=Y(02468ACE)=YE |
| 222 | psrlw xmm7,BYTE_BIT ; xmm7=Y(13579BDF)=YO |
| 223 | |
| 224 | movdqa xmm1,xmm0 ; xmm1=xmm0=(R-Y)(L/H) |
| 225 | movdqa xmm3,xmm2 ; xmm3=xmm2=(G-Y)(L/H) |
| 226 | movdqa xmm5,xmm4 ; xmm5=xmm4=(B-Y)(L/H) |
| 227 | |
| 228 | paddw xmm0,xmm6 ; xmm0=((R-Y)+YE)=RE=R(02468ACE) |
| 229 | paddw xmm1,xmm7 ; xmm1=((R-Y)+YO)=RO=R(13579BDF) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 230 | packuswb xmm0,xmm0 ; xmm0=R(02468ACE********) |
| 231 | packuswb xmm1,xmm1 ; xmm1=R(13579BDF********) |
| 232 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 233 | paddw xmm2,xmm6 ; xmm2=((G-Y)+YE)=GE=G(02468ACE) |
| 234 | paddw xmm3,xmm7 ; xmm3=((G-Y)+YO)=GO=G(13579BDF) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 235 | packuswb xmm2,xmm2 ; xmm2=G(02468ACE********) |
| 236 | packuswb xmm3,xmm3 ; xmm3=G(13579BDF********) |
| 237 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 238 | paddw xmm4,xmm6 ; xmm4=((B-Y)+YE)=BE=B(02468ACE) |
| 239 | paddw xmm5,xmm7 ; xmm5=((B-Y)+YO)=BO=B(13579BDF) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 240 | packuswb xmm4,xmm4 ; xmm4=B(02468ACE********) |
| 241 | packuswb xmm5,xmm5 ; xmm5=B(13579BDF********) |
| 242 | |
| 243 | %if RGB_PIXELSIZE == 3 ; --------------- |
| 244 | |
| 245 | ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) |
| 246 | ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) |
| 247 | ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) |
| 248 | ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **) |
| 249 | |
| 250 | punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) |
| 251 | punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F) |
| 252 | punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F) |
| 253 | |
| 254 | movdqa xmmG,xmmA |
| 255 | movdqa xmmH,xmmA |
| 256 | punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07) |
| 257 | punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F) |
| 258 | |
| 259 | psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --) |
| 260 | psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --) |
| 261 | |
| 262 | movdqa xmmC,xmmD |
| 263 | movdqa xmmB,xmmD |
| 264 | punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18) |
| 265 | punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --) |
| 266 | |
| 267 | psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --) |
| 268 | |
| 269 | movdqa xmmF,xmmE |
| 270 | punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29) |
| 271 | punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --) |
| 272 | |
| 273 | pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03) |
| 274 | movdqa xmmB,xmmE |
| 275 | punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14) |
| 276 | punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07) |
| 277 | punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29) |
| 278 | |
| 279 | pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B) |
| 280 | movdqa xmmB,xmmF |
| 281 | punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C) |
| 282 | punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F) |
| 283 | punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --) |
| 284 | |
| 285 | punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) |
| 286 | punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) |
| 287 | punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) |
| 288 | |
| 289 | cmp ecx, byte SIZEOF_XMMWORD |
| 290 | jb short .column_st32 |
| 291 | |
| 292 | test edi, SIZEOF_XMMWORD-1 |
| 293 | jnz short .out1 |
| 294 | ; --(aligned)------------------- |
| 295 | movntdq XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA |
| 296 | movntdq XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD |
| 297 | movntdq XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF |
| 298 | add edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr |
| 299 | jmp short .out0 |
| 300 | .out1: ; --(unaligned)----------------- |
| 301 | pcmpeqb xmmH,xmmH ; xmmH=(all 1's) |
| 302 | maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [edi], xmmA |
| 303 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 304 | maskmovdqu xmmD,xmmH ; movntdqu XMMWORD [edi], xmmD |
| 305 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 306 | maskmovdqu xmmF,xmmH ; movntdqu XMMWORD [edi], xmmF |
| 307 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 308 | .out0: |
| 309 | sub ecx, byte SIZEOF_XMMWORD |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 310 | jz near .endcolumn |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 311 | |
| 312 | add esi, byte SIZEOF_XMMWORD ; inptr0 |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 313 | dec al ; Yctr |
| 314 | jnz near .Yloop_2nd |
| 315 | |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 316 | add ebx, byte SIZEOF_XMMWORD ; inptr1 |
| 317 | add edx, byte SIZEOF_XMMWORD ; inptr2 |
| 318 | jmp near .columnloop |
| 319 | alignx 16,7 |
| 320 | |
| 321 | .column_st32: |
| 322 | pcmpeqb xmmH,xmmH ; xmmH=(all 1's) |
| 323 | lea ecx, [ecx+ecx*2] ; imul ecx, RGB_PIXELSIZE |
| 324 | cmp ecx, byte 2*SIZEOF_XMMWORD |
| 325 | jb short .column_st16 |
| 326 | maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [edi], xmmA |
| 327 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 328 | maskmovdqu xmmD,xmmH ; movntdqu XMMWORD [edi], xmmD |
| 329 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 330 | movdqa xmmA,xmmF |
| 331 | sub ecx, byte 2*SIZEOF_XMMWORD |
| 332 | jmp short .column_st15 |
| 333 | .column_st16: |
| 334 | cmp ecx, byte SIZEOF_XMMWORD |
| 335 | jb short .column_st15 |
| 336 | maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [edi], xmmA |
| 337 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 338 | movdqa xmmA,xmmD |
| 339 | sub ecx, byte SIZEOF_XMMWORD |
| 340 | .column_st15: |
| 341 | mov eax,ecx |
| 342 | xor ecx, byte 0x0F |
| 343 | shl ecx, 2 |
| 344 | movd xmmB,ecx |
| 345 | psrlq xmmH,4 |
| 346 | pcmpeqb xmmE,xmmE |
| 347 | psrlq xmmH,xmmB |
| 348 | psrlq xmmE,xmmB |
| 349 | punpcklbw xmmE,xmmH |
| 350 | ; ---------------- |
| 351 | mov ecx,edi |
| 352 | and ecx, byte SIZEOF_XMMWORD-1 |
| 353 | jz short .adj0 |
| 354 | add eax,ecx |
| 355 | cmp eax, byte SIZEOF_XMMWORD |
| 356 | ja short .adj0 |
| 357 | and edi, byte (-SIZEOF_XMMWORD) ; align to 16-byte boundary |
| 358 | shl ecx, 3 ; pslldq xmmA,ecx & pslldq xmmE,ecx |
| 359 | movdqa xmmG,xmmA |
| 360 | movdqa xmmC,xmmE |
| 361 | pslldq xmmA, SIZEOF_XMMWORD/2 |
| 362 | pslldq xmmE, SIZEOF_XMMWORD/2 |
| 363 | movd xmmD,ecx |
| 364 | sub ecx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT |
| 365 | jb short .adj1 |
| 366 | movd xmmF,ecx |
| 367 | psllq xmmA,xmmF |
| 368 | psllq xmmE,xmmF |
| 369 | jmp short .adj0 |
| 370 | .adj1: neg ecx |
| 371 | movd xmmF,ecx |
| 372 | psrlq xmmA,xmmF |
| 373 | psrlq xmmE,xmmF |
| 374 | psllq xmmG,xmmD |
| 375 | psllq xmmC,xmmD |
| 376 | por xmmA,xmmG |
| 377 | por xmmE,xmmC |
| 378 | .adj0: ; ---------------- |
| 379 | maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [edi], xmmA |
| 380 | |
| 381 | %else ; RGB_PIXELSIZE == 4 ; ----------- |
| 382 | |
| 383 | %ifdef RGBX_FILLER_0XFF |
| 384 | pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********) |
| 385 | pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********) |
| 386 | %else |
| 387 | pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********) |
| 388 | pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********) |
| 389 | %endif |
| 390 | ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) |
| 391 | ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) |
| 392 | ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) |
| 393 | ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **) |
| 394 | |
| 395 | punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) |
| 396 | punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E) |
| 397 | punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F) |
| 398 | punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F) |
| 399 | |
| 400 | movdqa xmmC,xmmA |
| 401 | punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36) |
| 402 | punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E) |
| 403 | movdqa xmmG,xmmB |
| 404 | punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37) |
| 405 | punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F) |
| 406 | |
| 407 | movdqa xmmD,xmmA |
| 408 | punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) |
| 409 | punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) |
| 410 | movdqa xmmH,xmmC |
| 411 | punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) |
| 412 | punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) |
| 413 | |
| 414 | cmp ecx, byte SIZEOF_XMMWORD |
| 415 | jb short .column_st32 |
| 416 | |
| 417 | test edi, SIZEOF_XMMWORD-1 |
| 418 | jnz short .out1 |
| 419 | ; --(aligned)------------------- |
| 420 | movntdq XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA |
| 421 | movntdq XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD |
| 422 | movntdq XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC |
| 423 | movntdq XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH |
| 424 | add edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr |
| 425 | jmp short .out0 |
| 426 | .out1: ; --(unaligned)----------------- |
| 427 | pcmpeqb xmmE,xmmE ; xmmE=(all 1's) |
| 428 | maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [edi], xmmA |
| 429 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 430 | maskmovdqu xmmD,xmmE ; movntdqu XMMWORD [edi], xmmD |
| 431 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 432 | maskmovdqu xmmC,xmmE ; movntdqu XMMWORD [edi], xmmC |
| 433 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 434 | maskmovdqu xmmH,xmmE ; movntdqu XMMWORD [edi], xmmH |
| 435 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 436 | .out0: |
| 437 | sub ecx, byte SIZEOF_XMMWORD |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 438 | jz near .endcolumn |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 439 | |
| 440 | add esi, byte SIZEOF_XMMWORD ; inptr0 |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 441 | dec al ; Yctr |
| 442 | jnz near .Yloop_2nd |
| 443 | |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 444 | add ebx, byte SIZEOF_XMMWORD ; inptr1 |
| 445 | add edx, byte SIZEOF_XMMWORD ; inptr2 |
| 446 | jmp near .columnloop |
| 447 | alignx 16,7 |
| 448 | |
| 449 | .column_st32: |
| 450 | pcmpeqb xmmE,xmmE ; xmmE=(all 1's) |
| 451 | cmp ecx, byte SIZEOF_XMMWORD/2 |
| 452 | jb short .column_st16 |
| 453 | maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [edi], xmmA |
| 454 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 455 | maskmovdqu xmmD,xmmE ; movntdqu XMMWORD [edi], xmmD |
| 456 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 457 | movdqa xmmA,xmmC |
| 458 | movdqa xmmD,xmmH |
| 459 | sub ecx, byte SIZEOF_XMMWORD/2 |
| 460 | .column_st16: |
| 461 | cmp ecx, byte SIZEOF_XMMWORD/4 |
| 462 | jb short .column_st15 |
| 463 | maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [edi], xmmA |
| 464 | add edi, byte SIZEOF_XMMWORD ; outptr |
| 465 | movdqa xmmA,xmmD |
| 466 | sub ecx, byte SIZEOF_XMMWORD/4 |
| 467 | .column_st15: |
| 468 | cmp ecx, byte SIZEOF_XMMWORD/16 |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 469 | jb short .endcolumn |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 470 | mov eax,ecx |
| 471 | xor ecx, byte 0x03 |
| 472 | inc ecx |
| 473 | shl ecx, 4 |
| 474 | movd xmmF,ecx |
| 475 | psrlq xmmE,xmmF |
| 476 | punpcklbw xmmE,xmmE |
| 477 | ; ---------------- |
| 478 | mov ecx,edi |
| 479 | and ecx, byte SIZEOF_XMMWORD-1 |
| 480 | jz short .adj0 |
| 481 | lea eax, [ecx+eax*4] ; RGB_PIXELSIZE |
| 482 | cmp eax, byte SIZEOF_XMMWORD |
| 483 | ja short .adj0 |
| 484 | and edi, byte (-SIZEOF_XMMWORD) ; align to 16-byte boundary |
| 485 | shl ecx, 3 ; pslldq xmmA,ecx & pslldq xmmE,ecx |
| 486 | movdqa xmmB,xmmA |
| 487 | movdqa xmmG,xmmE |
| 488 | pslldq xmmA, SIZEOF_XMMWORD/2 |
| 489 | pslldq xmmE, SIZEOF_XMMWORD/2 |
| 490 | movd xmmC,ecx |
| 491 | sub ecx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT |
| 492 | jb short .adj1 |
| 493 | movd xmmH,ecx |
| 494 | psllq xmmA,xmmH |
| 495 | psllq xmmE,xmmH |
| 496 | jmp short .adj0 |
| 497 | .adj1: neg ecx |
| 498 | movd xmmH,ecx |
| 499 | psrlq xmmA,xmmH |
| 500 | psrlq xmmE,xmmH |
| 501 | psllq xmmB,xmmC |
| 502 | psllq xmmG,xmmC |
| 503 | por xmmA,xmmB |
| 504 | por xmmE,xmmG |
| 505 | .adj0: ; ---------------- |
| 506 | maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [edi], xmmA |
| 507 | |
| 508 | %endif ; RGB_PIXELSIZE ; --------------- |
| 509 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 510 | .endcolumn: |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 511 | sfence ; flush the write buffer |
| 512 | |
| 513 | .return: |
| 514 | pop edi |
| 515 | pop esi |
| 516 | ; pop edx ; need not be preserved |
| 517 | ; pop ecx ; need not be preserved |
| 518 | pop ebx |
| 519 | mov esp,ebp ; esp <- aligned ebp |
| 520 | pop esp ; esp <- original ebp |
| 521 | pop ebp |
| 522 | ret |
| 523 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 524 | ; -------------------------------------------------------------------------- |
| 525 | ; |
| 526 | ; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. |
| 527 | ; |
| 528 | ; GLOBAL(void) |
| 529 | ; jsimd_h2v2_merged_upsample_sse2 (JDIMENSION output_width, |
| 530 | ; JSAMPIMAGE input_buf, |
| 531 | ; JDIMENSION in_row_group_ctr, |
| 532 | ; JSAMPARRAY output_buf); |
| 533 | ; |
| 534 | |
| 535 | %define output_width(b) (b)+8 ; JDIMENSION output_width |
| 536 | %define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf |
| 537 | %define in_row_group_ctr(b) (b)+16 ; JDIMENSION in_row_group_ctr |
| 538 | %define output_buf(b) (b)+20 ; JSAMPARRAY output_buf |
| 539 | |
| 540 | align 16 |
| 541 | global EXTN(jsimd_h2v2_merged_upsample_sse2) |
| 542 | |
| 543 | EXTN(jsimd_h2v2_merged_upsample_sse2): |
| 544 | push ebp |
| 545 | mov ebp,esp |
| 546 | push ebx |
| 547 | ; push ecx ; need not be preserved |
| 548 | ; push edx ; need not be preserved |
| 549 | push esi |
| 550 | push edi |
| 551 | |
| 552 | mov eax, POINTER [output_width(ebp)] |
| 553 | |
| 554 | mov edi, JSAMPIMAGE [input_buf(ebp)] |
| 555 | mov ecx, JDIMENSION [in_row_group_ctr(ebp)] |
| 556 | mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY] |
| 557 | mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY] |
| 558 | mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY] |
| 559 | mov edi, JSAMPARRAY [output_buf(ebp)] |
| 560 | lea esi, [esi+ecx*SIZEOF_JSAMPROW] |
| 561 | |
| 562 | push edx ; inptr2 |
| 563 | push ebx ; inptr1 |
| 564 | push esi ; inptr00 |
| 565 | mov ebx,esp |
| 566 | |
| 567 | push edi ; output_buf (outptr0) |
| 568 | push ecx ; in_row_group_ctr |
| 569 | push ebx ; input_buf |
| 570 | push eax ; output_width |
| 571 | |
| 572 | call near EXTN(jsimd_h2v1_merged_upsample_sse2) |
| 573 | |
| 574 | add esi, byte SIZEOF_JSAMPROW ; inptr01 |
| 575 | add edi, byte SIZEOF_JSAMPROW ; outptr1 |
| 576 | mov POINTER [ebx+0*SIZEOF_POINTER], esi |
| 577 | mov POINTER [ebx-1*SIZEOF_POINTER], edi |
| 578 | |
| 579 | call near EXTN(jsimd_h2v1_merged_upsample_sse2) |
| 580 | |
| 581 | add esp, byte 7*SIZEOF_DWORD |
| 582 | |
| 583 | pop edi |
| 584 | pop esi |
| 585 | ; pop edx ; need not be preserved |
| 586 | ; pop ecx ; need not be preserved |
| 587 | pop ebx |
| 588 | pop ebp |
| 589 | ret |
| 590 | |