1 |
;------------------------------------------------------------------------------ |
;/**************************************************************************** |
2 |
; |
; * |
3 |
; This file is part of XviD, a free MPEG-4 video encoder/decoder |
; * XVID MPEG-4 VIDEO CODEC |
4 |
; |
; * - MMX and XMM YV12->YV12 conversion - |
5 |
; This program is free software; you can redistribute it and/or modify it |
; * |
6 |
; under the terms of the GNU General Public License as published by |
; * Copyright(C) 2001 Michael Militzer <isibaar@xvid.org> |
7 |
; the Free Software Foundation; either version 2 of the License, or |
; * |
8 |
; (at your option) any later version. |
; * 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 |
; This program is distributed in the hope that it will be useful, but |
; * the Free Software Foundation; either version 2 of the License, or |
11 |
; WITHOUT ANY WARRANTY; without even the implied warranty of |
; * (at your option) any later version. |
12 |
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
; * |
13 |
; GNU General Public License for more details. |
; * This program is distributed in the hope that it will be useful, |
14 |
; |
; * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
; You should have received a copy of the GNU General Public License |
; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
; along with this program; if not, write to the Free Software |
; * GNU General Public License for more details. |
17 |
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
; * |
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 |
; yuv_to_yuv.asm, MMX optimized color conversion |
; * $Id: colorspace_yuv_mmx.asm,v 1.6 2006-10-30 10:52:00 Skal Exp $ |
23 |
; |
; * |
24 |
; Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org> |
; ***************************************************************************/ |
|
; |
|
|
; For more information visit the XviD homepage: http://www.xvid.org |
|
|
; |
|
|
;------------------------------------------------------------------------------ |
|
|
;------------------------------------------------------------------------------ |
|
|
; |
|
|
; Revision history: |
|
|
; |
|
|
; 24.11.2001 initial version (Isibaar) |
|
|
; 23.07.2002 thread safe (edgomez) |
|
|
; |
|
|
; $Id: colorspace_yuv_mmx.asm,v 1.2 2003-02-15 15:22:18 edgomez Exp $ |
|
|
; |
|
|
;------------------------------------------------------------------------------ |
|
25 |
|
|
26 |
BITS 32 |
BITS 32 |
27 |
|
|
28 |
%macro cglobal 1 |
%macro cglobal 1 |
29 |
%ifdef PREFIX |
%ifdef PREFIX |
30 |
|
%ifdef MARK_FUNCS |
31 |
|
global _%1:function %1.endfunc-%1 |
32 |
|
%define %1 _%1:function %1.endfunc-%1 |
33 |
|
%else |
34 |
global _%1 |
global _%1 |
35 |
%define %1 _%1 |
%define %1 _%1 |
36 |
|
%endif |
37 |
|
%else |
38 |
|
%ifdef MARK_FUNCS |
39 |
|
global %1:function %1.endfunc-%1 |
40 |
%else |
%else |
41 |
global %1 |
global %1 |
42 |
%endif |
%endif |
43 |
|
%endif |
44 |
%endmacro |
%endmacro |
45 |
|
|
46 |
SECTION .text |
;============================================================================= |
47 |
|
; Helper macros |
48 |
ALIGN 64 |
;============================================================================= |
49 |
|
|
50 |
;------------------------------------------------------------------------------ |
;------------------------------------------------------------------------------ |
51 |
; PLANE_COPY ( DST, DST_DIF, SRC, SRC_DIF, WIDTH, HEIGHT, OPT ) |
; PLANE_COPY ( DST, DST_STRIDE, SRC, SRC_STRIDE, WIDTH, HEIGHT, OPT ) |
52 |
; DST dst buffer |
; DST dst buffer |
53 |
; DST_DIF dst stride difference (e.g. stride - width) |
; DST_STRIDE dst stride |
54 |
; SRC src destination buffer |
; SRC src destination buffer |
55 |
; SRC_DIF src stride difference (e.g. stride - width) |
; SRC_STRIDE src stride |
56 |
; WIDTH width |
; WIDTH width |
57 |
; HEIGHT height |
; HEIGHT height |
58 |
; OPT 0=plain mmx, 1=xmm |
; OPT 0=plain mmx, 1=xmm |
59 |
;------------------------------------------------------------------------------ |
;------------------------------------------------------------------------------ |
60 |
|
|
61 |
%macro PLANE_COPY 7 |
%macro PLANE_COPY 7 |
62 |
%define DST %1 |
%define DST %1 |
63 |
%define DST_DIF %2 |
%define DST_STRIDE %2 |
64 |
%define SRC %3 |
%define SRC %3 |
65 |
%define SRC_DIF %4 |
%define SRC_STRIDE %4 |
66 |
%define WIDTH %5 |
%define WIDTH %5 |
67 |
%define HEIGHT %6 |
%define HEIGHT %6 |
68 |
%define OPT %7 |
%define OPT %7 |
76 |
shr eax, 6 ; $eax$ = width / 64 |
shr eax, 6 ; $eax$ = width / 64 |
77 |
and ebx, 63 ; remainder = width % 64 |
and ebx, 63 ; remainder = width % 64 |
78 |
mov edx, ebx |
mov edx, ebx |
79 |
shr ebx, 4 ; $ebx$ = reaminder / 16 |
shr ebx, 4 ; $ebx$ = remainder / 16 |
80 |
and edx, 15 ; $edx$ = remainder % 16 |
and edx, 15 ; $edx$ = remainder % 16 |
81 |
|
|
82 |
%%loop64_start |
%%loop64_start_pc: |
83 |
or eax, eax |
push edi |
84 |
jz %%loop16_start |
push esi |
85 |
mov ecx, eax ; width64 |
mov ecx, eax ; width64 |
86 |
%%loop64: |
test eax, eax |
87 |
|
jz %%loop16_start_pc |
88 |
|
|
89 |
|
%%loop64_pc: |
90 |
%if OPT == 1 ; xmm |
%if OPT == 1 ; xmm |
91 |
prefetchnta [esi + 64] ; non temporal prefetch |
prefetchnta [esi + 64] ; non temporal prefetch |
92 |
prefetchnta [esi + 96] |
prefetchnta [esi + 96] |
122 |
|
|
123 |
add esi, 64 |
add esi, 64 |
124 |
add edi, 64 |
add edi, 64 |
125 |
dec ecx |
loop %%loop64_pc |
|
jnz %%loop64 |
|
126 |
|
|
127 |
|
|
128 |
%%loop16_start |
%%loop16_start_pc: |
|
or ebx, ebx |
|
|
jz %%loop1_start |
|
129 |
mov ecx, ebx ; width16 |
mov ecx, ebx ; width16 |
130 |
%%loop16: |
test ebx, ebx |
131 |
|
jz %%loop1_start_pc |
132 |
|
|
133 |
|
%%loop16_pc: |
134 |
movq mm1, [esi] |
movq mm1, [esi] |
135 |
movq mm2, [esi + 8] |
movq mm2, [esi + 8] |
136 |
%if OPT == 0 ; plain mmx |
%if OPT == 0 ; plain mmx |
143 |
|
|
144 |
add esi, 16 |
add esi, 16 |
145 |
add edi, 16 |
add edi, 16 |
146 |
dec ecx |
loop %%loop16_pc |
|
jnz %%loop16 |
|
147 |
|
|
148 |
|
|
149 |
%%loop1_start |
%%loop1_start_pc: |
150 |
mov ecx, edx |
mov ecx, edx |
151 |
rep movsb |
rep movsb |
152 |
|
|
153 |
add esi, SRC_DIF |
pop esi |
154 |
add edi, DST_DIF |
pop edi |
155 |
|
add esi, SRC_STRIDE |
156 |
|
add edi, DST_STRIDE |
157 |
dec ebp |
dec ebp |
158 |
jnz near %%loop64_start |
jg near %%loop64_start_pc |
159 |
%endmacro |
%endmacro |
160 |
|
|
161 |
|
;------------------------------------------------------------------------------ |
162 |
|
; 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 |
; MAKE_YV12_TO_YV12( NAME, OPT ) |
; MAKE_YV12_TO_YV12( NAME, OPT ) |
260 |
%macro MAKE_YV12_TO_YV12 2 |
%macro MAKE_YV12_TO_YV12 2 |
261 |
%define NAME %1 |
%define NAME %1 |
262 |
%define OPT %2 |
%define OPT %2 |
263 |
align 16 |
ALIGN 16 |
264 |
cglobal NAME |
cglobal NAME |
265 |
NAME |
NAME: |
266 |
%define pushsize 16 |
%define pushsize 16 |
267 |
%define localsize 24 |
%define localsize 12 |
268 |
|
|
269 |
%define vflip esp + localsize + pushsize + 52 |
%define vflip esp + localsize + pushsize + 52 |
270 |
%define height esp + localsize + pushsize + 48 |
%define height esp + localsize + pushsize + 48 |
288 |
|
|
289 |
%define width2 esp + localsize - 4 |
%define width2 esp + localsize - 4 |
290 |
%define height2 esp + localsize - 8 |
%define height2 esp + localsize - 8 |
|
%define y_src_dif esp + localsize - 12 |
|
|
%define y_dst_dif esp + localsize - 16 |
|
|
%define uv_src_dif esp + localsize - 20 |
|
|
%define uv_dst_dif esp + localsize - 24 |
|
291 |
|
|
292 |
sub esp, localsize |
sub esp, localsize |
293 |
|
|
298 |
mov [width2], eax |
mov [width2], eax |
299 |
mov [height2], ebx |
mov [height2], ebx |
300 |
|
|
301 |
mov ebp, [vflip] |
mov eax, [vflip] |
302 |
or ebp, ebp |
test eax, eax |
303 |
jz near .dont_flip |
jz near .go |
304 |
|
|
305 |
; flipping support |
; flipping support |
306 |
mov eax, [height] |
mov eax, [height] |
307 |
mov esi, [y_src] |
mov esi, [y_src] |
308 |
mov edx, [y_src_stride] |
mov ecx, [y_src_stride] |
309 |
push edx |
sub eax, 1 |
310 |
mul edx |
imul eax, ecx |
|
pop edx |
|
311 |
add esi, eax ; y_src += (height-1) * y_src_stride |
add esi, eax ; y_src += (height-1) * y_src_stride |
312 |
neg edx |
neg ecx |
313 |
mov [y_src], esi |
mov [y_src], esi |
314 |
mov [y_src_stride], edx ; y_src_stride = -y_src_stride |
mov [y_src_stride], ecx ; y_src_stride = -y_src_stride |
315 |
|
|
316 |
mov eax, [height2] |
mov eax, [height2] |
317 |
mov esi, [u_src] |
mov esi, [u_src] |
318 |
mov edi, [v_src] |
mov edi, [v_src] |
319 |
mov edx, [uv_src_stride] |
mov ecx, [uv_src_stride] |
320 |
sub eax, 1 ; ebp = height2 - 1 |
test esi, esi |
321 |
push edx |
jz .go |
322 |
mul edx |
test edi, edi |
323 |
pop edx |
jz .go |
324 |
|
sub eax, 1 ; eax = height2 - 1 |
325 |
|
imul eax, ecx |
326 |
add esi, eax ; u_src += (height2-1) * uv_src_stride |
add esi, eax ; u_src += (height2-1) * uv_src_stride |
327 |
add edi, eax ; v_src += (height2-1) * uv_src_stride |
add edi, eax ; v_src += (height2-1) * uv_src_stride |
328 |
neg edx |
neg ecx |
329 |
mov [u_src], esi |
mov [u_src], esi |
330 |
mov [v_src], edi |
mov [v_src], edi |
331 |
mov [uv_src_stride], edx ; uv_src_stride = -uv_src_stride |
mov [uv_src_stride], ecx ; uv_src_stride = -uv_src_stride |
332 |
|
|
333 |
.dont_flip |
.go: |
334 |
|
|
335 |
mov eax, [y_src_stride] |
PLANE_COPY [y_dst], [y_dst_stride], [y_src], [y_src_stride], [width], [height], OPT |
336 |
mov ebx, [y_dst_stride] |
|
337 |
mov ecx, [uv_src_stride] |
mov eax, [u_src] |
338 |
mov edx, [uv_dst_stride] |
or eax, [v_src] |
339 |
sub eax, [width] |
jz near .UVFill_0x80 |
340 |
sub ebx, [width] |
PLANE_COPY [u_dst], [uv_dst_stride], [u_src], [uv_src_stride], [width2], [height2], OPT |
341 |
sub ecx, [width2] |
PLANE_COPY [v_dst], [uv_dst_stride], [v_src], [uv_src_stride], [width2], [height2], OPT |
|
sub edx, [width2] |
|
|
mov [y_src_dif], eax ; y_src_dif = y_src_stride - width |
|
|
mov [y_dst_dif], ebx ; y_dst_dif = y_dst_stride - width |
|
|
mov [uv_src_dif], ecx ; uv_src_dif = uv_src_stride - width2 |
|
|
mov [uv_dst_dif], edx ; uv_dst_dif = uv_dst_stride - width2 |
|
|
|
|
|
PLANE_COPY [y_dst], [y_dst_dif], [y_src], [y_src_dif], [width], [height], OPT |
|
|
PLANE_COPY [u_dst], [uv_dst_dif], [u_src], [uv_src_dif], [width2], [height2], OPT |
|
|
PLANE_COPY [v_dst], [uv_dst_dif], [v_src], [uv_src_dif], [width2], [height2], OPT |
|
342 |
|
|
343 |
|
.Done_UVPlane: |
344 |
add esp, localsize |
add esp, localsize |
345 |
pop ebp |
pop ebp |
346 |
pop edi |
pop edi |
347 |
pop esi |
pop esi |
348 |
pop ebx |
pop ebx |
|
|
|
349 |
ret |
ret |
350 |
|
|
351 |
|
.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 |
|
.endfunc |
356 |
%endmacro |
%endmacro |
|
;------------------------------------------------------------------------------ |
|
357 |
|
|
358 |
|
;============================================================================= |
359 |
|
; Code |
360 |
|
;============================================================================= |
361 |
|
|
362 |
|
SECTION .text |
363 |
|
|
364 |
MAKE_YV12_TO_YV12 yv12_to_yv12_mmx, 0 |
MAKE_YV12_TO_YV12 yv12_to_yv12_mmx, 0 |
365 |
|
|
366 |
MAKE_YV12_TO_YV12 yv12_to_yv12_xmm, 1 |
MAKE_YV12_TO_YV12 yv12_to_yv12_xmm, 1 |