Alexandre Lision | 744f742 | 2013-09-25 11:39:37 -0400 | [diff] [blame] | 1 | /* 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 */ |
| 5 | /** |
| 6 | @file arch.h |
| 7 | @brief Various architecture definitions for CELT |
| 8 | */ |
| 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 | |
| 21 | 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 COPYRIGHT OWNER |
| 25 | OR 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 | |
| 37 | #include "opus_types.h" |
| 38 | |
| 39 | # 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 | #define CELT_SIG_SCALE 32768.f |
| 49 | |
| 50 | #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__); |
| 51 | #ifdef ENABLE_ASSERTIONS |
| 52 | #include <stdio.h> |
| 53 | #include <stdlib.h> |
| 54 | #ifdef __GNUC__ |
| 55 | __attribute__((noreturn)) |
| 56 | #endif |
| 57 | static inline void _celt_fatal(const char *str, const char *file, int line) |
| 58 | { |
| 59 | fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); |
| 60 | abort(); |
| 61 | } |
| 62 | #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}} |
| 63 | #define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}} |
| 64 | #else |
| 65 | #define celt_assert(cond) |
| 66 | #define celt_assert2(cond, message) |
| 67 | #endif |
| 68 | |
| 69 | #define IMUL32(a,b) ((a)*(b)) |
| 70 | |
| 71 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ |
| 72 | #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ |
| 73 | #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */ |
| 74 | #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ |
| 75 | #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */ |
| 76 | #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */ |
| 77 | #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */ |
| 78 | #define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */ |
| 79 | #define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */ |
| 80 | #define UADD32(a,b) ((a)+(b)) |
| 81 | #define USUB32(a,b) ((a)-(b)) |
| 82 | |
| 83 | #define PRINT_MIPS(file) |
| 84 | |
| 85 | #ifdef FIXED_POINT |
| 86 | |
| 87 | typedef opus_int16 opus_val16; |
| 88 | typedef opus_int32 opus_val32; |
| 89 | |
| 90 | typedef opus_val32 celt_sig; |
| 91 | typedef opus_val16 celt_norm; |
| 92 | typedef opus_val32 celt_ener; |
| 93 | |
| 94 | #define Q15ONE 32767 |
| 95 | |
| 96 | #define SIG_SHIFT 12 |
| 97 | |
| 98 | #define NORM_SCALING 16384 |
| 99 | |
| 100 | #define DB_SHIFT 10 |
| 101 | |
| 102 | #define EPSILON 1 |
| 103 | #define VERY_LARGE16 ((opus_val16)32767) |
| 104 | #define Q15_ONE ((opus_val16)32767) |
| 105 | |
| 106 | #define SCALEIN(a) (a) |
| 107 | #define SCALEOUT(a) (a) |
| 108 | |
| 109 | #ifdef FIXED_DEBUG |
| 110 | #include "fixed_debug.h" |
| 111 | #else |
| 112 | |
| 113 | #include "fixed_generic.h" |
| 114 | |
| 115 | #ifdef ARM5E_ASM |
| 116 | #include "fixed_arm5e.h" |
| 117 | #elif defined (ARM4_ASM) |
| 118 | #include "fixed_arm4.h" |
| 119 | #elif defined (BFIN_ASM) |
| 120 | #include "fixed_bfin.h" |
| 121 | #elif defined (TI_C5X_ASM) |
| 122 | #include "fixed_c5x.h" |
| 123 | #elif defined (TI_C6X_ASM) |
| 124 | #include "fixed_c6x.h" |
| 125 | #endif |
| 126 | |
| 127 | #endif |
| 128 | |
| 129 | #else /* FIXED_POINT */ |
| 130 | |
| 131 | typedef float opus_val16; |
| 132 | typedef float opus_val32; |
| 133 | |
| 134 | typedef float celt_sig; |
| 135 | typedef float celt_norm; |
| 136 | typedef float celt_ener; |
| 137 | |
| 138 | #define Q15ONE 1.0f |
| 139 | |
| 140 | #define NORM_SCALING 1.f |
| 141 | |
| 142 | #define EPSILON 1e-15f |
| 143 | #define VERY_LARGE16 1e15f |
| 144 | #define Q15_ONE ((opus_val16)1.f) |
| 145 | |
| 146 | #define QCONST16(x,bits) (x) |
| 147 | #define QCONST32(x,bits) (x) |
| 148 | |
| 149 | #define NEG16(x) (-(x)) |
| 150 | #define NEG32(x) (-(x)) |
| 151 | #define EXTRACT16(x) (x) |
| 152 | #define EXTEND32(x) (x) |
| 153 | #define SHR16(a,shift) (a) |
| 154 | #define SHL16(a,shift) (a) |
| 155 | #define SHR32(a,shift) (a) |
| 156 | #define SHL32(a,shift) (a) |
| 157 | #define PSHR32(a,shift) (a) |
| 158 | #define VSHR32(a,shift) (a) |
| 159 | |
| 160 | #define PSHR(a,shift) (a) |
| 161 | #define SHR(a,shift) (a) |
| 162 | #define SHL(a,shift) (a) |
| 163 | #define SATURATE(x,a) (x) |
| 164 | |
| 165 | #define ROUND16(a,shift) (a) |
| 166 | #define HALF16(x) (.5f*(x)) |
| 167 | #define HALF32(x) (.5f*(x)) |
| 168 | |
| 169 | #define ADD16(a,b) ((a)+(b)) |
| 170 | #define SUB16(a,b) ((a)-(b)) |
| 171 | #define ADD32(a,b) ((a)+(b)) |
| 172 | #define SUB32(a,b) ((a)-(b)) |
| 173 | #define MULT16_16_16(a,b) ((a)*(b)) |
| 174 | #define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b)) |
| 175 | #define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b)) |
| 176 | |
| 177 | #define MULT16_32_Q15(a,b) ((a)*(b)) |
| 178 | #define MULT16_32_Q16(a,b) ((a)*(b)) |
| 179 | |
| 180 | #define MULT32_32_Q31(a,b) ((a)*(b)) |
| 181 | |
| 182 | #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) |
| 183 | |
| 184 | #define MULT16_16_Q11_32(a,b) ((a)*(b)) |
| 185 | #define MULT16_16_Q13(a,b) ((a)*(b)) |
| 186 | #define MULT16_16_Q14(a,b) ((a)*(b)) |
| 187 | #define MULT16_16_Q15(a,b) ((a)*(b)) |
| 188 | #define MULT16_16_P15(a,b) ((a)*(b)) |
| 189 | #define MULT16_16_P13(a,b) ((a)*(b)) |
| 190 | #define MULT16_16_P14(a,b) ((a)*(b)) |
| 191 | #define MULT16_32_P16(a,b) ((a)*(b)) |
| 192 | |
| 193 | #define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b)) |
| 194 | #define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b)) |
| 195 | |
| 196 | #define SCALEIN(a) ((a)*CELT_SIG_SCALE) |
| 197 | #define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE)) |
| 198 | |
| 199 | #endif /* !FIXED_POINT */ |
| 200 | |
| 201 | #ifndef GLOBAL_STACK_SIZE |
| 202 | #ifdef FIXED_POINT |
| 203 | #define GLOBAL_STACK_SIZE 100000 |
| 204 | #else |
| 205 | #define GLOBAL_STACK_SIZE 100000 |
| 206 | #endif |
| 207 | #endif |
| 208 | |
| 209 | #endif /* ARCH_H */ |