2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
12 // This header file includes the inline functions in
13 // the fix point signal processing library.
15 #ifndef WEBRTC_SPL_SPL_INL_H_
16 #define WEBRTC_SPL_SPL_INL_H_
18 #ifdef WEBRTC_ARCH_ARM_V7
19 #include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h"
22 #if defined(MIPS32_LE)
23 #include "webrtc/common_audio/signal_processing/include/spl_inl_mips.h"
26 #if !defined(MIPS_DSP_R1_LE)
27 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
28 int16_t out16 = (int16_t) value32;
32 else if (value32 < -32768)
38 static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
41 // Perform long addition
42 l_sum = l_var1 + l_var2;
44 if (l_var1 < 0) { // Check for underflow.
45 if ((l_var2 < 0) && (l_sum >= 0)) {
46 l_sum = (int32_t)0x80000000;
48 } else { // Check for overflow.
49 if ((l_var2 > 0) && (l_sum < 0)) {
50 l_sum = (int32_t)0x7FFFFFFF;
57 static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
60 // Perform subtraction.
61 l_diff = l_var1 - l_var2;
63 if (l_var1 < 0) { // Check for underflow.
64 if ((l_var2 > 0) && (l_diff > 0)) {
65 l_diff = (int32_t)0x80000000;
67 } else { // Check for overflow.
68 if ((l_var2 < 0) && (l_diff < 0)) {
69 l_diff = (int32_t)0x7FFFFFFF;
76 static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
77 return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b);
80 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
81 return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2);
83 #endif // #if !defined(MIPS_DSP_R1_LE)
85 #if !defined(MIPS32_LE)
86 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
94 if (0x0000FF00 & (n >> bits)) bits += 8;
95 if (0x000000F0 & (n >> bits)) bits += 4;
96 if (0x0000000C & (n >> bits)) bits += 2;
97 if (0x00000002 & (n >> bits)) bits += 1;
98 if (0x00000001 & (n >> bits)) bits += 1;
103 static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
113 if (!(0xFFFF8000 & a)) {
118 if (!(0xFF800000 & (a << zeros))) zeros += 8;
119 if (!(0xF8000000 & (a << zeros))) zeros += 4;
120 if (!(0xE0000000 & (a << zeros))) zeros += 2;
121 if (!(0xC0000000 & (a << zeros))) zeros += 1;
126 static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
129 if (a == 0) return 0;
131 if (!(0xFFFF0000 & a)) {
136 if (!(0xFF000000 & (a << zeros))) zeros += 8;
137 if (!(0xF0000000 & (a << zeros))) zeros += 4;
138 if (!(0xC0000000 & (a << zeros))) zeros += 2;
139 if (!(0x80000000 & (a << zeros))) zeros += 1;
144 static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
159 if (!(0xF800 & (a << zeros))) zeros += 4;
160 if (!(0xE000 & (a << zeros))) zeros += 2;
161 if (!(0xC000 & (a << zeros))) zeros += 1;
166 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
169 #endif // #if !defined(MIPS32_LE)
171 #endif // WEBRTC_ARCH_ARM_V7
173 #endif // WEBRTC_SPL_SPL_INL_H_