[svn] / trunk / xvidcore / src / image / x86_asm / yv12_to_rgb24_mmx.asm Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/image/x86_asm/yv12_to_rgb24_mmx.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 434 - (view) (download)

1 : chl 434 ;/*****************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * mmx yv12 to rgb24 conversion
5 :     ; *
6 :     ; * Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>
7 :     ; *
8 :     ; * This program is an implementation of a part of one or more MPEG-4
9 :     ; * Video tools as specified in ISO/IEC 14496-2 standard. Those intending
10 :     ; * to use this software module in hardware or software products are
11 :     ; * advised that its use may infringe existing patents or copyrights, and
12 :     ; * any such use would be at such party's own risk. The original
13 :     ; * developer of this software module and his/her company, and subsequent
14 :     ; * editors and their companies, will have no liability for use of this
15 :     ; * software or modifications or derivatives thereof.
16 :     ; *
17 :     ; * This program is free software; you can redistribute it and/or modify
18 :     ; * it under the terms of the GNU General Public License as published by
19 :     ; * the Free Software Foundation; either version 2 of the License, or
20 :     ; * (at your option) any later version.
21 :     ; *
22 :     ; * This program is distributed in the hope that it will be useful,
23 :     ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 :     ; * GNU General Public License for more details.
26 :     ; *
27 :     ; * You should have received a copy of the GNU General Public License
28 :     ; * along with this program; if not, write to the Free Software
29 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 :     ; *
31 :     ; ****************************************************************************/
32 : edgomez 330 ;
33 :     ;------------------------------------------------------------------------------
34 :     ; NB: n contrary to the c implementation this code does the conversion
35 :     ; using direct calculations. Input data width must be a multiple of 8
36 :     ; and height must be even.
37 :     ; This implementation is less precise than the c version but is
38 :     ; more than twice as fast :-)
39 :     ;------------------------------------------------------------------------------
40 :    
41 :     BITS 32
42 :    
43 :    
44 :     %macro cglobal 1
45 :     %ifdef PREFIX
46 :     global _%1
47 :     %define %1 _%1
48 :     %else
49 :     global %1
50 :     %endif
51 :     %endmacro
52 :    
53 :    
54 :     %define SCALEBITS 6
55 :    
56 :    
57 :     ALIGN 16
58 :    
59 :     SECTION .data
60 :    
61 :     Y_SUB dw 16, 16, 16, 16
62 :     U_SUB dw 128, 128, 128, 128
63 :     V_SUB dw 128, 128, 128, 128
64 :    
65 :     Y_MUL dw 74, 74, 74, 74
66 :    
67 :     UG_MUL dw 25, 25, 25, 25
68 :     VG_MUL dw 52, 52, 52, 52
69 :    
70 :     UB_MUL dw 129, 129, 129, 129
71 :     VR_MUL dw 102, 102, 102, 102
72 :    
73 :    
74 :     ALIGN 16
75 :    
76 :     SECTION .text
77 :    
78 :     ;------------------------------------------------------------------------------
79 :     ;
80 :     ; void yv12_to_rgb24_mmx(uint8_t *dst,
81 :     ; int dst_stride,
82 :     ; uint8_t *y_src,
83 :     ; uint8_t *u_src,
84 :     ; uint8_t *v_src,
85 :     ; int y_stride, int uv_stride,
86 :     ; int width, int height);
87 :     ;
88 :     ;------------------------------------------------------------------------------
89 :    
90 :     cglobal yv12_to_rgb24_mmx
91 :     yv12_to_rgb24_mmx:
92 :    
93 :     push ebx
94 :     push esi
95 :     push edi
96 :     push ebp
97 :    
98 :     ; local vars alloc
99 :     %define localsize 72
100 :     %define TEMP_Y1 esp
101 :     %define TEMP_Y2 esp + 8
102 :     %define TEMP_G1 esp + 16
103 :     %define TEMP_G2 esp + 24
104 :     %define TEMP_B1 esp + 32
105 :     %define TEMP_B2 esp + 40
106 :     %define y_dif esp + 48
107 :     %define dst_dif esp + 52
108 :     %define uv_dif esp + 56
109 :     %define height esp + 60
110 :     %define width_8 esp + 64
111 :     %define height_2 esp + 68
112 :     sub esp, localsize
113 :    
114 :    
115 :     mov eax, [esp + 52 + localsize] ; height -> eax
116 :     cmp eax, 0x00
117 :     jge near dont_flip ; flip?
118 :    
119 :     neg eax
120 :     mov [height], eax
121 :    
122 :     mov esi, [esp + 48 + localsize] ; width -> esi
123 :    
124 :     mov ebp, [esp + 40 + localsize] ; y_stride -> ebp
125 :     mov ebx, ebp
126 :     shl ebx, 1 ; 2 * y_stride -> ebx
127 :     neg ebx
128 :     sub ebx, esi ; y_dif -> eax
129 :    
130 :     mov [y_dif], ebx
131 :    
132 :     sub eax, 1 ; height - 1 -> eax
133 :     mul ebp ; (height - 1) * y_stride -> ebp
134 :     mov ecx, eax
135 :     mov eax, [esp + 28 + localsize] ; y_src -> eax
136 :     add eax, ecx ; y_src -> eax
137 :     mov ebx, eax
138 :     sub ebx, ebp ; y_src2 -> ebx
139 :    
140 :     mov ecx, [esp + 24 + localsize] ; dst_stride -> ecx
141 :     mov edx, ecx
142 :     add ecx, edx
143 :     shl edx, 2
144 :     add ecx, edx ; 6 * dst_stride -> ecx
145 :     mov edx, ecx
146 :     sub ecx, esi
147 :     shl esi, 1
148 :     sub ecx, esi ; 6 * dst_stride - 3 * width -> ecx
149 :    
150 :     mov [dst_dif], ecx
151 :    
152 :     mov esi, [esp + 20 + localsize] ; dst -> esi
153 :     mov edi, esi
154 :     shr edx, 1
155 :     add edi, edx ; dst2 -> edi
156 :    
157 :     mov ebp, [esp + 48 + localsize] ; width -> ebp
158 :     mov ecx, ebp ; width -> ecx
159 :     shr ecx, 1
160 :     shr ebp, 3 ; width / 8 -> ebp
161 :     mov [width_8], ebp
162 :    
163 :     mov ebp, [esp + 44 + localsize] ; uv_stride -> ebp
164 :     mov edx, ebp
165 :     neg edx
166 :     sub edx, ecx
167 :     mov [uv_dif], edx
168 :    
169 :     mov edx, ebp
170 :     mov ebp, eax
171 :     mov eax, [height] ; height -> eax
172 :     shr eax, 1 ; height / 2 -> eax
173 :    
174 :     mov ecx, [esp + 32 + localsize] ; u_src -> ecx
175 :     sub eax, 1
176 :     mul edx
177 :     add ecx, eax
178 :    
179 :     mov edx, [esp + 36 + localsize] ; v_src -> edx
180 :     add edx, eax
181 :    
182 :     mov eax, ebp
183 :    
184 :     mov ebp, [height] ; height -> ebp
185 :     shr ebp, 1 ; height / 2 -> ebp
186 :    
187 :     pxor mm7, mm7 ; clear mm7
188 :     jmp y_loop
189 :    
190 :    
191 :     dont_flip:
192 :     mov esi, [esp + 48 + localsize] ; width -> esi
193 :    
194 :     mov ebp, [esp + 40 + localsize] ; y_stride -> ebp
195 :     mov ebx, ebp
196 :     shl ebx, 1 ; 2 * y_stride -> ebx
197 :     sub ebx, esi ; y_dif -> ebx
198 :    
199 :     mov [y_dif], ebx
200 :    
201 :     mov eax, [esp + 28 + localsize] ; y_src -> eax
202 :     mov ebx, eax
203 :     add ebx, ebp ; y_src2 -> ebp
204 :    
205 :     mov ecx, [esp + 24 + localsize] ; dst_stride -> ecx
206 :     mov edx, ecx
207 :     add ecx, edx
208 :     shl edx, 2
209 :     add ecx, edx ; 6 * dst_stride -> ecx
210 :     mov edx, ecx
211 :     sub ecx, esi
212 :     shl esi, 1
213 :     sub ecx, esi ; 6 * dst_stride - 3 * width -> ecx
214 :    
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