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