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 #ifndef OUTSIDE_SPEEX
39 #include "speex/speexdsp_types.h"
40 #endif
41 
42 #define ABS(x) ((x) < 0 ? (-(x)) : (x))      /**< Absolute integer value. */
43 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 16-bit value.  */
44 #define MIN16(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
45 #define MAX16(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
46 #define ABS32(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 32-bit value.  */
47 #define MIN32(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
48 #define MAX32(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
49 
50 #ifdef FIXED_POINT
51 
52 typedef spx_int16_t spx_word16_t;
53 typedef spx_int32_t   spx_word32_t;
54 typedef spx_word32_t spx_mem_t;
55 typedef spx_word16_t spx_coef_t;
56 typedef spx_word16_t spx_lsp_t;
57 typedef spx_word32_t spx_sig_t;
58 
59 #define Q15ONE 32767
60 
61 #define LPC_SCALING  8192
62 #define SIG_SCALING  16384
63 #define LSP_SCALING  8192.
64 #define GAMMA_SCALING 32768.
65 #define GAIN_SCALING 64
66 #define GAIN_SCALING_1 0.015625
67 
68 #define LPC_SHIFT    13
69 #define LSP_SHIFT    13
70 #define SIG_SHIFT    14
71 
72 #define VERY_SMALL 0
73 #define VERY_LARGE32 ((spx_word32_t)2147483647)
74 #define VERY_LARGE16 ((spx_word16_t)32767)
75 #define Q15_ONE ((spx_word16_t)32767)
76 
77 
78 #ifdef FIXED_DEBUG
79 #include "fixed_debug.h"
80 #else
81 
82 #include "fixed_generic.h"
83 
84 #ifdef ARM5E_ASM
85 #include "fixed_arm5e.h"
86 #elif defined (ARM4_ASM)
87 #include "fixed_arm4.h"
88 #elif defined (ARM5E_ASM)
89 #include "fixed_arm5e.h"
90 #elif defined (BFIN_ASM)
91 #include "fixed_bfin.h"
92 #endif
93 
94 #endif
95 
96 
97 #else
98 
99 typedef float spx_mem_t;
100 typedef float spx_coef_t;
101 typedef float spx_lsp_t;
102 typedef float spx_sig_t;
103 typedef float spx_word16_t;
104 typedef float spx_word32_t;
105 
106 #define Q15ONE 1.0f
107 #define LPC_SCALING  1.f
108 #define SIG_SCALING  1.f
109 #define LSP_SCALING  1.f
110 #define GAMMA_SCALING 1.f
111 #define GAIN_SCALING 1.f
112 #define GAIN_SCALING_1 1.f
113 
114 #define LPC_SHIFT    0
115 #define LSP_SHIFT    0
116 #define SIG_SHIFT    0
117 
118 #define VERY_SMALL 1e-15f
119 #define VERY_LARGE32 1e15f
120 #define VERY_LARGE16 1e15f
121 #define Q15_ONE ((spx_word16_t)1.f)
122 
123 #define QCONST16(x,bits) (x)
124 #define QCONST32(x,bits) (x)
125 
126 #define NEG16(x) (-(x))
127 #define NEG32(x) (-(x))
128 #define EXTRACT16(x) (x)
129 #define EXTEND32(x) (x)
130 #define SHR16(a,shift) (a)
131 #define SHL16(a,shift) (a)
132 #define SHR32(a,shift) (a)
133 #define SHL32(a,shift) (a)
134 #define PSHR16(a,shift) (a)
135 #define PSHR32(a,shift) (a)
136 #define VSHR32(a,shift) (a)
137 #define SATURATE16(x,a) (x)
138 #define SATURATE32(x,a) (x)
139 
140 #define PSHR(a,shift)       (a)
141 #define SHR(a,shift)       (a)
142 #define SHL(a,shift)       (a)
143 #define SATURATE(x,a) (x)
144 
145 #define ADD16(a,b) ((a)+(b))
146 #define SUB16(a,b) ((a)-(b))
147 #define ADD32(a,b) ((a)+(b))
148 #define SUB32(a,b) ((a)-(b))
149 #define MULT16_16_16(a,b)     ((a)*(b))
150 #define MULT16_16(a,b)     ((spx_word32_t)(a)*(spx_word32_t)(b))
151 #define MAC16_16(c,a,b)     ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
152 
153 #define MULT16_32_Q11(a,b)     ((a)*(b))
154 #define MULT16_32_Q13(a,b)     ((a)*(b))
155 #define MULT16_32_Q14(a,b)     ((a)*(b))
156 #define MULT16_32_Q15(a,b)     ((a)*(b))
157 #define MULT16_32_P15(a,b)     ((a)*(b))
158 
159 #define MAC16_32_Q11(c,a,b)     ((c)+(a)*(b))
160 #define MAC16_32_Q15(c,a,b)     ((c)+(a)*(b))
161 
162 #define MAC16_16_Q11(c,a,b)     ((c)+(a)*(b))
163 #define MAC16_16_Q13(c,a,b)     ((c)+(a)*(b))
164 #define MAC16_16_P13(c,a,b)     ((c)+(a)*(b))
165 #define MULT16_16_Q11_32(a,b)     ((a)*(b))
166 #define MULT16_16_Q13(a,b)     ((a)*(b))
167 #define MULT16_16_Q14(a,b)     ((a)*(b))
168 #define MULT16_16_Q15(a,b)     ((a)*(b))
169 #define MULT16_16_P15(a,b)     ((a)*(b))
170 #define MULT16_16_P13(a,b)     ((a)*(b))
171 #define MULT16_16_P14(a,b)     ((a)*(b))
172 
173 #define DIV32_16(a,b)     (((spx_word32_t)(a))/(spx_word16_t)(b))
174 #define PDIV32_16(a,b)     (((spx_word32_t)(a))/(spx_word16_t)(b))
175 #define DIV32(a,b)     (((spx_word32_t)(a))/(spx_word32_t)(b))
176 #define PDIV32(a,b)     (((spx_word32_t)(a))/(spx_word32_t)(b))
177 
178 
179 #endif
180 
181 
182 #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
183 
184 /* 2 on TI C5x DSP */
185 #define BYTES_PER_CHAR 2
186 #define BITS_PER_CHAR 16
187 #define LOG2_BITS_PER_CHAR 4
188 
189 #else
190 
191 #define BYTES_PER_CHAR 1
192 #define BITS_PER_CHAR 8
193 #define LOG2_BITS_PER_CHAR 3
194 
195 #endif
196 
197 #endif
198