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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1742 - (view) (download)

1 : edgomez 1382 ;/****************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * - MMX and XMM YV12->YV12 conversion -
5 :     ; *
6 :     ; * Copyright(C) 2001 Michael Militzer <isibaar@xvid.org>
7 :     ; *
8 :     ; * This program is free software; you can redistribute it and/or modify it
9 :     ; * under the terms of the GNU General Public License as published by
10 :     ; * the Free Software Foundation; either version 2 of the License, or
11 :     ; * (at your option) any later version.
12 :     ; *
13 :     ; * This program is distributed in the hope that it will be useful,
14 :     ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     ; * GNU General Public License for more details.
17 :     ; *
18 :     ; * You should have received a copy of the GNU General Public License
19 :     ; * along with this program; if not, write to the Free Software
20 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 :     ; *
22 : Skal 1742 ; * $Id: colorspace_yuv_mmx.asm,v 1.6 2006-10-30 10:52:00 Skal Exp $
23 : edgomez 1382 ; *
24 :     ; ***************************************************************************/
25 : edgomez 851
26 :     BITS 32
27 :    
28 : edgomez 1382 %macro cglobal 1
29 : edgomez 1535 %ifdef PREFIX
30 :     %ifdef MARK_FUNCS
31 : edgomez 1540 global _%1:function %1.endfunc-%1
32 :     %define %1 _%1:function %1.endfunc-%1
33 : edgomez 1535 %else
34 :     global _%1
35 :     %define %1 _%1
36 :     %endif
37 : edgomez 851 %else
38 : edgomez 1535 %ifdef MARK_FUNCS
39 : edgomez 1540 global %1:function %1.endfunc-%1
40 : edgomez 1535 %else
41 :     global %1
42 :     %endif
43 : edgomez 851 %endif
44 :     %endmacro
45 :    
46 : edgomez 1382 ;=============================================================================
47 :     ; Helper macros
48 :     ;=============================================================================
49 : edgomez 851
50 :     ;------------------------------------------------------------------------------
51 : Skal 1742 ; PLANE_COPY ( DST, DST_STRIDE, SRC, SRC_STRIDE, WIDTH, HEIGHT, OPT )
52 : edgomez 851 ; DST dst buffer
53 : Skal 1742 ; DST_STRIDE dst stride
54 : edgomez 851 ; SRC src destination buffer
55 : Skal 1742 ; SRC_STRIDE src stride
56 : edgomez 851 ; WIDTH width
57 :     ; HEIGHT height
58 :     ; OPT 0=plain mmx, 1=xmm
59 :     ;------------------------------------------------------------------------------
60 : edgomez 1382
61 : edgomez 851 %macro PLANE_COPY 7
62 : Skal 1742 %define DST %1
63 :     %define DST_STRIDE %2
64 :     %define SRC %3
65 :     %define SRC_STRIDE %4
66 : edgomez 851 %define WIDTH %5
67 :     %define HEIGHT %6
68 : Skal 1742 %define OPT %7
69 : edgomez 851
70 : edgomez 1382 mov eax, WIDTH
71 :     mov ebp, HEIGHT ; $ebp$ = height
72 :     mov esi, SRC
73 :     mov edi, DST
74 : edgomez 851
75 : edgomez 1382 mov ebx, eax
76 :     shr eax, 6 ; $eax$ = width / 64
77 :     and ebx, 63 ; remainder = width % 64
78 :     mov edx, ebx
79 :     shr ebx, 4 ; $ebx$ = remainder / 16
80 :     and edx, 15 ; $edx$ = remainder % 16
81 : edgomez 851
82 : Skal 1742 %%loop64_start_pc:
83 :     push edi
84 :     push esi
85 :     mov ecx, eax ; width64
86 :     test eax, eax
87 :     jz %%loop16_start_pc
88 :    
89 :     %%loop64_pc:
90 : edgomez 1382 %if OPT == 1 ; xmm
91 :     prefetchnta [esi + 64] ; non temporal prefetch
92 :     prefetchnta [esi + 96]
93 : edgomez 851 %endif
94 : Skal 1742 movq mm1, [esi ] ; read from src
95 :     movq mm2, [esi + 8]
96 : edgomez 1382 movq mm3, [esi + 16]
97 :     movq mm4, [esi + 24]
98 :     movq mm5, [esi + 32]
99 :     movq mm6, [esi + 40]
100 :     movq mm7, [esi + 48]
101 :     movq mm0, [esi + 56]
102 : edgomez 851
103 : edgomez 1382 %if OPT == 0 ; plain mmx
104 : Skal 1742 movq [edi ], mm1 ; write to y_out
105 :     movq [edi + 8], mm2
106 : edgomez 1382 movq [edi + 16], mm3
107 :     movq [edi + 24], mm4
108 :     movq [edi + 32], mm5
109 :     movq [edi + 40], mm6
110 :     movq [edi + 48], mm7
111 :     movq [edi + 56], mm0
112 : edgomez 851 %else
113 : Skal 1742 movntq [edi ], mm1 ; write to y_out
114 :     movntq [edi + 8], mm2
115 : edgomez 1382 movntq [edi + 16], mm3
116 :     movntq [edi + 24], mm4
117 :     movntq [edi + 32], mm5
118 :     movntq [edi + 40], mm6
119 :     movntq [edi + 48], mm7
120 :     movntq [edi + 56], mm0
121 : edgomez 851 %endif
122 :    
123 : edgomez 1382 add esi, 64
124 :     add edi, 64
125 : Skal 1742 loop %%loop64_pc
126 : edgomez 851
127 :    
128 : Skal 1742 %%loop16_start_pc:
129 :     mov ecx, ebx ; width16
130 :     test ebx, ebx
131 :     jz %%loop1_start_pc
132 :    
133 :     %%loop16_pc:
134 : edgomez 1382 movq mm1, [esi]
135 :     movq mm2, [esi + 8]
136 :     %if OPT == 0 ; plain mmx
137 :     movq [edi], mm1
138 :     movq [edi + 8], mm2
139 : edgomez 851 %else
140 : edgomez 1382 movntq [edi], mm1
141 :     movntq [edi + 8], mm2
142 : edgomez 851 %endif
143 :    
144 : edgomez 1382 add esi, 16
145 :     add edi, 16
146 : Skal 1742 loop %%loop16_pc
147 : edgomez 851
148 :    
149 : Skal 1742 %%loop1_start_pc:
150 : edgomez 1382 mov ecx, edx
151 :     rep movsb
152 : edgomez 851
153 : Skal 1742 pop esi
154 :     pop edi
155 :     add esi, SRC_STRIDE
156 :     add edi, DST_STRIDE
157 : edgomez 1382 dec ebp
158 : Skal 1742 jg near %%loop64_start_pc
159 : edgomez 851 %endmacro
160 :    
161 :     ;------------------------------------------------------------------------------
162 : Skal 1742 ; PLANE_FILL ( DST, DST_STRIDE, WIDTH, HEIGHT, OPT )
163 :     ; DST dst buffer
164 :     ; DST_STRIDE dst stride
165 :     ; WIDTH width
166 :     ; HEIGHT height
167 :     ; OPT 0=plain mmx, 1=xmm
168 :     ;------------------------------------------------------------------------------
169 :    
170 :     %macro PLANE_FILL 5
171 :     %define DST %1
172 :     %define DST_STRIDE %2
173 :     %define WIDTH %3
174 :     %define HEIGHT %4
175 :     %define OPT %5
176 :    
177 :     mov esi, WIDTH
178 :     mov ebp, HEIGHT ; $ebp$ = height
179 :     mov edi, DST
180 :    
181 :     mov eax, 0x80808080
182 :     mov ebx, esi
183 :     shr esi, 6 ; $esi$ = width / 64
184 :     and ebx, 63 ; ebx = remainder = width % 64
185 :     movd mm0, eax
186 :     mov edx, ebx
187 :     shr ebx, 4 ; $ebx$ = remainder / 16
188 :     and edx, 15 ; $edx$ = remainder % 16
189 :     punpckldq mm0, mm0
190 :    
191 :     %%loop64_start_pf:
192 :     push edi
193 :     mov ecx, esi ; width64
194 :     test esi, esi
195 :     jz %%loop16_start_pf
196 :    
197 :     %%loop64_pf:
198 :    
199 :     %if OPT == 0 ; plain mmx
200 :     movq [edi ], mm0 ; write to y_out
201 :     movq [edi + 8], mm0
202 :     movq [edi + 16], mm0
203 :     movq [edi + 24], mm0
204 :     movq [edi + 32], mm0
205 :     movq [edi + 40], mm0
206 :     movq [edi + 48], mm0
207 :     movq [edi + 56], mm0
208 :     %else
209 :     movntq [edi ], mm0 ; write to y_out
210 :     movntq [edi + 8], mm0
211 :     movntq [edi + 16], mm0
212 :     movntq [edi + 24], mm0
213 :     movntq [edi + 32], mm0
214 :     movntq [edi + 40], mm0
215 :     movntq [edi + 48], mm0
216 :     movntq [edi + 56], mm0
217 :     %endif
218 :    
219 :     add edi, 64
220 :     loop %%loop64_pf
221 :    
222 :     %%loop16_start_pf:
223 :     mov ecx, ebx ; width16
224 :     test ebx, ebx
225 :     jz %%loop1_start_pf
226 :    
227 :     %%loop16_pf:
228 :     %if OPT == 0 ; plain mmx
229 :     movq [edi ], mm0
230 :     movq [edi + 8], mm0
231 :     %else
232 :     movntq [edi ], mm0
233 :     movntq [edi + 8], mm0
234 :     %endif
235 :    
236 :     add edi, 16
237 :     loop %%loop16_pf
238 :    
239 :     %%loop1_start_pf:
240 :     mov ecx, edx
241 :     rep stosb
242 :    
243 :     pop edi
244 :     add edi, DST_STRIDE
245 :     dec ebp
246 :     jg near %%loop64_start_pf
247 :     %endmacro
248 :    
249 :     ;------------------------------------------------------------------------------
250 : edgomez 851 ; MAKE_YV12_TO_YV12( NAME, OPT )
251 :     ; NAME function name
252 :     ; OPT 0=plain mmx, 1=xmm
253 :     ;
254 : edgomez 1382 ; yv12_to_yv12_mmx(uint8_t * y_dst, uint8_t * u_dst, uint8_t * v_dst,
255 : edgomez 851 ; int y_dst_stride, int uv_dst_stride,
256 : edgomez 1382 ; uint8_t * y_src, uint8_t * u_src, uint8_t * v_src,
257 : edgomez 851 ; int y_src_stride, int uv_src_stride,
258 :     ; int width, int height, int vflip)
259 :     ;------------------------------------------------------------------------------
260 :     %macro MAKE_YV12_TO_YV12 2
261 :     %define NAME %1
262 : Skal 1742 %define OPT %2
263 : edgomez 1382 ALIGN 16
264 : edgomez 851 cglobal NAME
265 : edgomez 1382 NAME:
266 : edgomez 851 %define pushsize 16
267 : Skal 1742 %define localsize 12
268 : edgomez 851
269 : Skal 1742 %define vflip esp + localsize + pushsize + 52
270 :     %define height esp + localsize + pushsize + 48
271 : edgomez 851 %define width esp + localsize + pushsize + 44
272 :     %define uv_src_stride esp + localsize + pushsize + 40
273 :     %define y_src_stride esp + localsize + pushsize + 36
274 : Skal 1742 %define v_src esp + localsize + pushsize + 32
275 :     %define u_src esp + localsize + pushsize + 28
276 :     %define y_src esp + localsize + pushsize + 24
277 : edgomez 851 %define uv_dst_stride esp + localsize + pushsize + 20
278 :     %define y_dst_stride esp + localsize + pushsize + 16
279 : Skal 1742 %define v_dst esp + localsize + pushsize + 12
280 :     %define u_dst esp + localsize + pushsize + 8
281 :     %define y_dst esp + localsize + pushsize + 4
282 :     %define _ip esp + localsize + pushsize + 0
283 : edgomez 851
284 : edgomez 1382 push ebx ; esp + localsize + 16
285 :     push esi ; esp + localsize + 8
286 :     push edi ; esp + localsize + 4
287 :     push ebp ; esp + localsize + 0
288 : edgomez 851
289 :     %define width2 esp + localsize - 4
290 :     %define height2 esp + localsize - 8
291 :    
292 : edgomez 1382 sub esp, localsize
293 : edgomez 851
294 : edgomez 1382 mov eax, [width]
295 :     mov ebx, [height]
296 :     shr eax, 1 ; calculate widht/2, heigh/2
297 :     shr ebx, 1
298 :     mov [width2], eax
299 :     mov [height2], ebx
300 : edgomez 851
301 : Skal 1742 mov eax, [vflip]
302 :     test eax, eax
303 :     jz near .go
304 : edgomez 851
305 : Skal 1742 ; flipping support
306 : edgomez 1382 mov eax, [height]
307 :     mov esi, [y_src]
308 : Skal 1742 mov ecx, [y_src_stride]
309 :     sub eax, 1
310 :     imul eax, ecx
311 : edgomez 1382 add esi, eax ; y_src += (height-1) * y_src_stride
312 : Skal 1742 neg ecx
313 : edgomez 1382 mov [y_src], esi
314 : Skal 1742 mov [y_src_stride], ecx ; y_src_stride = -y_src_stride
315 : edgomez 851
316 : edgomez 1382 mov eax, [height2]
317 :     mov esi, [u_src]
318 :     mov edi, [v_src]
319 : Skal 1742 mov ecx, [uv_src_stride]
320 :     test esi, esi
321 :     jz .go
322 :     test edi, edi
323 :     jz .go
324 :     sub eax, 1 ; eax = height2 - 1
325 :     imul eax, ecx
326 : edgomez 1382 add esi, eax ; u_src += (height2-1) * uv_src_stride
327 :     add edi, eax ; v_src += (height2-1) * uv_src_stride
328 : Skal 1742 neg ecx
329 : edgomez 1382 mov [u_src], esi
330 :     mov [v_src], edi
331 : Skal 1742 mov [uv_src_stride], ecx ; uv_src_stride = -uv_src_stride
332 : edgomez 851
333 : Skal 1742 .go:
334 : edgomez 851
335 : Skal 1742 PLANE_COPY [y_dst], [y_dst_stride], [y_src], [y_src_stride], [width], [height], OPT
336 : edgomez 851
337 : Skal 1742 mov eax, [u_src]
338 :     or eax, [v_src]
339 :     jz near .UVFill_0x80
340 :     PLANE_COPY [u_dst], [uv_dst_stride], [u_src], [uv_src_stride], [width2], [height2], OPT
341 :     PLANE_COPY [v_dst], [uv_dst_stride], [v_src], [uv_src_stride], [width2], [height2], OPT
342 : edgomez 851
343 : Skal 1742 .Done_UVPlane:
344 : edgomez 1382 add esp, localsize
345 :     pop ebp
346 :     pop edi
347 :     pop esi
348 :     pop ebx
349 : Skal 1742 ret
350 : edgomez 851
351 : Skal 1742 .UVFill_0x80:
352 :     PLANE_FILL [u_dst], [uv_dst_stride], [width2], [height2], OPT
353 :     PLANE_FILL [v_dst], [uv_dst_stride], [width2], [height2], OPT
354 :     jmp near .Done_UVPlane
355 : edgomez 1540 .endfunc
356 : edgomez 851 %endmacro
357 :    
358 : edgomez 1382 ;=============================================================================
359 :     ; Code
360 :     ;=============================================================================
361 : edgomez 851
362 : edgomez 1382 SECTION .text
363 :    
364 : edgomez 851 MAKE_YV12_TO_YV12 yv12_to_yv12_mmx, 0
365 : edgomez 1382
366 : edgomez 851 MAKE_YV12_TO_YV12 yv12_to_yv12_xmm, 1

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