diff options
Diffstat (limited to 'lib/rbcodec/codecs/libopus/celt/fixed_generic.h')
-rw-r--r-- | lib/rbcodec/codecs/libopus/celt/fixed_generic.h | 62 |
1 files changed, 7 insertions, 55 deletions
diff --git a/lib/rbcodec/codecs/libopus/celt/fixed_generic.h b/lib/rbcodec/codecs/libopus/celt/fixed_generic.h index 28a1598d3e..0e77976e83 100644 --- a/lib/rbcodec/codecs/libopus/celt/fixed_generic.h +++ b/lib/rbcodec/codecs/libopus/celt/fixed_generic.h @@ -42,64 +42,12 @@ /** 16x32 multiplication, followed by a 16-bit shift right (round-to-nearest). Results fits in 32 bits */ #define MULT16_32_P16(a,b) ADD32(MULT16_16((a),SHR((b),16)), PSHR(MULT16_16((a),((b)&0x0000ffff)),16)) -#if defined(CPU_COLDFIRE) -static inline int32_t MULT16_32_Q15(int32_t a, int32_t b) -{ - int32_t r; - asm volatile ("mac.l %[a], %[b], %%acc0;" - "movclr.l %%acc0, %[r];" - : [r] "=r" (r) - : [a] "r" (a<<16), [b] "r" (b) - : "cc"); - return r; -} - -#elif defined(CPU_ARM) -static inline int32_t MULT16_32_Q15(int32_t a, int32_t b) -{ - int32_t lo, hi; - asm volatile("smull %[lo], %[hi], %[b], %[a] \n\t" - "mov %[lo], %[lo], lsr #15 \n\t" - "orr %[hi], %[lo], %[hi], lsl #17 \n\t" - : [lo] "=&r" (lo), [hi] "=&r" (hi) - : [a] "r" (a), [b] "r" (b) ); - return(hi); -} - -#else /** 16x32 multiplication, followed by a 15-bit shift right. Results fits in 32 bits */ #define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),((b)&0x0000ffff)),15)) -#endif -#if defined(CPU_COLDFIRE) -static inline int32_t MULT32_32_Q31(int32_t a, int32_t b) -{ - int32_t r; - asm volatile ("mac.l %[a], %[b], %%acc0;" - "movclr.l %%acc0, %[r];" - : [r] "=r" (r) - : [a] "r" (a), [b] "r" (b) - : "cc"); - return r; -} - -#elif defined(CPU_ARM) -static inline int32_t MULT32_32_Q31(int32_t a, int32_t b) -{ - int32_t lo, hi; - asm volatile("smull %[lo], %[hi], %[a], %[b] \n\t" - "mov %[lo], %[lo], lsr #31 \n\t" - "orr %[hi], %[lo], %[hi], lsl #1 \n\t" - : [lo] "=&r" (lo), [hi] "=&r" (hi) - : [a] "r" (a), [b] "r" (b) ); - return(hi); -} - -#else /** 32x32 multiplication, followed by a 31-bit shift right. Results fits in 32 bits */ -//#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)) -#define MULT32_32_Q31(a,b) (opus_val32)((((int64_t)(a)) * ((int64_t)(b)))>>31) -#endif +#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)) + /** Compile-time conversion of float constant to 16-bit value */ #define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits)))) @@ -136,6 +84,8 @@ static inline int32_t MULT32_32_Q31(int32_t a, int32_t b) #define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift)) #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) +#define SATURATE16(x) (EXTRACT16((x)>32767 ? 32767 : (x)<-32768 ? -32768 : (x))) + /** Shift by a and round-to-neareast 32-bit value. Result is a 16-bit value */ #define ROUND16(x,a) (EXTRACT16(PSHR32((x),(a)))) /** Divide by two */ @@ -160,7 +110,9 @@ static inline int32_t MULT32_32_Q31(int32_t a, int32_t b) /** 16x16 multiply-add where the result fits in 32 bits */ #define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b)))) -/** 16x32 multiply-add, followed by a 15-bit shift right. Results fits in 32 bits */ +/** 16x32 multiply, followed by a 15-bit shift right and 32-bit add. + b must fit in 31 bits. + Result fits in 32 bits. */ #define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))) #define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11)) |