2 * MMX optimized DSP utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
8 * This file is part of Libav.
10 * Libav is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * Libav is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with Libav; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "libavutil/cpu.h"
27 #include "libavutil/x86/asm.h"
28 #include "dsputil_x86.h"
29 #include "inline_asm.h"
33 /* Draw the edges of width 'w' of an image of size width, height
34 * this MMX version can only handle w == 8 || w == 16. */
35 void ff_draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
36 int w, int h, int sides)
38 uint8_t *ptr, *last_line;
41 last_line = buf + (height - 1) * wrap;
47 "movd (%0), %%mm0 \n\t"
48 "punpcklbw %%mm0, %%mm0 \n\t"
49 "punpcklwd %%mm0, %%mm0 \n\t"
50 "punpckldq %%mm0, %%mm0 \n\t"
51 "movq %%mm0, -8(%0) \n\t"
52 "movq -8(%0, %2), %%mm1 \n\t"
53 "punpckhbw %%mm1, %%mm1 \n\t"
54 "punpckhwd %%mm1, %%mm1 \n\t"
55 "punpckhdq %%mm1, %%mm1 \n\t"
56 "movq %%mm1, (%0, %2) \n\t"
61 : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
62 "r" (ptr + wrap * height));
66 "movd (%0), %%mm0 \n\t"
67 "punpcklbw %%mm0, %%mm0 \n\t"
68 "punpcklwd %%mm0, %%mm0 \n\t"
69 "punpckldq %%mm0, %%mm0 \n\t"
70 "movq %%mm0, -8(%0) \n\t"
71 "movq %%mm0, -16(%0) \n\t"
72 "movq -8(%0, %2), %%mm1 \n\t"
73 "punpckhbw %%mm1, %%mm1 \n\t"
74 "punpckhwd %%mm1, %%mm1 \n\t"
75 "punpckhdq %%mm1, %%mm1 \n\t"
76 "movq %%mm1, (%0, %2) \n\t"
77 "movq %%mm1, 8(%0, %2) \n\t"
82 : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
83 "r" (ptr + wrap * height));
86 /* top and bottom (and hopefully also the corners) */
87 if (sides & EDGE_TOP) {
88 for (i = 0; i < h; i += 4) {
89 ptr = buf - (i + 1) * wrap - w;
92 "movq (%1, %0), %%mm0 \n\t"
93 "movq %%mm0, (%0) \n\t"
94 "movq %%mm0, (%0, %2) \n\t"
95 "movq %%mm0, (%0, %2, 2) \n\t"
96 "movq %%mm0, (%0, %3) \n\t"
101 : "r" ((x86_reg) buf - (x86_reg) ptr - w),
102 "r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3),
103 "r" (ptr + width + 2 * w));
107 if (sides & EDGE_BOTTOM) {
108 for (i = 0; i < h; i += 4) {
109 ptr = last_line + (i + 1) * wrap - w;
112 "movq (%1, %0), %%mm0 \n\t"
113 "movq %%mm0, (%0) \n\t"
114 "movq %%mm0, (%0, %2) \n\t"
115 "movq %%mm0, (%0, %2, 2) \n\t"
116 "movq %%mm0, (%0, %3) \n\t"
121 : "r" ((x86_reg) last_line - (x86_reg) ptr - w),
122 "r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3),
123 "r" (ptr + width + 2 * w));
128 #endif /* HAVE_INLINE_ASM */