]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/dsputil_mmx.c
dsputil: Split off IDCT bits into their own context
[ffmpeg] / libavcodec / x86 / dsputil_mmx.c
1 /*
2  * MMX optimized DSP utils
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
7  *
8  * This file is part of Libav.
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include "config.h"
26 #include "libavutil/cpu.h"
27 #include "libavutil/x86/asm.h"
28 #include "dsputil_x86.h"
29 #include "inline_asm.h"
30
31 #if HAVE_INLINE_ASM
32
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)
37 {
38     uint8_t *ptr, *last_line;
39     int i;
40
41     last_line = buf + (height - 1) * wrap;
42     /* left and right */
43     ptr = buf;
44     if (w == 8) {
45         __asm__ volatile (
46             "1:                             \n\t"
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"
57             "add               %1, %0       \n\t"
58             "cmp               %3, %0       \n\t"
59             "jb                1b           \n\t"
60             : "+r" (ptr)
61             : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
62               "r" (ptr + wrap * height));
63     } else {
64         __asm__ volatile (
65             "1:                                 \n\t"
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"
78             "add               %1, %0           \n\t"
79             "cmp               %3, %0           \n\t"
80             "jb                1b               \n\t"
81             : "+r" (ptr)
82             : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
83               "r" (ptr + wrap * height));
84     }
85
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;
90             __asm__ volatile (
91                 "1:                             \n\t"
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"
97                 "add        $8, %0              \n\t"
98                 "cmp        %4, %0              \n\t"
99                 "jb         1b                  \n\t"
100                 : "+r" (ptr)
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));
104         }
105     }
106
107     if (sides & EDGE_BOTTOM) {
108         for (i = 0; i < h; i += 4) {
109             ptr = last_line + (i + 1) * wrap - w;
110             __asm__ volatile (
111                 "1:                             \n\t"
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"
117                 "add        $8, %0              \n\t"
118                 "cmp        %4, %0              \n\t"
119                 "jb         1b                  \n\t"
120                 : "+r" (ptr)
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));
124         }
125     }
126 }
127
128 #endif /* HAVE_INLINE_ASM */