OSDN Git Service

Import UnkoTim220
[timidity41/timidity41.git] / libmpg123 / src / libmpg123 / optimize.h
1 #ifndef MPG123_H_OPTIMIZE
2 #define MPG123_H_OPTIMIZE
3 /*
4         optimize: get a grip on the different optimizations
5
6         copyright 2007-2013 by the mpg123 project - free software under the terms of the LGPL 2.1
7         see COPYING and AUTHORS files in distribution or http://mpg123.org
8         initially written by Thomas Orgis, taking from mpg123.[hc]
9
10         for building mpg123 with one optimization only, you have to choose exclusively between
11         OPT_GENERIC (generic C code for everyone)
12         OPT_GENERIC_DITHER (same with dithering for 1to1)
13         OPT_I386 (Intel i386)
14         OPT_I486 (Somewhat special code for i486; does not work together with others.)
15         OPT_I586 (Intel Pentium)
16         OPT_I586_DITHER (Intel Pentium with dithering/noise shaping for enhanced quality)
17         OPT_MMX (Intel Pentium and compatibles with MMX, fast, but not the best accuracy)
18         OPT_3DNOW (AMD 3DNow!, K6-2/3, Athlon, compatibles...)
19         OPT_3DNOW_VINTAGE
20         OPT_3DNOWEXT (AMD 3DNow! extended, generally Athlon, compatibles...)
21         OPT_3DNOWEXT_VINTAGE
22         OPT_SSE
23         OPT_SSE_VINTAGE
24         OPT_ALTIVEC (Motorola/IBM PPC with AltiVec under MacOSX)
25         OPT_X86_64 (x86-64 / AMD64 / Intel 64)
26         OPT_AVX
27
28         or you define OPT_MULTI and give a combination which makes sense (do not include i486, do not mix altivec and x86).
29
30         I still have to examine the dynamics of this here together with REAL_IS_FIXED.
31         Basic point is: Don't use REAL_IS_FIXED with something else than generic or i386.
32
33         Also, one should minimize code size by really ensuring that only functions that are really needed are included.
34         Currently, all generic functions will be always there (to be safe for fallbacks for advanced decoders).
35         Strictly, at least the synth_1to1 should not be necessary for single-decoder mode.
36 */
37
38
39 /* Runtime optimization interface now here: */
40
41 /* Nedit inline Perl script to generate decoder list and name mapping in one place
42    optimize.c defining I_AM_OPTIMIZE to get the names
43
44 perl <<'EOT'
45 ## order is important (autodec first, nodec last)
46 @names=
47 (
48  ['autodec', 'auto']
49 ,['generic', 'generic']
50 ,['generic_dither', 'generic_dither']
51 ,['idrei', 'i386']
52 ,['ivier', 'i486']
53 ,['ifuenf', 'i586']
54 ,['ifuenf_dither', 'i586_dither']
55 ,['mmx', 'MMX']
56 ,['dreidnow', '3DNow']
57 ,['dreidnowext', '3DNowExt']
58 ,['altivec', 'AltiVec']
59 ,['sse', 'SSE']
60 ,['x86_64', 'x86-64']
61 ,['arm','ARM']
62 ,['neon','NEON']
63 ,['avx','AVX']
64 ,['dreidnow_vintage', '3DNow_vintage']
65 ,['dreidnowext_vintage', '3DNowExt_vintage']
66 ,['sse_vintage', 'SSE_vintage']
67 ,['nodec', 'nodec']
68 );
69
70 print "enum optdec\n{\n";
71 for my $n (@names)
72 {
73         $name = $n->[0];
74         $enum = $name eq 'autodec' ? $name = " $name=0" : ",$name";
75         print "\t$enum\n"
76 }
77 print "};\n";
78 print "##ifdef I_AM_OPTIMIZE\n";
79 for my $n (@names)
80 {
81         my $key = $n->[0];
82         my $val = $n->[1];
83         print "static const char dn_$key\[\] = \"$val\";\n";
84 }
85 print "static const char* decname[] =\n{\n";
86 for my $n (@names)
87 {
88         my $key = $n->[0];
89         print "\t".($key eq 'autodec' ? ' ' : ',')."dn_$key\n";
90 }
91 print "};\n##endif"
92 EOT
93 */
94 enum optdec
95 {
96          autodec=0
97         ,generic
98         ,generic_dither
99         ,idrei
100         ,ivier
101         ,ifuenf
102         ,ifuenf_dither
103         ,mmx
104         ,dreidnow
105         ,dreidnowext
106         ,altivec
107         ,sse
108         ,x86_64
109         ,arm
110         ,neon
111         ,neon64
112         ,avx
113         ,dreidnow_vintage
114         ,dreidnowext_vintage
115         ,sse_vintage
116         ,nodec
117 };
118 #ifdef I_AM_OPTIMIZE
119 static const char dn_autodec[] = "auto";
120 static const char dn_generic[] = "generic";
121 static const char dn_generic_dither[] = "generic_dither";
122 static const char dn_idrei[] = "i386";
123 static const char dn_ivier[] = "i486";
124 static const char dn_ifuenf[] = "i586";
125 static const char dn_ifuenf_dither[] = "i586_dither";
126 static const char dn_mmx[] = "MMX";
127 static const char dn_dreidnow[] = "3DNow";
128 static const char dn_dreidnowext[] = "3DNowExt";
129 static const char dn_altivec[] = "AltiVec";
130 static const char dn_sse[] = "SSE";
131 static const char dn_x86_64[] = "x86-64";
132 static const char dn_arm[] = "ARM";
133 static const char dn_neon[] = "NEON";
134 static const char dn_neon64[] = "NEON64";
135 static const char dn_avx[] = "AVX";
136 static const char dn_dreidnow_vintage[] = "3DNow_vintage";
137 static const char dn_dreidnowext_vintage[] = "3DNowExt_vintage";
138 static const char dn_sse_vintage[] = "SSE_vintage";
139 static const char dn_nodec[] = "nodec";
140 static const char* decname[] =
141 {
142          dn_autodec
143         ,dn_generic
144         ,dn_generic_dither
145         ,dn_idrei
146         ,dn_ivier
147         ,dn_ifuenf
148         ,dn_ifuenf_dither
149         ,dn_mmx
150         ,dn_dreidnow
151         ,dn_dreidnowext
152         ,dn_altivec
153         ,dn_sse
154         ,dn_x86_64
155         ,dn_arm
156         ,dn_neon
157         ,dn_neon64
158         ,dn_avx
159         ,dn_dreidnow_vintage
160         ,dn_dreidnowext_vintage
161         ,dn_sse_vintage
162         ,dn_nodec
163 };
164 #endif
165
166 enum optcla { nocla=0, normal, mmxsse };
167
168 /*  - Set up the table of synth functions for current decoder choice. */
169 int frame_cpu_opt(mpg123_handle *fr, const char* cpu);
170 /*  - Choose, from the synth table, the synth functions to use for current output format/rate. */
171 int set_synth_functions(mpg123_handle *fr);
172 /*  - Parse decoder name and return numerical code. */
173 enum optdec dectype(const char* decoder);
174 /*  - Return the default decoder type. */
175 enum optdec defdec(void);
176 /*  - Return the class of a decoder type (mmxsse or normal). */
177 enum optcla decclass(const enum optdec);
178
179 /* Now comes a whole lot of definitions, for multi decoder mode and single decoder mode.
180    Because of the latter, it may look redundant at times. */
181
182 /* this is included in mpg123.h, which includes config.h */
183 #ifdef CCALIGN
184 #define ALIGNED(a) __attribute__((aligned(a)))
185 #else
186 #define ALIGNED(a)
187 #endif
188
189 /* Safety catch for invalid decoder choice. */
190 #ifdef REAL_IS_FIXED
191 #if (defined OPT_I486)  || (defined OPT_I586) || (defined OPT_I586_DITHER) \
192  || (defined OPT_MMX)   || (defined OPT_SSE)  || (defined_OPT_ALTIVEC) \
193  || (defined OPT_3DNOW) || (defined OPT_3DNOWEXT) || (defined OPT_X86_64) \
194  || (defined OPT_3DNOW_VINTAGE) || (defined OPT_3DNOWEXT_VINTAGE) \
195  || (defined OPT_SSE_VINTAGE) \
196  || (defined OPT_NEON) || (defined OPT_NEON64) || (defined OPT_AVX) \
197  || (defined OPT_GENERIC_DITHER)
198 #error "Bad decoder choice together with fixed point math!"
199 #endif
200 #endif
201
202 #if (defined NO_LAYER1 && defined NO_LAYER2)
203 #define NO_LAYER12
204 #endif
205
206 #ifdef OPT_GENERIC
207 #ifndef OPT_MULTI
208 #       define defopt generic
209 #endif
210 #endif
211
212 #ifdef OPT_GENERIC_DITHER
213 #define OPT_DITHER
214 #ifndef OPT_MULTI
215 #       define defopt generic_dither
216 #endif
217 #endif
218
219 /* i486 is special... always alone! */
220 #ifdef OPT_I486
221 #define OPT_X86
222 #define defopt ivier
223 #ifdef OPT_MULTI
224 #error "i486 can only work alone!"
225 #endif
226 #define FIR_BUFFER_SIZE  128
227 #define FIR_SIZE 16
228 #endif
229
230 #ifdef OPT_I386
231 #define OPT_X86
232 #ifndef OPT_MULTI
233 #       define defopt idrei
234 #endif
235 #endif
236
237 #ifdef OPT_I586
238 #define OPT_X86
239 #ifndef OPT_MULTI
240 #       define defopt ifuenf
241 #endif
242 #endif
243
244 #ifdef OPT_I586_DITHER
245 #define OPT_X86
246 #define OPT_DITHER
247 #ifndef OPT_MULTI
248 #       define defopt ifuenf_dither
249 #endif
250 #endif
251
252 /* We still have some special code around MMX tables. */
253
254 #ifdef OPT_MMX
255 #define OPT_MMXORSSE
256 #define OPT_X86
257 #ifndef OPT_MULTI
258 #       define defopt mmx
259 #endif
260 #endif
261
262 #ifdef OPT_SSE
263 #define OPT_MMXORSSE
264 #define OPT_MPLAYER
265 #define OPT_X86
266 #ifndef OPT_MULTI
267 #       define defopt sse
268 #       define opt_dct36(fr) dct36_sse
269 #endif
270 #endif
271
272 #ifdef OPT_SSE_VINTAGE
273 #define OPT_MMXORSSE
274 #define OPT_MPLAYER
275 #define OPT_X86
276 #ifndef OPT_MULTI
277 #       define defopt sse
278 #endif
279 #endif
280
281 #ifdef OPT_3DNOWEXT
282 #define OPT_MMXORSSE
283 #define OPT_MPLAYER
284 #define OPT_X86
285 #ifndef OPT_MULTI
286 #       define defopt dreidnowext
287 #endif
288 #endif
289
290 /* same as above but also using 3DNowExt dct36 */
291 #ifdef OPT_3DNOWEXT_VINTAGE
292 #define OPT_MMXORSSE
293 #define OPT_MPLAYER
294 #define OPT_X86
295 #ifndef OPT_MULTI
296 #       define defopt dreidnowext_vintage
297 #       define opt_dct36(fr) dct36_3dnowext
298 #endif
299 #endif
300
301 #ifdef OPT_MPLAYER
302 extern const int costab_mmxsse[];
303 #endif
304
305 /* 3dnow used to use synth_1to1_i586 for mono / 8bit conversion - was that intentional? */
306 /* I'm trying to skip the pentium code here ... until I see that that is indeed a bad idea */
307 #ifdef OPT_3DNOW
308 #define OPT_X86
309 #ifndef OPT_MULTI
310 #       define defopt dreidnow
311 #endif
312 #endif
313
314 /* same as above but also using 3DNow dct36 */
315 #ifdef OPT_3DNOW_VINTAGE
316 #define OPT_X86
317 #ifndef OPT_MULTI
318 #       define defopt dreidnow_vintage
319 #       define opt_dct36(fr) dct36_3dnow
320 #endif
321 #endif
322
323 #ifdef OPT_ALTIVEC
324 #ifndef OPT_MULTI
325 #       define defopt altivec
326 #endif
327 #endif
328
329 #ifdef OPT_X86_64
330 #define OPT_MMXORSSE
331 #ifndef OPT_MULTI
332 #       define defopt x86_64
333 #       define opt_dct36(fr) dct36_x86_64
334 #endif
335 #endif
336
337 #ifdef OPT_AVX
338 #define OPT_MMXORSSE
339 #ifndef OPT_MULTI
340 #       define defopt avx
341 #       define opt_dct36(fr) dct36_avx
342 #endif
343 #endif
344
345 #ifdef OPT_ARM
346 #ifndef OPT_MULTI
347 #       define defopt arm
348 #endif
349 #endif
350
351 #ifdef OPT_NEON
352 #define OPT_MMXORSSE
353 #ifndef OPT_MULTI
354 #       define defopt neon
355 #       define opt_dct36(fr) dct36_neon
356 #endif
357 #endif
358
359 #ifdef OPT_NEON64
360 #define OPT_MMXORSSE
361 #ifndef OPT_MULTI
362 #       define defopt neon64
363 #       define opt_dct36(fr) dct36_neon64
364 #endif
365 #endif
366
367 /* used for multi opt mode and the single 3dnow mode to have the old 3dnow test flag still working */
368 void check_decoders(void);
369
370 /*
371         Now come two blocks of standard definitions for multi-decoder mode and single-decoder mode.
372         Most stuff is so automatic that it's indeed generated by some inline shell script.
373         Remember to use these scripts when possible, instead of direct repetitive hacking.
374 */
375
376 #ifdef OPT_MULTI
377
378 #       define defopt nodec
379
380 #       if (defined OPT_3DNOW_VINTAGE || defined OPT_3DNOWEXT_VINTAGE || defined OPT_SSE || defined OPT_X86_64 || defined OPT_AVX || defined OPT_NEON || defined OPT_NEON64)
381 #               define opt_dct36(fr) ((fr)->cpu_opts.the_dct36)
382 #       endif
383
384 #endif /* OPT_MULTI else */
385
386 #       ifndef opt_dct36
387 #               define opt_dct36(fr) dct36
388 #       endif
389
390 #endif /* MPG123_H_OPTIMIZE */
391