1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/celt/fixed_generic.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* Copyright (C) 2007-2009 Xiph.Org Foundation 1.5 + Copyright (C) 2003-2008 Jean-Marc Valin 1.6 + Copyright (C) 2007-2008 CSIRO */ 1.7 +/** 1.8 + @file fixed_generic.h 1.9 + @brief Generic fixed-point operations 1.10 +*/ 1.11 +/* 1.12 + Redistribution and use in source and binary forms, with or without 1.13 + modification, are permitted provided that the following conditions 1.14 + are met: 1.15 + 1.16 + - Redistributions of source code must retain the above copyright 1.17 + notice, this list of conditions and the following disclaimer. 1.18 + 1.19 + - Redistributions in binary form must reproduce the above copyright 1.20 + notice, this list of conditions and the following disclaimer in the 1.21 + documentation and/or other materials provided with the distribution. 1.22 + 1.23 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 1.27 + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.28 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.29 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.30 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.31 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.32 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.33 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 +*/ 1.35 + 1.36 +#ifndef FIXED_GENERIC_H 1.37 +#define FIXED_GENERIC_H 1.38 + 1.39 +/** Multiply a 16-bit signed value by a 16-bit unsigned value. The result is a 32-bit signed value */ 1.40 +#define MULT16_16SU(a,b) ((opus_val32)(opus_val16)(a)*(opus_val32)(opus_uint16)(b)) 1.41 + 1.42 +/** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */ 1.43 +#define MULT16_32_Q16(a,b) ADD32(MULT16_16((a),SHR((b),16)), SHR(MULT16_16SU((a),((b)&0x0000ffff)),16)) 1.44 + 1.45 +/** 16x32 multiplication, followed by a 16-bit shift right (round-to-nearest). Results fits in 32 bits */ 1.46 +#define MULT16_32_P16(a,b) ADD32(MULT16_16((a),SHR((b),16)), PSHR(MULT16_16SU((a),((b)&0x0000ffff)),16)) 1.47 + 1.48 +/** 16x32 multiplication, followed by a 15-bit shift right. Results fits in 32 bits */ 1.49 +#define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),((b)&0x0000ffff)),15)) 1.50 + 1.51 +/** 32x32 multiplication, followed by a 31-bit shift right. Results fits in 32 bits */ 1.52 +#define MULT32_32_Q31(a,b) ADD32(ADD32(SHL(MULT16_16(SHR((a),16),SHR((b),16)),1), SHR(MULT16_16SU(SHR((a),16),((b)&0x0000ffff)),15)), SHR(MULT16_16SU(SHR((b),16),((a)&0x0000ffff)),15)) 1.53 + 1.54 +/** Compile-time conversion of float constant to 16-bit value */ 1.55 +#define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits)))) 1.56 + 1.57 +/** Compile-time conversion of float constant to 32-bit value */ 1.58 +#define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits)))) 1.59 + 1.60 +/** Negate a 16-bit value */ 1.61 +#define NEG16(x) (-(x)) 1.62 +/** Negate a 32-bit value */ 1.63 +#define NEG32(x) (-(x)) 1.64 + 1.65 +/** Change a 32-bit value into a 16-bit value. The value is assumed to fit in 16-bit, otherwise the result is undefined */ 1.66 +#define EXTRACT16(x) ((opus_val16)(x)) 1.67 +/** Change a 16-bit value into a 32-bit value */ 1.68 +#define EXTEND32(x) ((opus_val32)(x)) 1.69 + 1.70 +/** Arithmetic shift-right of a 16-bit value */ 1.71 +#define SHR16(a,shift) ((a) >> (shift)) 1.72 +/** Arithmetic shift-left of a 16-bit value */ 1.73 +#define SHL16(a,shift) ((opus_int16)((opus_uint16)(a)<<(shift))) 1.74 +/** Arithmetic shift-right of a 32-bit value */ 1.75 +#define SHR32(a,shift) ((a) >> (shift)) 1.76 +/** Arithmetic shift-left of a 32-bit value */ 1.77 +#define SHL32(a,shift) ((opus_int32)((opus_uint32)(a)<<(shift))) 1.78 + 1.79 +/** 32-bit arithmetic shift right with rounding-to-nearest instead of rounding down */ 1.80 +#define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift)) 1.81 +/** 32-bit arithmetic shift right where the argument can be negative */ 1.82 +#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) 1.83 + 1.84 +/** "RAW" macros, should not be used outside of this header file */ 1.85 +#define SHR(a,shift) ((a) >> (shift)) 1.86 +#define SHL(a,shift) SHL32(a,shift) 1.87 +#define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift)) 1.88 +#define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 1.89 + 1.90 +#define SATURATE16(x) (EXTRACT16((x)>32767 ? 32767 : (x)<-32768 ? -32768 : (x))) 1.91 + 1.92 +/** Shift by a and round-to-neareast 32-bit value. Result is a 16-bit value */ 1.93 +#define ROUND16(x,a) (EXTRACT16(PSHR32((x),(a)))) 1.94 +/** Divide by two */ 1.95 +#define HALF16(x) (SHR16(x,1)) 1.96 +#define HALF32(x) (SHR32(x,1)) 1.97 + 1.98 +/** Add two 16-bit values */ 1.99 +#define ADD16(a,b) ((opus_val16)((opus_val16)(a)+(opus_val16)(b))) 1.100 +/** Subtract two 16-bit values */ 1.101 +#define SUB16(a,b) ((opus_val16)(a)-(opus_val16)(b)) 1.102 +/** Add two 32-bit values */ 1.103 +#define ADD32(a,b) ((opus_val32)(a)+(opus_val32)(b)) 1.104 +/** Subtract two 32-bit values */ 1.105 +#define SUB32(a,b) ((opus_val32)(a)-(opus_val32)(b)) 1.106 + 1.107 +/** 16x16 multiplication where the result fits in 16 bits */ 1.108 +#define MULT16_16_16(a,b) ((((opus_val16)(a))*((opus_val16)(b)))) 1.109 + 1.110 +/* (opus_val32)(opus_val16) gives TI compiler a hint that it's 16x16->32 multiply */ 1.111 +/** 16x16 multiplication where the result fits in 32 bits */ 1.112 +#define MULT16_16(a,b) (((opus_val32)(opus_val16)(a))*((opus_val32)(opus_val16)(b))) 1.113 + 1.114 +/** 16x16 multiply-add where the result fits in 32 bits */ 1.115 +#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b)))) 1.116 +/** 16x32 multiply, followed by a 15-bit shift right and 32-bit add. 1.117 + b must fit in 31 bits. 1.118 + Result fits in 32 bits. */ 1.119 +#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))) 1.120 + 1.121 +#define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11)) 1.122 +#define MULT16_16_Q11(a,b) (SHR(MULT16_16((a),(b)),11)) 1.123 +#define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13)) 1.124 +#define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14)) 1.125 +#define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15)) 1.126 + 1.127 +#define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13)) 1.128 +#define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14)) 1.129 +#define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15)) 1.130 + 1.131 +/** Divide a 32-bit value by a 16-bit value. Result fits in 16 bits */ 1.132 +#define DIV32_16(a,b) ((opus_val16)(((opus_val32)(a))/((opus_val16)(b)))) 1.133 + 1.134 +/** Divide a 32-bit value by a 32-bit value. Result fits in 32 bits */ 1.135 +#define DIV32(a,b) (((opus_val32)(a))/((opus_val32)(b))) 1.136 + 1.137 +#endif