demux_mkv: fix minor memory leak
[mplayer.git] / libvo / aclib.c
blob7328de794aea34bb647ee62d96c1b49f26378adc
1 /*
2 * aclib - advanced C library ;)
3 * Functions which improve and expand the standard C library, see aclib_template.c.
4 * This file only contains runtime CPU detection and config option stuff.
5 * runtime CPU detection by Michael Niedermayer (michaelni@gmx.at)
7 * This file is part of MPlayer.
9 * MPlayer is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * MPlayer 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
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "config.h"
25 #include <stddef.h>
26 #include <stdint.h>
27 #include <string.h>
28 #include "cpudetect.h"
29 #include "fastmemcpy.h"
30 #include "ffmpeg_files/x86_cpu.h"
31 #undef memcpy
33 #define BLOCK_SIZE 4096
34 #define CONFUSION_FACTOR 0
35 //Feel free to fine-tune the above 2, it might be possible to get some speedup with them :)
37 //#define STATISTICS
39 //Note: we have MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
40 //Plain C versions
41 //#if !HAVE_MMX || CONFIG_RUNTIME_CPUDETECT
42 //#define COMPILE_C
43 //#endif
45 #if ARCH_X86
47 #if (HAVE_MMX && !HAVE_AMD3DNOW && !HAVE_MMX2) || CONFIG_RUNTIME_CPUDETECT
48 #define COMPILE_MMX
49 #endif
51 #if (HAVE_MMX2 && !HAVE_SSE2) || CONFIG_RUNTIME_CPUDETECT
52 #define COMPILE_MMX2
53 #endif
55 #if (HAVE_AMD3DNOW && !HAVE_MMX2) || CONFIG_RUNTIME_CPUDETECT
56 #define COMPILE_3DNOW
57 #endif
59 #if HAVE_SSE2 || CONFIG_RUNTIME_CPUDETECT
60 #define COMPILE_SSE
61 #endif
63 #undef HAVE_MMX
64 #undef HAVE_MMX2
65 #undef HAVE_AMD3DNOW
66 #undef HAVE_SSE
67 #undef HAVE_SSE2
68 #define HAVE_MMX 0
69 #define HAVE_MMX2 0
70 #define HAVE_AMD3DNOW 0
71 #define HAVE_SSE 0
72 #define HAVE_SSE2 0
74 #ifdef COMPILE_C
75 #undef HAVE_MMX
76 #undef HAVE_MMX2
77 #undef HAVE_AMD3DNOW
78 #undef HAVE_SSE
79 #undef HAVE_SSE2
80 #define HAVE_MMX 0
81 #define HAVE_MMX2 0
82 #define HAVE_AMD3DNOW 0
83 #define HAVE_SSE 0
84 #define HAVE_SSE2 0
85 #define RENAME(a) a ## _C
86 #include "aclib_template.c"
87 #endif
89 //MMX versions
90 #ifdef COMPILE_MMX
91 #undef RENAME
92 #undef HAVE_MMX
93 #undef HAVE_MMX2
94 #undef HAVE_AMD3DNOW
95 #undef HAVE_SSE
96 #undef HAVE_SSE2
97 #define HAVE_MMX 1
98 #define HAVE_MMX2 0
99 #define HAVE_AMD3DNOW 0
100 #define HAVE_SSE 0
101 #define HAVE_SSE2 0
102 #define RENAME(a) a ## _MMX
103 #include "aclib_template.c"
104 #endif
106 //MMX2 versions
107 #ifdef COMPILE_MMX2
108 #undef RENAME
109 #undef HAVE_MMX
110 #undef HAVE_MMX2
111 #undef HAVE_AMD3DNOW
112 #undef HAVE_SSE
113 #undef HAVE_SSE2
114 #define HAVE_MMX 1
115 #define HAVE_MMX2 1
116 #define HAVE_AMD3DNOW 0
117 #define HAVE_SSE 0
118 #define HAVE_SSE2 0
119 #define RENAME(a) a ## _MMX2
120 #include "aclib_template.c"
121 #endif
123 //3DNOW versions
124 #ifdef COMPILE_3DNOW
125 #undef RENAME
126 #undef HAVE_MMX
127 #undef HAVE_MMX2
128 #undef HAVE_AMD3DNOW
129 #undef HAVE_SSE
130 #undef HAVE_SSE2
131 #define HAVE_MMX 1
132 #define HAVE_MMX2 0
133 #define HAVE_AMD3DNOW 1
134 #define HAVE_SSE 0
135 #define HAVE_SSE2 0
136 #define RENAME(a) a ## _3DNow
137 #include "aclib_template.c"
138 #endif
140 //SSE versions (only used on SSE2 cpus)
141 #ifdef COMPILE_SSE
142 #undef RENAME
143 #undef HAVE_MMX
144 #undef HAVE_MMX2
145 #undef HAVE_AMD3DNOW
146 #undef HAVE_SSE
147 #undef HAVE_SSE2
148 #define HAVE_MMX 1
149 #define HAVE_MMX2 1
150 #define HAVE_AMD3DNOW 0
151 #define HAVE_SSE 1
152 #define HAVE_SSE2 1
153 #define RENAME(a) a ## _SSE
154 #include "aclib_template.c"
155 #endif
157 #endif /* ARCH_X86 */
160 #undef fast_memcpy
161 void * fast_memcpy(void * to, const void * from, size_t len)
163 #if CONFIG_RUNTIME_CPUDETECT
164 #if ARCH_X86
165 // ordered per speed fasterst first
166 if(gCpuCaps.hasSSE2)
167 fast_memcpy_SSE(to, from, len);
168 else if(gCpuCaps.hasMMX2)
169 fast_memcpy_MMX2(to, from, len);
170 else if(gCpuCaps.has3DNow)
171 fast_memcpy_3DNow(to, from, len);
172 else if(gCpuCaps.hasMMX)
173 fast_memcpy_MMX(to, from, len);
174 else
175 #endif
176 memcpy(to, from, len); // prior to mmx we use the standart memcpy
177 #else
178 #if HAVE_SSE2
179 fast_memcpy_SSE(to, from, len);
180 #elif HAVE_MMX2
181 fast_memcpy_MMX2(to, from, len);
182 #elif HAVE_AMD3DNOW
183 fast_memcpy_3DNow(to, from, len);
184 #elif HAVE_MMX
185 fast_memcpy_MMX(to, from, len);
186 #else
187 memcpy(to, from, len); // prior to mmx we use the standart memcpy
188 #endif
190 #endif //!CONFIG_RUNTIME_CPUDETECT
191 return to;
194 #undef mem2agpcpy
195 void * mem2agpcpy(void * to, const void * from, size_t len)
197 #if CONFIG_RUNTIME_CPUDETECT
198 #if ARCH_X86
199 // ordered per speed fasterst first
200 if(gCpuCaps.hasSSE2)
201 mem2agpcpy_SSE(to, from, len);
202 else if(gCpuCaps.hasMMX2)
203 mem2agpcpy_MMX2(to, from, len);
204 else if(gCpuCaps.has3DNow)
205 mem2agpcpy_3DNow(to, from, len);
206 else if(gCpuCaps.hasMMX)
207 mem2agpcpy_MMX(to, from, len);
208 else
209 #endif
210 memcpy(to, from, len); // prior to mmx we use the standart memcpy
211 #else
212 #if HAVE_SSE2
213 mem2agpcpy_SSE(to, from, len);
214 #elif HAVE_MMX2
215 mem2agpcpy_MMX2(to, from, len);
216 #elif HAVE_AMD3DNOW
217 mem2agpcpy_3DNow(to, from, len);
218 #elif HAVE_MMX
219 mem2agpcpy_MMX(to, from, len);
220 #else
221 memcpy(to, from, len); // prior to mmx we use the standart memcpy
222 #endif
224 #endif //!CONFIG_RUNTIME_CPUDETECT
225 return to;