Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Copyright (c) 2003-2008 Jean-Marc Valin |
michael@0 | 2 | Copyright (c) 2007-2008 CSIRO |
michael@0 | 3 | Copyright (c) 2007-2009 Xiph.Org Foundation |
michael@0 | 4 | Written by Jean-Marc Valin */ |
michael@0 | 5 | /** |
michael@0 | 6 | @file arch.h |
michael@0 | 7 | @brief Various architecture definitions for CELT |
michael@0 | 8 | */ |
michael@0 | 9 | /* |
michael@0 | 10 | Redistribution and use in source and binary forms, with or without |
michael@0 | 11 | modification, are permitted provided that the following conditions |
michael@0 | 12 | are met: |
michael@0 | 13 | |
michael@0 | 14 | - Redistributions of source code must retain the above copyright |
michael@0 | 15 | notice, this list of conditions and the following disclaimer. |
michael@0 | 16 | |
michael@0 | 17 | - Redistributions in binary form must reproduce the above copyright |
michael@0 | 18 | notice, this list of conditions and the following disclaimer in the |
michael@0 | 19 | documentation and/or other materials provided with the distribution. |
michael@0 | 20 | |
michael@0 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
michael@0 | 25 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
michael@0 | 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
michael@0 | 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
michael@0 | 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
michael@0 | 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
michael@0 | 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 32 | */ |
michael@0 | 33 | |
michael@0 | 34 | #ifndef ARCH_H |
michael@0 | 35 | #define ARCH_H |
michael@0 | 36 | |
michael@0 | 37 | #include "opus_types.h" |
michael@0 | 38 | #include "opus_defines.h" |
michael@0 | 39 | |
michael@0 | 40 | # if !defined(__GNUC_PREREQ) |
michael@0 | 41 | # if defined(__GNUC__)&&defined(__GNUC_MINOR__) |
michael@0 | 42 | # define __GNUC_PREREQ(_maj,_min) \ |
michael@0 | 43 | ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) |
michael@0 | 44 | # else |
michael@0 | 45 | # define __GNUC_PREREQ(_maj,_min) 0 |
michael@0 | 46 | # endif |
michael@0 | 47 | # endif |
michael@0 | 48 | |
michael@0 | 49 | #define CELT_SIG_SCALE 32768.f |
michael@0 | 50 | |
michael@0 | 51 | #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__); |
michael@0 | 52 | #ifdef ENABLE_ASSERTIONS |
michael@0 | 53 | #include <stdio.h> |
michael@0 | 54 | #include <stdlib.h> |
michael@0 | 55 | #ifdef __GNUC__ |
michael@0 | 56 | __attribute__((noreturn)) |
michael@0 | 57 | #endif |
michael@0 | 58 | static OPUS_INLINE void _celt_fatal(const char *str, const char *file, int line) |
michael@0 | 59 | { |
michael@0 | 60 | fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); |
michael@0 | 61 | abort(); |
michael@0 | 62 | } |
michael@0 | 63 | #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}} |
michael@0 | 64 | #define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}} |
michael@0 | 65 | #else |
michael@0 | 66 | #define celt_assert(cond) |
michael@0 | 67 | #define celt_assert2(cond, message) |
michael@0 | 68 | #endif |
michael@0 | 69 | |
michael@0 | 70 | #define IMUL32(a,b) ((a)*(b)) |
michael@0 | 71 | |
michael@0 | 72 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ |
michael@0 | 73 | #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ |
michael@0 | 74 | #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */ |
michael@0 | 75 | #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ |
michael@0 | 76 | #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */ |
michael@0 | 77 | #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */ |
michael@0 | 78 | #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */ |
michael@0 | 79 | #define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */ |
michael@0 | 80 | #define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */ |
michael@0 | 81 | #define UADD32(a,b) ((a)+(b)) |
michael@0 | 82 | #define USUB32(a,b) ((a)-(b)) |
michael@0 | 83 | |
michael@0 | 84 | #define PRINT_MIPS(file) |
michael@0 | 85 | |
michael@0 | 86 | #ifdef FIXED_POINT |
michael@0 | 87 | |
michael@0 | 88 | typedef opus_int16 opus_val16; |
michael@0 | 89 | typedef opus_int32 opus_val32; |
michael@0 | 90 | |
michael@0 | 91 | typedef opus_val32 celt_sig; |
michael@0 | 92 | typedef opus_val16 celt_norm; |
michael@0 | 93 | typedef opus_val32 celt_ener; |
michael@0 | 94 | |
michael@0 | 95 | #define Q15ONE 32767 |
michael@0 | 96 | |
michael@0 | 97 | #define SIG_SHIFT 12 |
michael@0 | 98 | |
michael@0 | 99 | #define NORM_SCALING 16384 |
michael@0 | 100 | |
michael@0 | 101 | #define DB_SHIFT 10 |
michael@0 | 102 | |
michael@0 | 103 | #define EPSILON 1 |
michael@0 | 104 | #define VERY_SMALL 0 |
michael@0 | 105 | #define VERY_LARGE16 ((opus_val16)32767) |
michael@0 | 106 | #define Q15_ONE ((opus_val16)32767) |
michael@0 | 107 | |
michael@0 | 108 | #define SCALEIN(a) (a) |
michael@0 | 109 | #define SCALEOUT(a) (a) |
michael@0 | 110 | |
michael@0 | 111 | #ifdef FIXED_DEBUG |
michael@0 | 112 | #include "fixed_debug.h" |
michael@0 | 113 | #else |
michael@0 | 114 | |
michael@0 | 115 | #include "fixed_generic.h" |
michael@0 | 116 | |
michael@0 | 117 | #ifdef OPUS_ARM_INLINE_EDSP |
michael@0 | 118 | #include "arm/fixed_armv5e.h" |
michael@0 | 119 | #elif defined (OPUS_ARM_INLINE_ASM) |
michael@0 | 120 | #include "arm/fixed_armv4.h" |
michael@0 | 121 | #elif defined (BFIN_ASM) |
michael@0 | 122 | #include "fixed_bfin.h" |
michael@0 | 123 | #elif defined (TI_C5X_ASM) |
michael@0 | 124 | #include "fixed_c5x.h" |
michael@0 | 125 | #elif defined (TI_C6X_ASM) |
michael@0 | 126 | #include "fixed_c6x.h" |
michael@0 | 127 | #endif |
michael@0 | 128 | |
michael@0 | 129 | #endif |
michael@0 | 130 | |
michael@0 | 131 | #else /* FIXED_POINT */ |
michael@0 | 132 | |
michael@0 | 133 | typedef float opus_val16; |
michael@0 | 134 | typedef float opus_val32; |
michael@0 | 135 | |
michael@0 | 136 | typedef float celt_sig; |
michael@0 | 137 | typedef float celt_norm; |
michael@0 | 138 | typedef float celt_ener; |
michael@0 | 139 | |
michael@0 | 140 | #define Q15ONE 1.0f |
michael@0 | 141 | |
michael@0 | 142 | #define NORM_SCALING 1.f |
michael@0 | 143 | |
michael@0 | 144 | #define EPSILON 1e-15f |
michael@0 | 145 | #define VERY_SMALL 1e-30f |
michael@0 | 146 | #define VERY_LARGE16 1e15f |
michael@0 | 147 | #define Q15_ONE ((opus_val16)1.f) |
michael@0 | 148 | |
michael@0 | 149 | #define QCONST16(x,bits) (x) |
michael@0 | 150 | #define QCONST32(x,bits) (x) |
michael@0 | 151 | |
michael@0 | 152 | #define NEG16(x) (-(x)) |
michael@0 | 153 | #define NEG32(x) (-(x)) |
michael@0 | 154 | #define EXTRACT16(x) (x) |
michael@0 | 155 | #define EXTEND32(x) (x) |
michael@0 | 156 | #define SHR16(a,shift) (a) |
michael@0 | 157 | #define SHL16(a,shift) (a) |
michael@0 | 158 | #define SHR32(a,shift) (a) |
michael@0 | 159 | #define SHL32(a,shift) (a) |
michael@0 | 160 | #define PSHR32(a,shift) (a) |
michael@0 | 161 | #define VSHR32(a,shift) (a) |
michael@0 | 162 | |
michael@0 | 163 | #define PSHR(a,shift) (a) |
michael@0 | 164 | #define SHR(a,shift) (a) |
michael@0 | 165 | #define SHL(a,shift) (a) |
michael@0 | 166 | #define SATURATE(x,a) (x) |
michael@0 | 167 | #define SATURATE16(x) (x) |
michael@0 | 168 | |
michael@0 | 169 | #define ROUND16(a,shift) (a) |
michael@0 | 170 | #define HALF16(x) (.5f*(x)) |
michael@0 | 171 | #define HALF32(x) (.5f*(x)) |
michael@0 | 172 | |
michael@0 | 173 | #define ADD16(a,b) ((a)+(b)) |
michael@0 | 174 | #define SUB16(a,b) ((a)-(b)) |
michael@0 | 175 | #define ADD32(a,b) ((a)+(b)) |
michael@0 | 176 | #define SUB32(a,b) ((a)-(b)) |
michael@0 | 177 | #define MULT16_16_16(a,b) ((a)*(b)) |
michael@0 | 178 | #define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b)) |
michael@0 | 179 | #define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b)) |
michael@0 | 180 | |
michael@0 | 181 | #define MULT16_32_Q15(a,b) ((a)*(b)) |
michael@0 | 182 | #define MULT16_32_Q16(a,b) ((a)*(b)) |
michael@0 | 183 | |
michael@0 | 184 | #define MULT32_32_Q31(a,b) ((a)*(b)) |
michael@0 | 185 | |
michael@0 | 186 | #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) |
michael@0 | 187 | |
michael@0 | 188 | #define MULT16_16_Q11_32(a,b) ((a)*(b)) |
michael@0 | 189 | #define MULT16_16_Q11(a,b) ((a)*(b)) |
michael@0 | 190 | #define MULT16_16_Q13(a,b) ((a)*(b)) |
michael@0 | 191 | #define MULT16_16_Q14(a,b) ((a)*(b)) |
michael@0 | 192 | #define MULT16_16_Q15(a,b) ((a)*(b)) |
michael@0 | 193 | #define MULT16_16_P15(a,b) ((a)*(b)) |
michael@0 | 194 | #define MULT16_16_P13(a,b) ((a)*(b)) |
michael@0 | 195 | #define MULT16_16_P14(a,b) ((a)*(b)) |
michael@0 | 196 | #define MULT16_32_P16(a,b) ((a)*(b)) |
michael@0 | 197 | |
michael@0 | 198 | #define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b)) |
michael@0 | 199 | #define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b)) |
michael@0 | 200 | |
michael@0 | 201 | #define SCALEIN(a) ((a)*CELT_SIG_SCALE) |
michael@0 | 202 | #define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE)) |
michael@0 | 203 | |
michael@0 | 204 | #endif /* !FIXED_POINT */ |
michael@0 | 205 | |
michael@0 | 206 | #ifndef GLOBAL_STACK_SIZE |
michael@0 | 207 | #ifdef FIXED_POINT |
michael@0 | 208 | #define GLOBAL_STACK_SIZE 100000 |
michael@0 | 209 | #else |
michael@0 | 210 | #define GLOBAL_STACK_SIZE 100000 |
michael@0 | 211 | #endif |
michael@0 | 212 | #endif |
michael@0 | 213 | |
michael@0 | 214 | #endif /* ARCH_H */ |