2 * MMX optimized DSP utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg 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 GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
26 #include "libavutil/avassert.h"
27 #include "libavutil/cpu.h"
28 #include "libavutil/x86/asm.h"
29 #include "libavcodec/pixels.h"
30 #include "libavcodec/videodsp.h"
31 #include "dsputil_x86.h"
32 #include "inline_asm.h"
36 /* Draw the edges of width 'w' of an image of size width, height
37 * this MMX version can only handle w == 8 || w == 16. */
38 void ff_draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
39 int w, int h, int sides)
41 uint8_t *ptr, *last_line;
44 last_line = buf + (height - 1) * wrap;
50 "movd (%0), %%mm0 \n\t"
51 "punpcklbw %%mm0, %%mm0 \n\t"
52 "punpcklwd %%mm0, %%mm0 \n\t"
53 "punpckldq %%mm0, %%mm0 \n\t"
54 "movq %%mm0, -8(%0) \n\t"
55 "movq -8(%0, %2), %%mm1 \n\t"
56 "punpckhbw %%mm1, %%mm1 \n\t"
57 "punpckhwd %%mm1, %%mm1 \n\t"
58 "punpckhdq %%mm1, %%mm1 \n\t"
59 "movq %%mm1, (%0, %2) \n\t"
64 : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
65 "r" (ptr + wrap * height));
69 "movd (%0), %%mm0 \n\t"
70 "punpcklbw %%mm0, %%mm0 \n\t"
71 "punpcklwd %%mm0, %%mm0 \n\t"
72 "punpckldq %%mm0, %%mm0 \n\t"
73 "movq %%mm0, -8(%0) \n\t"
74 "movq %%mm0, -16(%0) \n\t"
75 "movq -8(%0, %2), %%mm1 \n\t"
76 "punpckhbw %%mm1, %%mm1 \n\t"
77 "punpckhwd %%mm1, %%mm1 \n\t"
78 "punpckhdq %%mm1, %%mm1 \n\t"
79 "movq %%mm1, (%0, %2) \n\t"
80 "movq %%mm1, 8(%0, %2) \n\t"
85 : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
91 "movd (%0), %%mm0 \n\t"
92 "punpcklbw %%mm0, %%mm0 \n\t"
93 "punpcklwd %%mm0, %%mm0 \n\t"
94 "movd %%mm0, -4(%0) \n\t"
95 "movd -4(%0, %2), %%mm1 \n\t"
96 "punpcklbw %%mm1, %%mm1 \n\t"
97 "punpckhwd %%mm1, %%mm1 \n\t"
98 "punpckhdq %%mm1, %%mm1 \n\t"
99 "movd %%mm1, (%0, %2) \n\t"
104 : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
105 "r" (ptr + wrap * height));
108 /* top and bottom (and hopefully also the corners) */
109 if (sides & EDGE_TOP) {
110 for (i = 0; i < h; i += 4) {
111 ptr = buf - (i + 1) * wrap - w;
114 "movq (%1, %0), %%mm0 \n\t"
115 "movq %%mm0, (%0) \n\t"
116 "movq %%mm0, (%0, %2) \n\t"
117 "movq %%mm0, (%0, %2, 2) \n\t"
118 "movq %%mm0, (%0, %3) \n\t"
123 : "r" ((x86_reg) buf - (x86_reg) ptr - w),
124 "r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3),
125 "r" (ptr + width + 2 * w));
129 if (sides & EDGE_BOTTOM) {
130 for (i = 0; i < h; i += 4) {
131 ptr = last_line + (i + 1) * wrap - w;
134 "movq (%1, %0), %%mm0 \n\t"
135 "movq %%mm0, (%0) \n\t"
136 "movq %%mm0, (%0, %2) \n\t"
137 "movq %%mm0, (%0, %2, 2) \n\t"
138 "movq %%mm0, (%0, %3) \n\t"
143 : "r" ((x86_reg) last_line - (x86_reg) ptr - w),
144 "r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3),
145 "r" (ptr + width + 2 * w));
150 #endif /* HAVE_INLINE_ASM */