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 extern const int8_t kWebRtcSpl_CountLeadingZeros32_Table[64]; | |
21 | |
22 // Don't call this directly except in tests! | |
23 static __inline int WebRtcSpl_CountLeadingZeros32_NotBuiltin(uint32_t n) { | |
24 // Normalize n by rounding up to the nearest number that is a sequence of 0 | |
25 // bits followed by a sequence of 1 bits. This number has the same number of | |
26 // leading zeros as the original n. There are exactly 33 such values. | |
27 n |= n >> 1; | |
28 n |= n >> 2; | |
29 n |= n >> 4; | |
30 n |= n >> 8; | |
31 n |= n >> 16; | |
32 | |
33 // Multiply the modified n with a constant selected (by exhaustive search) | |
34 // such that each of the 33 possible values of n give a product whose 6 most | |
35 // significant bits are unique. Then look up the answer in the table. | |
36 return kWebRtcSpl_CountLeadingZeros32_Table[(n * 0x8c0b2891) >> 26]; | |
37 } | |
38 | |
39 // Don't call this directly except in tests! | |
40 static __inline int WebRtcSpl_CountLeadingZeros64_NotBuiltin(uint64_t n) { | |
41 const int leading_zeros = n >> 32 == 0 ? 32 : 0; | |
42 return leading_zeros + WebRtcSpl_CountLeadingZeros32_NotBuiltin( | |
43 (uint32_t)(n >> (32 - leading_zeros))); | |
44 } | |
45 | |
46 // Returns the number of leading zero bits in the argument. | |
47 static __inline int WebRtcSpl_CountLeadingZeros32(uint32_t n) { | |
48 #ifdef __GNUC__ | |
49 COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t)); | |
50 return n == 0 ? 32 : __builtin_clz(n); | |
51 #else | |
52 return WebRtcSpl_CountLeadingZeros32_NotBuiltin(n); | |
53 #endif | |
54 } | |
55 | |
56 // Returns the number of leading zero bits in the argument. | |
57 static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) { | |
58 #ifdef __GNUC__ | |
59 COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t)); | |
60 return n == 0 ? 64 : __builtin_clzll(n); | |
61 #else | |
62 return WebRtcSpl_CountLeadingZeros64_NotBuiltin(n); | |
63 #endif | |
64 } | |
65 | |
18 #ifdef WEBRTC_ARCH_ARM_V7 | 66 #ifdef WEBRTC_ARCH_ARM_V7 |
19 #include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h" | 67 #include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h" |
20 #else | 68 #else |
21 | 69 |
22 #if defined(MIPS32_LE) | 70 #if defined(MIPS32_LE) |
23 #include "webrtc/common_audio/signal_processing/include/spl_inl_mips.h" | 71 #include "webrtc/common_audio/signal_processing/include/spl_inl_mips.h" |
24 #endif | 72 #endif |
25 | 73 |
26 #if !defined(MIPS_DSP_R1_LE) | 74 #if !defined(MIPS_DSP_R1_LE) |
27 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { | 75 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); | 115 return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b); |
68 } | 116 } |
69 | 117 |
70 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { | 118 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { |
71 return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2); | 119 return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2); |
72 } | 120 } |
73 #endif // #if !defined(MIPS_DSP_R1_LE) | 121 #endif // #if !defined(MIPS_DSP_R1_LE) |
74 | 122 |
75 #if !defined(MIPS32_LE) | 123 #if !defined(MIPS32_LE) |
76 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { | 124 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { |
77 int16_t bits; | 125 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 } | 126 } |
92 | 127 |
128 // Return the number of steps a can be left-shifted without overflow, or 0 if a | |
tlegrand-webrtc
2016/06/02 09:49:11
Nit: move 'a' to next line.
kwiberg-webrtc
2016/06/02 09:55:34
Done.
| |
129 // == 0. | |
93 static __inline int16_t WebRtcSpl_NormW32(int32_t a) { | 130 static __inline int16_t WebRtcSpl_NormW32(int32_t a) { |
94 int16_t zeros; | 131 return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a < 0 ? ~a : a) - 1; |
95 | |
96 if (a == 0) { | |
97 return 0; | |
98 } | |
99 else if (a < 0) { | |
100 a = ~a; | |
101 } | |
102 | |
103 if (!(0xFFFF8000 & a)) { | |
104 zeros = 16; | |
105 } else { | |
106 zeros = 0; | |
107 } | |
108 if (!(0xFF800000 & (a << zeros))) zeros += 8; | |
109 if (!(0xF8000000 & (a << zeros))) zeros += 4; | |
110 if (!(0xE0000000 & (a << zeros))) zeros += 2; | |
111 if (!(0xC0000000 & (a << zeros))) zeros += 1; | |
112 | |
113 return zeros; | |
114 } | 132 } |
115 | 133 |
134 // Return the number of steps a can be left-shifted without overflow, or 0 if a | |
135 // == 0. | |
tlegrand-webrtc
2016/06/02 09:49:11
Same nit.
kwiberg-webrtc
2016/06/02 09:55:34
Done.
| |
116 static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { | 136 static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { |
117 int16_t zeros; | 137 return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a); |
118 | |
119 if (a == 0) return 0; | |
120 | |
121 if (!(0xFFFF0000 & a)) { | |
122 zeros = 16; | |
123 } else { | |
124 zeros = 0; | |
125 } | |
126 if (!(0xFF000000 & (a << zeros))) zeros += 8; | |
127 if (!(0xF0000000 & (a << zeros))) zeros += 4; | |
128 if (!(0xC0000000 & (a << zeros))) zeros += 2; | |
129 if (!(0x80000000 & (a << zeros))) zeros += 1; | |
130 | |
131 return zeros; | |
132 } | 138 } |
133 | 139 |
140 // Return the number of steps a can be left-shifted without overflow, or 0 if a | |
tlegrand-webrtc
2016/06/02 09:49:11
...and here. :)
kwiberg-webrtc
2016/06/02 09:55:34
Done.
| |
141 // == 0. | |
134 static __inline int16_t WebRtcSpl_NormW16(int16_t a) { | 142 static __inline int16_t WebRtcSpl_NormW16(int16_t a) { |
135 int16_t zeros; | 143 const int32_t a32 = a; |
136 | 144 return a == 0 ? 0 : WebRtcSpl_CountLeadingZeros32(a < 0 ? ~a32 : a32) - 17; |
137 if (a == 0) { | |
138 return 0; | |
139 } | |
140 else if (a < 0) { | |
141 a = ~a; | |
142 } | |
143 | |
144 if (!(0xFF80 & a)) { | |
145 zeros = 8; | |
146 } else { | |
147 zeros = 0; | |
148 } | |
149 if (!(0xF800 & (a << zeros))) zeros += 4; | |
150 if (!(0xE000 & (a << zeros))) zeros += 2; | |
151 if (!(0xC000 & (a << zeros))) zeros += 1; | |
152 | |
153 return zeros; | |
154 } | 145 } |
155 | 146 |
156 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { | 147 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { |
157 return (a * b + c); | 148 return (a * b + c); |
158 } | 149 } |
159 #endif // #if !defined(MIPS32_LE) | 150 #endif // #if !defined(MIPS32_LE) |
160 | 151 |
161 #endif // WEBRTC_ARCH_ARM_V7 | 152 #endif // WEBRTC_ARCH_ARM_V7 |
162 | 153 |
163 #endif // WEBRTC_SPL_SPL_INL_H_ | 154 #endif // WEBRTC_SPL_SPL_INL_H_ |
OLD | NEW |