OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 | 11 |
12 // This header file includes the inline functions in | 12 // This header file includes the inline functions in |
13 // the fix point signal processing library. | 13 // the fix point signal processing library. |
14 | 14 |
15 #ifndef WEBRTC_SPL_SPL_INL_H_ | 15 #ifndef WEBRTC_SPL_SPL_INL_H_ |
16 #define WEBRTC_SPL_SPL_INL_H_ | 16 #define WEBRTC_SPL_SPL_INL_H_ |
17 | 17 |
18 #include "webrtc/system_wrappers/include/compile_assert_c.h" | |
19 | |
20 // Don't call this directly except in tests! | |
21 static __inline int WebRtcSpl_CountLeadingZeros32_NotBuiltin(uint32_t n) { | |
22 int leading_zeros = n >> 16 == 0 ? 16 : 0; | |
23 leading_zeros += (n << leading_zeros) >> 24 == 0 ? 8 : 0; | |
24 leading_zeros += (n << leading_zeros) >> 28 == 0 ? 4 : 0; | |
25 leading_zeros += (n << leading_zeros) >> 30 == 0 ? 2 : 0; | |
26 leading_zeros += (n << leading_zeros) >> 31 == 0 ? 1 : 0; | |
27 leading_zeros += (n << leading_zeros) >> 31 == 0 ? 1 : 0; | |
28 return leading_zeros; | |
29 } | |
30 | |
31 // Don't call this directly except in tests! | |
32 static __inline int WebRtcSpl_CountLeadingZeros64_NotBuiltin(uint64_t n) { | |
33 const int leading_zeros = n >> 32 == 0 ? 32 : 0; | |
34 return leading_zeros + WebRtcSpl_CountLeadingZeros32_NotBuiltin( | |
35 (uint32_t)(n >> (32 - leading_zeros))); | |
36 } | |
37 | |
38 // Returns the number of leading zero bits in the argument. | |
39 static __inline int WebRtcSpl_CountLeadingZeros32(uint32_t n) { | |
40 #ifdef __GNUC__ | |
41 COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t)); | |
42 return n == 0 ? 32 : __builtin_clz(n); | |
43 #else | |
44 return WebRtcSpl_CountLeadingZeros32_NotBuiltin(n); | |
45 #endif | |
46 } | |
47 | |
48 // Returns the number of leading zero bits in the argument. | |
49 static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) { | |
50 #ifdef __GNUC__ | |
51 COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t)); | |
52 return n == 0 ? 64 : __builtin_clzll(n); | |
53 #else | |
54 return WebRtcSpl_CountLeadingZeros64_NotBuiltin(n); | |
55 #endif | |
56 } | |
57 | |
18 #ifdef WEBRTC_ARCH_ARM_V7 | 58 #ifdef WEBRTC_ARCH_ARM_V7 |
19 #include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h" | 59 #include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h" |
20 #else | 60 #else |
21 | 61 |
22 #if defined(MIPS32_LE) | 62 #if defined(MIPS32_LE) |
23 #include "webrtc/common_audio/signal_processing/include/spl_inl_mips.h" | 63 #include "webrtc/common_audio/signal_processing/include/spl_inl_mips.h" |
24 #endif | 64 #endif |
25 | 65 |
26 #if !defined(MIPS_DSP_R1_LE) | 66 #if !defined(MIPS_DSP_R1_LE) |
27 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { | 67 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b); | 107 return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b); |
68 } | 108 } |
69 | 109 |
70 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { | 110 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { |
71 return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2); | 111 return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2); |
72 } | 112 } |
73 #endif // #if !defined(MIPS_DSP_R1_LE) | 113 #endif // #if !defined(MIPS_DSP_R1_LE) |
74 | 114 |
75 #if !defined(MIPS32_LE) | 115 #if !defined(MIPS32_LE) |
76 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { | 116 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { |
77 int16_t bits; | 117 return 32 - WebRtcSpl_CountLeadingZeros32(n); |
78 | |
79 if (0xFFFF0000 & n) { | |
80 bits = 16; | |
81 } else { | |
82 bits = 0; | |
83 } | |
84 if (0x0000FF00 & (n >> bits)) bits += 8; | |
85 if (0x000000F0 & (n >> bits)) bits += 4; | |
86 if (0x0000000C & (n >> bits)) bits += 2; | |
87 if (0x00000002 & (n >> bits)) bits += 1; | |
88 if (0x00000001 & (n >> bits)) bits += 1; | |
89 | |
90 return bits; | |
91 } | 118 } |
92 | 119 |
93 static __inline int16_t WebRtcSpl_NormW32(int32_t a) { | 120 static __inline int16_t WebRtcSpl_NormW32(int32_t a) { |
tlegrand-webrtc
2016/05/26 12:01:46
Maybe use your new function here as well?
| |
94 int16_t zeros; | 121 int16_t zeros; |
95 | 122 |
96 if (a == 0) { | 123 if (a == 0) { |
97 return 0; | 124 return 0; |
98 } | 125 } |
99 else if (a < 0) { | 126 else if (a < 0) { |
100 a = ~a; | 127 a = ~a; |
101 } | 128 } |
102 | 129 |
103 if (!(0xFFFF8000 & a)) { | 130 if (!(0xFFFF8000 & a)) { |
104 zeros = 16; | 131 zeros = 16; |
105 } else { | 132 } else { |
106 zeros = 0; | 133 zeros = 0; |
107 } | 134 } |
108 if (!(0xFF800000 & (a << zeros))) zeros += 8; | 135 if (!(0xFF800000 & (a << zeros))) zeros += 8; |
109 if (!(0xF8000000 & (a << zeros))) zeros += 4; | 136 if (!(0xF8000000 & (a << zeros))) zeros += 4; |
110 if (!(0xE0000000 & (a << zeros))) zeros += 2; | 137 if (!(0xE0000000 & (a << zeros))) zeros += 2; |
111 if (!(0xC0000000 & (a << zeros))) zeros += 1; | 138 if (!(0xC0000000 & (a << zeros))) zeros += 1; |
112 | 139 |
113 return zeros; | 140 return zeros; |
114 } | 141 } |
115 | 142 |
116 static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { | 143 static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { |
tlegrand-webrtc
2016/05/26 12:01:46
And here.
| |
117 int16_t zeros; | 144 int16_t zeros; |
118 | 145 |
119 if (a == 0) return 0; | 146 if (a == 0) return 0; |
120 | 147 |
121 if (!(0xFFFF0000 & a)) { | 148 if (!(0xFFFF0000 & a)) { |
122 zeros = 16; | 149 zeros = 16; |
123 } else { | 150 } else { |
124 zeros = 0; | 151 zeros = 0; |
125 } | 152 } |
126 if (!(0xFF000000 & (a << zeros))) zeros += 8; | 153 if (!(0xFF000000 & (a << zeros))) zeros += 8; |
(...skipping 27 matching lines...) Expand all Loading... | |
154 } | 181 } |
155 | 182 |
156 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { | 183 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { |
157 return (a * b + c); | 184 return (a * b + c); |
158 } | 185 } |
159 #endif // #if !defined(MIPS32_LE) | 186 #endif // #if !defined(MIPS32_LE) |
160 | 187 |
161 #endif // WEBRTC_ARCH_ARM_V7 | 188 #endif // WEBRTC_ARCH_ARM_V7 |
162 | 189 |
163 #endif // WEBRTC_SPL_SPL_INL_H_ | 190 #endif // WEBRTC_SPL_SPL_INL_H_ |
OLD | NEW |