blob: 519b7f89ea1e6dd6b3288c1dc8a4dbadcbdf7e2a [file] [log] [blame]
Jean-Marc Valin63590892007-11-29 17:01:16 +11001/* 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
Jean-Marc Valinabe043f2008-01-31 14:26:29 +110038#include "celt_types.h"
Jean-Marc Valina85657b2008-02-20 11:59:30 +110039#include "stack_alloc.h"
Jean-Marc Valin63590892007-11-29 17:01:16 +110040
41#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
42#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
43#define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */
44#define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
45#define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
46#define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */
47#define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
48
49#ifdef FIXED_POINT
50
Jean-Marc Valinabe043f2008-01-31 14:26:29 +110051typedef celt_int16_t celt_word16_t;
52typedef celt_int32_t celt_word32_t;
Jean-Marc Valin63590892007-11-29 17:01:16 +110053
Jean-Marc Valin5c032a42008-02-25 14:55:09 +110054typedef celt_word32_t celt_sig_t;
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +110055typedef float celt_norm_t;
56
Jean-Marc Valin63590892007-11-29 17:01:16 +110057#define Q15ONE 32767
58
59#define LPC_SCALING 8192
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +110060#define SIG_SCALING 16384.f
61#define SIG_SCALING_1 0.000061035
62
Jean-Marc Valin63590892007-11-29 17:01:16 +110063#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#define GAIN_SHIFT 6
72
73#define VERY_SMALL 0
Jean-Marc Valinabe043f2008-01-31 14:26:29 +110074#define VERY_LARGE32 ((celt_word32_t)2147483647)
75#define VERY_LARGE16 ((celt_word16_t)32767)
76#define Q15_ONE ((celt_word16_t)32767)
Jean-Marc Valin63590892007-11-29 17:01:16 +110077
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 (BFIN_ASM)
90#include "fixed_bfin.h"
91#endif
92
93#endif
94
95
Jean-Marc Valin18ddc022008-02-22 14:24:50 +110096#else /* FIXED_POINT */
Jean-Marc Valin63590892007-11-29 17:01:16 +110097
Jean-Marc Valinabe043f2008-01-31 14:26:29 +110098typedef float celt_word16_t;
99typedef float celt_word32_t;
Jean-Marc Valin63590892007-11-29 17:01:16 +1100100
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100101typedef float celt_sig_t;
102typedef float celt_norm_t;
103
Jean-Marc Valin63590892007-11-29 17:01:16 +1100104#define Q15ONE 1.0f
105#define LPC_SCALING 1.f
106#define SIG_SCALING 1.f
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +1100107#define SIG_SCALING_1 1.f
Jean-Marc Valin63590892007-11-29 17:01:16 +1100108#define LSP_SCALING 1.f
109#define GAMMA_SCALING 1.f
110#define GAIN_SCALING 1.f
111#define GAIN_SCALING_1 1.f
112
113
114#define VERY_SMALL 1e-15f
115#define VERY_LARGE32 1e15f
116#define VERY_LARGE16 1e15f
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100117#define Q15_ONE ((celt_word16_t)1.f)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100118
119#define QCONST16(x,bits) (x)
120#define QCONST32(x,bits) (x)
121
122#define NEG16(x) (-(x))
123#define NEG32(x) (-(x))
124#define EXTRACT16(x) (x)
125#define EXTEND32(x) (x)
126#define SHR16(a,shift) (a)
127#define SHL16(a,shift) (a)
128#define SHR32(a,shift) (a)
129#define SHL32(a,shift) (a)
130#define PSHR16(a,shift) (a)
131#define PSHR32(a,shift) (a)
132#define VSHR32(a,shift) (a)
133#define SATURATE16(x,a) (x)
134#define SATURATE32(x,a) (x)
135
136#define PSHR(a,shift) (a)
137#define SHR(a,shift) (a)
138#define SHL(a,shift) (a)
139#define SATURATE(x,a) (x)
140
141#define ADD16(a,b) ((a)+(b))
142#define SUB16(a,b) ((a)-(b))
143#define ADD32(a,b) ((a)+(b))
144#define SUB32(a,b) ((a)-(b))
145#define MULT16_16_16(a,b) ((a)*(b))
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100146#define MULT16_16(a,b) ((celt_word32_t)(a)*(celt_word32_t)(b))
147#define MAC16_16(c,a,b) ((c)+(celt_word32_t)(a)*(celt_word32_t)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100148
149#define MULT16_32_Q11(a,b) ((a)*(b))
150#define MULT16_32_Q13(a,b) ((a)*(b))
151#define MULT16_32_Q14(a,b) ((a)*(b))
152#define MULT16_32_Q15(a,b) ((a)*(b))
153#define MULT16_32_P15(a,b) ((a)*(b))
154
155#define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
156#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
157
158#define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
159#define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
160#define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
161#define MULT16_16_Q11_32(a,b) ((a)*(b))
162#define MULT16_16_Q13(a,b) ((a)*(b))
163#define MULT16_16_Q14(a,b) ((a)*(b))
164#define MULT16_16_Q15(a,b) ((a)*(b))
165#define MULT16_16_P15(a,b) ((a)*(b))
166#define MULT16_16_P13(a,b) ((a)*(b))
167#define MULT16_16_P14(a,b) ((a)*(b))
168
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100169#define DIV32_16(a,b) (((celt_word32_t)(a))/(celt_word16_t)(b))
170#define PDIV32_16(a,b) (((celt_word32_t)(a))/(celt_word16_t)(b))
171#define DIV32(a,b) (((celt_word32_t)(a))/(celt_word32_t)(b))
172#define PDIV32(a,b) (((celt_word32_t)(a))/(celt_word32_t)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100173
174
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100175#endif /* !FIXED_POINT */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100176
177
178#if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
179
180/* 2 on TI C5x DSP */
181#define BYTES_PER_CHAR 2
182#define BITS_PER_CHAR 16
183#define LOG2_BITS_PER_CHAR 4
184
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100185#else /* CONFIG_TI_C54X */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100186
187#define BYTES_PER_CHAR 1
188#define BITS_PER_CHAR 8
189#define LOG2_BITS_PER_CHAR 3
190
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100191#endif /* !CONFIG_TI_C54X */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100192
193
194
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100195#endif /* ARCH_H */