annotate src/opus-1.3/celt/arch.h @ 79:91c729825bca pa_catalina

Update build for AUDIO_COMPONENT_FIX
author Chris Cannam
date Wed, 30 Oct 2019 12:40:34 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /* Copyright (c) 2003-2008 Jean-Marc Valin
Chris@69 2 Copyright (c) 2007-2008 CSIRO
Chris@69 3 Copyright (c) 2007-2009 Xiph.Org Foundation
Chris@69 4 Written by Jean-Marc Valin */
Chris@69 5 /**
Chris@69 6 @file arch.h
Chris@69 7 @brief Various architecture definitions for CELT
Chris@69 8 */
Chris@69 9 /*
Chris@69 10 Redistribution and use in source and binary forms, with or without
Chris@69 11 modification, are permitted provided that the following conditions
Chris@69 12 are met:
Chris@69 13
Chris@69 14 - Redistributions of source code must retain the above copyright
Chris@69 15 notice, this list of conditions and the following disclaimer.
Chris@69 16
Chris@69 17 - Redistributions in binary form must reproduce the above copyright
Chris@69 18 notice, this list of conditions and the following disclaimer in the
Chris@69 19 documentation and/or other materials provided with the distribution.
Chris@69 20
Chris@69 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@69 22 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@69 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@69 24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
Chris@69 25 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@69 26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@69 27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Chris@69 28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Chris@69 29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Chris@69 30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@69 31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@69 32 */
Chris@69 33
Chris@69 34 #ifndef ARCH_H
Chris@69 35 #define ARCH_H
Chris@69 36
Chris@69 37 #include "opus_types.h"
Chris@69 38 #include "opus_defines.h"
Chris@69 39
Chris@69 40 # if !defined(__GNUC_PREREQ)
Chris@69 41 # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
Chris@69 42 # define __GNUC_PREREQ(_maj,_min) \
Chris@69 43 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
Chris@69 44 # else
Chris@69 45 # define __GNUC_PREREQ(_maj,_min) 0
Chris@69 46 # endif
Chris@69 47 # endif
Chris@69 48
Chris@69 49 #if OPUS_GNUC_PREREQ(3, 0)
Chris@69 50 #define opus_likely(x) (__builtin_expect(!!(x), 1))
Chris@69 51 #define opus_unlikely(x) (__builtin_expect(!!(x), 0))
Chris@69 52 #else
Chris@69 53 #define opus_likely(x) (!!(x))
Chris@69 54 #define opus_unlikely(x) (!!(x))
Chris@69 55 #endif
Chris@69 56
Chris@69 57 #define CELT_SIG_SCALE 32768.f
Chris@69 58
Chris@69 59 #define CELT_FATAL(str) celt_fatal(str, __FILE__, __LINE__);
Chris@69 60
Chris@69 61 #if defined(ENABLE_ASSERTIONS) || defined(ENABLE_HARDENING)
Chris@69 62 #ifdef __GNUC__
Chris@69 63 __attribute__((noreturn))
Chris@69 64 #endif
Chris@69 65 void celt_fatal(const char *str, const char *file, int line);
Chris@69 66
Chris@69 67 #if defined(CELT_C) && !defined(OVERRIDE_celt_fatal)
Chris@69 68 #include <stdio.h>
Chris@69 69 #include <stdlib.h>
Chris@69 70 #ifdef __GNUC__
Chris@69 71 __attribute__((noreturn))
Chris@69 72 #endif
Chris@69 73 void celt_fatal(const char *str, const char *file, int line)
Chris@69 74 {
Chris@69 75 fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
Chris@69 76 abort();
Chris@69 77 }
Chris@69 78 #endif
Chris@69 79
Chris@69 80 #define celt_assert(cond) {if (!(cond)) {CELT_FATAL("assertion failed: " #cond);}}
Chris@69 81 #define celt_assert2(cond, message) {if (!(cond)) {CELT_FATAL("assertion failed: " #cond "\n" message);}}
Chris@69 82 #define MUST_SUCCEED(call) celt_assert((call) == OPUS_OK)
Chris@69 83 #else
Chris@69 84 #define celt_assert(cond)
Chris@69 85 #define celt_assert2(cond, message)
Chris@69 86 #define MUST_SUCCEED(call) do {if((call) != OPUS_OK) {RESTORE_STACK; return OPUS_INTERNAL_ERROR;} } while (0)
Chris@69 87 #endif
Chris@69 88
Chris@69 89 #if defined(ENABLE_ASSERTIONS)
Chris@69 90 #define celt_sig_assert(cond) {if (!(cond)) {CELT_FATAL("signal assertion failed: " #cond);}}
Chris@69 91 #else
Chris@69 92 #define celt_sig_assert(cond)
Chris@69 93 #endif
Chris@69 94
Chris@69 95 #define IMUL32(a,b) ((a)*(b))
Chris@69 96
Chris@69 97 #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */
Chris@69 98 #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
Chris@69 99 #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */
Chris@69 100 #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
Chris@69 101 #define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */
Chris@69 102 #define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */
Chris@69 103 #define UADD32(a,b) ((a)+(b))
Chris@69 104 #define USUB32(a,b) ((a)-(b))
Chris@69 105
Chris@69 106 /* Set this if opus_int64 is a native type of the CPU. */
Chris@69 107 /* Assume that all LP64 architectures have fast 64-bit types; also x86_64
Chris@69 108 (which can be ILP32 for x32) and Win64 (which is LLP64). */
Chris@69 109 #if defined(__x86_64__) || defined(__LP64__) || defined(_WIN64)
Chris@69 110 #define OPUS_FAST_INT64 1
Chris@69 111 #else
Chris@69 112 #define OPUS_FAST_INT64 0
Chris@69 113 #endif
Chris@69 114
Chris@69 115 #define PRINT_MIPS(file)
Chris@69 116
Chris@69 117 #ifdef FIXED_POINT
Chris@69 118
Chris@69 119 typedef opus_int16 opus_val16;
Chris@69 120 typedef opus_int32 opus_val32;
Chris@69 121 typedef opus_int64 opus_val64;
Chris@69 122
Chris@69 123 typedef opus_val32 celt_sig;
Chris@69 124 typedef opus_val16 celt_norm;
Chris@69 125 typedef opus_val32 celt_ener;
Chris@69 126
Chris@69 127 #define celt_isnan(x) 0
Chris@69 128
Chris@69 129 #define Q15ONE 32767
Chris@69 130
Chris@69 131 #define SIG_SHIFT 12
Chris@69 132 /* Safe saturation value for 32-bit signals. Should be less than
Chris@69 133 2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/
Chris@69 134 #define SIG_SAT (300000000)
Chris@69 135
Chris@69 136 #define NORM_SCALING 16384
Chris@69 137
Chris@69 138 #define DB_SHIFT 10
Chris@69 139
Chris@69 140 #define EPSILON 1
Chris@69 141 #define VERY_SMALL 0
Chris@69 142 #define VERY_LARGE16 ((opus_val16)32767)
Chris@69 143 #define Q15_ONE ((opus_val16)32767)
Chris@69 144
Chris@69 145 #define SCALEIN(a) (a)
Chris@69 146 #define SCALEOUT(a) (a)
Chris@69 147
Chris@69 148 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))
Chris@69 149 #define ABS32(x) ((x) < 0 ? (-(x)) : (x))
Chris@69 150
Chris@69 151 static OPUS_INLINE opus_int16 SAT16(opus_int32 x) {
Chris@69 152 return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
Chris@69 153 }
Chris@69 154
Chris@69 155 #ifdef FIXED_DEBUG
Chris@69 156 #include "fixed_debug.h"
Chris@69 157 #else
Chris@69 158
Chris@69 159 #include "fixed_generic.h"
Chris@69 160
Chris@69 161 #ifdef OPUS_ARM_PRESUME_AARCH64_NEON_INTR
Chris@69 162 #include "arm/fixed_arm64.h"
Chris@69 163 #elif OPUS_ARM_INLINE_EDSP
Chris@69 164 #include "arm/fixed_armv5e.h"
Chris@69 165 #elif defined (OPUS_ARM_INLINE_ASM)
Chris@69 166 #include "arm/fixed_armv4.h"
Chris@69 167 #elif defined (BFIN_ASM)
Chris@69 168 #include "fixed_bfin.h"
Chris@69 169 #elif defined (TI_C5X_ASM)
Chris@69 170 #include "fixed_c5x.h"
Chris@69 171 #elif defined (TI_C6X_ASM)
Chris@69 172 #include "fixed_c6x.h"
Chris@69 173 #endif
Chris@69 174
Chris@69 175 #endif
Chris@69 176
Chris@69 177 #else /* FIXED_POINT */
Chris@69 178
Chris@69 179 typedef float opus_val16;
Chris@69 180 typedef float opus_val32;
Chris@69 181 typedef float opus_val64;
Chris@69 182
Chris@69 183 typedef float celt_sig;
Chris@69 184 typedef float celt_norm;
Chris@69 185 typedef float celt_ener;
Chris@69 186
Chris@69 187 #ifdef FLOAT_APPROX
Chris@69 188 /* This code should reliably detect NaN/inf even when -ffast-math is used.
Chris@69 189 Assumes IEEE 754 format. */
Chris@69 190 static OPUS_INLINE int celt_isnan(float x)
Chris@69 191 {
Chris@69 192 union {float f; opus_uint32 i;} in;
Chris@69 193 in.f = x;
Chris@69 194 return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0;
Chris@69 195 }
Chris@69 196 #else
Chris@69 197 #ifdef __FAST_MATH__
Chris@69 198 #error Cannot build libopus with -ffast-math unless FLOAT_APPROX is defined. This could result in crashes on extreme (e.g. NaN) input
Chris@69 199 #endif
Chris@69 200 #define celt_isnan(x) ((x)!=(x))
Chris@69 201 #endif
Chris@69 202
Chris@69 203 #define Q15ONE 1.0f
Chris@69 204
Chris@69 205 #define NORM_SCALING 1.f
Chris@69 206
Chris@69 207 #define EPSILON 1e-15f
Chris@69 208 #define VERY_SMALL 1e-30f
Chris@69 209 #define VERY_LARGE16 1e15f
Chris@69 210 #define Q15_ONE ((opus_val16)1.f)
Chris@69 211
Chris@69 212 /* This appears to be the same speed as C99's fabsf() but it's more portable. */
Chris@69 213 #define ABS16(x) ((float)fabs(x))
Chris@69 214 #define ABS32(x) ((float)fabs(x))
Chris@69 215
Chris@69 216 #define QCONST16(x,bits) (x)
Chris@69 217 #define QCONST32(x,bits) (x)
Chris@69 218
Chris@69 219 #define NEG16(x) (-(x))
Chris@69 220 #define NEG32(x) (-(x))
Chris@69 221 #define NEG32_ovflw(x) (-(x))
Chris@69 222 #define EXTRACT16(x) (x)
Chris@69 223 #define EXTEND32(x) (x)
Chris@69 224 #define SHR16(a,shift) (a)
Chris@69 225 #define SHL16(a,shift) (a)
Chris@69 226 #define SHR32(a,shift) (a)
Chris@69 227 #define SHL32(a,shift) (a)
Chris@69 228 #define PSHR32(a,shift) (a)
Chris@69 229 #define VSHR32(a,shift) (a)
Chris@69 230
Chris@69 231 #define PSHR(a,shift) (a)
Chris@69 232 #define SHR(a,shift) (a)
Chris@69 233 #define SHL(a,shift) (a)
Chris@69 234 #define SATURATE(x,a) (x)
Chris@69 235 #define SATURATE16(x) (x)
Chris@69 236
Chris@69 237 #define ROUND16(a,shift) (a)
Chris@69 238 #define SROUND16(a,shift) (a)
Chris@69 239 #define HALF16(x) (.5f*(x))
Chris@69 240 #define HALF32(x) (.5f*(x))
Chris@69 241
Chris@69 242 #define ADD16(a,b) ((a)+(b))
Chris@69 243 #define SUB16(a,b) ((a)-(b))
Chris@69 244 #define ADD32(a,b) ((a)+(b))
Chris@69 245 #define SUB32(a,b) ((a)-(b))
Chris@69 246 #define ADD32_ovflw(a,b) ((a)+(b))
Chris@69 247 #define SUB32_ovflw(a,b) ((a)-(b))
Chris@69 248 #define MULT16_16_16(a,b) ((a)*(b))
Chris@69 249 #define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b))
Chris@69 250 #define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b))
Chris@69 251
Chris@69 252 #define MULT16_32_Q15(a,b) ((a)*(b))
Chris@69 253 #define MULT16_32_Q16(a,b) ((a)*(b))
Chris@69 254
Chris@69 255 #define MULT32_32_Q31(a,b) ((a)*(b))
Chris@69 256
Chris@69 257 #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
Chris@69 258 #define MAC16_32_Q16(c,a,b) ((c)+(a)*(b))
Chris@69 259
Chris@69 260 #define MULT16_16_Q11_32(a,b) ((a)*(b))
Chris@69 261 #define MULT16_16_Q11(a,b) ((a)*(b))
Chris@69 262 #define MULT16_16_Q13(a,b) ((a)*(b))
Chris@69 263 #define MULT16_16_Q14(a,b) ((a)*(b))
Chris@69 264 #define MULT16_16_Q15(a,b) ((a)*(b))
Chris@69 265 #define MULT16_16_P15(a,b) ((a)*(b))
Chris@69 266 #define MULT16_16_P13(a,b) ((a)*(b))
Chris@69 267 #define MULT16_16_P14(a,b) ((a)*(b))
Chris@69 268 #define MULT16_32_P16(a,b) ((a)*(b))
Chris@69 269
Chris@69 270 #define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b))
Chris@69 271 #define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b))
Chris@69 272
Chris@69 273 #define SCALEIN(a) ((a)*CELT_SIG_SCALE)
Chris@69 274 #define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE))
Chris@69 275
Chris@69 276 #define SIG2WORD16(x) (x)
Chris@69 277
Chris@69 278 #endif /* !FIXED_POINT */
Chris@69 279
Chris@69 280 #ifndef GLOBAL_STACK_SIZE
Chris@69 281 #ifdef FIXED_POINT
Chris@69 282 #define GLOBAL_STACK_SIZE 120000
Chris@69 283 #else
Chris@69 284 #define GLOBAL_STACK_SIZE 120000
Chris@69 285 #endif
Chris@69 286 #endif
Chris@69 287
Chris@69 288 #endif /* ARCH_H */