blob: 52066196d43ae6540c1c60eba1de11f6d7b9c10c [file] [log] [blame]
Benny Prijonoeb30bf52006-03-04 20:43:52 +00001/* 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#include "speex/speex_types.h"
39
40#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
41#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
42#define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
43#define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
44
45#ifdef FIXED_POINT
46
47typedef spx_int16_t spx_word16_t;
48typedef spx_int32_t spx_word32_t;
49#ifdef _MSC_VER
50typedef __int64 spx_word64_t;
51#elif defined NO_LONGLONG
52typedef double spx_word64_t;
53#else
54typedef long long spx_word64_t;
55#endif
56typedef spx_word32_t spx_mem_t;
57typedef spx_word16_t spx_coef_t;
58typedef spx_word16_t spx_lsp_t;
59typedef spx_word32_t spx_sig_t;
60
61#define Q15ONE 32767
62
63#define LPC_SCALING 8192
64#define SIG_SCALING 16384
65#define LSP_SCALING 8192.
66#define GAMMA_SCALING 32768.
67#define GAIN_SCALING 64
68#define GAIN_SCALING_1 0.015625
69
70#define LPC_SHIFT 13
71#define LSP_SHIFT 13
72#define SIG_SHIFT 14
73
74#define VERY_SMALL 0
75#define VERY_LARGE32 ((spx_word32_t)2147483647)
76#define VERY_LARGE16 ((spx_word16_t)32767)
77
78
79#ifdef FIXED_DEBUG
80#include "fixed_debug.h"
81#else
82
83#include "fixed_generic.h"
84
85#ifdef ARM5E_ASM
86#include "fixed_arm5e.h"
87#elif defined (ARM4_ASM)
88#include "fixed_arm4.h"
89#elif defined (ARM5E_ASM)
90#include "fixed_arm5e.h"
91#elif defined (BFIN_ASM)
92#include "fixed_bfin.h"
93#endif
94
95#endif
96
97
98#else
99
100typedef float spx_mem_t;
101typedef float spx_coef_t;
102typedef float spx_lsp_t;
103typedef float spx_sig_t;
104typedef float spx_word16_t;
105typedef float spx_word32_t;
106typedef float spx_word64_t;
107
108#define Q15ONE 1.0f
109#define LPC_SCALING 1.f
110#define SIG_SCALING 1.f
111#define LSP_SCALING 1.f
112#define GAMMA_SCALING 1.f
113#define GAIN_SCALING 1.f
114#define GAIN_SCALING_1 1.f
115
116#define LPC_SHIFT 0
117#define LSP_SHIFT 0
118#define SIG_SHIFT 0
119
120#define VERY_SMALL 1e-15f
121#define VERY_LARGE32 1e15f
122#define VERY_LARGE16 1e15f
123
124#define QCONST16(x,bits) (x)
125#define QCONST32(x,bits) (x)
126
127#define NEG16(x) (-(x))
128#define NEG32(x) (-(x))
129#define EXTRACT16(x) (x)
130#define EXTEND32(x) (x)
131#define SHR16(a,shift) (a)
132#define SHL16(a,shift) (a)
133#define SHR32(a,shift) (a)
134#define SHL32(a,shift) (a)
135#define PSHR16(a,shift) (a)
136#define PSHR32(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 ADD64(a,b) ((a)+(b))
150#define MULT16_16_16(a,b) ((a)*(b))
151#define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
152#define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
153
154#define MULT16_32_Q11(a,b) ((a)*(b))
155#define MULT16_32_Q13(a,b) ((a)*(b))
156#define MULT16_32_Q14(a,b) ((a)*(b))
157#define MULT16_32_Q15(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 MULT16_16_Q11_32(a,b) ((a)*(b))
165#define MULT16_16_Q13(a,b) ((a)*(b))
166#define MULT16_16_Q14(a,b) ((a)*(b))
167#define MULT16_16_Q15(a,b) ((a)*(b))
168#define MULT16_16_P15(a,b) ((a)*(b))
169
170#define DIV32_16(a,b) ((a)/(b))
171#define DIV32(a,b) ((a)/(b))
172
173
174#endif
175
176
177#ifdef CONFIG_TI_C55X
178
179/* 2 on TI C5x DSP */
180#define BYTES_PER_CHAR 2
181#define BITS_PER_CHAR 16
182#define LOG2_BITS_PER_CHAR 4
183
184#else
185
186#define BYTES_PER_CHAR 1
187#define BITS_PER_CHAR 8
188#define LOG2_BITS_PER_CHAR 3
189
190#endif
191
192#endif