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 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 | 132 |
133 */ | 133 */ |
134 | 134 |
135 int16_t x_norm, nshift, t16, sh; | 135 int16_t x_norm, nshift, t16, sh; |
136 int32_t A; | 136 int32_t A; |
137 | 137 |
138 int16_t k_sqrt_2 = 23170; // 1/sqrt2 (==5a82) | 138 int16_t k_sqrt_2 = 23170; // 1/sqrt2 (==5a82) |
139 | 139 |
140 A = value; | 140 A = value; |
141 | 141 |
142 // The convention in this function is to calculate sqrt(abs(A)). Negate the | |
143 // input if it is negative. | |
144 if (A == WEBRTC_SPL_WORD32_MIN) { | |
145 // This number cannot be held in an int32_t after negating. | |
146 // Map it to the maximum positive value. | |
147 A = WEBRTC_SPL_WORD32_MAX; | |
148 } else if (A < 0) { | |
149 A = -A; | |
150 } | |
kwiberg-webrtc
2016/02/11 09:28:10
The optimizer may already be doing this for you, b
hlundin-webrtc
2016/02/11 22:02:29
Much better. Done.
| |
151 | |
142 if (A == 0) | 152 if (A == 0) |
143 return (int32_t)0; // sqrt(0) = 0 | 153 return (int32_t)0; // sqrt(0) = 0 |
144 | 154 |
145 sh = WebRtcSpl_NormW32(A); // # shifts to normalize A | 155 sh = WebRtcSpl_NormW32(A); // # shifts to normalize A |
146 A = WEBRTC_SPL_LSHIFT_W32(A, sh); // Normalize A | 156 A = WEBRTC_SPL_LSHIFT_W32(A, sh); // Normalize A |
147 if (A < (WEBRTC_SPL_WORD32_MAX - 32767)) | 157 if (A < (WEBRTC_SPL_WORD32_MAX - 32767)) |
148 { | 158 { |
149 A = A + ((int32_t)32768); // Round off bit | 159 A = A + ((int32_t)32768); // Round off bit |
150 } else | 160 } else |
151 { | 161 { |
(...skipping 23 matching lines...) Expand all Loading... | |
175 } else | 185 } else |
176 { | 186 { |
177 A >>= 16; // A = A>>16 | 187 A >>= 16; // A = A>>16 |
178 } | 188 } |
179 | 189 |
180 A = A & ((int32_t)0x0000ffff); | 190 A = A & ((int32_t)0x0000ffff); |
181 A >>= nshift; // De-normalize the result. | 191 A >>= nshift; // De-normalize the result. |
182 | 192 |
183 return A; | 193 return A; |
184 } | 194 } |
OLD | NEW |