Parent Directory
|
Revision Log
Revision 582 - (view) (download)
1 : | edgomez | 332 | ;------------------------------------------------------------------------------ |
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_rgb32.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_rgb32_mmx.asm,v 1.2.2.1 2002-10-06 07:05:51 suxen_drol Exp $ |
37 : | edgomez | 332 | ; |
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_rgb32_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_rgb32_mmx | ||
97 : | yv12_to_rgb32_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 : | ; function code | ||
121 : | mov eax, [esp + 52 + localsize] ; height -> eax | ||
122 : | cmp eax, 0x00 | ||
123 : | jge near dont_flip ; flip? | ||
124 : | |||
125 : | neg eax ; neg height | ||
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 : | mov edx, ecx | ||
148 : | suxen_drol | 582 | shl edx, 1 |
149 : | mov ecx, edx ; 2 * dst_stride -> ecx | ||
150 : | edgomez | 332 | shl esi, 2 |
151 : | suxen_drol | 582 | sub ecx, esi ; 2 * dst_stride - 4 * width -> ecx |
152 : | edgomez | 332 | |
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 | ||
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 -> edx | ||
211 : | edgomez | 332 | shl esi, 2 |
212 : | suxen_drol | 582 | sub ecx, esi ; 2 * dst_stride - 4 * width -> ecx |
213 : | edgomez | 332 | |
214 : | mov [dst_dif], ecx | ||
215 : | |||
216 : | mov esi, [esp + 20 + localsize] ; dst -> esi | ||
217 : | mov edi, esi | ||
218 : | shr edx, 1 | ||
219 : | add edi, edx ; dst2 -> edi | ||
220 : | |||
221 : | mov ebp, [esp + 48 + localsize] ; width -> ebp | ||
222 : | mov ecx, ebp ; width -> ecx | ||
223 : | shr ecx, 1 | ||
224 : | shr ebp, 3 ; width / 8 -> ebp | ||
225 : | mov [width_8], ebp | ||
226 : | |||
227 : | mov ebp, [esp + 44 + localsize] ; uv_stride -> ebp | ||
228 : | sub ebp, ecx | ||
229 : | mov [uv_dif], ebp | ||
230 : | |||
231 : | mov ecx, [esp + 32 + localsize] ; u_src -> ecx | ||
232 : | mov edx, [esp + 36 + localsize] ; v_src -> edx | ||
233 : | |||
234 : | mov ebp, [esp + 52 + localsize] ; height -> ebp | ||
235 : | shr ebp, 1 ; height / 2 -> ebp | ||
236 : | |||
237 : | pxor mm7, mm7 | ||
238 : | |||
239 : | y_loop: | ||
240 : | mov [height_2], ebp | ||
241 : | mov ebp, [width_8] | ||
242 : | |||
243 : | x_loop: | ||
244 : | movd mm2, [ecx] | ||
245 : | movd mm3, [edx] | ||
246 : | |||
247 : | punpcklbw mm2, mm7 ; u3u2u1u0 -> mm2 | ||
248 : | punpcklbw mm3, mm7 ; v3v2v1v0 -> mm3 | ||
249 : | |||
250 : | psubsw mm2, [U_SUB] ; U - 128 | ||
251 : | psubsw mm3, [V_SUB] ; V - 128 | ||
252 : | |||
253 : | movq mm4, mm2 | ||
254 : | movq mm5, mm3 | ||
255 : | |||
256 : | pmullw mm2, [UG_MUL] | ||
257 : | pmullw mm3, [VG_MUL] | ||
258 : | |||
259 : | movq mm6, mm2 ; u3u2u1u0 -> mm6 | ||
260 : | punpckhwd mm2, mm2 ; u3u3u2u2 -> mm2 | ||
261 : | punpcklwd mm6, mm6 ; u1u1u0u0 -> mm6 | ||
262 : | |||
263 : | pmullw mm4, [UB_MUL] ; B_ADD -> mm4 | ||
264 : | |||
265 : | movq mm0, mm3 | ||
266 : | punpckhwd mm3, mm3 ; v3v3v2v2 -> mm2 | ||
267 : | punpcklwd mm0, mm0 ; v1v1v0v0 -> mm6 | ||
268 : | |||
269 : | paddsw mm2, mm3 | ||
270 : | paddsw mm6, mm0 | ||
271 : | |||
272 : | pmullw mm5, [VR_MUL] ; R_ADD -> mm5 | ||
273 : | |||
274 : | movq mm0, [eax] ; y7y6y5y4y3y2y1y0 -> mm0 | ||
275 : | |||
276 : | movq mm1, mm0 | ||
277 : | punpckhbw mm1, mm7 ; y7y6y5y4 -> mm1 | ||
278 : | punpcklbw mm0, mm7 ; y3y2y1y0 -> mm0 | ||
279 : | |||
280 : | psubsw mm0, [Y_SUB] ; Y - Y_SUB | ||
281 : | psubsw mm1, [Y_SUB] ; Y - Y_SUB | ||
282 : | |||
283 : | pmullw mm1, [Y_MUL] | ||
284 : | pmullw mm0, [Y_MUL] | ||
285 : | |||
286 : | movq [TEMP_Y2], mm1 ; y7y6y5y4 -> mm3 | ||
287 : | movq [TEMP_Y1], mm0 ; y3y2y1y0 -> mm7 | ||
288 : | |||
289 : | psubsw mm1, mm2 ; g7g6g5g4 -> mm1 | ||
290 : | psubsw mm0, mm6 ; g3g2g1g0 -> mm0 | ||
291 : | |||
292 : | psraw mm1, SCALEBITS | ||
293 : | psraw mm0, SCALEBITS | ||
294 : | |||
295 : | packuswb mm0, mm1 ;g7g6g5g4g3g2g1g0 -> mm0 | ||
296 : | |||
297 : | movq [TEMP_G1], mm0 | ||
298 : | |||
299 : | movq mm0, [ebx] ; y7y6y5y4y3y2y1y0 -> mm0 | ||
300 : | |||
301 : | movq mm1, mm0 | ||
302 : | |||
303 : | punpckhbw mm1, mm7 ; y7y6y5y4 -> mm1 | ||
304 : | punpcklbw mm0, mm7 ; y3y2y1y0 -> mm0 | ||
305 : | |||
306 : | psubsw mm0, [Y_SUB] ; Y - Y_SUB | ||
307 : | psubsw mm1, [Y_SUB] ; Y - Y_SUB | ||
308 : | |||
309 : | pmullw mm1, [Y_MUL] | ||
310 : | pmullw mm0, [Y_MUL] | ||
311 : | |||
312 : | movq mm3, mm1 | ||
313 : | psubsw mm1, mm2 ; g7g6g5g4 -> mm1 | ||
314 : | |||
315 : | movq mm2, mm0 | ||
316 : | psubsw mm0, mm6 ; g3g2g1g0 -> mm0 | ||
317 : | |||
318 : | psraw mm1, SCALEBITS | ||
319 : | psraw mm0, SCALEBITS | ||
320 : | |||
321 : | packuswb mm0, mm1 ; g7g6g5g4g3g2g1g0 -> mm0 | ||
322 : | |||
323 : | movq [TEMP_G2], mm0 | ||
324 : | |||
325 : | movq mm0, mm4 | ||
326 : | punpckhwd mm4, mm4 ; u3u3u2u2 -> mm2 | ||
327 : | punpcklwd mm0, mm0 ; u1u1u0u0 -> mm6 | ||
328 : | |||
329 : | movq mm1, mm3 ; y7y6y5y4 -> mm1 | ||
330 : | paddsw mm3, mm4 ; b7b6b5b4 -> mm3 | ||
331 : | |||
332 : | movq mm7, mm2 ; y3y2y1y0 -> mm7 | ||
333 : | |||
334 : | paddsw mm2, mm0 ; b3b2b1b0 -> mm2 | ||
335 : | |||
336 : | psraw mm3, SCALEBITS | ||
337 : | psraw mm2, SCALEBITS | ||
338 : | |||
339 : | packuswb mm2, mm3 ; b7b6b5b4b3b2b1b0 -> mm2 | ||
340 : | |||
341 : | movq [TEMP_B2], mm2 | ||
342 : | |||
343 : | movq mm3, [TEMP_Y2] | ||
344 : | movq mm2, [TEMP_Y1] | ||
345 : | |||
346 : | movq mm6, mm3 ; TEMP_Y2 -> mm6 | ||
347 : | paddsw mm3, mm4 ; b7b6b5b4 -> mm3 | ||
348 : | |||
349 : | movq mm4, mm2 ; TEMP_Y1 -> mm4 | ||
350 : | paddsw mm2, mm0 ; b3b2b1b0 -> mm2 | ||
351 : | |||
352 : | psraw mm3, SCALEBITS | ||
353 : | psraw mm2, SCALEBITS | ||
354 : | |||
355 : | packuswb mm2, mm3 ; b7b6b5b4b3b2b1b0 -> mm2 | ||
356 : | |||
357 : | movq [TEMP_B1], mm2 | ||
358 : | |||
359 : | movq mm0, mm5 | ||
360 : | punpckhwd mm5, mm5 ; v3v3v2v2 -> mm5 | ||
361 : | punpcklwd mm0, mm0 ; v1v1v0v0 -> mm0 | ||
362 : | |||
363 : | paddsw mm1, mm5 ; r7r6r5r4 -> mm1 | ||
364 : | paddsw mm7, mm0 ; r3r2r1r0 -> mm7 | ||
365 : | |||
366 : | psraw mm1, SCALEBITS | ||
367 : | psraw mm7, SCALEBITS | ||
368 : | |||
369 : | packuswb mm7, mm1 ; r7r6r5r4r3r2r1r0 -> mm7 (TEMP_R2) | ||
370 : | |||
371 : | paddsw mm6, mm5 ; r7r6r5r4 -> mm6 | ||
372 : | paddsw mm4, mm0 ; r3r2r1r0 -> mm4 | ||
373 : | |||
374 : | psraw mm6, SCALEBITS | ||
375 : | psraw mm4, SCALEBITS | ||
376 : | |||
377 : | packuswb mm4, mm6 ; r7r6r5r4r3r2r1r0 -> mm4 (TEMP_R1) | ||
378 : | |||
379 : | movq mm0, [TEMP_B1] | ||
380 : | movq mm1, [TEMP_G1] | ||
381 : | |||
382 : | movq mm6, mm7 | ||
383 : | |||
384 : | movq mm2, mm0 | ||
385 : | punpcklbw mm2, mm4 ; r3b3r2b2r1b1r0b0 -> mm2 | ||
386 : | punpckhbw mm0, mm4 ; r7b7r6b6r5b5r4b4 -> mm0 | ||
387 : | |||
388 : | pxor mm7, mm7 | ||
389 : | |||
390 : | movq mm3, mm1 | ||
391 : | punpcklbw mm1, mm7 ; 0g30g20g10g0 -> mm1 | ||
392 : | punpckhbw mm3, mm7 ; 0g70g60g50g4 -> mm3 | ||
393 : | |||
394 : | movq mm4, mm2 | ||
395 : | punpcklbw mm2, mm1 ; 0r1g1b10r0g0b0 -> mm2 | ||
396 : | punpckhbw mm4, mm1 ; 0r3g3b30r2g2b2 -> mm4 | ||
397 : | |||
398 : | movq mm5, mm0 | ||
399 : | punpcklbw mm0, mm3 ; 0r5g5b50r4g4b4 -> mm0 | ||
400 : | punpckhbw mm5, mm3 ; 0r7g7b70r6g6b6 -> mm5 | ||
401 : | |||
402 : | movq [esi], mm2 | ||
403 : | movq [esi + 8], mm4 | ||
404 : | movq [esi + 16], mm0 | ||
405 : | movq [esi + 24], mm5 | ||
406 : | |||
407 : | movq mm0, [TEMP_B2] | ||
408 : | movq mm1, [TEMP_G2] | ||
409 : | |||
410 : | movq mm2, mm0 | ||
411 : | punpcklbw mm2, mm6 ; r3b3r2b2r1b1r0b0 -> mm2 | ||
412 : | punpckhbw mm0, mm6 ; r7b7r6b6r5b5r4b4 -> mm0 | ||
413 : | |||
414 : | movq mm3, mm1 | ||
415 : | punpcklbw mm1, mm7 ; 0g30g20g10g0 -> mm1 | ||
416 : | punpckhbw mm3, mm7 ; 0g70g60g50g4 -> mm3 | ||
417 : | |||
418 : | movq mm4, mm2 | ||
419 : | punpcklbw mm2, mm1 ; 0r1g1b10r0g0b0 -> mm2 | ||
420 : | punpckhbw mm4, mm1 ; 0r3g3b30r2g2b2 -> mm4 | ||
421 : | |||
422 : | movq mm5, mm0 | ||
423 : | punpcklbw mm0, mm3 ; 0r5g5b50r4g4b4 -> mm0 | ||
424 : | punpckhbw mm5, mm3 ; 0r7g7b70r6g6b6 -> mm5 | ||
425 : | |||
426 : | movq [edi], mm2 | ||
427 : | movq [edi + 8], mm4 | ||
428 : | movq [edi + 16], mm0 | ||
429 : | movq [edi + 24], mm5 | ||
430 : | |||
431 : | add esi, 32 | ||
432 : | add edi, 32 | ||
433 : | |||
434 : | add eax, 8 | ||
435 : | add ebx, 8 | ||
436 : | add ecx, 4 | ||
437 : | add edx, 4 | ||
438 : | |||
439 : | dec ebp | ||
440 : | |||
441 : | jnz near x_loop | ||
442 : | |||
443 : | add esi, [dst_dif] | ||
444 : | add edi, [dst_dif] | ||
445 : | |||
446 : | add eax, [y_dif] | ||
447 : | add ebx, [y_dif] | ||
448 : | |||
449 : | add ecx, [uv_dif] | ||
450 : | add edx, [uv_dif] | ||
451 : | |||
452 : | mov ebp, [height_2] | ||
453 : | dec ebp | ||
454 : | jnz near y_loop | ||
455 : | |||
456 : | emms | ||
457 : | |||
458 : | ;; Local vars deallocation | ||
459 : | add esp, localsize | ||
460 : | %undef TEMP_Y1 | ||
461 : | %undef TEMP_Y2 | ||
462 : | %undef TEMP_G1 | ||
463 : | %undef TEMP_G2 | ||
464 : | %undef TEMP_B1 | ||
465 : | %undef TEMP_B2 | ||
466 : | %undef y_dif | ||
467 : | %undef dst_dif | ||
468 : | %undef uv_dif | ||
469 : | %undef height | ||
470 : | %undef width_8 | ||
471 : | %undef height_2 | ||
472 : | %undef localsize | ||
473 : | |||
474 : | pop ebp | ||
475 : | pop edi | ||
476 : | pop esi | ||
477 : | pop ebx | ||
478 : | |||
479 : | ret |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |