Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Unified Diff: webrtc/common_audio/signal_processing/include/spl_inl.h

Issue 2014023002: Add clz functions (Count number of Leading Zero bits), 32-and 64-bit variants (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@bug601787-1
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/common_audio/signal_processing/signal_processing_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_audio/signal_processing/include/spl_inl.h
diff --git a/webrtc/common_audio/signal_processing/include/spl_inl.h b/webrtc/common_audio/signal_processing/include/spl_inl.h
index 3c0a81cf34a7e5fba062801936d5d2a31adfd922..7aa6f579129596d1392edbb268b6b7f9788b948a 100644
--- a/webrtc/common_audio/signal_processing/include/spl_inl.h
+++ b/webrtc/common_audio/signal_processing/include/spl_inl.h
@@ -15,6 +15,46 @@
#ifndef WEBRTC_SPL_SPL_INL_H_
#define WEBRTC_SPL_SPL_INL_H_
+#include "webrtc/system_wrappers/include/compile_assert_c.h"
+
+// Don't call this directly except in tests!
+static __inline int WebRtcSpl_CountLeadingZeros32_NotBuiltin(uint32_t n) {
+ int leading_zeros = n >> 16 == 0 ? 16 : 0;
+ leading_zeros += (n << leading_zeros) >> 24 == 0 ? 8 : 0;
+ leading_zeros += (n << leading_zeros) >> 28 == 0 ? 4 : 0;
+ leading_zeros += (n << leading_zeros) >> 30 == 0 ? 2 : 0;
+ leading_zeros += (n << leading_zeros) >> 31 == 0 ? 1 : 0;
+ leading_zeros += (n << leading_zeros) >> 31 == 0 ? 1 : 0;
+ return leading_zeros;
+}
+
+// Don't call this directly except in tests!
+static __inline int WebRtcSpl_CountLeadingZeros64_NotBuiltin(uint64_t n) {
+ const int leading_zeros = n >> 32 == 0 ? 32 : 0;
+ return leading_zeros + WebRtcSpl_CountLeadingZeros32_NotBuiltin(
+ (uint32_t)(n >> (32 - leading_zeros)));
+}
+
+// Returns the number of leading zero bits in the argument.
+static __inline int WebRtcSpl_CountLeadingZeros32(uint32_t n) {
+#ifdef __GNUC__
+ COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t));
+ return n == 0 ? 32 : __builtin_clz(n);
+#else
+ return WebRtcSpl_CountLeadingZeros32_NotBuiltin(n);
+#endif
+}
+
+// Returns the number of leading zero bits in the argument.
+static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) {
+#ifdef __GNUC__
+ COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t));
+ return n == 0 ? 64 : __builtin_clzll(n);
+#else
+ return WebRtcSpl_CountLeadingZeros64_NotBuiltin(n);
+#endif
+}
+
#ifdef WEBRTC_ARCH_ARM_V7
#include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h"
#else
@@ -74,20 +114,7 @@ static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
#if !defined(MIPS32_LE)
static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
- int16_t bits;
-
- if (0xFFFF0000 & n) {
- bits = 16;
- } else {
- bits = 0;
- }
- if (0x0000FF00 & (n >> bits)) bits += 8;
- if (0x000000F0 & (n >> bits)) bits += 4;
- if (0x0000000C & (n >> bits)) bits += 2;
- if (0x00000002 & (n >> bits)) bits += 1;
- if (0x00000001 & (n >> bits)) bits += 1;
-
- return bits;
+ return 32 - WebRtcSpl_CountLeadingZeros32(n);
}
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?
« no previous file with comments | « no previous file | webrtc/common_audio/signal_processing/signal_processing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698