[svn] / branches / dev-api-3 / xvidcore / src / image / x86_asm / yv12_to_rgb24_mmx.asm Repository:
ViewVC logotype

Annotation of /branches/dev-api-3/xvidcore/src/image/x86_asm/yv12_to_rgb24_mmx.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 582 - (view) (download)

1 : edgomez 330 ;------------------------------------------------------------------------------
2 :     ;
3 :     ; This file is part of XviD, a free MPEG-4 video encoder/decoder
4 :     ;
5 :     ; XviD is free software; you can redistribute it and/or modify it
6 :     ; under the terms of the GNU General Public License as published by
7 :     ; the Free Software Foundation; either version 2 of the License, or
8 :     ; (at your option) any later version.
9 :     ;
10 :     ; XviD is distributed in the hope that it will be useful, but
11 :     ; WITHOUT ANY WARRANTY; without even the implied warranty of
12 :     ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 :     ; GNU General Public License for more details.
14 :     ;
15 :     ; You should have received a copy of the GNU General Public License
16 :     ; along with this program; if not, write to the Free Software
17 :     ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 :     ;
19 :     ;------------------------------------------------------------------------------
20 :     ;------------------------------------------------------------------------------
21 :     ;
22 :     ; yuv_to_rgb24.asm, MMX optimized color conversion
23 :     ;
24 :     ; Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>
25 :     ;
26 :     ; For more information visit the XviD homepage: http://www.xvid.org
27 :     ;
28 :     ;------------------------------------------------------------------------------
29 :     ;------------------------------------------------------------------------------
30 :     ;
31 :     ; Revision history :
32 :     ;
33 :     ; 13.12.2001 initial version (Isibaar)
34 :     ; 23.07.2002 Thread safe version (edgomez)
35 :     ;
36 : suxen_drol 582 ; $Id: yv12_to_rgb24_mmx.asm,v 1.2.2.1 2002-10-06 07:05:51 suxen_drol Exp $
37 : edgomez 330 ;
38 :     ;------------------------------------------------------------------------------
39 :     ;------------------------------------------------------------------------------
40 :     ; NB: n contrary to the c implementation this code does the conversion
41 :     ; using direct calculations. Input data width must be a multiple of 8
42 :     ; and height must be even.
43 :     ; This implementation is less precise than the c version but is
44 :     ; more than twice as fast :-)
45 :     ;------------------------------------------------------------------------------
46 :    
47 :     BITS 32
48 :    
49 :    
50 :     %macro cglobal 1
51 :     %ifdef PREFIX
52 :     global _%1
53 :     %define %1 _%1
54 :     %else
55 :     global %1
56 :     %endif
57 :     %endmacro
58 :    
59 :    
60 :     %define SCALEBITS 6
61 :    
62 :    
63 :     ALIGN 16
64 :    
65 :     SECTION .data
66 :    
67 :     Y_SUB dw 16, 16, 16, 16
68 :     U_SUB dw 128, 128, 128, 128
69 :     V_SUB dw 128, 128, 128, 128
70 :    
71 :     Y_MUL dw 74, 74, 74, 74
72 :    
73 :     UG_MUL dw 25, 25, 25, 25
74 :     VG_MUL dw 52, 52, 52, 52
75 :    
76 :     UB_MUL dw 129, 129, 129, 129
77 :     VR_MUL dw 102, 102, 102, 102
78 :    
79 :    
80 :     ALIGN 16
81 :    
82 :     SECTION .text
83 :    
84 :     ;------------------------------------------------------------------------------
85 :     ;
86 :     ; void yv12_to_rgb24_mmx(uint8_t *dst,
87 :     ; int dst_stride,
88 :     ; uint8_t *y_src,
89 :     ; uint8_t *u_src,
90 :     ; uint8_t *v_src,
91 :     ; int y_stride, int uv_stride,
92 :     ; int width, int height);
93 :     ;
94 :     ;------------------------------------------------------------------------------
95 :    
96 :     cglobal yv12_to_rgb24_mmx
97 :     yv12_to_rgb24_mmx:
98 :    
99 :     push ebx
100 :     push esi
101 :     push edi
102 :     push ebp
103 :    
104 :     ; local vars alloc
105 :     %define localsize 72
106 :     %define TEMP_Y1 esp
107 :     %define TEMP_Y2 esp + 8
108 :     %define TEMP_G1 esp + 16
109 :     %define TEMP_G2 esp + 24
110 :     %define TEMP_B1 esp + 32
111 :     %define TEMP_B2 esp + 40
112 :     %define y_dif esp + 48
113 :     %define dst_dif esp + 52
114 :     %define uv_dif esp + 56
115 :     %define height esp + 60
116 :     %define width_8 esp + 64
117 :     %define height_2 esp + 68
118 :     sub esp, localsize
119 :    
120 :    
121 :     mov eax, [esp + 52 + localsize] ; height -> eax
122 :     cmp eax, 0x00
123 :     jge near dont_flip ; flip?
124 :    
125 :     neg eax
126 :     mov [height], eax
127 :    
128 :     mov esi, [esp + 48 + localsize] ; width -> esi
129 :    
130 :     mov ebp, [esp + 40 + localsize] ; y_stride -> ebp
131 :     mov ebx, ebp
132 :     shl ebx, 1 ; 2 * y_stride -> ebx
133 :     neg ebx
134 :     sub ebx, esi ; y_dif -> eax
135 :    
136 :     mov [y_dif], ebx
137 :    
138 :     sub eax, 1 ; height - 1 -> eax
139 :     mul ebp ; (height - 1) * y_stride -> ebp
140 :     mov ecx, eax
141 :     mov eax, [esp + 28 + localsize] ; y_src -> eax
142 :     add eax, ecx ; y_src -> eax
143 :     mov ebx, eax
144 :     sub ebx, ebp ; y_src2 -> ebx
145 :    
146 :     mov ecx, [esp + 24 + localsize] ; dst_stride -> ecx
147 : suxen_drol 582 shl ecx, 1
148 :     mov edx, ecx ; 2 * dst_stride -> ecx
149 : edgomez 330 sub ecx, esi
150 :     shl esi, 1
151 : suxen_drol 582 sub ecx, esi ; 2 * dst_stride - 3 * width -> ecx
152 : edgomez 330
153 :     mov [dst_dif], ecx
154 :    
155 :     mov esi, [esp + 20 + localsize] ; dst -> esi
156 :     mov edi, esi
157 :     shr edx, 1
158 :     add edi, edx ; dst2 -> edi
159 :    
160 :     mov ebp, [esp + 48 + localsize] ; width -> ebp
161 :     mov ecx, ebp ; width -> ecx
162 :     shr ecx, 1
163 :     shr ebp, 3 ; width / 8 -> ebp
164 :     mov [width_8], ebp
165 :    
166 :     mov ebp, [esp + 44 + localsize] ; uv_stride -> ebp
167 :     mov edx, ebp
168 :     neg edx
169 :     sub edx, ecx
170 :     mov [uv_dif], edx
171 :    
172 :     mov edx, ebp
173 :     mov ebp, eax
174 :     mov eax, [height] ; height -> eax
175 :     shr eax, 1 ; height / 2 -> eax
176 :    
177 :     mov ecx, [esp + 32 + localsize] ; u_src -> ecx
178 :     sub eax, 1
179 :     mul edx
180 :     add ecx, eax
181 :    
182 :     mov edx, [esp + 36 + localsize] ; v_src -> edx
183 :     add edx, eax
184 :    
185 :     mov eax, ebp
186 :    
187 :     mov ebp, [height] ; height -> ebp
188 :     shr ebp, 1 ; height / 2 -> ebp
189 :    
190 :     pxor mm7, mm7 ; clear mm7
191 :     jmp y_loop
192 :    
193 :    
194 :     dont_flip:
195 :     mov esi, [esp + 48 + localsize] ; width -> esi
196 :    
197 :     mov ebp, [esp + 40 + localsize] ; y_stride -> ebp
198 :     mov ebx, ebp
199 :     shl ebx, 1 ; 2 * y_stride -> ebx
200 :     sub ebx, esi ; y_dif -> ebx
201 :    
202 :     mov [y_dif], ebx
203 :    
204 :     mov eax, [esp + 28 + localsize] ; y_src -> eax
205 :     mov ebx, eax
206 :     add ebx, ebp ; y_src2 -> ebp
207 :    
208 :     mov ecx, [esp + 24 + localsize] ; dst_stride -> ecx
209 : suxen_drol 582 shl ecx, 1
210 :     mov edx, ecx ; 2 * dst_stride -> ecx
211 : edgomez 330 sub ecx, esi
212 :     shl esi, 1
213 : suxen_drol 582 sub ecx, esi ; 2 * dst_stride - 3 * width -> ecx
214 : edgomez 330
215 :     mov [dst_dif], ecx
216 :    
217 :     mov esi, [esp + 20 + localsize] ; dst -> esi
218 :     mov edi, esi
219 :     shr edx, 1
220 :     add edi, edx ; dst2 -> edi
221 :    
222 :     mov ebp, [esp + 48 + localsize] ; width -> ebp
223 :     mov ecx, ebp ; width -> ecx
224 :     shr ecx, 1
225 :     shr ebp, 3 ; width / 8 -> ebp
226 :     mov [width_8], ebp
227 :    
228 :     mov ebp, [esp + 44 + localsize] ; uv_stride -> ebp
229 :     sub ebp, ecx
230 :     mov [uv_dif], ebp
231 :    
232 :     mov ecx, [esp + 32 + localsize] ; u_src -> ecx
233 :     mov edx, [esp + 36 + localsize] ; v_src -> edx
234 :    
235 :     mov ebp, [esp + 52 + localsize] ; height -> ebp
236 :     shr ebp, 1 ; height / 2 -> ebp
237 :    
238 :     pxor mm7, mm7
239 :    
240 :     y_loop:
241 :     mov [height_2], ebp
242 :     mov ebp, [width_8]
243 :    
244 :     x_loop:
245 :     movd mm2, [ecx]
246 :     movd mm3, [edx]
247 :    
248 :     punpcklbw mm2, mm7 ; u3u2u1u0 -> mm2
249 :     punpcklbw mm3, mm7 ; v3v2v1v0 -> mm3
250 :    
251 :     psubsw mm2, [U_SUB] ; U - 128
252 :     psubsw mm3, [V_SUB] ; V - 128
253 :    
254 :     movq mm4, mm2
255 :     movq mm5, mm3
256 :    
257 :     pmullw mm2, [UG_MUL]
258 :     pmullw mm3, [VG_MUL]
259 :    
260 :     movq mm6, mm2 ; u3u2u1u0 -> mm6
261 :     punpckhwd mm2, mm2 ; u3u3u2u2 -> mm2
262 :     punpcklwd mm6, mm6 ; u1u1u0u0 -> mm6
263 :    
264 :     pmullw mm4, [UB_MUL] ; B_ADD -> mm4
265 :    
266 :     movq mm0, mm3
267 :     punpckhwd mm3, mm3 ; v3v3v2v2 -> mm2
268 :     punpcklwd mm0, mm0 ; v1v1v0v0 -> mm6
269 :    
270 :     paddsw mm2, mm3
271 :     paddsw mm6, mm0
272 :    
273 :     pmullw mm5, [VR_MUL] ; R_ADD -> mm5
274 :    
275 :     movq mm0, [eax] ; y7y6y5y4y3y2y1y0 -> mm0
276 :    
277 :     movq mm1, mm0
278 :     punpckhbw mm1, mm7 ; y7y6y5y4 -> mm1
279 :     punpcklbw mm0, mm7 ; y3y2y1y0 -> mm0
280 :    
281 :     psubsw mm0, [Y_SUB] ; Y - Y_SUB
282 :     psubsw mm1, [Y_SUB] ; Y - Y_SUB
283 :    
284 :     pmullw mm1, [Y_MUL]
285 :     pmullw mm0, [Y_MUL]
286 :    
287 :     movq [TEMP_Y2], mm1 ; y7y6y5y4 -> mm3
288 :     movq [TEMP_Y1], mm0 ; y3y2y1y0 -> mm7
289 :    
290 :     psubsw mm1, mm2 ; g7g6g5g4 -> mm1
291 :     psubsw mm0, mm6 ; g3g2g1g0 -> mm0
292 :    
293 :     psraw mm1, SCALEBITS
294 :     psraw mm0, SCALEBITS
295 :    
296 :     packuswb mm0, mm1 ;g7g6g5g4g3g2g1g0 -> mm0
297 :    
298 :     movq [TEMP_G1], mm0
299 :    
300 :     movq mm0, [ebx] ; y7y6y5y4y3y2y1y0 -> mm0
301 :    
302 :     movq mm1, mm0
303 :    
304 :     punpckhbw mm1, mm7 ; y7y6y5y4 -> mm1
305 :     punpcklbw mm0, mm7 ; y3y2y1y0 -> mm0
306 :    
307 :     psubsw mm0, [Y_SUB] ; Y - Y_SUB
308 :     psubsw mm1, [Y_SUB] ; Y - Y_SUB
309 :    
310 :     pmullw mm1, [Y_MUL]
311 :     pmullw mm0, [Y_MUL]
312 :    
313 :     movq mm3, mm1
314 :     psubsw mm1, mm2 ; g7g6g5g4 -> mm1
315 :    
316 :     movq mm2, mm0
317 :     psubsw mm0, mm6 ; g3g2g1g0 -> mm0
318 :    
319 :     psraw mm1, SCALEBITS
320 :     psraw mm0, SCALEBITS
321 :    
322 :     packuswb mm0, mm1 ; g7g6g5g4g3g2g1g0 -> mm0
323 :    
324 :     movq [TEMP_G2], mm0
325 :    
326 :     movq mm0, mm4
327 :     punpckhwd mm4, mm4 ; u3u3u2u2 -> mm2
328 :     punpcklwd mm0, mm0 ; u1u1u0u0 -> mm6
329 :    
330 :     movq mm1, mm3 ; y7y6y5y4 -> mm1
331 :     paddsw mm3, mm4 ; b7b6b5b4 -> mm3
332 :    
333 :     movq mm7, mm2 ; y3y2y1y0 -> mm7
334 :    
335 :     paddsw mm2, mm0 ; b3b2b1b0 -> mm2
336 :    
337 :     psraw mm3, SCALEBITS
338 :     psraw mm2, SCALEBITS
339 :    
340 :     packuswb mm2, mm3 ; b7b6b5b4b3b2b1b0 -> mm2
341 :    
342 :     movq [TEMP_B2], mm2
343 :    
344 :     movq mm3, [TEMP_Y2]
345 :     movq mm2, [TEMP_Y1]
346 :    
347 :     movq mm6, mm3 ; TEMP_Y2 -> mm6
348 :     paddsw mm3, mm4 ; b7b6b5b4 -> mm3
349 :    
350 :     movq mm4, mm2 ; TEMP_Y1 -> mm4
351 :     paddsw mm2, mm0 ; b3b2b1b0 -> mm2
352 :    
353 :     psraw mm3, SCALEBITS
354 :     psraw mm2, SCALEBITS
355 :    
356 :     packuswb mm2, mm3 ; b7b6b5b4b3b2b1b0 -> mm2
357 :    
358 :     movq [TEMP_B1], mm2
359 :    
360 :     movq mm0, mm5
361 :     punpckhwd mm5, mm5 ; v3v3v2v2 -> mm5
362 :     punpcklwd mm0, mm0 ; v1v1v0v0 -> mm0
363 :    
364 :     paddsw mm1, mm5 ; r7r6r5r4 -> mm1
365 :     paddsw mm7, mm0 ; r3r2r1r0 -> mm7
366 :    
367 :     psraw mm1, SCALEBITS
368 :     psraw mm7, SCALEBITS
369 :    
370 :     packuswb mm7, mm1 ; r7r6r5r4r3r2r1r0 -> mm7 (TEMP_R2)
371 :    
372 :     paddsw mm6, mm5 ; r7r6r5r4 -> mm6
373 :     paddsw mm4, mm0 ; r3r2r1r0 -> mm4
374 :    
375 :     psraw mm6, SCALEBITS
376 :     psraw mm4, SCALEBITS
377 :    
378 :     packuswb mm4, mm6 ; r7r6r5r4r3r2r1r0 -> mm4 (TEMP_R1)
379 :    
380 :     movq mm0, [TEMP_B1]
381 :     movq mm1, [TEMP_G1]
382 :    
383 :     movq mm6, mm7
384 :    
385 :     movq mm2, mm0
386 :     punpcklbw mm2, mm4 ; r3b3r2b2r1b1r0b0 -> mm2
387 :     punpckhbw mm0, mm4 ; r7b7r6b6r5b5r4b4 -> mm0
388 :    
389 :     pxor mm7, mm7
390 :    
391 :     movq mm3, mm1
392 :     punpcklbw mm1, mm7 ; 0g30g20g10g0 -> mm1
393 :     punpckhbw mm3, mm7 ; 0g70g60g50g4 -> mm3
394 :    
395 :     movq mm4, mm2
396 :     punpcklbw mm2, mm1 ; 0r1g1b10r0g0b0 -> mm2
397 :     punpckhbw mm4, mm1 ; 0r3g3b30r2g2b2 -> mm4
398 :    
399 :     movq mm5, mm0
400 :     punpcklbw mm0, mm3 ; 0r5g5b50r4g4b4 -> mm0
401 :     punpckhbw mm5, mm3 ; 0r7g7b70r6g6b6 -> mm5
402 :    
403 :     movd [esi], mm2
404 :     psrlq mm2, 32
405 :    
406 :     movd [esi + 3], mm2
407 :     movd [esi + 6], mm4
408 :    
409 :     psrlq mm4, 32
410 :    
411 :     movd [esi + 9], mm4
412 :     movd [esi + 12], mm0
413 :    
414 :     psrlq mm0, 32
415 :    
416 :     movd [esi + 15], mm0
417 :     movd [esi + 18], mm5
418 :    
419 :     psrlq mm5, 32
420 :    
421 :     movd [esi + 21], mm5
422 :    
423 :     movq mm0, [TEMP_B2]
424 :     movq mm1, [TEMP_G2]
425 :    
426 :     movq mm2, mm0
427 :     punpcklbw mm2, mm6 ; r3b3r2b2r1b1r0b0 -> mm2
428 :     punpckhbw mm0, mm6 ; r7b7r6b6r5b5r4b4 -> mm0
429 :    
430 :     movq mm3, mm1
431 :     punpcklbw mm1, mm7 ; 0g30g20g10g0 -> mm1
432 :     punpckhbw mm3, mm7 ; 0g70g60g50g4 -> mm3
433 :    
434 :     movq mm4, mm2
435 :     punpcklbw mm2, mm1 ; 0r1g1b10r0g0b0 -> mm2
436 :     punpckhbw mm4, mm1 ; 0r3g3b30r2g2b2 -> mm4
437 :    
438 :     movq mm5, mm0
439 :     punpcklbw mm0, mm3 ; 0r5g5b50r4g4b4 -> mm0
440 :     punpckhbw mm5, mm3 ; 0r7g7b70r6g6b6 -> mm5
441 :    
442 :     movd [edi], mm2
443 :     psrlq mm2, 32
444 :    
445 :     movd [edi + 3], mm2
446 :     movd [edi + 6], mm4
447 :    
448 :     psrlq mm4, 32
449 :    
450 :     movd [edi + 9], mm4
451 :     movd [edi + 12], mm0
452 :    
453 :     psrlq mm0, 32
454 :    
455 :     movd [edi + 15], mm0
456 :     movd [edi + 18], mm5
457 :    
458 :     psrlq mm5, 32
459 :    
460 :     movd [edi + 21], mm5
461 :    
462 :     add esi, 24
463 :     add edi, 24
464 :    
465 :     add eax, 8
466 :     add ebx, 8
467 :     add ecx, 4
468 :     add edx, 4
469 :    
470 :     dec ebp
471 :    
472 :     jnz near x_loop
473 :    
474 :     add esi, [dst_dif]
475 :     add edi, [dst_dif]
476 :    
477 :     add eax, [y_dif]
478 :     add ebx, [y_dif]
479 :    
480 :     add ecx, [uv_dif]
481 :     add edx, [uv_dif]
482 :    
483 :     mov ebp, [height_2]
484 :     dec ebp
485 :     jnz near y_loop
486 :    
487 :     emms
488 :    
489 :     ;; Local vars deallocation
490 :     add esp, localsize
491 :     %undef TEMP_Y1
492 :     %undef TEMP_Y2
493 :     %undef TEMP_G1
494 :     %undef TEMP_G2
495 :     %undef TEMP_B1
496 :     %undef TEMP_B2
497 :     %undef y_dif
498 :     %undef dst_dif
499 :     %undef uv_dif
500 :     %undef height
501 :     %undef width_8
502 :     %undef height_2
503 :     %undef localsize
504 :    
505 :     pop ebp
506 :     pop edi
507 :     pop esi
508 :     pop ebx
509 :    
510 :     ret

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4