ex
Fork of mbed-os-example-mbed5-blinky by
Embed:
(wiki syntax)
Show/hide line numbers
fixed_generic.h
Go to the documentation of this file.
00001 /* Copyright (C) 2003 Jean-Marc Valin */ 00002 /** 00003 @file fixed_generic.h 00004 @brief Generic fixed-point operations 00005 */ 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_GENERIC_H 00036 #define FIXED_GENERIC_H 00037 00038 #define QCONST16(x,bits) ((spx_word16_t)(.5+(x)*(((spx_word32_t)1)<<(bits)))) 00039 #define QCONST32(x,bits) ((spx_word32_t)(.5+(x)*(((spx_word32_t)1)<<(bits)))) 00040 00041 #define NEG16(x) (-(x)) 00042 #define NEG32(x) (-(x)) 00043 #define EXTRACT16(x) ((spx_word16_t)(x)) 00044 #define EXTEND32(x) ((spx_word32_t)(x)) 00045 #define SHR16(a,shift) ((a) >> (shift)) 00046 #define SHL16(a,shift) ((a) << (shift)) 00047 #define SHR32(a,shift) ((a) >> (shift)) 00048 #define SHL32(a,shift) ((a) << (shift)) 00049 #define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift)) 00050 #define PSHR32(a,shift) (SHR32((a)+((1<<((shift))>>1)),shift)) 00051 #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) 00052 #define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 00053 #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 00054 00055 #define SHR(a,shift) ((a) >> (shift)) 00056 #define SHL(a,shift) ((spx_word32_t)(a) << (shift)) 00057 #define PSHR(a,shift) (SHR((a)+((1<<((shift))>>1)),shift)) 00058 #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 00059 00060 00061 #define ADD16(a,b) ((spx_word16_t)((spx_word16_t)(a)+(spx_word16_t)(b))) 00062 #define SUB16(a,b) ((spx_word16_t)(a)-(spx_word16_t)(b)) 00063 #define ADD32(a,b) ((spx_word32_t)(a)+(spx_word32_t)(b)) 00064 #define SUB32(a,b) ((spx_word32_t)(a)-(spx_word32_t)(b)) 00065 00066 00067 /* result fits in 16 bits */ 00068 #define MULT16_16_16(a,b) ((((spx_word16_t)(a))*((spx_word16_t)(b)))) 00069 00070 /* (spx_word32_t)(spx_word16_t) gives TI compiler a hint that it's 16x16->32 multiply */ 00071 #define MULT16_16(a,b) (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b))) 00072 00073 #define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b)))) 00074 #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12)) 00075 #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13)) 00076 #define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14)) 00077 00078 #define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)) 00079 #define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))) 00080 00081 #define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15)) 00082 #define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)) 00083 #define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))) 00084 00085 00086 #define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11))) 00087 #define MAC16_16_Q13(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),13))) 00088 #define MAC16_16_P13(c,a,b) (ADD32((c),SHR(ADD32(4096,MULT16_16((a),(b))),13))) 00089 00090 #define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11)) 00091 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13)) 00092 #define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14)) 00093 #define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15)) 00094 00095 #define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13)) 00096 #define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14)) 00097 #define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15)) 00098 00099 #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15)) 00100 00101 #define DIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a))/((spx_word16_t)(b)))) 00102 #define PDIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a)+((spx_word16_t)(b)>>1))/((spx_word16_t)(b)))) 00103 #define DIV32(a,b) (((spx_word32_t)(a))/((spx_word32_t)(b))) 00104 #define PDIV32(a,b) (((spx_word32_t)(a)+((spx_word16_t)(b)>>1))/((spx_word32_t)(b))) 00105 00106 #endif
Generated on Tue Jul 12 2022 16:28:53 by
1.7.2
