| 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 | #include "common.h" |
| 39 |
| 40 | # if !defined(__GNUC_PREREQ) |
| 41 | # if defined(__GNUC__)&&defined(__GNUC_MINOR__) |
| 42 | # define __GNUC_PREREQ(_maj,_min) \ |
| 43 | ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) |
| 44 | # else |
| 45 | # define __GNUC_PREREQ(_maj,_min) 0 |
| 46 | # endif |
| 47 | # endif |
| 48 |
| 49 | #define CELT_SIG_SCALE 32768.f |
| 50 |
| 51 | #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__); |
| 52 | #ifdef ENABLE_ASSERTIONS |
| 53 | #include <stdio.h> |
| 54 | #include <stdlib.h> |
| 55 | #ifdef __GNUC__ |
| 56 | __attribute__((noreturn)) |
| 57 | #endif |
| 58 | static OPUS_INLINE void _celt_fatal(const char *str, const char *file, int line) |
| 59 | { |
| 60 | fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); |
| 61 | abort(); |
| 62 | } |
| 63 | #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}} |
| 64 | #define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}} |
| 65 | #else |
| 66 | #define celt_assert(cond) |
| 67 | #define celt_assert2(cond, message) |
| 68 | #endif |
| 69 |
| 70 | #define IMUL32(a,b) ((a)*(b)) |
| 71 |
| 72 | #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */ |
| 73 | #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ |
| 74 | #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */ |
| 75 | #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */ |
| 76 | #define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */ |
| 77 | #define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */ |
| 78 | #define UADD32(a,b) ((a)+(b)) |
| 79 | #define USUB32(a,b) ((a)-(b)) |
| 80 |
| 81 | /* Set this if opus_int64 is a native type of the CPU. */ |
| 82 | /* Assume that all LP64 architectures have fast 64-bit types; also x86_64 |
| 83 | (which can be ILP32 for x32) and Win64 (which is LLP64). */ |
| 84 | #if defined(__x86_64__) || defined(__LP64__) || defined(_WIN64) |
| 85 | #define OPUS_FAST_INT64 1 |
| 86 | #else |
| 87 | #define OPUS_FAST_INT64 0 |
| 88 | #endif |
| 89 |
| 90 | #define PRINT_MIPS(file) |
| 91 |
| 92 | #ifdef FIXED_POINT |
| 93 |
| 94 | typedef opus_int16 opus_val16; |
| 95 | typedef opus_int32 opus_val32; |
| 96 | typedef opus_int64 opus_val64; |
| 97 |
| 98 | typedef opus_val32 celt_sig; |
| 99 | typedef opus_val16 celt_norm; |
| 100 | typedef opus_val32 celt_ener; |
| 101 |
| 102 | #define Q15ONE 32767 |
| 103 |
| 104 | #define SIG_SHIFT 12 |
| 105 | /* Safe saturation value for 32-bit signals. Should be less than |
| 106 | 2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/ |
| 107 | #define SIG_SAT (300000000) |
| 108 |
| 109 | #define NORM_SCALING 16384 |
| 110 |
| 111 | #define DB_SHIFT 10 |
| 112 |
| 113 | #define EPSILON 1 |
| 114 | #define VERY_SMALL 0 |
| 115 | #define VERY_LARGE16 ((opus_val16)32767) |
| 116 | #define Q15_ONE ((opus_val16)32767) |
| 117 |
| 118 | #define SCALEIN(a) (a) |
| 119 | #define SCALEOUT(a) (a) |
| 120 |
| 121 | #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) |
| 122 | #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) |
| 123 |
| 124 | static OPUS_INLINE opus_int16 SAT16(opus_int32 x) { |
| 125 | return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x; |
| 126 | } |
| 127 |
| 128 | #ifdef FIXED_DEBUG |
| 129 | #include "fixed_debug.h" |
| 130 | #else |
| 131 |
| 132 | #include "fixed_generic.h" |
| 133 |
| 134 | #ifdef OPUS_ARM_PRESUME_AARCH64_NEON_INTR |
| 135 | #include "arm/fixed_arm64.h" |
| 136 | #elif OPUS_ARM_INLINE_EDSP |
| 137 | #include "arm/fixed_armv5e.h" |
| 138 | #elif defined (OPUS_ARM_INLINE_ASM) |
| 139 | #include "arm/fixed_armv4.h" |
| 140 | #elif defined (BFIN_ASM) |
| 141 | #include "fixed_bfin.h" |
| 142 | #elif defined (TI_C5X_ASM) |
| 143 | #include "fixed_c5x.h" |
| 144 | #elif defined (TI_C6X_ASM) |
| 145 | #include "fixed_c6x.h" |
| 146 | #endif |
| 147 |
| 148 | #endif |
| 149 |
| 150 | #else /* FIXED_POINT */ |
| 151 |
| 152 | typedef float opus_val16; |
| 153 | typedef float opus_val32; |
| 154 | typedef float opus_val64; |
| 155 |
| 156 | typedef float celt_sig; |
| 157 | typedef float celt_norm; |
| 158 | typedef float celt_ener; |
| 159 |
| 160 | #ifdef FLOAT_APPROX |
| 161 | /* This code should reliably detect NaN/inf even when -ffast-math is used. |
| 162 | Assumes IEEE 754 format. */ |
| 163 | static OPUS_INLINE int celt_isnan(float x) |
| 164 | { |
| 165 | union {float f; opus_uint32 i;} in; |
| 166 | in.f = x; |
| 167 | return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0; |
| 168 | } |
| 169 | #else |
| 170 | #ifdef __FAST_MATH__ |
| 171 | #error Cannot build libopus with -ffast-math unless FLOAT_APPROX is defined. This could result in crashes on extreme (e.g. NaN) input |
| 172 | #endif |
| 173 | #define celt_isnan(x) ((x)!=(x)) |
| 174 | #endif |
| 175 |
| 176 | #define Q15ONE 1.0f |
| 177 |
| 178 | #define NORM_SCALING 1.f |
| 179 |
| 180 | #define EPSILON 1e-15f |
| 181 | #define VERY_SMALL 1e-30f |
| 182 | #define VERY_LARGE16 1e15f |
| 183 | #define Q15_ONE ((opus_val16)1.f) |
| 184 |
| 185 | /* This appears to be the same speed as C99's fabsf() but it's more portable. */ |
| 186 | #define ABS16(x) ((float)fabs(x)) |
| 187 | #define ABS32(x) ((float)fabs(x)) |
| 188 |
| 189 | #define QCONST16(x,bits) (x) |
| 190 | #define QCONST32(x,bits) (x) |
| 191 |
| 192 | #define NEG16(x) (-(x)) |
| 193 | #define NEG32(x) (-(x)) |
| 194 | #define NEG32_ovflw(x) (-(x)) |
| 195 | #define EXTRACT16(x) (x) |
| 196 | #define EXTEND32(x) (x) |
| 197 | #define SHR16(a,shift) (a) |
| 198 | #define SHL16(a,shift) (a) |
| 199 | #define SHR32(a,shift) (a) |
| 200 | #define SHL32(a,shift) (a) |
| 201 | #define PSHR32(a,shift) (a) |
| 202 | #define VSHR32(a,shift) (a) |
| 203 |
| 204 | #define PSHR(a,shift) (a) |
| 205 | #define SHR(a,shift) (a) |
| 206 | #define SHL(a,shift) (a) |
| 207 | #define SATURATE(x,a) (x) |
| 208 | #define SATURATE16(x) (x) |
| 209 |
| 210 | #define ROUND16(a,shift) (a) |
| 211 | #define SROUND16(a,shift) (a) |
| 212 | #define HALF16(x) (.5f*(x)) |
| 213 | #define HALF32(x) (.5f*(x)) |
| 214 |
| 215 | #define ADD16(a,b) ((a)+(b)) |
| 216 | #define SUB16(a,b) ((a)-(b)) |
| 217 | #define ADD32(a,b) ((a)+(b)) |
| 218 | #define SUB32(a,b) ((a)-(b)) |
| 219 | #define ADD32_ovflw(a,b) ((a)+(b)) |
| 220 | #define SUB32_ovflw(a,b) ((a)-(b)) |
| 221 | #define MULT16_16_16(a,b) ((a)*(b)) |
| 222 | #define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b)) |
| 223 | #define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b)) |
| 224 |
| 225 | #define MULT16_32_Q15(a,b) ((a)*(b)) |
| 226 | #define MULT16_32_Q16(a,b) ((a)*(b)) |
| 227 |
| 228 | #define MULT32_32_Q31(a,b) ((a)*(b)) |
| 229 |
| 230 | #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) |
| 231 | #define MAC16_32_Q16(c,a,b) ((c)+(a)*(b)) |
| 232 |
| 233 | #define MULT16_16_Q11_32(a,b) ((a)*(b)) |
| 234 | #define MULT16_16_Q11(a,b) ((a)*(b)) |
| 235 | #define MULT16_16_Q13(a,b) ((a)*(b)) |
| 236 | #define MULT16_16_Q14(a,b) ((a)*(b)) |
| 237 | #define MULT16_16_Q15(a,b) ((a)*(b)) |
| 238 | #define MULT16_16_P15(a,b) ((a)*(b)) |
| 239 | #define MULT16_16_P13(a,b) ((a)*(b)) |
| 240 | #define MULT16_16_P14(a,b) ((a)*(b)) |
| 241 | #define MULT16_32_P16(a,b) ((a)*(b)) |
| 242 |
| 243 | #define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b)) |
| 244 | #define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b)) |
| 245 |
| 246 | #define SCALEIN(a) ((a)*CELT_SIG_SCALE) |
| 247 | #define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE)) |
| 248 |
| 249 | #define SIG2WORD16(x) (x) |
| 250 |
| 251 | #endif /* !FIXED_POINT */ |
| 252 |
| 253 | #ifndef GLOBAL_STACK_SIZE |
| 254 | #ifdef FIXED_POINT |
| 255 | #define GLOBAL_STACK_SIZE 120000 |
| 256 | #else |
| 257 | #define GLOBAL_STACK_SIZE 120000 |
| 258 | #endif |
| 259 | #endif |
| 260 |
| 261 | #endif /* ARCH_H */ |
| 262 |