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 | 821945d | 2008-04-10 13:24:48 +1000 | [diff] [blame] | 50 | #define IMUL32(a,b) ((a)*(b)) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 51 | |
| 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 Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 62 | typedef celt_int16_t celt_word16_t; |
| 63 | typedef celt_int32_t celt_word32_t; |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 64 | |
Jean-Marc Valin | 5c032a4 | 2008-02-25 14:55:09 +1100 | [diff] [blame] | 65 | typedef celt_word32_t celt_sig_t; |
Jean-Marc Valin | 2fa8aff | 2008-02-26 11:38:00 +1100 | [diff] [blame] | 66 | typedef celt_word16_t celt_norm_t; |
Jean-Marc Valin | b60340f | 2008-02-26 15:41:51 +1100 | [diff] [blame] | 67 | typedef celt_word32_t celt_ener_t; |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 68 | typedef celt_word16_t celt_pgain_t; |
Jean-Marc Valin | b624cdd | 2008-03-05 13:40:20 +1100 | [diff] [blame] | 69 | typedef celt_word32_t celt_mask_t; |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 70 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 71 | #define Q15ONE 32767 |
Jean-Marc Valin | 9237669 | 2008-03-05 11:31:57 +1100 | [diff] [blame] | 72 | #define Q30ONE 1073741823 |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 73 | |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 74 | #define SIG_SCALING 16384.f |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 75 | #define SIG_SCALING_1 (1.f/16384.f) |
Jean-Marc Valin | 4207438 | 2008-02-27 11:08:53 +1100 | [diff] [blame] | 76 | #define SIG_SHIFT 14 |
| 77 | |
Jean-Marc Valin | 03892c1 | 2008-03-07 17:25:47 +1100 | [diff] [blame] | 78 | #define NORM_SCALING 16384 |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 79 | #define NORM_SCALING_1 (1.f/16384.f) |
Jean-Marc Valin | f675adc | 2008-02-28 12:15:17 +1100 | [diff] [blame] | 80 | #define NORM_SHIFT 14 |
| 81 | |
Jean-Marc Valin | b60340f | 2008-02-26 15:41:51 +1100 | [diff] [blame] | 82 | #define ENER_SCALING 16384.f |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 83 | #define ENER_SCALING_1 (1.f/16384.f) |
Jean-Marc Valin | bd2828f | 2008-03-26 08:10:27 +1100 | [diff] [blame] | 84 | #define ENER_SHIFT 14 |
Jean-Marc Valin | ff74e39 | 2008-02-27 15:35:43 +1100 | [diff] [blame] | 85 | |
Jean-Marc Valin | 2805a14 | 2008-02-26 17:02:08 +1100 | [diff] [blame] | 86 | #define PGAIN_SCALING 32768.f |
| 87 | #define PGAIN_SCALING_1 (1.f/32768.f) |
Jean-Marc Valin | ff74e39 | 2008-02-27 15:35:43 +1100 | [diff] [blame] | 88 | #define PGAIN_SHIFT 15 |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 89 | |
Jean-Marc Valin | 5d56183 | 2008-02-27 11:59:05 +1100 | [diff] [blame] | 90 | #define DB_SCALING 256.f |
| 91 | #define DB_SCALING_1 (1.f/256.f) |
| 92 | |
Jean-Marc Valin | ff74e39 | 2008-02-27 15:35:43 +1100 | [diff] [blame] | 93 | #define EPSILON 1 |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 94 | #define VERY_SMALL 0 |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 95 | #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 Valin | 9d8d9b3 | 2008-02-27 16:17:39 +1100 | [diff] [blame] | 98 | #define Q15_ONE_1 (1.f/32768.f) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 99 | |
Gregory Maxwell | 5f2a74b | 2008-08-11 23:50:07 -0400 | [diff] [blame^] | 100 | #define SCALEIN(a) (a) |
| 101 | #define SCALEOUT(a) (a) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 102 | |
| 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 Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 115 | #elif defined (TI_C5X_ASM) |
| 116 | #include "fixed_c5x.h" |
Jean-Marc Valin | eac9970 | 2008-04-15 21:31:42 +1000 | [diff] [blame] | 117 | #elif defined (TI_C6X_ASM) |
| 118 | #include "fixed_c6x.h" |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 119 | #endif |
| 120 | |
| 121 | #endif |
| 122 | |
| 123 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 124 | #else /* FIXED_POINT */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 125 | |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 126 | typedef float celt_word16_t; |
| 127 | typedef float celt_word32_t; |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 128 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 129 | typedef float celt_sig_t; |
| 130 | typedef float celt_norm_t; |
Jean-Marc Valin | e901fe3 | 2008-02-26 14:46:26 +1100 | [diff] [blame] | 131 | typedef float celt_ener_t; |
Jean-Marc Valin | 017d445 | 2008-02-26 16:19:03 +1100 | [diff] [blame] | 132 | typedef float celt_pgain_t; |
Jean-Marc Valin | 5f09ea5 | 2008-02-26 16:43:04 +1100 | [diff] [blame] | 133 | typedef float celt_mask_t; |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 134 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 135 | #define Q15ONE 1.0f |
Jean-Marc Valin | 9237669 | 2008-03-05 11:31:57 +1100 | [diff] [blame] | 136 | #define Q30ONE 1.0f |
Jean-Marc Valin | b60340f | 2008-02-26 15:41:51 +1100 | [diff] [blame] | 137 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 138 | #define SIG_SCALING 1.f |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 139 | #define SIG_SCALING_1 1.f |
Jean-Marc Valin | b4dfce4 | 2008-02-25 17:41:30 +1100 | [diff] [blame] | 140 | #define NORM_SCALING 1.f |
| 141 | #define NORM_SCALING_1 1.f |
Jean-Marc Valin | b60340f | 2008-02-26 15:41:51 +1100 | [diff] [blame] | 142 | #define ENER_SCALING 1.f |
| 143 | #define ENER_SCALING_1 1.f |
Jean-Marc Valin | 017d445 | 2008-02-26 16:19:03 +1100 | [diff] [blame] | 144 | #define PGAIN_SCALING 1.f |
| 145 | #define PGAIN_SCALING_1 1.f |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 146 | |
Jean-Marc Valin | 5d56183 | 2008-02-27 11:59:05 +1100 | [diff] [blame] | 147 | #define DB_SCALING 1.f |
| 148 | #define DB_SCALING_1 1.f |
| 149 | |
Jean-Marc Valin | d9584db | 2008-03-26 00:00:18 +1100 | [diff] [blame] | 150 | #define EPSILON 1e-15f |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 151 | #define VERY_SMALL 1e-15f |
| 152 | #define VERY_LARGE32 1e15f |
| 153 | #define VERY_LARGE16 1e15f |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 154 | #define Q15_ONE ((celt_word16_t)1.f) |
Jean-Marc Valin | 9d8d9b3 | 2008-02-27 16:17:39 +1100 | [diff] [blame] | 155 | #define Q15_ONE_1 ((celt_word16_t)1.f) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 156 | |
| 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 Valin | c209c34 | 2008-03-07 17:50:45 +1100 | [diff] [blame] | 174 | #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 Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 178 | |
Jean-Marc Valin | f5b0587 | 2008-03-21 10:46:17 +1100 | [diff] [blame] | 179 | #define ROUND16(a,shift) (a) |
Jean-Marc Valin | c209c34 | 2008-03-07 17:50:45 +1100 | [diff] [blame] | 180 | #define HALF32(x) (.5f*(x)) |
Jean-Marc Valin | a02ca1e | 2008-02-28 11:33:22 +1100 | [diff] [blame] | 181 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 182 | #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 Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 187 | #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 Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 189 | |
| 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 Valin | ef0d5f1 | 2008-04-22 09:49:22 +1000 | [diff] [blame] | 194 | #define MULT16_32_Q16(a,b) ((a)*(b)) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 195 | #define MULT16_32_P15(a,b) ((a)*(b)) |
| 196 | |
Jean-Marc Valin | d857ac4 | 2008-03-12 13:26:37 +1100 | [diff] [blame] | 197 | #define MULT32_32_Q31(a,b) ((a)*(b)) |
| 198 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 199 | #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 Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 213 | #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 Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 217 | |
Gregory Maxwell | 5f2a74b | 2008-08-11 23:50:07 -0400 | [diff] [blame^] | 218 | #define SCALEIN(a) ((a)*32768.) |
| 219 | #define SCALEOUT(a) ((a)*(1/32768.)) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 220 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 221 | #endif /* !FIXED_POINT */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 222 | |
| 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 Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 231 | #else /* CONFIG_TI_C54X */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 232 | |
| 233 | #define BYTES_PER_CHAR 1 |
| 234 | #define BITS_PER_CHAR 8 |
| 235 | #define LOG2_BITS_PER_CHAR 3 |
| 236 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 237 | #endif /* !CONFIG_TI_C54X */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 238 | |
| 239 | |
| 240 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 241 | #endif /* ARCH_H */ |