Fix bug introduced by me in r28756
[mplayer/glamo.git] / libvo / aclib.c
blobcae86dd3d4c32ce7de1ee63896c49bd44a856e0f
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 <string.h>
27 #include "cpudetect.h"
28 #include "fastmemcpy.h"
29 #undef memcpy
31 #define BLOCK_SIZE 4096
32 #define CONFUSION_FACTOR 0
33 //Feel free to fine-tune the above 2, it might be possible to get some speedup with them :)
35 //#define STATISTICS
36 #if ARCH_X86
37 #define CAN_COMPILE_X86_ASM
38 #endif
40 //Note: we have MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
41 //Plain C versions
42 //#if !HAVE_MMX || defined (RUNTIME_CPUDETECT)
43 //#define COMPILE_C
44 //#endif
46 #ifdef CAN_COMPILE_X86_ASM
48 #if (HAVE_MMX && !HAVE_AMD3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
49 #define COMPILE_MMX
50 #endif
52 #if (HAVE_MMX2 && !HAVE_SSE2) || defined (RUNTIME_CPUDETECT)
53 #define COMPILE_MMX2
54 #endif
56 #if (HAVE_AMD3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
57 #define COMPILE_3DNOW
58 #endif
60 #if HAVE_SSE2 || defined (RUNTIME_CPUDETECT)
61 #define COMPILE_SSE
62 #endif
64 #undef HAVE_MMX
65 #undef HAVE_MMX2
66 #undef HAVE_AMD3DNOW
67 #undef HAVE_SSE
68 #undef HAVE_SSE2
69 #define HAVE_MMX 0
70 #define HAVE_MMX2 0
71 #define HAVE_AMD3DNOW 0
72 #define HAVE_SSE 0
73 #define HAVE_SSE2 0
75 #ifdef COMPILE_C
76 #undef HAVE_MMX
77 #undef HAVE_MMX2
78 #undef HAVE_AMD3DNOW
79 #undef HAVE_SSE
80 #undef HAVE_SSE2
81 #define HAVE_MMX 0
82 #define HAVE_MMX2 0
83 #define HAVE_AMD3DNOW 0
84 #define HAVE_SSE 0
85 #define HAVE_SSE2 0
86 #define RENAME(a) a ## _C
87 #include "aclib_template.c"
88 #endif
90 //MMX versions
91 #ifdef COMPILE_MMX
92 #undef RENAME
93 #undef HAVE_MMX
94 #undef HAVE_MMX2
95 #undef HAVE_AMD3DNOW
96 #undef HAVE_SSE
97 #undef HAVE_SSE2
98 #define HAVE_MMX 1
99 #define HAVE_MMX2 0
100 #define HAVE_AMD3DNOW 0
101 #define HAVE_SSE 0
102 #define HAVE_SSE2 0
103 #define RENAME(a) a ## _MMX
104 #include "aclib_template.c"
105 #endif
107 //MMX2 versions
108 #ifdef COMPILE_MMX2
109 #undef RENAME
110 #undef HAVE_MMX
111 #undef HAVE_MMX2
112 #undef HAVE_AMD3DNOW
113 #undef HAVE_SSE
114 #undef HAVE_SSE2
115 #define HAVE_MMX 1
116 #define HAVE_MMX2 1
117 #define HAVE_AMD3DNOW 0
118 #define HAVE_SSE 0
119 #define HAVE_SSE2 0
120 #define RENAME(a) a ## _MMX2
121 #include "aclib_template.c"
122 #endif
124 //3DNOW versions
125 #ifdef COMPILE_3DNOW
126 #undef RENAME
127 #undef HAVE_MMX
128 #undef HAVE_MMX2
129 #undef HAVE_AMD3DNOW
130 #undef HAVE_SSE
131 #undef HAVE_SSE2
132 #define HAVE_MMX 1
133 #define HAVE_MMX2 0
134 #define HAVE_AMD3DNOW 1
135 #define HAVE_SSE 0
136 #define HAVE_SSE2 0
137 #define RENAME(a) a ## _3DNow
138 #include "aclib_template.c"
139 #endif
141 //SSE versions (only used on SSE2 cpus)
142 #ifdef COMPILE_SSE
143 #undef RENAME
144 #undef HAVE_MMX
145 #undef HAVE_MMX2
146 #undef HAVE_AMD3DNOW
147 #undef HAVE_SSE
148 #undef HAVE_SSE2
149 #define HAVE_MMX 1
150 #define HAVE_MMX2 1
151 #define HAVE_AMD3DNOW 0
152 #define HAVE_SSE 1
153 #define HAVE_SSE2 1
154 #define RENAME(a) a ## _SSE
155 #include "aclib_template.c"
156 #endif
158 #endif // CAN_COMPILE_X86_ASM
161 #undef fast_memcpy
162 void * fast_memcpy(void * to, const void * from, size_t len)
164 #ifdef RUNTIME_CPUDETECT
165 #ifdef CAN_COMPILE_X86_ASM
166 // ordered per speed fasterst first
167 if(gCpuCaps.hasSSE2)
168 fast_memcpy_SSE(to, from, len);
169 else if(gCpuCaps.hasMMX2)
170 fast_memcpy_MMX2(to, from, len);
171 else if(gCpuCaps.has3DNow)
172 fast_memcpy_3DNow(to, from, len);
173 else if(gCpuCaps.hasMMX)
174 fast_memcpy_MMX(to, from, len);
175 else
176 #endif //CAN_COMPILE_X86_ASM
177 memcpy(to, from, len); // prior to mmx we use the standart memcpy
178 #else
179 #if HAVE_SSE2
180 fast_memcpy_SSE(to, from, len);
181 #elif HAVE_MMX2
182 fast_memcpy_MMX2(to, from, len);
183 #elif HAVE_AMD3DNOW
184 fast_memcpy_3DNow(to, from, len);
185 #elif HAVE_MMX
186 fast_memcpy_MMX(to, from, len);
187 #else
188 memcpy(to, from, len); // prior to mmx we use the standart memcpy
189 #endif
191 #endif //!RUNTIME_CPUDETECT
192 return to;
195 #undef mem2agpcpy
196 void * mem2agpcpy(void * to, const void * from, size_t len)
198 #ifdef RUNTIME_CPUDETECT
199 #ifdef CAN_COMPILE_X86_ASM
200 // ordered per speed fasterst first
201 if(gCpuCaps.hasSSE2)
202 mem2agpcpy_SSE(to, from, len);
203 else if(gCpuCaps.hasMMX2)
204 mem2agpcpy_MMX2(to, from, len);
205 else if(gCpuCaps.has3DNow)
206 mem2agpcpy_3DNow(to, from, len);
207 else if(gCpuCaps.hasMMX)
208 mem2agpcpy_MMX(to, from, len);
209 else
210 #endif //CAN_COMPILE_X86_ASM
211 memcpy(to, from, len); // prior to mmx we use the standart memcpy
212 #else
213 #if HAVE_SSE2
214 mem2agpcpy_SSE(to, from, len);
215 #elif HAVE_MMX2
216 mem2agpcpy_MMX2(to, from, len);
217 #elif HAVE_AMD3DNOW
218 mem2agpcpy_3DNow(to, from, len);
219 #elif HAVE_MMX
220 mem2agpcpy_MMX(to, from, len);
221 #else
222 memcpy(to, from, len); // prior to mmx we use the standart memcpy
223 #endif
225 #endif //!RUNTIME_CPUDETECT
226 return to;