blob: f52fb1225cac7d70e6326f4626eedc6b6bca58e8 [file] [log] [blame]
Jean-Marc Valin72e80032008-03-12 10:16:26 +11001/* Copyright (C) 2003-2008 Jean-Marc Valin */
Jean-Marc Valin63590892007-11-29 17:01:16 +11002/**
3 @file arch.h
Jean-Marc Valinc7e0b762008-03-16 07:55:29 +11004 @brief Various architecture definitions for CELT
Jean-Marc Valin63590892007-11-29 17:01:16 +11005*/
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 Valinc7e0b762008-03-16 07:55:29 +110039
40
41#define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
42#ifdef ENABLE_ASSERTIONS
43#define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}}
44#define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}}
45#else
46#define celt_assert(cond)
47#define celt_assert2(cond, message)
48#endif
49
Jean-Marc Valin63590892007-11-29 17:01:16 +110050
51#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
52#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
53#define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */
54#define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
55#define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
56#define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */
57#define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
58
59#ifdef FIXED_POINT
60
Jean-Marc Valinabe043f2008-01-31 14:26:29 +110061typedef celt_int16_t celt_word16_t;
62typedef celt_int32_t celt_word32_t;
Jean-Marc Valin63590892007-11-29 17:01:16 +110063
Jean-Marc Valin5c032a42008-02-25 14:55:09 +110064typedef celt_word32_t celt_sig_t;
Jean-Marc Valin2fa8aff2008-02-26 11:38:00 +110065typedef celt_word16_t celt_norm_t;
Jean-Marc Valinb60340f2008-02-26 15:41:51 +110066typedef celt_word32_t celt_ener_t;
Jean-Marc Valin2805a142008-02-26 17:02:08 +110067typedef celt_word16_t celt_pgain_t;
Jean-Marc Valinb624cdd2008-03-05 13:40:20 +110068typedef celt_word32_t celt_mask_t;
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +110069
Jean-Marc Valin63590892007-11-29 17:01:16 +110070#define Q15ONE 32767
Jean-Marc Valin92376692008-03-05 11:31:57 +110071#define Q30ONE 1073741823
Jean-Marc Valin63590892007-11-29 17:01:16 +110072
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +110073#define SIG_SCALING 16384.f
Jean-Marc Valin2805a142008-02-26 17:02:08 +110074#define SIG_SCALING_1 (1.f/16384.f)
Jean-Marc Valin42074382008-02-27 11:08:53 +110075#define SIG_SHIFT 14
76
Jean-Marc Valin03892c12008-03-07 17:25:47 +110077#define NORM_SCALING 16384
Jean-Marc Valin2805a142008-02-26 17:02:08 +110078#define NORM_SCALING_1 (1.f/16384.f)
Jean-Marc Valinf675adc2008-02-28 12:15:17 +110079#define NORM_SHIFT 14
80
Jean-Marc Valinb60340f2008-02-26 15:41:51 +110081#define ENER_SCALING 16384.f
Jean-Marc Valin2805a142008-02-26 17:02:08 +110082#define ENER_SCALING_1 (1.f/16384.f)
Jean-Marc Valinff74e392008-02-27 15:35:43 +110083
Jean-Marc Valin2805a142008-02-26 17:02:08 +110084#define PGAIN_SCALING 32768.f
85#define PGAIN_SCALING_1 (1.f/32768.f)
Jean-Marc Valinff74e392008-02-27 15:35:43 +110086#define PGAIN_SHIFT 15
Jean-Marc Valin63590892007-11-29 17:01:16 +110087
Jean-Marc Valin5d561832008-02-27 11:59:05 +110088#define DB_SCALING 256.f
89#define DB_SCALING_1 (1.f/256.f)
90
Jean-Marc Valinff74e392008-02-27 15:35:43 +110091#define EPSILON 1
Jean-Marc Valin63590892007-11-29 17:01:16 +110092#define VERY_SMALL 0
Jean-Marc Valinabe043f2008-01-31 14:26:29 +110093#define VERY_LARGE32 ((celt_word32_t)2147483647)
94#define VERY_LARGE16 ((celt_word16_t)32767)
95#define Q15_ONE ((celt_word16_t)32767)
Jean-Marc Valin9d8d9b32008-02-27 16:17:39 +110096#define Q15_ONE_1 (1.f/32768.f)
Jean-Marc Valin63590892007-11-29 17:01:16 +110097
98
99#ifdef FIXED_DEBUG
100#include "fixed_debug.h"
101#else
102
103#include "fixed_generic.h"
104
105#ifdef ARM5E_ASM
106#include "fixed_arm5e.h"
107#elif defined (ARM4_ASM)
108#include "fixed_arm4.h"
109#elif defined (BFIN_ASM)
110#include "fixed_bfin.h"
Jean-Marc Valin72e80032008-03-12 10:16:26 +1100111#elif defined (TI_C5X_ASM)
112#include "fixed_c5x.h"
Jean-Marc Valin63590892007-11-29 17:01:16 +1100113#endif
114
115#endif
116
117
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100118#else /* FIXED_POINT */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100119
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100120typedef float celt_word16_t;
121typedef float celt_word32_t;
Jean-Marc Valin63590892007-11-29 17:01:16 +1100122
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100123typedef float celt_sig_t;
124typedef float celt_norm_t;
Jean-Marc Valine901fe32008-02-26 14:46:26 +1100125typedef float celt_ener_t;
Jean-Marc Valin017d4452008-02-26 16:19:03 +1100126typedef float celt_pgain_t;
Jean-Marc Valin5f09ea52008-02-26 16:43:04 +1100127typedef float celt_mask_t;
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100128
Jean-Marc Valin63590892007-11-29 17:01:16 +1100129#define Q15ONE 1.0f
Jean-Marc Valin92376692008-03-05 11:31:57 +1100130#define Q30ONE 1.0f
Jean-Marc Valinb60340f2008-02-26 15:41:51 +1100131
Jean-Marc Valin63590892007-11-29 17:01:16 +1100132#define SIG_SCALING 1.f
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +1100133#define SIG_SCALING_1 1.f
Jean-Marc Valinb4dfce42008-02-25 17:41:30 +1100134#define NORM_SCALING 1.f
135#define NORM_SCALING_1 1.f
Jean-Marc Valinb60340f2008-02-26 15:41:51 +1100136#define ENER_SCALING 1.f
137#define ENER_SCALING_1 1.f
Jean-Marc Valin017d4452008-02-26 16:19:03 +1100138#define PGAIN_SCALING 1.f
139#define PGAIN_SCALING_1 1.f
Jean-Marc Valin63590892007-11-29 17:01:16 +1100140
Jean-Marc Valin5d561832008-02-27 11:59:05 +1100141#define DB_SCALING 1.f
142#define DB_SCALING_1 1.f
143
Jean-Marc Valind9584db2008-03-26 00:00:18 +1100144#define EPSILON 1e-15f
Jean-Marc Valin63590892007-11-29 17:01:16 +1100145#define VERY_SMALL 1e-15f
146#define VERY_LARGE32 1e15f
147#define VERY_LARGE16 1e15f
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100148#define Q15_ONE ((celt_word16_t)1.f)
Jean-Marc Valin9d8d9b32008-02-27 16:17:39 +1100149#define Q15_ONE_1 ((celt_word16_t)1.f)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100150
151#define QCONST16(x,bits) (x)
152#define QCONST32(x,bits) (x)
153
154#define NEG16(x) (-(x))
155#define NEG32(x) (-(x))
156#define EXTRACT16(x) (x)
157#define EXTEND32(x) (x)
158#define SHR16(a,shift) (a)
159#define SHL16(a,shift) (a)
160#define SHR32(a,shift) (a)
161#define SHL32(a,shift) (a)
162#define PSHR16(a,shift) (a)
163#define PSHR32(a,shift) (a)
164#define VSHR32(a,shift) (a)
165#define SATURATE16(x,a) (x)
166#define SATURATE32(x,a) (x)
167
Jean-Marc Valinc209c342008-03-07 17:50:45 +1100168#define PSHR(a,shift) (a)
169#define SHR(a,shift) (a)
170#define SHL(a,shift) (a)
171#define SATURATE(x,a) (x)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100172
Jean-Marc Valinf5b05872008-03-21 10:46:17 +1100173#define ROUND16(a,shift) (a)
Jean-Marc Valinc209c342008-03-07 17:50:45 +1100174#define HALF32(x) (.5f*(x))
Jean-Marc Valina02ca1e2008-02-28 11:33:22 +1100175
Jean-Marc Valin63590892007-11-29 17:01:16 +1100176#define ADD16(a,b) ((a)+(b))
177#define SUB16(a,b) ((a)-(b))
178#define ADD32(a,b) ((a)+(b))
179#define SUB32(a,b) ((a)-(b))
180#define MULT16_16_16(a,b) ((a)*(b))
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100181#define MULT16_16(a,b) ((celt_word32_t)(a)*(celt_word32_t)(b))
182#define MAC16_16(c,a,b) ((c)+(celt_word32_t)(a)*(celt_word32_t)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100183
184#define MULT16_32_Q11(a,b) ((a)*(b))
185#define MULT16_32_Q13(a,b) ((a)*(b))
186#define MULT16_32_Q14(a,b) ((a)*(b))
187#define MULT16_32_Q15(a,b) ((a)*(b))
188#define MULT16_32_P15(a,b) ((a)*(b))
189
Jean-Marc Valind857ac42008-03-12 13:26:37 +1100190#define MULT32_32_Q31(a,b) ((a)*(b))
191
Jean-Marc Valin63590892007-11-29 17:01:16 +1100192#define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
193#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
194
195#define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
196#define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
197#define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
198#define MULT16_16_Q11_32(a,b) ((a)*(b))
199#define MULT16_16_Q13(a,b) ((a)*(b))
200#define MULT16_16_Q14(a,b) ((a)*(b))
201#define MULT16_16_Q15(a,b) ((a)*(b))
202#define MULT16_16_P15(a,b) ((a)*(b))
203#define MULT16_16_P13(a,b) ((a)*(b))
204#define MULT16_16_P14(a,b) ((a)*(b))
205
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100206#define DIV32_16(a,b) (((celt_word32_t)(a))/(celt_word16_t)(b))
207#define PDIV32_16(a,b) (((celt_word32_t)(a))/(celt_word16_t)(b))
208#define DIV32(a,b) (((celt_word32_t)(a))/(celt_word32_t)(b))
209#define PDIV32(a,b) (((celt_word32_t)(a))/(celt_word32_t)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100210
211
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100212#endif /* !FIXED_POINT */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100213
214
215#if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
216
217/* 2 on TI C5x DSP */
218#define BYTES_PER_CHAR 2
219#define BITS_PER_CHAR 16
220#define LOG2_BITS_PER_CHAR 4
221
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100222#else /* CONFIG_TI_C54X */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100223
224#define BYTES_PER_CHAR 1
225#define BITS_PER_CHAR 8
226#define LOG2_BITS_PER_CHAR 3
227
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100228#endif /* !CONFIG_TI_C54X */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100229
230
231
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100232#endif /* ARCH_H */