FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fpel_mmx.c
Go to the documentation of this file.
1 /*
2  * MMX-optimized avg/put pixel routines
3  *
4  * Copyright (c) 2000, 2001 Fabrice Bellard
5  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #include "config.h"
28 #include "fpel.h"
29 #include "inline_asm.h"
30 
31 #if HAVE_MMX_INLINE
32 
33 // in case more speed is needed - unrolling would certainly help
34 void ff_avg_pixels8_mmx(uint8_t *block, const uint8_t *pixels,
35  ptrdiff_t line_size, int h)
36 {
37  MOVQ_BFE(mm6);
38  JUMPALIGN();
39  do {
40  __asm__ volatile(
41  "movq %0, %%mm0 \n\t"
42  "movq %1, %%mm1 \n\t"
43  PAVGB_MMX(%%mm0, %%mm1, %%mm2, %%mm6)
44  "movq %%mm2, %0 \n\t"
45  :"+m"(*block)
46  :"m"(*pixels)
47  :"memory");
48  pixels += line_size;
49  block += line_size;
50  }
51  while (--h);
52 }
53 
54 void ff_avg_pixels16_mmx(uint8_t *block, const uint8_t *pixels,
55  ptrdiff_t line_size, int h)
56 {
57  MOVQ_BFE(mm6);
58  JUMPALIGN();
59  do {
60  __asm__ volatile(
61  "movq %0, %%mm0 \n\t"
62  "movq %1, %%mm1 \n\t"
63  PAVGB_MMX(%%mm0, %%mm1, %%mm2, %%mm6)
64  "movq %%mm2, %0 \n\t"
65  "movq 8%0, %%mm0 \n\t"
66  "movq 8%1, %%mm1 \n\t"
67  PAVGB_MMX(%%mm0, %%mm1, %%mm2, %%mm6)
68  "movq %%mm2, 8%0 \n\t"
69  :"+m"(*block)
70  :"m"(*pixels)
71  :"memory");
72  pixels += line_size;
73  block += line_size;
74  }
75  while (--h);
76 }
77 
78 void ff_put_pixels8_mmx(uint8_t *block, const uint8_t *pixels,
79  ptrdiff_t line_size, int h)
80 {
81  __asm__ volatile (
82  "lea (%3, %3), %%"REG_a" \n\t"
83  ".p2align 3 \n\t"
84  "1: \n\t"
85  "movq (%1 ), %%mm0 \n\t"
86  "movq (%1, %3), %%mm1 \n\t"
87  "movq %%mm0, (%2) \n\t"
88  "movq %%mm1, (%2, %3) \n\t"
89  "add %%"REG_a", %1 \n\t"
90  "add %%"REG_a", %2 \n\t"
91  "movq (%1 ), %%mm0 \n\t"
92  "movq (%1, %3), %%mm1 \n\t"
93  "movq %%mm0, (%2) \n\t"
94  "movq %%mm1, (%2, %3) \n\t"
95  "add %%"REG_a", %1 \n\t"
96  "add %%"REG_a", %2 \n\t"
97  "subl $4, %0 \n\t"
98  "jnz 1b \n\t"
99  : "+g"(h), "+r"(pixels), "+r"(block)
100  : "r"((x86_reg)line_size)
101  : "%"REG_a, "memory"
102  );
103 }
104 
105 void ff_put_pixels16_mmx(uint8_t *block, const uint8_t *pixels,
106  ptrdiff_t line_size, int h)
107 {
108  __asm__ volatile (
109  "lea (%3, %3), %%"REG_a" \n\t"
110  ".p2align 3 \n\t"
111  "1: \n\t"
112  "movq (%1 ), %%mm0 \n\t"
113  "movq 8(%1 ), %%mm4 \n\t"
114  "movq (%1, %3), %%mm1 \n\t"
115  "movq 8(%1, %3), %%mm5 \n\t"
116  "movq %%mm0, (%2) \n\t"
117  "movq %%mm4, 8(%2) \n\t"
118  "movq %%mm1, (%2, %3) \n\t"
119  "movq %%mm5, 8(%2, %3) \n\t"
120  "add %%"REG_a", %1 \n\t"
121  "add %%"REG_a", %2 \n\t"
122  "movq (%1 ), %%mm0 \n\t"
123  "movq 8(%1 ), %%mm4 \n\t"
124  "movq (%1, %3), %%mm1 \n\t"
125  "movq 8(%1, %3), %%mm5 \n\t"
126  "movq %%mm0, (%2) \n\t"
127  "movq %%mm4, 8(%2) \n\t"
128  "movq %%mm1, (%2, %3) \n\t"
129  "movq %%mm5, 8(%2, %3) \n\t"
130  "add %%"REG_a", %1 \n\t"
131  "add %%"REG_a", %2 \n\t"
132  "subl $4, %0 \n\t"
133  "jnz 1b \n\t"
134  : "+g"(h), "+r"(pixels), "+r"(block)
135  : "r"((x86_reg)line_size)
136  : "%"REG_a, "memory"
137  );
138 }
139 
140 #endif /* HAVE_MMX_INLINE */