• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2003 Jean-Marc Valin */
2 /**
3    @file arch.h
4    @brief Various architecture definitions Speex
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 /* A couple test to catch stupid option combinations */
39 #ifdef FIXED_POINT
40 
41 #ifdef FLOATING_POINT
42 #error You cannot compile as floating point and fixed point at the same time
43 #endif
44 #ifdef _USE_SSE
45 #error SSE is only for floating-point
46 #endif
47 #if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM))
48 #error Make up your mind. What CPU do you have?
49 #endif
50 #ifdef VORBIS_PSYCHO
51 #error Vorbis-psy model currently not implemented in fixed-point
52 #endif
53 
54 #else
55 
56 #ifndef FLOATING_POINT
57 #error You now need to define either FIXED_POINT or FLOATING_POINT
58 #endif
59 #if defined (ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM)
60 #error I suppose you can have a [ARM4/ARM5E/Blackfin] that has float instructions?
61 #endif
62 #ifdef FIXED_POINT_DEBUG
63 #error "Don't you think enabling fixed-point is a good thing to do if you want to debug that?"
64 #endif
65 
66 
67 #endif
68 
69 #ifndef OUTSIDE_SPEEX
70 #include "speex/speexdsp_types.h"
71 #endif
72 
73 #define ABS(x) ((x) < 0 ? (-(x)) : (x))      /**< Absolute integer value. */
74 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 16-bit value.  */
75 #define MIN16(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
76 #define MAX16(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
77 #define ABS32(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 32-bit value.  */
78 #define MIN32(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
79 #define MAX32(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
80 
81 #ifdef FIXED_POINT
82 
83 typedef spx_int16_t spx_word16_t;
84 typedef spx_int32_t spx_word32_t;
85 typedef spx_word32_t spx_mem_t;
86 typedef spx_word16_t spx_coef_t;
87 typedef spx_word16_t spx_lsp_t;
88 typedef spx_word32_t spx_sig_t;
89 
90 #define Q15ONE 32767
91 
92 #define LPC_SCALING  8192
93 #define SIG_SCALING  16384
94 #define LSP_SCALING  8192.
95 #define GAMMA_SCALING 32768.
96 #define GAIN_SCALING 64
97 #define GAIN_SCALING_1 0.015625
98 
99 #define LPC_SHIFT    13
100 #define LSP_SHIFT    13
101 #define SIG_SHIFT    14
102 #define GAIN_SHIFT   6
103 
104 #define VERY_SMALL 0
105 #define VERY_LARGE32 ((spx_word32_t)2147483647)
106 #define VERY_LARGE16 ((spx_word16_t)32767)
107 #define Q15_ONE ((spx_word16_t)32767)
108 
109 
110 #ifdef FIXED_DEBUG
111 #include "fixed_debug.h"
112 #else
113 
114 #include "fixed_generic.h"
115 
116 #ifdef ARM5E_ASM
117 #include "fixed_arm5e.h"
118 #elif defined (ARM4_ASM)
119 #include "fixed_arm4.h"
120 #elif defined (BFIN_ASM)
121 #include "fixed_bfin.h"
122 #endif
123 
124 #endif
125 
126 
127 #else
128 
129 typedef float spx_mem_t;
130 typedef float spx_coef_t;
131 typedef float spx_lsp_t;
132 typedef float spx_sig_t;
133 typedef float spx_word16_t;
134 typedef float spx_word32_t;
135 
136 #define Q15ONE 1.0f
137 #define LPC_SCALING  1.f
138 #define SIG_SCALING  1.f
139 #define LSP_SCALING  1.f
140 #define GAMMA_SCALING 1.f
141 #define GAIN_SCALING 1.f
142 #define GAIN_SCALING_1 1.f
143 
144 
145 #define VERY_SMALL 1e-15f
146 #define VERY_LARGE32 1e15f
147 #define VERY_LARGE16 1e15f
148 #define Q15_ONE ((spx_word16_t)1.f)
149 
150 #define QCONST16(x,bits) (x)
151 #define QCONST32(x,bits) (x)
152 
153 #define NEG16(x) (-(x))
154 #define NEG32(x) (-(x))
155 #define EXTRACT16(x) (x)
156 #define EXTEND32(x) (x)
157 #define SHR16(a,shift) (a)
158 #define SHL16(a,shift) (a)
159 #define SHR32(a,shift) (a)
160 #define SHL32(a,shift) (a)
161 #define PSHR16(a,shift) (a)
162 #define PSHR32(a,shift) (a)
163 #define VSHR32(a,shift) (a)
164 #define SATURATE16(x,a) (x)
165 #define SATURATE32(x,a) (x)
166 #define SATURATE32PSHR(x,shift,a) (x)
167 
168 #define PSHR(a,shift)       (a)
169 #define SHR(a,shift)       (a)
170 #define SHL(a,shift)       (a)
171 #define SATURATE(x,a) (x)
172 
173 #define ADD16(a,b) ((a)+(b))
174 #define SUB16(a,b) ((a)-(b))
175 #define ADD32(a,b) ((a)+(b))
176 #define SUB32(a,b) ((a)-(b))
177 #define MULT16_16_16(a,b)     ((a)*(b))
178 #define MULT16_16(a,b)     ((spx_word32_t)(a)*(spx_word32_t)(b))
179 #define MAC16_16(c,a,b)     ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
180 
181 #define MULT16_32_Q11(a,b)     ((a)*(b))
182 #define MULT16_32_Q13(a,b)     ((a)*(b))
183 #define MULT16_32_Q14(a,b)     ((a)*(b))
184 #define MULT16_32_Q15(a,b)     ((a)*(b))
185 #define MULT16_32_P15(a,b)     ((a)*(b))
186 
187 #define MAC16_32_Q11(c,a,b)     ((c)+(a)*(b))
188 #define MAC16_32_Q15(c,a,b)     ((c)+(a)*(b))
189 
190 #define MAC16_16_Q11(c,a,b)     ((c)+(a)*(b))
191 #define MAC16_16_Q13(c,a,b)     ((c)+(a)*(b))
192 #define MAC16_16_P13(c,a,b)     ((c)+(a)*(b))
193 #define MULT16_16_Q11_32(a,b)     ((a)*(b))
194 #define MULT16_16_Q13(a,b)     ((a)*(b))
195 #define MULT16_16_Q14(a,b)     ((a)*(b))
196 #define MULT16_16_Q15(a,b)     ((a)*(b))
197 #define MULT16_16_P15(a,b)     ((a)*(b))
198 #define MULT16_16_P13(a,b)     ((a)*(b))
199 #define MULT16_16_P14(a,b)     ((a)*(b))
200 
201 #define DIV32_16(a,b)     (((spx_word32_t)(a))/(spx_word16_t)(b))
202 #define PDIV32_16(a,b)     (((spx_word32_t)(a))/(spx_word16_t)(b))
203 #define DIV32(a,b)     (((spx_word32_t)(a))/(spx_word32_t)(b))
204 #define PDIV32(a,b)     (((spx_word32_t)(a))/(spx_word32_t)(b))
205 
206 
207 #endif
208 
209 
210 #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
211 
212 /* 2 on TI C5x DSP */
213 #define BYTES_PER_CHAR 2
214 #define BITS_PER_CHAR 16
215 #define LOG2_BITS_PER_CHAR 4
216 
217 #else
218 
219 #define BYTES_PER_CHAR 1
220 #define BITS_PER_CHAR 8
221 #define LOG2_BITS_PER_CHAR 3
222 
223 #endif
224 
225 
226 
227 #ifdef FIXED_DEBUG
228 extern long long spx_mips;
229 #endif
230 
231 
232 #endif
233