Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 1 | /* Copyright (C) 2003 Jean-Marc Valin */ |
| 2 | /** |
| 3 | @file arch.h |
| 4 | @brief Various architecture definitions Speex |
| 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 | a85657b | 2008-02-20 11:59:30 +1100 | [diff] [blame] | 39 | #include "stack_alloc.h" |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 40 | |
| 41 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ |
| 42 | #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ |
| 43 | #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */ |
| 44 | #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ |
| 45 | #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */ |
| 46 | #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */ |
| 47 | #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */ |
| 48 | |
| 49 | #ifdef FIXED_POINT |
| 50 | |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 51 | typedef celt_int16_t celt_word16_t; |
| 52 | typedef celt_int32_t celt_word32_t; |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 53 | |
Jean-Marc Valin | 5c032a4 | 2008-02-25 14:55:09 +1100 | [diff] [blame^] | 54 | typedef celt_word32_t celt_sig_t; |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 55 | typedef float celt_norm_t; |
| 56 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 57 | #define Q15ONE 32767 |
| 58 | |
| 59 | #define LPC_SCALING 8192 |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 60 | #define SIG_SCALING 16384.f |
| 61 | #define SIG_SCALING_1 0.000061035 |
| 62 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 63 | #define LSP_SCALING 8192. |
| 64 | #define GAMMA_SCALING 32768. |
| 65 | #define GAIN_SCALING 64 |
| 66 | #define GAIN_SCALING_1 0.015625 |
| 67 | |
| 68 | #define LPC_SHIFT 13 |
| 69 | #define LSP_SHIFT 13 |
| 70 | #define SIG_SHIFT 14 |
| 71 | #define GAIN_SHIFT 6 |
| 72 | |
| 73 | #define VERY_SMALL 0 |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 74 | #define VERY_LARGE32 ((celt_word32_t)2147483647) |
| 75 | #define VERY_LARGE16 ((celt_word16_t)32767) |
| 76 | #define Q15_ONE ((celt_word16_t)32767) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 77 | |
| 78 | |
| 79 | #ifdef FIXED_DEBUG |
| 80 | #include "fixed_debug.h" |
| 81 | #else |
| 82 | |
| 83 | #include "fixed_generic.h" |
| 84 | |
| 85 | #ifdef ARM5E_ASM |
| 86 | #include "fixed_arm5e.h" |
| 87 | #elif defined (ARM4_ASM) |
| 88 | #include "fixed_arm4.h" |
| 89 | #elif defined (BFIN_ASM) |
| 90 | #include "fixed_bfin.h" |
| 91 | #endif |
| 92 | |
| 93 | #endif |
| 94 | |
| 95 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 96 | #else /* FIXED_POINT */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 97 | |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 98 | typedef float celt_word16_t; |
| 99 | typedef float celt_word32_t; |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 100 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 101 | typedef float celt_sig_t; |
| 102 | typedef float celt_norm_t; |
| 103 | |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 104 | #define Q15ONE 1.0f |
| 105 | #define LPC_SCALING 1.f |
| 106 | #define SIG_SCALING 1.f |
Jean-Marc Valin | 49ca99e | 2008-02-25 14:05:10 +1100 | [diff] [blame] | 107 | #define SIG_SCALING_1 1.f |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 108 | #define LSP_SCALING 1.f |
| 109 | #define GAMMA_SCALING 1.f |
| 110 | #define GAIN_SCALING 1.f |
| 111 | #define GAIN_SCALING_1 1.f |
| 112 | |
| 113 | |
| 114 | #define VERY_SMALL 1e-15f |
| 115 | #define VERY_LARGE32 1e15f |
| 116 | #define VERY_LARGE16 1e15f |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 117 | #define Q15_ONE ((celt_word16_t)1.f) |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 118 | |
| 119 | #define QCONST16(x,bits) (x) |
| 120 | #define QCONST32(x,bits) (x) |
| 121 | |
| 122 | #define NEG16(x) (-(x)) |
| 123 | #define NEG32(x) (-(x)) |
| 124 | #define EXTRACT16(x) (x) |
| 125 | #define EXTEND32(x) (x) |
| 126 | #define SHR16(a,shift) (a) |
| 127 | #define SHL16(a,shift) (a) |
| 128 | #define SHR32(a,shift) (a) |
| 129 | #define SHL32(a,shift) (a) |
| 130 | #define PSHR16(a,shift) (a) |
| 131 | #define PSHR32(a,shift) (a) |
| 132 | #define VSHR32(a,shift) (a) |
| 133 | #define SATURATE16(x,a) (x) |
| 134 | #define SATURATE32(x,a) (x) |
| 135 | |
| 136 | #define PSHR(a,shift) (a) |
| 137 | #define SHR(a,shift) (a) |
| 138 | #define SHL(a,shift) (a) |
| 139 | #define SATURATE(x,a) (x) |
| 140 | |
| 141 | #define ADD16(a,b) ((a)+(b)) |
| 142 | #define SUB16(a,b) ((a)-(b)) |
| 143 | #define ADD32(a,b) ((a)+(b)) |
| 144 | #define SUB32(a,b) ((a)-(b)) |
| 145 | #define MULT16_16_16(a,b) ((a)*(b)) |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 146 | #define MULT16_16(a,b) ((celt_word32_t)(a)*(celt_word32_t)(b)) |
| 147 | #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] | 148 | |
| 149 | #define MULT16_32_Q11(a,b) ((a)*(b)) |
| 150 | #define MULT16_32_Q13(a,b) ((a)*(b)) |
| 151 | #define MULT16_32_Q14(a,b) ((a)*(b)) |
| 152 | #define MULT16_32_Q15(a,b) ((a)*(b)) |
| 153 | #define MULT16_32_P15(a,b) ((a)*(b)) |
| 154 | |
| 155 | #define MAC16_32_Q11(c,a,b) ((c)+(a)*(b)) |
| 156 | #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) |
| 157 | |
| 158 | #define MAC16_16_Q11(c,a,b) ((c)+(a)*(b)) |
| 159 | #define MAC16_16_Q13(c,a,b) ((c)+(a)*(b)) |
| 160 | #define MAC16_16_P13(c,a,b) ((c)+(a)*(b)) |
| 161 | #define MULT16_16_Q11_32(a,b) ((a)*(b)) |
| 162 | #define MULT16_16_Q13(a,b) ((a)*(b)) |
| 163 | #define MULT16_16_Q14(a,b) ((a)*(b)) |
| 164 | #define MULT16_16_Q15(a,b) ((a)*(b)) |
| 165 | #define MULT16_16_P15(a,b) ((a)*(b)) |
| 166 | #define MULT16_16_P13(a,b) ((a)*(b)) |
| 167 | #define MULT16_16_P14(a,b) ((a)*(b)) |
| 168 | |
Jean-Marc Valin | abe043f | 2008-01-31 14:26:29 +1100 | [diff] [blame] | 169 | #define DIV32_16(a,b) (((celt_word32_t)(a))/(celt_word16_t)(b)) |
| 170 | #define PDIV32_16(a,b) (((celt_word32_t)(a))/(celt_word16_t)(b)) |
| 171 | #define DIV32(a,b) (((celt_word32_t)(a))/(celt_word32_t)(b)) |
| 172 | #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] | 173 | |
| 174 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 175 | #endif /* !FIXED_POINT */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 176 | |
| 177 | |
| 178 | #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) |
| 179 | |
| 180 | /* 2 on TI C5x DSP */ |
| 181 | #define BYTES_PER_CHAR 2 |
| 182 | #define BITS_PER_CHAR 16 |
| 183 | #define LOG2_BITS_PER_CHAR 4 |
| 184 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 185 | #else /* CONFIG_TI_C54X */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 186 | |
| 187 | #define BYTES_PER_CHAR 1 |
| 188 | #define BITS_PER_CHAR 8 |
| 189 | #define LOG2_BITS_PER_CHAR 3 |
| 190 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 191 | #endif /* !CONFIG_TI_C54X */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 192 | |
| 193 | |
| 194 | |
Jean-Marc Valin | 18ddc02 | 2008-02-22 14:24:50 +1100 | [diff] [blame] | 195 | #endif /* ARCH_H */ |