Main Page | Class List | File List | Class Members | File Members

fixed_arm.h

Go to the documentation of this file.
00001 /* Copyright (C) 2003 Jean-Marc Valin */ 00006 /* 00007 Redistribution and use in source and binary forms, with or without 00008 modification, are permitted provided that the following conditions 00009 are met: 00010 00011 - Redistributions of source code must retain the above copyright 00012 notice, this list of conditions and the following disclaimer. 00013 00014 - Redistributions in binary form must reproduce the above copyright 00015 notice, this list of conditions and the following disclaimer in the 00016 documentation and/or other materials provided with the distribution. 00017 00018 - Neither the name of the Xiph.org Foundation nor the names of its 00019 contributors may be used to endorse or promote products derived from 00020 this software without specific prior written permission. 00021 00022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 00026 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00027 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00028 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00029 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00030 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00031 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00032 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 00035 #ifndef FIXED_ARM_H 00036 #define FIXED_ARM_H 00037 00038 #define SHR(a,shift) ((a) >> (shift)) 00039 #define SHL(a,shift) ((a) << (shift)) 00040 00041 #define SATURATE(x,a) ((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)) 00042 00043 00044 #define ADD16(a,b) ((short)((short)(a)+(short)(b))) 00045 #define SUB16(a,b) ((a)-(b)) 00046 #define ADD32(a,b) ((a)+(b)) 00047 #define SUB32(a,b) ((a)-(b)) 00048 #define ADD64(a,b) ((a)+(b)) 00049 00050 #define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift)) 00051 00052 /* result fits in 16 bits */ 00053 #define MULT16_16_16(a,b) (((short)(a))*((short)(b))) 00054 00055 static inline spx_word32_t MULT16_16(spx_word16_t x, spx_word16_t y) { 00056 int res; 00057 asm ("smulbb %0,%1,%2;\n" 00058 : "=&r"(res) 00059 : "%r"(x),"r"(y)); 00060 return(res); 00061 } 00062 00063 static inline spx_word32_t MAC16_16(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 00064 int res; 00065 asm ("smlabb %0,%1,%2,%3;\n" 00066 : "=&r"(res) 00067 : "%r"(x),"r"(y),"r"(a)); 00068 return(res); 00069 } 00070 00071 #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12)) 00072 #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13)) 00073 #define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14)) 00074 00075 static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) { 00076 int res; 00077 asm ("smulwb %0,%1,%2;\n" 00078 : "=&r"(res) 00079 : "%r"(y<<1),"r"(x)); 00080 return(res); 00081 } 00082 static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 00083 int res; 00084 asm ("smlawb %0,%1,%2,%3;\n" 00085 : "=&r"(res) 00086 : "%r"(y<<1),"r"(x),"r"(a)); 00087 return(res); 00088 } 00089 static inline spx_word32_t MULT16_32_Q11(spx_word16_t x, spx_word32_t y) { 00090 int res; 00091 asm ("smulwb %0,%1,%2;\n" 00092 : "=&r"(res) 00093 : "%r"(y<<5),"r"(x)); 00094 return(res); 00095 } 00096 static inline spx_word32_t MAC16_32_Q11(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 00097 int res; 00098 asm ("smlawb %0,%1,%2,%3;\n" 00099 : "=&r"(res) 00100 : "%r"(y<<5),"r"(x),"r"(a)); 00101 return(res); 00102 } 00103 00104 #define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11))) 00105 00106 #define MULT16_16_Q11(a,b) (SHR(MULT16_16((a),(b)),11)) 00107 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13)) 00108 #define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14)) 00109 #define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15)) 00110 00111 #define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13)) 00112 #define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14)) 00113 #define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15)) 00114 00115 #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15)) 00116 00117 00118 00119 #define DIV32_16(a,b) ((short)(((signed int)(a))/((short)(b)))) 00120 #define DIV32(a,b) (((signed int)(a))/((signed int)(b))) 00121 00122 00123 00124 #endif

Generated on Thu Aug 12 11:55:01 2004 for speex by doxygen 1.3.8