summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorGanesh Ajjanagadde <gajjanagadde@gmail.com>2017-02-22 12:53:33 -0500
committerVittorio Giovara <vittorio.giovara@gmail.com>2017-03-01 11:23:19 -0500
commit7bfda7d157eb6f7a2df908addd60221a7a6f5eb0 (patch)
treedb02192c17a61a82f3948c200090d51c899cb42d /libavutil
parent5ff3b5cafcc685b6936d16602b0f80aa09a95870 (diff)
intmath: add faster clz support
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/intmath.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/libavutil/intmath.h b/libavutil/intmath.h
index a5ee6525ee..780bbab039 100644
--- a/libavutil/intmath.h
+++ b/libavutil/intmath.h
@@ -44,6 +44,10 @@
# endif
#endif /* ff_log2 */
+#ifndef ff_clz
+# define ff_clz(v) __builtin_clz(v)
+#endif /* ff_clz */
+
#endif /* AV_GCC_VERSION_AT_LEAST(3,4) */
extern const uint8_t ff_log2_tab[256];
@@ -132,6 +136,21 @@ static av_always_inline av_const int ff_ctz_c(int v)
}
#endif
+#ifndef ff_clz
+#define ff_clz ff_clz_c
+static av_always_inline av_const unsigned ff_clz_c(unsigned x)
+{
+ unsigned i = sizeof(x) * 8;
+
+ while (x) {
+ x >>= 1;
+ i--;
+ }
+
+ return i;
+}
+#endif
+
/**
* Trailing zero bit count.
*