1 /* Copyright (C) 2003 Jean-Marc Valin */ 2 /** 3 @file arch.h 4 @brief Various architecture definitions Speex 5 */ 6 /* 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions 9 are met: 10 11 - Redistributions of source code must retain the above copyright 12 notice, this list of conditions and the following disclaimer. 13 14 - Redistributions in binary form must reproduce the above copyright 15 notice, this list of conditions and the following disclaimer in the 16 documentation and/or other materials provided with the distribution. 17 18 - Neither the name of the Xiph.org Foundation nor the names of its 19 contributors may be used to endorse or promote products derived from 20 this software without specific prior written permission. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef ARCH_H 36 #define ARCH_H 37 38 #include "speex/speex_types.h" 39 40 #define ABS(x) ((x) < 0 ? (-(x)) : (x)) 41 42 #ifdef FIXED_POINT 43 44 typedef spx_int16_t spx_word16_t; 45 typedef spx_int32_t spx_word32_t; 46 #ifdef _MSC_VER 47 typedef __int64 spx_word64_t; 48 #else 49 typedef long long spx_word64_t; 50 #endif 51 typedef spx_word32_t spx_mem_t; 52 typedef spx_word16_t spx_coef_t; 53 typedef spx_word16_t spx_lsp_t; 54 typedef spx_word32_t spx_sig_t; 55 56 #define LPC_SCALING 8192 57 #define SIG_SCALING 16384 58 #define LSP_SCALING 8192. 59 #define GAMMA_SCALING 32768. 60 #define GAIN_SCALING 64 61 #define GAIN_SCALING_1 0.015625 62 63 #define LPC_SHIFT 13 64 #define SIG_SHIFT 14 65 66 #define VERY_SMALL 0 67 68 69 #ifdef ARM5E_ASM 70 #include "fixed_arm5e.h" 71 #elif defined (ARM4_ASM) 72 #include "fixed_arm4.h" 73 #elif defined (FIXED_DEBUG) 74 #include "fixed_debug.h" 75 #else 76 #include "fixed_generic.h" 77 #endif 78 79 80 81 #else 82 83 typedef float spx_mem_t; 84 typedef float spx_coef_t; 85 typedef float spx_lsp_t; 86 typedef float spx_sig_t; 87 typedef float spx_word16_t; 88 typedef float spx_word32_t; 89 typedef float spx_word64_t; 90 91 #define LPC_SCALING 1. 92 #define SIG_SCALING 1. 93 #define LSP_SCALING 1. 94 #define GAMMA_SCALING 1. 95 #define GAIN_SCALING 1. 96 #define GAIN_SCALING_1 1. 97 98 #define LPC_SHIFT 0 99 #define SIG_SHIFT 0 100 101 #define VERY_SMALL 1e-15 102 103 #define NEG16(x) (-(x)) 104 #define NEG32(x) (-(x)) 105 #define EXTRACT16(x) (x) 106 #define EXTEND32(x) (x) 107 #define SHR16(a,shift) (a) 108 #define SHL16(a,shift) (a) 109 #define SHR32(a,shift) (a) 110 #define SHL32(a,shift) (a) 111 #define PSHR16(a,shift) (a) 112 #define PSHR32(a,shift) (a) 113 #define SATURATE16(x,a) (x) 114 #define SATURATE32(x,a) (x) 115 116 #define PSHR(a,shift) (a) 117 #define SHR(a,shift) (a) 118 #define SHL(a,shift) (a) 119 #define SATURATE(x,a) (x) 120 121 #define ADD16(a,b) ((a)+(b)) 122 #define SUB16(a,b) ((a)-(b)) 123 #define ADD32(a,b) ((a)+(b)) 124 #define SUB32(a,b) ((a)-(b)) 125 #define ADD64(a,b) ((a)+(b)) 126 #define MULT16_16_16(a,b) ((a)*(b)) 127 #define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b)) 128 #define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b)) 129 130 #define MULT16_32_Q11(a,b) ((a)*(b)) 131 #define MULT16_32_Q13(a,b) ((a)*(b)) 132 #define MULT16_32_Q14(a,b) ((a)*(b)) 133 #define MULT16_32_Q15(a,b) ((a)*(b)) 134 135 #define MAC16_32_Q11(c,a,b) ((c)+(a)*(b)) 136 #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) 137 138 #define MAC16_16_Q11(c,a,b) ((c)+(a)*(b)) 139 #define MAC16_16_Q13(c,a,b) ((c)+(a)*(b)) 140 #define MULT16_16_Q11_32(a,b) ((a)*(b)) 141 #define MULT16_16_Q13(a,b) ((a)*(b)) 142 #define MULT16_16_Q14(a,b) ((a)*(b)) 143 #define MULT16_16_Q15(a,b) ((a)*(b)) 144 #define MULT16_16_P15(a,b) ((a)*(b)) 145 146 #define DIV32_16(a,b) ((a)/(b)) 147 #define DIV32(a,b) ((a)/(b)) 148 149 150 #endif 151 152 153 #ifdef CONFIG_TI_C55X 154 155 /* 2 on TI C5x DSP */ 156 #define BYTES_PER_CHAR 2 157 #define BITS_PER_CHAR 16 158 #define LOG2_BITS_PER_CHAR 4 159 160 #else 161 162 #define BYTES_PER_CHAR 1 163 #define BITS_PER_CHAR 8 164 #define LOG2_BITS_PER_CHAR 3 165 166 #endif 167 168 #endif 169