Fix wrong setting of samplesize (must be bytes per sample, not bits)
[mplayer/glamo.git] / libvo / aclib.c
blob13bb3df643588c4741ac8c7b9bb88de1f63c2f53
1 #include "config.h"
2 #ifdef USE_FASTMEMCPY
4 /*
5 aclib - advanced C library ;)
6 This file contains functions which improve and expand standard C-library
7 see aclib_template.c ... this file only contains runtime cpu detection and config options stuff
8 runtime cpu detection by michael niedermayer (michaelni@gmx.at) is under GPL
9 */
10 #include <stddef.h>
11 #include <string.h>
12 #include "cpudetect.h"
13 #include "fastmemcpy.h"
14 #undef memcpy
16 #define BLOCK_SIZE 4096
17 #define CONFUSION_FACTOR 0
18 //Feel free to fine-tune the above 2, it might be possible to get some speedup with them :)
20 //#define STATISTICS
21 #ifdef ARCH_X86
22 #define CAN_COMPILE_X86_ASM
23 #endif
25 //Note: we have MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
26 //Plain C versions
27 //#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT)
28 //#define COMPILE_C
29 //#endif
31 #ifdef CAN_COMPILE_X86_ASM
33 #if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
34 #define COMPILE_MMX
35 #endif
37 #if (defined (HAVE_MMX2) && !defined (HAVE_SSE2)) || defined (RUNTIME_CPUDETECT)
38 #define COMPILE_MMX2
39 #endif
41 #if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
42 #define COMPILE_3DNOW
43 #endif
45 #if defined (HAVE_SSE2) || defined (RUNTIME_CPUDETECT)
46 #define COMPILE_SSE
47 #endif
49 #undef HAVE_MMX
50 #undef HAVE_MMX2
51 #undef HAVE_3DNOW
52 #undef HAVE_SSE
53 #undef HAVE_SSE2
55 #ifdef COMPILE_C
56 #undef HAVE_MMX
57 #undef HAVE_MMX2
58 #undef HAVE_3DNOW
59 #undef ARCH_X86
60 #define RENAME(a) a ## _C
61 #include "aclib_template.c"
62 #endif
64 //MMX versions
65 #ifdef COMPILE_MMX
66 #undef RENAME
67 #define HAVE_MMX
68 #undef HAVE_MMX2
69 #undef HAVE_3DNOW
70 #undef HAVE_SSE
71 #undef HAVE_SSE2
72 #define RENAME(a) a ## _MMX
73 #include "aclib_template.c"
74 #endif
76 //MMX2 versions
77 #ifdef COMPILE_MMX2
78 #undef RENAME
79 #define HAVE_MMX
80 #define HAVE_MMX2
81 #undef HAVE_3DNOW
82 #undef HAVE_SSE
83 #undef HAVE_SSE2
84 #define RENAME(a) a ## _MMX2
85 #include "aclib_template.c"
86 #endif
88 //3DNOW versions
89 #ifdef COMPILE_3DNOW
90 #undef RENAME
91 #define HAVE_MMX
92 #undef HAVE_MMX2
93 #define HAVE_3DNOW
94 #undef HAVE_SSE
95 #undef HAVE_SSE2
96 #define RENAME(a) a ## _3DNow
97 #include "aclib_template.c"
98 #endif
100 //SSE versions (only used on SSE2 cpus)
101 #ifdef COMPILE_SSE
102 #undef RENAME
103 #define HAVE_MMX
104 #define HAVE_MMX2
105 #undef HAVE_3DNOW
106 #define HAVE_SSE
107 #define HAVE_SSE2
108 #define RENAME(a) a ## _SSE
109 #include "aclib_template.c"
110 #endif
112 #endif // CAN_COMPILE_X86_ASM
115 void * fast_memcpy(void * to, const void * from, size_t len)
117 #ifdef RUNTIME_CPUDETECT
118 #ifdef CAN_COMPILE_X86_ASM
119 // ordered per speed fasterst first
120 if(gCpuCaps.hasSSE2)
121 fast_memcpy_SSE(to, from, len);
122 else if(gCpuCaps.hasMMX2)
123 fast_memcpy_MMX2(to, from, len);
124 else if(gCpuCaps.has3DNow)
125 fast_memcpy_3DNow(to, from, len);
126 else if(gCpuCaps.hasMMX)
127 fast_memcpy_MMX(to, from, len);
128 else
129 #endif //CAN_COMPILE_X86_ASM
130 memcpy(to, from, len); // prior to mmx we use the standart memcpy
131 #else
132 #ifdef HAVE_SSE2
133 fast_memcpy_SSE(to, from, len);
134 #elif defined (HAVE_MMX2)
135 fast_memcpy_MMX2(to, from, len);
136 #elif defined (HAVE_3DNOW)
137 fast_memcpy_3DNow(to, from, len);
138 #elif defined (HAVE_MMX)
139 fast_memcpy_MMX(to, from, len);
140 #else
141 memcpy(to, from, len); // prior to mmx we use the standart memcpy
142 #endif
144 #endif //!RUNTIME_CPUDETECT
145 return to;
148 #undef mem2agpcpy
149 void * mem2agpcpy(void * to, const void * from, size_t len)
151 #ifdef RUNTIME_CPUDETECT
152 #ifdef CAN_COMPILE_X86_ASM
153 // ordered per speed fasterst first
154 if(gCpuCaps.hasSSE2)
155 mem2agpcpy_SSE(to, from, len);
156 else if(gCpuCaps.hasMMX2)
157 mem2agpcpy_MMX2(to, from, len);
158 else if(gCpuCaps.has3DNow)
159 mem2agpcpy_3DNow(to, from, len);
160 else if(gCpuCaps.hasMMX)
161 mem2agpcpy_MMX(to, from, len);
162 else
163 #endif //CAN_COMPILE_X86_ASM
164 memcpy(to, from, len); // prior to mmx we use the standart memcpy
165 #else
166 #ifdef HAVE_SSE2
167 mem2agpcpy_SSE(to, from, len);
168 #elif defined (HAVE_MMX2)
169 mem2agpcpy_MMX2(to, from, len);
170 #elif defined (HAVE_3DNOW)
171 mem2agpcpy_3DNow(to, from, len);
172 #elif defined (HAVE_MMX)
173 mem2agpcpy_MMX(to, from, len);
174 #else
175 memcpy(to, from, len); // prior to mmx we use the standart memcpy
176 #endif
178 #endif //!RUNTIME_CPUDETECT
179 return to;
182 #endif /* use fastmemcpy */