blob: 35c609b224d5df7b5d86672b5371743432582386 [file] [log] [blame]
Jean-Marc Valin8b2ff0d2009-10-17 21:40:10 -04001/* Copyright (c) 2003-2008 Jean-Marc Valin
2 Copyright (c) 2007-2008 CSIRO
3 Copyright (c) 2007-2009 Xiph.Org Foundation
4 Written by Jean-Marc Valin */
Jean-Marc Valin63590892007-11-29 17:01:16 +11005/**
6 @file arch.h
Jean-Marc Valinc7e0b762008-03-16 07:55:29 +11007 @brief Various architecture definitions for CELT
Jean-Marc Valin63590892007-11-29 17:01:16 +11008*/
9/*
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions
12 are met:
13
14 - Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16
17 - Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20
Jean-Marc Valin63590892007-11-29 17:01:16 +110021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*/
33
34#ifndef ARCH_H
35#define ARCH_H
36
Jean-Marc Valind77d6a52011-07-29 17:33:06 -040037#include "opus_types.h"
Jean-Marc Valinc7e0b762008-03-16 07:55:29 +110038
Timothy B. Terriberry1a458862011-05-04 15:03:30 -070039# if !defined(__GNUC_PREREQ)
40# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
41# define __GNUC_PREREQ(_maj,_min) \
42 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
43# else
44# define __GNUC_PREREQ(_maj,_min) 0
45# endif
46# endif
47
48# if defined(_MSC_VER)
49# pragma warning(disable:4554)
50# endif
51# if __GNUC_PREREQ(4,2)
52# pragma GCC diagnostic ignored "-Wparentheses"
53# endif
54
Jean-Marc Valin628c0252010-04-16 20:57:56 -040055#define CELT_SIG_SCALE 32768.f
Jean-Marc Valinc7e0b762008-03-16 07:55:29 +110056
57#define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
58#ifdef ENABLE_ASSERTIONS
Jean-Marc Valin6d3829f2010-08-27 17:52:38 -040059#include <stdio.h>
60#include <stdlib.h>
61static inline void _celt_fatal(const char *str, const char *file, int line)
62{
63 fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
64 abort();
65}
Jean-Marc Valinc7e0b762008-03-16 07:55:29 +110066#define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}}
67#define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}}
68#else
69#define celt_assert(cond)
70#define celt_assert2(cond, message)
71#endif
72
Jean-Marc Valin821945d2008-04-10 13:24:48 +100073#define IMUL32(a,b) ((a)*(b))
Jean-Marc Valind77d6a52011-07-29 17:33:06 -040074#define UMUL32(a,b) ((opus_int32)(a)*(opus_int32)(b))
75#define UMUL16_16(a,b) ((opus_int32)(a)*(opus_int32)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +110076
77#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
78#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
Gregory Maxwell8842fde2009-05-04 15:58:40 -040079#define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */
Jean-Marc Valin63590892007-11-29 17:01:16 +110080#define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
81#define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
Gregory Maxwell8842fde2009-05-04 15:58:40 -040082#define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */
Jean-Marc Valin63590892007-11-29 17:01:16 +110083#define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
Gregory Maxwell8842fde2009-05-04 15:58:40 -040084#define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */
Jean-Marc Valinc24b5182008-09-19 16:49:26 -040085#define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */
Jean-Marc Valin453ccd82008-09-12 20:52:27 -040086#define UADD32(a,b) ((a)+(b))
87#define USUB32(a,b) ((a)-(b))
88
89#define PRINT_MIPS(file)
Jean-Marc Valin63590892007-11-29 17:01:16 +110090
91#ifdef FIXED_POINT
92
Jean-Marc Valinff5f7222011-07-29 18:59:12 -040093typedef opus_int16 opus_val16;
94typedef opus_int32 opus_val32;
Jean-Marc Valin63590892007-11-29 17:01:16 +110095
Jean-Marc Valinff5f7222011-07-29 18:59:12 -040096typedef opus_val32 celt_sig;
97typedef opus_val16 celt_norm;
98typedef opus_val32 celt_ener;
99typedef opus_val32 celt_mask;
Jean-Marc Valin49ca99e2008-02-25 14:05:10 +1100100
Jean-Marc Valin63590892007-11-29 17:01:16 +1100101#define Q15ONE 32767
Jean-Marc Valin92376692008-03-05 11:31:57 +1100102#define Q30ONE 1073741823
Jean-Marc Valin63590892007-11-29 17:01:16 +1100103
Jean-Marc Valin5c3bc672008-08-28 23:34:24 -0400104#define SIG_SHIFT 12
Jean-Marc Valin42074382008-02-27 11:08:53 +1100105
Jean-Marc Valin03892c12008-03-07 17:25:47 +1100106#define NORM_SCALING 16384
Jean-Marc Valin2805a142008-02-26 17:02:08 +1100107#define NORM_SCALING_1 (1.f/16384.f)
Jean-Marc Valinf675adc2008-02-28 12:15:17 +1100108#define NORM_SHIFT 14
109
Jean-Marc Valinb60340f2008-02-26 15:41:51 +1100110#define ENER_SCALING 16384.f
Jean-Marc Valin2805a142008-02-26 17:02:08 +1100111#define ENER_SCALING_1 (1.f/16384.f)
Jean-Marc Valinbd2828f2008-03-26 08:10:27 +1100112#define ENER_SHIFT 14
Jean-Marc Valinff74e392008-02-27 15:35:43 +1100113
Jean-Marc Valin2805a142008-02-26 17:02:08 +1100114#define PGAIN_SCALING 32768.f
115#define PGAIN_SCALING_1 (1.f/32768.f)
Jean-Marc Valinff74e392008-02-27 15:35:43 +1100116#define PGAIN_SHIFT 15
Jean-Marc Valin63590892007-11-29 17:01:16 +1100117
Jean-Marc Valinbd0610d2010-03-13 10:04:19 -0500118#define DB_SHIFT 10
Jean-Marc Valin5d561832008-02-27 11:59:05 +1100119
Jean-Marc Valinff74e392008-02-27 15:35:43 +1100120#define EPSILON 1
Jean-Marc Valin63590892007-11-29 17:01:16 +1100121#define VERY_SMALL 0
Jean-Marc Valinff5f7222011-07-29 18:59:12 -0400122#define VERY_LARGE32 ((opus_val32)2147483647)
123#define VERY_LARGE16 ((opus_val16)32767)
124#define Q15_ONE ((opus_val16)32767)
Jean-Marc Valin9d8d9b32008-02-27 16:17:39 +1100125#define Q15_ONE_1 (1.f/32768.f)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100126
Gregory Maxwell5f2a74b2008-08-11 23:50:07 -0400127#define SCALEIN(a) (a)
128#define SCALEOUT(a) (a)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100129
130#ifdef FIXED_DEBUG
131#include "fixed_debug.h"
132#else
133
134#include "fixed_generic.h"
135
136#ifdef ARM5E_ASM
137#include "fixed_arm5e.h"
138#elif defined (ARM4_ASM)
139#include "fixed_arm4.h"
140#elif defined (BFIN_ASM)
141#include "fixed_bfin.h"
Jean-Marc Valin72e80032008-03-12 10:16:26 +1100142#elif defined (TI_C5X_ASM)
143#include "fixed_c5x.h"
Jean-Marc Valineac99702008-04-15 21:31:42 +1000144#elif defined (TI_C6X_ASM)
145#include "fixed_c6x.h"
Jean-Marc Valin63590892007-11-29 17:01:16 +1100146#endif
147
148#endif
149
150
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100151#else /* FIXED_POINT */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100152
Jean-Marc Valinff5f7222011-07-29 18:59:12 -0400153typedef float opus_val16;
154typedef float opus_val32;
Jean-Marc Valin63590892007-11-29 17:01:16 +1100155
Jean-Marc Valin234969c2009-10-17 22:12:42 -0400156typedef float celt_sig;
157typedef float celt_norm;
158typedef float celt_ener;
159typedef float celt_pgain;
160typedef float celt_mask;
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100161
Jean-Marc Valin63590892007-11-29 17:01:16 +1100162#define Q15ONE 1.0f
Jean-Marc Valin92376692008-03-05 11:31:57 +1100163#define Q30ONE 1.0f
Jean-Marc Valinb60340f2008-02-26 15:41:51 +1100164
Jean-Marc Valinb4dfce42008-02-25 17:41:30 +1100165#define NORM_SCALING 1.f
166#define NORM_SCALING_1 1.f
Jean-Marc Valinb60340f2008-02-26 15:41:51 +1100167#define ENER_SCALING 1.f
168#define ENER_SCALING_1 1.f
Jean-Marc Valin017d4452008-02-26 16:19:03 +1100169#define PGAIN_SCALING 1.f
170#define PGAIN_SCALING_1 1.f
Jean-Marc Valin63590892007-11-29 17:01:16 +1100171
Jean-Marc Valind9584db2008-03-26 00:00:18 +1100172#define EPSILON 1e-15f
Jean-Marc Valin63590892007-11-29 17:01:16 +1100173#define VERY_SMALL 1e-15f
174#define VERY_LARGE32 1e15f
175#define VERY_LARGE16 1e15f
Jean-Marc Valinff5f7222011-07-29 18:59:12 -0400176#define Q15_ONE ((opus_val16)1.f)
177#define Q15_ONE_1 ((opus_val16)1.f)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100178
179#define QCONST16(x,bits) (x)
180#define QCONST32(x,bits) (x)
181
182#define NEG16(x) (-(x))
183#define NEG32(x) (-(x))
184#define EXTRACT16(x) (x)
185#define EXTEND32(x) (x)
186#define SHR16(a,shift) (a)
187#define SHL16(a,shift) (a)
188#define SHR32(a,shift) (a)
189#define SHL32(a,shift) (a)
190#define PSHR16(a,shift) (a)
191#define PSHR32(a,shift) (a)
192#define VSHR32(a,shift) (a)
193#define SATURATE16(x,a) (x)
194#define SATURATE32(x,a) (x)
195
Jean-Marc Valinc209c342008-03-07 17:50:45 +1100196#define PSHR(a,shift) (a)
197#define SHR(a,shift) (a)
198#define SHL(a,shift) (a)
199#define SATURATE(x,a) (x)
Jean-Marc Valin63590892007-11-29 17:01:16 +1100200
Jean-Marc Valinf5b05872008-03-21 10:46:17 +1100201#define ROUND16(a,shift) (a)
Jean-Marc Valin21b11342011-05-13 17:41:33 -0400202#define HALF16(x) (.5f*(x))
Jean-Marc Valinc209c342008-03-07 17:50:45 +1100203#define HALF32(x) (.5f*(x))
Jean-Marc Valina02ca1e2008-02-28 11:33:22 +1100204
Jean-Marc Valin63590892007-11-29 17:01:16 +1100205#define ADD16(a,b) ((a)+(b))
206#define SUB16(a,b) ((a)-(b))
207#define ADD32(a,b) ((a)+(b))
208#define SUB32(a,b) ((a)-(b))
209#define MULT16_16_16(a,b) ((a)*(b))
Jean-Marc Valinff5f7222011-07-29 18:59:12 -0400210#define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b))
211#define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100212
213#define MULT16_32_Q11(a,b) ((a)*(b))
214#define MULT16_32_Q13(a,b) ((a)*(b))
215#define MULT16_32_Q14(a,b) ((a)*(b))
216#define MULT16_32_Q15(a,b) ((a)*(b))
Jean-Marc Valinef0d5f12008-04-22 09:49:22 +1000217#define MULT16_32_Q16(a,b) ((a)*(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100218#define MULT16_32_P15(a,b) ((a)*(b))
219
Jean-Marc Valind857ac42008-03-12 13:26:37 +1100220#define MULT32_32_Q31(a,b) ((a)*(b))
221
Jean-Marc Valin63590892007-11-29 17:01:16 +1100222#define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
223#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
224
225#define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
226#define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
227#define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
228#define MULT16_16_Q11_32(a,b) ((a)*(b))
229#define MULT16_16_Q13(a,b) ((a)*(b))
230#define MULT16_16_Q14(a,b) ((a)*(b))
231#define MULT16_16_Q15(a,b) ((a)*(b))
232#define MULT16_16_P15(a,b) ((a)*(b))
233#define MULT16_16_P13(a,b) ((a)*(b))
234#define MULT16_16_P14(a,b) ((a)*(b))
235
Jean-Marc Valinff5f7222011-07-29 18:59:12 -0400236#define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b))
237#define PDIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b))
238#define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b))
239#define PDIV32(a,b) (((opus_val32)(a))/(opus_val32)(b))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100240
Jean-Marc Valin0b405d12011-02-04 01:03:42 -0500241#define SCALEIN(a) ((a)*CELT_SIG_SCALE)
Gregory Maxwell0ac2b2f2009-05-21 23:08:46 -0400242#define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE))
Jean-Marc Valin63590892007-11-29 17:01:16 +1100243
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100244#endif /* !FIXED_POINT */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100245
246
247#if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
248
249/* 2 on TI C5x DSP */
250#define BYTES_PER_CHAR 2
251#define BITS_PER_CHAR 16
252#define LOG2_BITS_PER_CHAR 4
253
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100254#else /* CONFIG_TI_C54X */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100255
256#define BYTES_PER_CHAR 1
257#define BITS_PER_CHAR 8
258#define LOG2_BITS_PER_CHAR 3
259
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100260#endif /* !CONFIG_TI_C54X */
Jean-Marc Valin63590892007-11-29 17:01:16 +1100261
Gregory Maxwell242eee32009-02-03 16:07:01 -0500262#ifndef GLOBAL_STACK_SIZE
263#ifdef FIXED_POINT
Jean-Marc Valin43dd8a52009-07-13 17:50:59 -0400264#define GLOBAL_STACK_SIZE 100000
Gregory Maxwell242eee32009-02-03 16:07:01 -0500265#else
Jean-Marc Valin43dd8a52009-07-13 17:50:59 -0400266#define GLOBAL_STACK_SIZE 100000
Gregory Maxwell242eee32009-02-03 16:07:01 -0500267#endif
268#endif
Jean-Marc Valin63590892007-11-29 17:01:16 +1100269
Jean-Marc Valin18ddc022008-02-22 14:24:50 +1100270#endif /* ARCH_H */