blob: 4722bbe6c70fdae931918169794094de6bfa3641 [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 Valin821945d2008-04-10 13:24:48 +100050#define IMUL32(a,b) ((a)*(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +110051
52#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
53#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
54#define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */
55#define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
56#define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
57#define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */
58#define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
59
60#ifdef FIXED_POINT
61
Jean-Marc Valinabe043f2008-01-31 14:26:29 +110062typedef celt_int16_t celt_word16_t;
63typedef celt_int32_t celt_word32_t;
Jean-Marc Valin63590892007-11-29 17:01:16 +110064
Jean-Marc Valin5c032a42008-02-25 14:55:09 +110065typedef celt_word32_t celt_sig_t;
Jean-Marc Valin2fa8aff2008-02-26 11:38:00 +110066typedef celt_word16_t celt_norm_t;
Jean-Marc Valinb60340f2008-02-26 15:41:51 +110067typedef celt_word32_t celt_ener_t;
Jean-Marc Valin2805a142008-02-26 17:02:08 +110068typedef celt_word16_t celt_pgain_t;
Jean-Marc Valinb624cdd2008-03-05 13:40:20 +110069typedef celt_word32_t celt_mask_t;
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +110070
Jean-Marc Valin63590892007-11-29 17:01:16 +110071#define Q15ONE 32767
Jean-Marc Valin92376692008-03-05 11:31:57 +110072#define Q30ONE 1073741823
Jean-Marc Valin63590892007-11-29 17:01:16 +110073
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +110074#define SIG_SCALING 16384.f
Jean-Marc Valin2805a142008-02-26 17:02:08 +110075#define SIG_SCALING_1 (1.f/16384.f)
Jean-Marc Valin42074382008-02-27 11:08:53 +110076#define SIG_SHIFT 14
77
Jean-Marc Valin03892c12008-03-07 17:25:47 +110078#define NORM_SCALING 16384
Jean-Marc Valin2805a142008-02-26 17:02:08 +110079#define NORM_SCALING_1 (1.f/16384.f)
Jean-Marc Valinf675adc2008-02-28 12:15:17 +110080#define NORM_SHIFT 14
81
Jean-Marc Valinb60340f2008-02-26 15:41:51 +110082#define ENER_SCALING 16384.f
Jean-Marc Valin2805a142008-02-26 17:02:08 +110083#define ENER_SCALING_1 (1.f/16384.f)
Jean-Marc Valinbd2828f2008-03-26 08:10:27 +110084#define ENER_SHIFT 14
Jean-Marc Valinff74e392008-02-27 15:35:43 +110085
Jean-Marc Valin2805a142008-02-26 17:02:08 +110086#define PGAIN_SCALING 32768.f
87#define PGAIN_SCALING_1 (1.f/32768.f)
Jean-Marc Valinff74e392008-02-27 15:35:43 +110088#define PGAIN_SHIFT 15
Jean-Marc Valin63590892007-11-29 17:01:16 +110089
Jean-Marc Valin5d561832008-02-27 11:59:05 +110090#define DB_SCALING 256.f
91#define DB_SCALING_1 (1.f/256.f)
92
Jean-Marc Valinff74e392008-02-27 15:35:43 +110093#define EPSILON 1
Jean-Marc Valin63590892007-11-29 17:01:16 +110094#define VERY_SMALL 0
Jean-Marc Valinabe043f2008-01-31 14:26:29 +110095#define VERY_LARGE32 ((celt_word32_t)2147483647)
96#define VERY_LARGE16 ((celt_word16_t)32767)
97#define Q15_ONE ((celt_word16_t)32767)
Jean-Marc Valin9d8d9b32008-02-27 16:17:39 +110098#define Q15_ONE_1 (1.f/32768.f)
Jean-Marc Valin63590892007-11-29 17:01:16 +110099
Gregory Maxwell5f2a74b2008-08-11 23:50:07 -0400100#define SCALEIN(a) (a)
101#define SCALEOUT(a) (a)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100102
103#ifdef FIXED_DEBUG
104#include "fixed_debug.h"
105#else
106
107#include "fixed_generic.h"
108
109#ifdef ARM5E_ASM
110#include "fixed_arm5e.h"
111#elif defined (ARM4_ASM)
112#include "fixed_arm4.h"
113#elif defined (BFIN_ASM)
114#include "fixed_bfin.h"
Jean-Marc Valin72e80032008-03-12 10:16:26 +1100115#elif defined (TI_C5X_ASM)
116#include "fixed_c5x.h"
Jean-Marc Valineac99702008-04-15 21:31:42 +1000117#elif defined (TI_C6X_ASM)
118#include "fixed_c6x.h"
Jean-Marc Valin63590892007-11-29 17:01:16 +1100119#endif
120
121#endif
122
123
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100124#else /* FIXED_POINT */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100125
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100126typedef float celt_word16_t;
127typedef float celt_word32_t;
Jean-Marc Valin63590892007-11-29 17:01:16 +1100128
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100129typedef float celt_sig_t;
130typedef float celt_norm_t;
Jean-Marc Valine901fe32008-02-26 14:46:26 +1100131typedef float celt_ener_t;
Jean-Marc Valin017d4452008-02-26 16:19:03 +1100132typedef float celt_pgain_t;
Jean-Marc Valin5f09ea52008-02-26 16:43:04 +1100133typedef float celt_mask_t;
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100134
Jean-Marc Valin63590892007-11-29 17:01:16 +1100135#define Q15ONE 1.0f
Jean-Marc Valin92376692008-03-05 11:31:57 +1100136#define Q30ONE 1.0f
Jean-Marc Valinb60340f2008-02-26 15:41:51 +1100137
Jean-Marc Valin63590892007-11-29 17:01:16 +1100138#define SIG_SCALING 1.f
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +1100139#define SIG_SCALING_1 1.f
Jean-Marc Valinb4dfce42008-02-25 17:41:30 +1100140#define NORM_SCALING 1.f
141#define NORM_SCALING_1 1.f
Jean-Marc Valinb60340f2008-02-26 15:41:51 +1100142#define ENER_SCALING 1.f
143#define ENER_SCALING_1 1.f
Jean-Marc Valin017d4452008-02-26 16:19:03 +1100144#define PGAIN_SCALING 1.f
145#define PGAIN_SCALING_1 1.f
Jean-Marc Valin63590892007-11-29 17:01:16 +1100146
Jean-Marc Valin5d561832008-02-27 11:59:05 +1100147#define DB_SCALING 1.f
148#define DB_SCALING_1 1.f
149
Jean-Marc Valind9584db2008-03-26 00:00:18 +1100150#define EPSILON 1e-15f
Jean-Marc Valin63590892007-11-29 17:01:16 +1100151#define VERY_SMALL 1e-15f
152#define VERY_LARGE32 1e15f
153#define VERY_LARGE16 1e15f
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100154#define Q15_ONE ((celt_word16_t)1.f)
Jean-Marc Valin9d8d9b32008-02-27 16:17:39 +1100155#define Q15_ONE_1 ((celt_word16_t)1.f)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100156
157#define QCONST16(x,bits) (x)
158#define QCONST32(x,bits) (x)
159
160#define NEG16(x) (-(x))
161#define NEG32(x) (-(x))
162#define EXTRACT16(x) (x)
163#define EXTEND32(x) (x)
164#define SHR16(a,shift) (a)
165#define SHL16(a,shift) (a)
166#define SHR32(a,shift) (a)
167#define SHL32(a,shift) (a)
168#define PSHR16(a,shift) (a)
169#define PSHR32(a,shift) (a)
170#define VSHR32(a,shift) (a)
171#define SATURATE16(x,a) (x)
172#define SATURATE32(x,a) (x)
173
Jean-Marc Valinc209c342008-03-07 17:50:45 +1100174#define PSHR(a,shift) (a)
175#define SHR(a,shift) (a)
176#define SHL(a,shift) (a)
177#define SATURATE(x,a) (x)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100178
Jean-Marc Valinf5b05872008-03-21 10:46:17 +1100179#define ROUND16(a,shift) (a)
Jean-Marc Valinc209c342008-03-07 17:50:45 +1100180#define HALF32(x) (.5f*(x))
Jean-Marc Valina02ca1e2008-02-28 11:33:22 +1100181
Jean-Marc Valin63590892007-11-29 17:01:16 +1100182#define ADD16(a,b) ((a)+(b))
183#define SUB16(a,b) ((a)-(b))
184#define ADD32(a,b) ((a)+(b))
185#define SUB32(a,b) ((a)-(b))
186#define MULT16_16_16(a,b) ((a)*(b))
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100187#define MULT16_16(a,b) ((celt_word32_t)(a)*(celt_word32_t)(b))
188#define MAC16_16(c,a,b) ((c)+(celt_word32_t)(a)*(celt_word32_t)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100189
190#define MULT16_32_Q11(a,b) ((a)*(b))
191#define MULT16_32_Q13(a,b) ((a)*(b))
192#define MULT16_32_Q14(a,b) ((a)*(b))
193#define MULT16_32_Q15(a,b) ((a)*(b))
Jean-Marc Valinef0d5f12008-04-22 09:49:22 +1000194#define MULT16_32_Q16(a,b) ((a)*(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100195#define MULT16_32_P15(a,b) ((a)*(b))
196
Jean-Marc Valind857ac42008-03-12 13:26:37 +1100197#define MULT32_32_Q31(a,b) ((a)*(b))
198
Jean-Marc Valin63590892007-11-29 17:01:16 +1100199#define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
200#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
201
202#define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
203#define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
204#define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
205#define MULT16_16_Q11_32(a,b) ((a)*(b))
206#define MULT16_16_Q13(a,b) ((a)*(b))
207#define MULT16_16_Q14(a,b) ((a)*(b))
208#define MULT16_16_Q15(a,b) ((a)*(b))
209#define MULT16_16_P15(a,b) ((a)*(b))
210#define MULT16_16_P13(a,b) ((a)*(b))
211#define MULT16_16_P14(a,b) ((a)*(b))
212
Jean-Marc Valinabe043f2008-01-31 14:26:29 +1100213#define DIV32_16(a,b) (((celt_word32_t)(a))/(celt_word16_t)(b))
214#define PDIV32_16(a,b) (((celt_word32_t)(a))/(celt_word16_t)(b))
215#define DIV32(a,b) (((celt_word32_t)(a))/(celt_word32_t)(b))
216#define PDIV32(a,b) (((celt_word32_t)(a))/(celt_word32_t)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100217
Gregory Maxwell5f2a74b2008-08-11 23:50:07 -0400218#define SCALEIN(a) ((a)*32768.)
219#define SCALEOUT(a) ((a)*(1/32768.))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100220
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100221#endif /* !FIXED_POINT */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100222
223
224#if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
225
226/* 2 on TI C5x DSP */
227#define BYTES_PER_CHAR 2
228#define BITS_PER_CHAR 16
229#define LOG2_BITS_PER_CHAR 4
230
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100231#else /* CONFIG_TI_C54X */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100232
233#define BYTES_PER_CHAR 1
234#define BITS_PER_CHAR 8
235#define LOG2_BITS_PER_CHAR 3
236
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100237#endif /* !CONFIG_TI_C54X */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100238
239
240
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100241#endif /* ARCH_H */