Using icode attribute for S5L870x is faster on some codecs. Speed up for mpc is ...
[kugel-rb.git] / apps / codecs / libfaad / common.h
blob109dfe67cb63c60d324898c52d9af10c705cf20b
1 /*
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 ** Any non-GPL usage of this software or parts of this software is strictly
20 ** forbidden.
22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
25 ** $Id$
26 **/
28 #ifndef __COMMON_H__
29 #define __COMMON_H__
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 #include "faad_config.h"
36 #include "codeclib.h"
38 extern struct codec_api* ci;
40 #if defined(DEBUG) || defined(SIMULATOR)
41 #undef DEBUGF
42 #define DEBUGF ci->debugf
43 #else
44 #define DEBUGF(...)
45 #endif
47 #ifdef ROCKBOX_HAS_LOGF
48 #undef LOGF
49 #define LOGF ci->logf
50 #else
51 #define LOGF(...)
52 #endif
54 #if (CONFIG_CPU == MCF5250)
55 /* Enough IRAM but performance suffers with ICODE_ATTR. */
56 #define IBSS_ATTR_FAAD_LARGE_IRAM IBSS_ATTR
57 #define ICODE_ATTR_FAAD_LARGE_IRAM
58 #define ICONST_ATTR_FAAD_LARGE_IRAM ICONST_ATTR
60 #elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || defined(CPU_S5L870X)
61 /* Enough IRAM to move additional data and code to it. */
62 #define IBSS_ATTR_FAAD_LARGE_IRAM IBSS_ATTR
63 #define ICODE_ATTR_FAAD_LARGE_IRAM ICODE_ATTR
64 #define ICONST_ATTR_FAAD_LARGE_IRAM ICONST_ATTR
66 #else
67 /* Not enough IRAM available. */
68 #define IBSS_ATTR_FAAD_LARGE_IRAM
69 #define ICODE_ATTR_FAAD_LARGE_IRAM
70 #define ICONST_ATTR_FAAD_LARGE_IRAM
71 #endif
73 #define INLINE __inline
74 #if 0 //defined(_WIN32) && !defined(_WIN32_WCE)
75 #define ALIGN __declspec(align(16))
76 #else
77 #define ALIGN
78 #endif
80 #ifndef max
81 #define max(a, b) (((a) > (b)) ? (a) : (b))
82 #endif
83 #ifndef min
84 #define min(a, b) (((a) < (b)) ? (a) : (b))
85 #endif
87 /* COMPILE TIME DEFINITIONS */
89 /* use double precision */
90 /* #define USE_DOUBLE_PRECISION */
91 /* use fixed point reals */
92 #define FIXED_POINT
93 #define BIG_IQ_TABLE /* BIG_IQ_TABLE results in faster requantization */
95 /* Use if target platform has address generators with autoincrement */
96 //#define PREFER_POINTERS
98 #define ERROR_RESILIENCE
101 /* Allow decoding of MAIN profile AAC */
102 #define MAIN_DEC
103 #if MEMORYSIZE > 2
104 /* Allow decoding of SSR profile AAC */
105 #define SSR_DEC
106 #endif
107 /* Allow decoding of LTP profile AAC */
108 #define LTP_DEC
109 /* Allow decoding of LD profile AAC */
110 #define LD_DEC
111 /* Allow decoding of scalable profiles */
112 //#define SCALABLE_DEC
113 /* Allow decoding of Digital Radio Mondiale (DRM) */
114 //#define DRM
115 //#define DRM_PS
117 /* LD can't do without LTP */
118 #ifdef LD_DEC
119 #ifndef ERROR_RESILIENCE
120 #define ERROR_RESILIENCE
121 #endif
122 #ifndef LTP_DEC
123 #define LTP_DEC
124 #endif
125 #endif
127 #define ALLOW_SMALL_FRAMELENGTH
130 // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC)
131 #define LC_ONLY_DECODER
132 #ifdef LC_ONLY_DECODER
133 #undef LD_DEC
134 #undef LTP_DEC
135 #undef MAIN_DEC
136 #undef SSR_DEC
137 #undef DRM
138 #undef ALLOW_SMALL_FRAMELENGTH
139 #undef ERROR_RESILIENCE
140 #endif
142 #if MEMORYSIZE > 2
143 #define SBR_DEC
144 //#define SBR_LOW_POWER
145 #define PS_DEC
146 #endif
148 /* FIXED POINT: No MAIN decoding */
149 #ifdef FIXED_POINT
150 # ifdef MAIN_DEC
151 # undef MAIN_DEC
152 # endif
153 #endif // FIXED_POINT
155 #ifdef DRM
156 # ifndef SCALABLE_DEC
157 # define SCALABLE_DEC
158 # endif
159 #endif
162 #ifdef FIXED_POINT
163 #define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B)
164 #define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B)
165 #define DIV_Q(A, B) (((int64_t)A << Q2_BITS )/B)
166 #else
167 #define DIV_R(A, B) ((A)/(B))
168 #define DIV_C(A, B) ((A)/(B))
169 #define DIV_Q(A, B) ((A)/(B))
170 #endif
172 #ifndef SBR_LOW_POWER
173 #define qmf_t complex_t
174 #define QMF_RE(A) RE(A)
175 #define QMF_IM(A) IM(A)
176 #else
177 #define qmf_t real_t
178 #define QMF_RE(A) (A)
179 #define QMF_IM(A)
180 #endif
183 /* END COMPILE TIME DEFINITIONS */
185 #if defined(_WIN32) && !defined(__MINGW32__)
187 #include <stdlib.h>
189 typedef unsigned __int64 uint64_t;
190 typedef unsigned __int32 uint32_t;
191 typedef unsigned __int16 uint16_t;
192 typedef unsigned __int8 uint8_t;
193 typedef __int64 int64_t;
194 typedef __int32 int32_t;
195 typedef __int16 int16_t;
196 typedef __int8 int8_t;
197 typedef float float32_t;
200 #else
202 #include <stdio.h>
203 #ifdef HAVE_SYS_TYPES_H
204 # include "inttypes.h"
205 #endif
206 #ifdef HAVE_SYS_STAT_H
207 # include <sys/stat.h>
208 #endif
209 #ifdef STDC_HEADERS
210 # include <stdlib.h>
211 # include <stddef.h>
212 #else
213 # ifdef HAVE_STDLIB_H
214 # include <stdlib.h>
215 # endif
216 #endif
217 #ifdef HAVE_STRING_H
218 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
219 # include <memory.h>
220 # endif
221 //# include <string.h>
222 #endif
223 #ifdef HAVE_STRINGS_H
224 //# include <strings.h>
225 #endif
226 #ifdef HAVE_INTTYPES_H
227 # include <inttypes.h>
228 #else
229 # ifdef HAVE_STDINT_H
230 # include <stdint.h>
231 # else
232 /* we need these... */
233 typedef unsigned long long uint64_t;
234 typedef unsigned long uint32_t;
235 typedef unsigned short uint16_t;
236 typedef unsigned char uint8_t;
237 typedef long long int64_t;
238 typedef long int32_t;
239 typedef short int16_t;
240 typedef char int8_t;
241 # endif
242 #endif
243 #ifdef HAVE_UNISTD_H
244 # include <unistd.h>
245 #endif
247 #ifndef HAVE_FLOAT32_T
248 typedef float float32_t;
249 #endif
251 #if STDC_HEADERS
252 //# include <string.h>
253 #else
254 # if !HAVE_STRCHR
255 # define strchr index
256 # define strrchr rindex
257 # endif
258 char *strchr(), *strrchr();
259 # if !HAVE_MEMCPY
260 # define memcpy(d, s, n) bcopy((s), (d), (n))
261 # define memmove(d, s, n) bcopy((s), (d), (n))
262 # endif
263 #endif
265 #endif
267 #ifdef WORDS_BIGENDIAN
268 #define ARCH_IS_BIG_ENDIAN
269 #endif
271 /* FIXED_POINT doesn't work with MAIN and SSR yet */
272 #ifdef FIXED_POINT
273 #undef MAIN_DEC
274 #undef SSR_DEC
275 #endif
278 #if defined(FIXED_POINT)
280 #include "fixed.h"
282 #elif defined(USE_DOUBLE_PRECISION)
284 typedef double real_t;
286 #include <math.h>
288 #define MUL_R(A,B) ((A)*(B))
289 #define MUL_C(A,B) ((A)*(B))
290 #define MUL_F(A,B) ((A)*(B))
291 #define MUL_Q2(A,B) ((A)*(B))
293 /* Complex multiplication */
294 static INLINE void ComplexMult(real_t *y1, real_t *y2,
295 real_t x1, real_t x2, real_t c1, real_t c2)
297 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
298 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
301 #define REAL_CONST(A) ((real_t)(A))
302 #define COEF_CONST(A) ((real_t)(A))
303 #define Q2_CONST(A) ((real_t)(A))
304 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
306 #else /* Normal floating point operation */
308 typedef float real_t;
310 #define MUL_R(A,B) ((A)*(B))
311 #define MUL_C(A,B) ((A)*(B))
312 #define MUL_F(A,B) ((A)*(B))
313 #define MUL_Q2(A,B) ((A)*(B))
315 #define REAL_CONST(A) ((real_t)(A))
316 #define COEF_CONST(A) ((real_t)(A))
317 #define Q2_CONST(A) ((real_t)(A))
318 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
320 /* Complex multiplication */
321 static INLINE void ComplexMult(real_t *y1, real_t *y2,
322 real_t x1, real_t x2, real_t c1, real_t c2)
324 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
325 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
328 /* rockbox: must be commented to build for non-FP
329 #if defined(_WIN32) && !defined(__MINGW32__)
330 #define HAS_LRINTF
331 static INLINE int lrintf(float f)
333 int i;
334 __asm
336 fld f
337 fistp i
339 return i;
341 #elif (defined(__i386__) && defined(__GNUC__))
342 #define HAS_LRINTF
343 // from http://www.stereopsis.com/FPU.html
344 static INLINE int lrintf(float f)
346 int i;
347 __asm__ __volatile__ (
348 "flds %1 \n\t"
349 "fistpl %0 \n\t"
350 : "=m" (i)
351 : "m" (f));
352 return i;
354 #endif
357 #ifdef __ICL /* only Intel C compiler has fmath ??? */
359 #include <mathf.h>
361 #define sin sinf
362 #define cos cosf
363 #define log logf
364 #define floor floorf
365 #define ceil ceilf
366 #define sqrt sqrtf
368 #else
370 #ifdef HAVE_LRINTF
371 # define HAS_LRINTF
372 # define _ISOC9X_SOURCE 1
373 # define _ISOC99_SOURCE 1
374 # define __USE_ISOC9X 1
375 # define __USE_ISOC99 1
376 #endif
378 #include <math.h>
380 #ifdef HAVE_SINF
381 # define sin sinf
382 #error
383 #endif
384 #ifdef HAVE_COSF
385 # define cos cosf
386 #endif
387 #ifdef HAVE_LOGF
388 # define log logf
389 #endif
390 #ifdef HAVE_EXPF
391 # define exp expf
392 #endif
393 #ifdef HAVE_FLOORF
394 # define floor floorf
395 #endif
396 #ifdef HAVE_CEILF
397 # define ceil ceilf
398 #endif
399 #ifdef HAVE_SQRTF
400 # define sqrt sqrtf
401 #endif
403 #endif
405 #endif
407 #ifndef HAS_LRINTF
408 /* standard cast */
409 #define lrintf(f) ((int32_t)(f))
410 #endif
412 typedef real_t complex_t[2];
413 #define RE(A) A[0]
414 #define IM(A) A[1]
417 /* common functions */
418 uint8_t cpu_has_sse(void);
419 uint32_t random_int(void);
420 #define wl_min_lzc(x) bs_generic(x, BS_LOG2|BS_0_0)
421 #ifdef FIXED_POINT
422 #define LOG2_MIN_INF REAL_CONST(-10000)
423 int32_t log2_int(uint32_t val);
424 int32_t log2_fix(uint32_t val);
425 uint32_t pow2_int(real_t val);
426 uint32_t pow2_fix(real_t val);
427 #endif
428 uint8_t get_sr_index(const uint32_t samplerate);
429 uint8_t max_pred_sfb(const uint8_t sr_index);
430 uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
431 const uint8_t is_short);
432 uint32_t get_sample_rate(const uint8_t sr_index);
433 int8_t can_decode_ot(const uint8_t object_type);
435 void *faad_malloc(size_t size);
436 void faad_free(void *b);
438 //#define PROFILE
439 #ifdef PROFILE
440 static int64_t faad_get_ts()
442 __asm
444 rdtsc
447 #endif
449 #ifndef M_PI
450 #define M_PI 3.14159265358979323846
451 #endif
452 #ifndef M_PI_2 /* PI/2 */
453 #define M_PI_2 1.57079632679489661923
454 #endif
457 #ifdef __cplusplus
459 #endif
460 #endif