uploaded original spice-server-0.12.4 and celt-0.5.1.3
[sdk/emulator/libs/spice-server.git] / lib / celt-0.5.1.3 / libcelt / arch.h
1 /* Copyright (C) 2003-2008 Jean-Marc Valin */
2 /**
3    @file arch.h
4    @brief Various architecture definitions for CELT
5 */
6 /*
7    Redistribution and use in source and binary forms, with or without
8    modification, are permitted provided that the following conditions
9    are met:
10    
11    - Redistributions of source code must retain the above copyright
12    notice, this list of conditions and the following disclaimer.
13    
14    - Redistributions in binary form must reproduce the above copyright
15    notice, this list of conditions and the following disclaimer in the
16    documentation and/or other materials provided with the distribution.
17    
18    - Neither the name of the Xiph.org Foundation nor the names of its
19    contributors may be used to endorse or promote products derived from
20    this software without specific prior written permission.
21    
22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
26    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #ifndef ARCH_H
36 #define ARCH_H
37
38 #include "celt_types.h"
39
40
41 #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
42 #ifdef ENABLE_ASSERTIONS
43 #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}}
44 #define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}}
45 #else
46 #define celt_assert(cond)
47 #define celt_assert2(cond, message)
48 #endif
49
50 #define IMUL32(a,b) ((a)*(b))
51
52 #define ABS(x) ((x) < 0 ? (-(x)) : (x))      /**< Absolute integer value. */
53 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 16-bit value.  */
54 #define MIN16(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
55 #define MAX16(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
56 #define ABS32(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 32-bit value.  */
57 #define MIN32(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
58 #define MAX32(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
59 #define IMAX(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum int value.   */
60 #define UADD32(a,b) ((a)+(b))
61 #define USUB32(a,b) ((a)-(b))
62
63 #define PRINT_MIPS(file)
64
65 #ifdef FIXED_POINT
66
67 typedef celt_int16_t celt_word16_t;
68 typedef celt_int32_t celt_word32_t;
69
70 typedef celt_word32_t celt_sig_t;
71 typedef celt_word16_t celt_norm_t;
72 typedef celt_word32_t celt_ener_t;
73 typedef celt_word16_t celt_pgain_t;
74 typedef celt_word32_t celt_mask_t;
75
76 #define Q15ONE 32767
77 #define Q30ONE 1073741823
78
79 #define SIG_SHIFT 12
80
81 #define NORM_SCALING 16384
82 #define NORM_SCALING_1 (1.f/16384.f)
83 #define NORM_SHIFT 14
84
85 #define ENER_SCALING 16384.f
86 #define ENER_SCALING_1 (1.f/16384.f)
87 #define ENER_SHIFT 14
88
89 #define PGAIN_SCALING 32768.f
90 #define PGAIN_SCALING_1 (1.f/32768.f)
91 #define PGAIN_SHIFT 15
92
93 #define DB_SCALING 256.f
94 #define DB_SCALING_1 (1.f/256.f)
95
96 #define EPSILON 1
97 #define VERY_SMALL 0
98 #define VERY_LARGE32 ((celt_word32_t)2147483647)
99 #define VERY_LARGE16 ((celt_word16_t)32767)
100 #define Q15_ONE ((celt_word16_t)32767)
101 #define Q15_ONE_1 (1.f/32768.f)
102
103 #define SCALEIN(a)      (a)
104 #define SCALEOUT(a)     (a)
105
106 #ifdef FIXED_DEBUG
107 #include "fixed_debug.h"
108 #else
109
110 #include "fixed_generic.h"
111
112 #ifdef ARM5E_ASM
113 #include "fixed_arm5e.h"
114 #elif defined (ARM4_ASM)
115 #include "fixed_arm4.h"
116 #elif defined (BFIN_ASM)
117 #include "fixed_bfin.h"
118 #elif defined (TI_C5X_ASM)
119 #include "fixed_c5x.h"
120 #elif defined (TI_C6X_ASM)
121 #include "fixed_c6x.h"
122 #endif
123
124 #endif
125
126
127 #else /* FIXED_POINT */
128
129 typedef float celt_word16_t;
130 typedef float celt_word32_t;
131
132 typedef float celt_sig_t;
133 typedef float celt_norm_t;
134 typedef float celt_ener_t;
135 typedef float celt_pgain_t;
136 typedef float celt_mask_t;
137
138 #define Q15ONE 1.0f
139 #define Q30ONE 1.0f
140
141 #define NORM_SCALING 1.f
142 #define NORM_SCALING_1 1.f
143 #define ENER_SCALING 1.f
144 #define ENER_SCALING_1 1.f
145 #define PGAIN_SCALING 1.f
146 #define PGAIN_SCALING_1 1.f
147
148 #define DB_SCALING 1.f
149 #define DB_SCALING_1 1.f
150
151 #define EPSILON 1e-15f
152 #define VERY_SMALL 1e-15f
153 #define VERY_LARGE32 1e15f
154 #define VERY_LARGE16 1e15f
155 #define Q15_ONE ((celt_word16_t)1.f)
156 #define Q15_ONE_1 ((celt_word16_t)1.f)
157
158 #define QCONST16(x,bits) (x)
159 #define QCONST32(x,bits) (x)
160
161 #define NEG16(x) (-(x))
162 #define NEG32(x) (-(x))
163 #define EXTRACT16(x) (x)
164 #define EXTEND32(x) (x)
165 #define SHR16(a,shift) (a)
166 #define SHL16(a,shift) (a)
167 #define SHR32(a,shift) (a)
168 #define SHL32(a,shift) (a)
169 #define PSHR16(a,shift) (a)
170 #define PSHR32(a,shift) (a)
171 #define VSHR32(a,shift) (a)
172 #define SATURATE16(x,a) (x)
173 #define SATURATE32(x,a) (x)
174
175 #define PSHR(a,shift)   (a)
176 #define SHR(a,shift)    (a)
177 #define SHL(a,shift)    (a)
178 #define SATURATE(x,a)   (x)
179
180 #define ROUND16(a,shift)  (a)
181 #define HALF32(x)       (.5f*(x))
182
183 #define ADD16(a,b) ((a)+(b))
184 #define SUB16(a,b) ((a)-(b))
185 #define ADD32(a,b) ((a)+(b))
186 #define SUB32(a,b) ((a)-(b))
187 #define MULT16_16_16(a,b)     ((a)*(b))
188 #define MULT16_16(a,b)     ((celt_word32_t)(a)*(celt_word32_t)(b))
189 #define MAC16_16(c,a,b)     ((c)+(celt_word32_t)(a)*(celt_word32_t)(b))
190
191 #define MULT16_32_Q11(a,b)     ((a)*(b))
192 #define MULT16_32_Q13(a,b)     ((a)*(b))
193 #define MULT16_32_Q14(a,b)     ((a)*(b))
194 #define MULT16_32_Q15(a,b)     ((a)*(b))
195 #define MULT16_32_Q16(a,b)     ((a)*(b))
196 #define MULT16_32_P15(a,b)     ((a)*(b))
197
198 #define MULT32_32_Q31(a,b)     ((a)*(b))
199
200 #define MAC16_32_Q11(c,a,b)     ((c)+(a)*(b))
201 #define MAC16_32_Q15(c,a,b)     ((c)+(a)*(b))
202
203 #define MAC16_16_Q11(c,a,b)     ((c)+(a)*(b))
204 #define MAC16_16_Q13(c,a,b)     ((c)+(a)*(b))
205 #define MAC16_16_P13(c,a,b)     ((c)+(a)*(b))
206 #define MULT16_16_Q11_32(a,b)     ((a)*(b))
207 #define MULT16_16_Q13(a,b)     ((a)*(b))
208 #define MULT16_16_Q14(a,b)     ((a)*(b))
209 #define MULT16_16_Q15(a,b)     ((a)*(b))
210 #define MULT16_16_P15(a,b)     ((a)*(b))
211 #define MULT16_16_P13(a,b)     ((a)*(b))
212 #define MULT16_16_P14(a,b)     ((a)*(b))
213
214 #define DIV32_16(a,b)     (((celt_word32_t)(a))/(celt_word16_t)(b))
215 #define PDIV32_16(a,b)     (((celt_word32_t)(a))/(celt_word16_t)(b))
216 #define DIV32(a,b)     (((celt_word32_t)(a))/(celt_word32_t)(b))
217 #define PDIV32(a,b)     (((celt_word32_t)(a))/(celt_word32_t)(b))
218
219 #define SCALEIN(a)      ((a)*32768.)
220 #define SCALEOUT(a)     ((a)*(1/32768.))
221
222 #endif /* !FIXED_POINT */
223
224
225 #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
226
227 /* 2 on TI C5x DSP */
228 #define BYTES_PER_CHAR 2 
229 #define BITS_PER_CHAR 16
230 #define LOG2_BITS_PER_CHAR 4
231
232 #else /* CONFIG_TI_C54X */
233
234 #define BYTES_PER_CHAR 1
235 #define BITS_PER_CHAR 8
236 #define LOG2_BITS_PER_CHAR 3
237
238 #endif /* !CONFIG_TI_C54X */
239
240 #ifndef GLOBAL_STACK_SIZE 
241 #ifdef FIXED_POINT
242 #define GLOBAL_STACK_SIZE 25000
243 #else
244 #define GLOBAL_STACK_SIZE 40000
245 #endif
246 #endif 
247
248 #endif /* ARCH_H */