media/libjpeg/simd/jdmrgss2.asm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial