michael@0: /* Copyright (c) 2003-2008 Jean-Marc Valin michael@0: Copyright (c) 2007-2008 CSIRO michael@0: Copyright (c) 2007-2009 Xiph.Org Foundation michael@0: Written by Jean-Marc Valin */ michael@0: /** michael@0: @file arch.h michael@0: @brief Various architecture definitions for CELT michael@0: */ michael@0: /* michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions michael@0: are met: michael@0: michael@0: - Redistributions of source code must retain the above copyright michael@0: notice, this list of conditions and the following disclaimer. michael@0: michael@0: - Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER michael@0: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF michael@0: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING michael@0: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS michael@0: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifndef ARCH_H michael@0: #define ARCH_H michael@0: michael@0: #include "opus_types.h" michael@0: #include "opus_defines.h" michael@0: michael@0: # if !defined(__GNUC_PREREQ) michael@0: # if defined(__GNUC__)&&defined(__GNUC_MINOR__) michael@0: # define __GNUC_PREREQ(_maj,_min) \ michael@0: ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) michael@0: # else michael@0: # define __GNUC_PREREQ(_maj,_min) 0 michael@0: # endif michael@0: # endif michael@0: michael@0: #define CELT_SIG_SCALE 32768.f michael@0: michael@0: #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__); michael@0: #ifdef ENABLE_ASSERTIONS michael@0: #include michael@0: #include michael@0: #ifdef __GNUC__ michael@0: __attribute__((noreturn)) michael@0: #endif michael@0: static OPUS_INLINE void _celt_fatal(const char *str, const char *file, int line) michael@0: { michael@0: fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); michael@0: abort(); michael@0: } michael@0: #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}} michael@0: #define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}} michael@0: #else michael@0: #define celt_assert(cond) michael@0: #define celt_assert2(cond, message) michael@0: #endif michael@0: michael@0: #define IMUL32(a,b) ((a)*(b)) michael@0: michael@0: #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ michael@0: #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ michael@0: #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */ michael@0: #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ michael@0: #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */ michael@0: #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */ michael@0: #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */ michael@0: #define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */ michael@0: #define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */ michael@0: #define UADD32(a,b) ((a)+(b)) michael@0: #define USUB32(a,b) ((a)-(b)) michael@0: michael@0: #define PRINT_MIPS(file) michael@0: michael@0: #ifdef FIXED_POINT michael@0: michael@0: typedef opus_int16 opus_val16; michael@0: typedef opus_int32 opus_val32; michael@0: michael@0: typedef opus_val32 celt_sig; michael@0: typedef opus_val16 celt_norm; michael@0: typedef opus_val32 celt_ener; michael@0: michael@0: #define Q15ONE 32767 michael@0: michael@0: #define SIG_SHIFT 12 michael@0: michael@0: #define NORM_SCALING 16384 michael@0: michael@0: #define DB_SHIFT 10 michael@0: michael@0: #define EPSILON 1 michael@0: #define VERY_SMALL 0 michael@0: #define VERY_LARGE16 ((opus_val16)32767) michael@0: #define Q15_ONE ((opus_val16)32767) michael@0: michael@0: #define SCALEIN(a) (a) michael@0: #define SCALEOUT(a) (a) michael@0: michael@0: #ifdef FIXED_DEBUG michael@0: #include "fixed_debug.h" michael@0: #else michael@0: michael@0: #include "fixed_generic.h" michael@0: michael@0: #ifdef OPUS_ARM_INLINE_EDSP michael@0: #include "arm/fixed_armv5e.h" michael@0: #elif defined (OPUS_ARM_INLINE_ASM) michael@0: #include "arm/fixed_armv4.h" michael@0: #elif defined (BFIN_ASM) michael@0: #include "fixed_bfin.h" michael@0: #elif defined (TI_C5X_ASM) michael@0: #include "fixed_c5x.h" michael@0: #elif defined (TI_C6X_ASM) michael@0: #include "fixed_c6x.h" michael@0: #endif michael@0: michael@0: #endif michael@0: michael@0: #else /* FIXED_POINT */ michael@0: michael@0: typedef float opus_val16; michael@0: typedef float opus_val32; michael@0: michael@0: typedef float celt_sig; michael@0: typedef float celt_norm; michael@0: typedef float celt_ener; michael@0: michael@0: #define Q15ONE 1.0f michael@0: michael@0: #define NORM_SCALING 1.f michael@0: michael@0: #define EPSILON 1e-15f michael@0: #define VERY_SMALL 1e-30f michael@0: #define VERY_LARGE16 1e15f michael@0: #define Q15_ONE ((opus_val16)1.f) michael@0: michael@0: #define QCONST16(x,bits) (x) michael@0: #define QCONST32(x,bits) (x) michael@0: michael@0: #define NEG16(x) (-(x)) michael@0: #define NEG32(x) (-(x)) michael@0: #define EXTRACT16(x) (x) michael@0: #define EXTEND32(x) (x) michael@0: #define SHR16(a,shift) (a) michael@0: #define SHL16(a,shift) (a) michael@0: #define SHR32(a,shift) (a) michael@0: #define SHL32(a,shift) (a) michael@0: #define PSHR32(a,shift) (a) michael@0: #define VSHR32(a,shift) (a) michael@0: michael@0: #define PSHR(a,shift) (a) michael@0: #define SHR(a,shift) (a) michael@0: #define SHL(a,shift) (a) michael@0: #define SATURATE(x,a) (x) michael@0: #define SATURATE16(x) (x) michael@0: michael@0: #define ROUND16(a,shift) (a) michael@0: #define HALF16(x) (.5f*(x)) michael@0: #define HALF32(x) (.5f*(x)) michael@0: michael@0: #define ADD16(a,b) ((a)+(b)) michael@0: #define SUB16(a,b) ((a)-(b)) michael@0: #define ADD32(a,b) ((a)+(b)) michael@0: #define SUB32(a,b) ((a)-(b)) michael@0: #define MULT16_16_16(a,b) ((a)*(b)) michael@0: #define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b)) michael@0: #define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b)) michael@0: michael@0: #define MULT16_32_Q15(a,b) ((a)*(b)) michael@0: #define MULT16_32_Q16(a,b) ((a)*(b)) michael@0: michael@0: #define MULT32_32_Q31(a,b) ((a)*(b)) michael@0: michael@0: #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) michael@0: michael@0: #define MULT16_16_Q11_32(a,b) ((a)*(b)) michael@0: #define MULT16_16_Q11(a,b) ((a)*(b)) michael@0: #define MULT16_16_Q13(a,b) ((a)*(b)) michael@0: #define MULT16_16_Q14(a,b) ((a)*(b)) michael@0: #define MULT16_16_Q15(a,b) ((a)*(b)) michael@0: #define MULT16_16_P15(a,b) ((a)*(b)) michael@0: #define MULT16_16_P13(a,b) ((a)*(b)) michael@0: #define MULT16_16_P14(a,b) ((a)*(b)) michael@0: #define MULT16_32_P16(a,b) ((a)*(b)) michael@0: michael@0: #define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b)) michael@0: #define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b)) michael@0: michael@0: #define SCALEIN(a) ((a)*CELT_SIG_SCALE) michael@0: #define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE)) michael@0: michael@0: #endif /* !FIXED_POINT */ michael@0: michael@0: #ifndef GLOBAL_STACK_SIZE michael@0: #ifdef FIXED_POINT michael@0: #define GLOBAL_STACK_SIZE 100000 michael@0: #else michael@0: #define GLOBAL_STACK_SIZE 100000 michael@0: #endif michael@0: #endif michael@0: michael@0: #endif /* ARCH_H */