Jean-Marc Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 1 | /* Copyright (C) 2003-2008 Jean-Marc Valin */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 2 | /** |
| 3 | @file arch.h |
Jean-Marc Valin | c7e0b76 | 2008-03-16 07:55:29 +1100 | [diff] [blame] | 4 | @brief Various architecture definitions for CELT |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 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 Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 38 | #include "celt_types.h" |
Jean-Marc Valin | c7e0b76 | 2008-03-16 07:55:29 +1100 | [diff] [blame] | 39 | |
| 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 Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 50 | |
| 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 Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 61 | typedef celt_int16_t celt_word16_t; |
| 62 | typedef celt_int32_t celt_word32_t; |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 63 | |
Jean-Marc Valin | 5c032a4 | 2008-02-25 14:55:09 +1100 | [diff] [blame] | 64 | typedef celt_word32_t celt_sig_t; |
Jean-Marc Valin | 2fa8aff | 2008-02-26 11:38:00 +1100 | [diff] [blame] | 65 | typedef celt_word16_t celt_norm_t; |
Jean-Marc Valin | b60340f | 2008-02-26 15:41:51 +1100 | [diff] [blame] | 66 | typedef celt_word32_t celt_ener_t; |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 67 | typedef celt_word16_t celt_pgain_t; |
Jean-Marc Valin | b624cdd | 2008-03-05 13:40:20 +1100 | [diff] [blame] | 68 | typedef celt_word32_t celt_mask_t; |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 69 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 70 | #define Q15ONE 32767 |
Jean-Marc Valin | 9237669 | 2008-03-05 11:31:57 +1100 | [diff] [blame] | 71 | #define Q30ONE 1073741823 |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 72 | |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 73 | #define SIG_SCALING 16384.f |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 74 | #define SIG_SCALING_1 (1.f/16384.f) |
Jean-Marc Valin | 4207438 | 2008-02-27 11:08:53 +1100 | [diff] [blame] | 75 | #define SIG_SHIFT 14 |
| 76 | |
Jean-Marc Valin | 03892c1 | 2008-03-07 17:25:47 +1100 | [diff] [blame] | 77 | #define NORM_SCALING 16384 |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 78 | #define NORM_SCALING_1 (1.f/16384.f) |
Jean-Marc Valin | f675adc | 2008-02-28 12:15:17 +1100 | [diff] [blame] | 79 | #define NORM_SHIFT 14 |
| 80 | |
Jean-Marc Valin | b60340f | 2008-02-26 15:41:51 +1100 | [diff] [blame] | 81 | #define ENER_SCALING 16384.f |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 82 | #define ENER_SCALING_1 (1.f/16384.f) |
Jean-Marc Valin | ff74e39 | 2008-02-27 15:35:43 +1100 | [diff] [blame] | 83 | |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 84 | #define PGAIN_SCALING 32768.f |
| 85 | #define PGAIN_SCALING_1 (1.f/32768.f) |
Jean-Marc Valin | ff74e39 | 2008-02-27 15:35:43 +1100 | [diff] [blame] | 86 | #define PGAIN_SHIFT 15 |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 87 | |
Jean-Marc Valin | 5d56183 | 2008-02-27 11:59:05 +1100 | [diff] [blame] | 88 | #define DB_SCALING 256.f |
| 89 | #define DB_SCALING_1 (1.f/256.f) |
| 90 | |
Jean-Marc Valin | ff74e39 | 2008-02-27 15:35:43 +1100 | [diff] [blame] | 91 | #define EPSILON 1 |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 92 | #define VERY_SMALL 0 |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 93 | #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 Valin | 9d8d9b3 | 2008-02-27 16:17:39 +1100 | [diff] [blame] | 96 | #define Q15_ONE_1 (1.f/32768.f) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 97 | |
| 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 Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 111 | #elif defined (TI_C5X_ASM) |
| 112 | #include "fixed_c5x.h" |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | #endif |
| 116 | |
| 117 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 118 | #else /* FIXED_POINT */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 119 | |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 120 | typedef float celt_word16_t; |
| 121 | typedef float celt_word32_t; |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 122 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 123 | typedef float celt_sig_t; |
| 124 | typedef float celt_norm_t; |
Jean-Marc Valin | e901fe3 | 2008-02-26 14:46:26 +1100 | [diff] [blame] | 125 | typedef float celt_ener_t; |
Jean-Marc Valin | 017d445 | 2008-02-26 16:19:03 +1100 | [diff] [blame] | 126 | typedef float celt_pgain_t; |
Jean-Marc Valin | 5f09ea5 | 2008-02-26 16:43:04 +1100 | [diff] [blame] | 127 | typedef float celt_mask_t; |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 128 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 129 | #define Q15ONE 1.0f |
Jean-Marc Valin | 9237669 | 2008-03-05 11:31:57 +1100 | [diff] [blame] | 130 | #define Q30ONE 1.0f |
Jean-Marc Valin | b60340f | 2008-02-26 15:41:51 +1100 | [diff] [blame] | 131 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 132 | #define SIG_SCALING 1.f |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 133 | #define SIG_SCALING_1 1.f |
Jean-Marc Valin | b4dfce4 | 2008-02-25 17:41:30 +1100 | [diff] [blame] | 134 | #define NORM_SCALING 1.f |
| 135 | #define NORM_SCALING_1 1.f |
Jean-Marc Valin | b60340f | 2008-02-26 15:41:51 +1100 | [diff] [blame] | 136 | #define ENER_SCALING 1.f |
| 137 | #define ENER_SCALING_1 1.f |
Jean-Marc Valin | 017d445 | 2008-02-26 16:19:03 +1100 | [diff] [blame] | 138 | #define PGAIN_SCALING 1.f |
| 139 | #define PGAIN_SCALING_1 1.f |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 140 | |
Jean-Marc Valin | 5d56183 | 2008-02-27 11:59:05 +1100 | [diff] [blame] | 141 | #define DB_SCALING 1.f |
| 142 | #define DB_SCALING_1 1.f |
| 143 | |
Jean-Marc Valin | d9584db | 2008-03-26 00:00:18 +1100 | [diff] [blame^] | 144 | #define EPSILON 1e-15f |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 145 | #define VERY_SMALL 1e-15f |
| 146 | #define VERY_LARGE32 1e15f |
| 147 | #define VERY_LARGE16 1e15f |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 148 | #define Q15_ONE ((celt_word16_t)1.f) |
Jean-Marc Valin | 9d8d9b3 | 2008-02-27 16:17:39 +1100 | [diff] [blame] | 149 | #define Q15_ONE_1 ((celt_word16_t)1.f) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 150 | |
| 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 Valin | c209c34 | 2008-03-07 17:50:45 +1100 | [diff] [blame] | 168 | #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 Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 172 | |
Jean-Marc Valin | f5b0587 | 2008-03-21 10:46:17 +1100 | [diff] [blame] | 173 | #define ROUND16(a,shift) (a) |
Jean-Marc Valin | c209c34 | 2008-03-07 17:50:45 +1100 | [diff] [blame] | 174 | #define HALF32(x) (.5f*(x)) |
Jean-Marc Valin | a02ca1e | 2008-02-28 11:33:22 +1100 | [diff] [blame] | 175 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 176 | #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 Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 181 | #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 Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 183 | |
| 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 Valin | d857ac4 | 2008-03-12 13:26:37 +1100 | [diff] [blame] | 190 | #define MULT32_32_Q31(a,b) ((a)*(b)) |
| 191 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 192 | #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 Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 206 | #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 Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 210 | |
| 211 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 212 | #endif /* !FIXED_POINT */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 213 | |
| 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 Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 222 | #else /* CONFIG_TI_C54X */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 223 | |
| 224 | #define BYTES_PER_CHAR 1 |
| 225 | #define BITS_PER_CHAR 8 |
| 226 | #define LOG2_BITS_PER_CHAR 3 |
| 227 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 228 | #endif /* !CONFIG_TI_C54X */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 229 | |
| 230 | |
| 231 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 232 | #endif /* ARCH_H */ |