Smart Remote 3 nRF52 v1.2
arch.h
1 /* Copyright (c) 2003-2008 Jean-Marc Valin
2  Copyright (c) 2007-2008 CSIRO
3  Copyright (c) 2007-2009 Xiph.Org Foundation
4  Written by Jean-Marc Valin */
9 /*
10  Redistribution and use in source and binary forms, with or without
11  modification, are permitted provided that the following conditions
12  are met:
13 
14  - Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16 
17  - Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 #ifndef ARCH_H
35 #define ARCH_H
36 
37 #include "opus_types.h"
38 #include "opus_defines.h"
39 #include "app_error.h"
40 
41 # if !defined(__GNUC_PREREQ)
42 # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
43 # define __GNUC_PREREQ(_maj,_min) \
44  ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
45 # else
46 # define __GNUC_PREREQ(_maj,_min) 0
47 # endif
48 # endif
49 
50 #if OPUS_GNUC_PREREQ(3, 0)
51 #define opus_likely(x) (__builtin_expect(!!(x), 1))
52 #define opus_unlikely(x) (__builtin_expect(!!(x), 0))
53 #else
54 #define opus_likely(x) (!!(x))
55 #define opus_unlikely(x) (!!(x))
56 #endif
57 
58 #define CELT_SIG_SCALE 32768.f
59 
60 #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
61 #ifdef ENABLE_ASSERTIONS
62 #include <stdio.h>
63 #include <stdlib.h>
64 static OPUS_INLINE void _celt_fatal(const char *str, const char *file, int line)
65 {
66  APP_ERROR_CHECK_BOOL(false);
67 }
68 #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}}
69 #define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}}
70 #else
71 #define celt_assert(cond)
72 #define celt_assert2(cond, message)
73 #endif
74 
75 #define IMUL32(a,b) ((a)*(b))
76 
77 #define MIN16(a,b) ((a) < (b) ? (a) : (b))
78 #define MAX16(a,b) ((a) > (b) ? (a) : (b))
79 #define MIN32(a,b) ((a) < (b) ? (a) : (b))
80 #define MAX32(a,b) ((a) > (b) ? (a) : (b))
81 #define IMIN(a,b) ((a) < (b) ? (a) : (b))
82 #define IMAX(a,b) ((a) > (b) ? (a) : (b))
83 #define UADD32(a,b) ((a)+(b))
84 #define USUB32(a,b) ((a)-(b))
85 
86 /* Set this if opus_int64 is a native type of the CPU. */
87 /* Assume that all LP64 architectures have fast 64-bit types; also x86_64
88  (which can be ILP32 for x32) and Win64 (which is LLP64). */
89 #if defined(__x86_64__) || defined(__LP64__) || defined(_WIN64)
90 #define OPUS_FAST_INT64 1
91 #else
92 #define OPUS_FAST_INT64 0
93 #endif
94 
95 #define PRINT_MIPS(file)
96 
97 #ifdef FIXED_POINT
98 
99 typedef opus_int16 opus_val16;
100 typedef opus_int32 opus_val32;
101 typedef opus_int64 opus_val64;
102 
103 typedef opus_val32 celt_sig;
104 typedef opus_val16 celt_norm;
105 typedef opus_val32 celt_ener;
106 
107 #define Q15ONE 32767
108 
109 #define SIG_SHIFT 12
110 /* Safe saturation value for 32-bit signals. Should be less than
111  2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/
112 #define SIG_SAT (300000000)
113 
114 #define NORM_SCALING 16384
115 
116 #define DB_SHIFT 10
117 
118 #define EPSILON 1
119 #define VERY_SMALL 0
120 #define VERY_LARGE16 ((opus_val16)32767)
121 #define Q15_ONE ((opus_val16)32767)
122 
123 #define SCALEIN(a) (a)
124 #define SCALEOUT(a) (a)
125 
126 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))
127 #define ABS32(x) ((x) < 0 ? (-(x)) : (x))
128 
129 static OPUS_INLINE opus_int16 SAT16(opus_int32 x) {
130  return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
131 }
132 
133 #ifdef FIXED_DEBUG
134 #include "fixed_debug.h"
135 #else
136 
137 #include "fixed_generic.h"
138 
139 #ifdef OPUS_ARM_PRESUME_AARCH64_NEON_INTR
140 #include "arm/fixed_arm64.h"
141 #elif OPUS_ARM_INLINE_EDSP
142 #include "arm/fixed_armv5e.h"
143 #elif defined (OPUS_ARM_INLINE_ASM)
144 #include "arm/fixed_armv4.h"
145 #elif defined (BFIN_ASM)
146 #include "fixed_bfin.h"
147 #elif defined (TI_C5X_ASM)
148 #include "fixed_c5x.h"
149 #elif defined (TI_C6X_ASM)
150 #include "fixed_c6x.h"
151 #endif
152 
153 #endif
154 
155 #else /* FIXED_POINT */
156 
157 typedef float opus_val16;
158 typedef float opus_val32;
159 typedef float opus_val64;
160 
161 typedef float celt_sig;
162 typedef float celt_norm;
163 typedef float celt_ener;
164 
165 #ifdef FLOAT_APPROX
166 /* This code should reliably detect NaN/inf even when -ffast-math is used.
167  Assumes IEEE 754 format. */
168 static OPUS_INLINE int celt_isnan(float x)
169 {
170  union {float f; opus_uint32 i;} in;
171  in.f = x;
172  return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0;
173 }
174 #else
175 #ifdef __FAST_MATH__
176 #error Cannot build libopus with -ffast-math unless FLOAT_APPROX is defined. This could result in crashes on extreme (e.g. NaN) input
177 #endif
178 #define celt_isnan(x) ((x)!=(x))
179 #endif
180 
181 #define Q15ONE 1.0f
182 
183 #define NORM_SCALING 1.f
184 
185 #define EPSILON 1e-15f
186 #define VERY_SMALL 1e-30f
187 #define VERY_LARGE16 1e15f
188 #define Q15_ONE ((opus_val16)1.f)
189 
190 /* This appears to be the same speed as C99's fabsf() but it's more portable. */
191 #define ABS16(x) ((float)fabs(x))
192 #define ABS32(x) ((float)fabs(x))
193 
194 #define QCONST16(x,bits) (x)
195 #define QCONST32(x,bits) (x)
196 
197 #define NEG16(x) (-(x))
198 #define NEG32(x) (-(x))
199 #define NEG32_ovflw(x) (-(x))
200 #define EXTRACT16(x) (x)
201 #define EXTEND32(x) (x)
202 #define SHR16(a,shift) (a)
203 #define SHL16(a,shift) (a)
204 #define SHR32(a,shift) (a)
205 #define SHL32(a,shift) (a)
206 #define PSHR32(a,shift) (a)
207 #define VSHR32(a,shift) (a)
208 
209 #define PSHR(a,shift) (a)
210 #define SHR(a,shift) (a)
211 #define SHL(a,shift) (a)
212 #define SATURATE(x,a) (x)
213 #define SATURATE16(x) (x)
214 
215 #define ROUND16(a,shift) (a)
216 #define SROUND16(a,shift) (a)
217 #define HALF16(x) (.5f*(x))
218 #define HALF32(x) (.5f*(x))
219 
220 #define ADD16(a,b) ((a)+(b))
221 #define SUB16(a,b) ((a)-(b))
222 #define ADD32(a,b) ((a)+(b))
223 #define SUB32(a,b) ((a)-(b))
224 #define ADD32_ovflw(a,b) ((a)+(b))
225 #define SUB32_ovflw(a,b) ((a)-(b))
226 #define MULT16_16_16(a,b) ((a)*(b))
227 #define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b))
228 #define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b))
229 
230 #define MULT16_32_Q15(a,b) ((a)*(b))
231 #define MULT16_32_Q16(a,b) ((a)*(b))
232 
233 #define MULT32_32_Q31(a,b) ((a)*(b))
234 
235 #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
236 #define MAC16_32_Q16(c,a,b) ((c)+(a)*(b))
237 
238 #define MULT16_16_Q11_32(a,b) ((a)*(b))
239 #define MULT16_16_Q11(a,b) ((a)*(b))
240 #define MULT16_16_Q13(a,b) ((a)*(b))
241 #define MULT16_16_Q14(a,b) ((a)*(b))
242 #define MULT16_16_Q15(a,b) ((a)*(b))
243 #define MULT16_16_P15(a,b) ((a)*(b))
244 #define MULT16_16_P13(a,b) ((a)*(b))
245 #define MULT16_16_P14(a,b) ((a)*(b))
246 #define MULT16_32_P16(a,b) ((a)*(b))
247 
248 #define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b))
249 #define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b))
250 
251 #define SCALEIN(a) ((a)*CELT_SIG_SCALE)
252 #define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE))
253 
254 #define SIG2WORD16(x) (x)
255 
256 #endif /* !FIXED_POINT */
257 
258 #ifndef GLOBAL_STACK_SIZE
259 #ifdef FIXED_POINT
260 #define GLOBAL_STACK_SIZE 120000
261 #else
262 #define GLOBAL_STACK_SIZE 120000
263 #endif
264 #endif
265 
266 #endif /* ARCH_H */

Documentation feedback | Developer Zone | Subscribe | Updated