aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/intmath.h
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-10-26 14:48:40 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2012-11-05 15:32:29 -0500
commitdfde8a34e5419ac99265e3ecc2e82f378674128a (patch)
tree2eeec23b9d802e26b2483815c18475c7ff2075b3 /libavutil/intmath.h
parent6a744d261930f8101132bc6d207b6eac41d9cf18 (diff)
downloadffmpeg-dfde8a34e5419ac99265e3ecc2e82f378674128a.tar.gz
lavu: add av_ctz() for trailing zero bit count
Diffstat (limited to 'libavutil/intmath.h')
-rw-r--r--libavutil/intmath.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/libavutil/intmath.h b/libavutil/intmath.h
index 2cb313240b..a5ee6525ee 100644
--- a/libavutil/intmath.h
+++ b/libavutil/intmath.h
@@ -88,4 +88,59 @@ static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
/**
* @}
*/
+
+/**
+ * @addtogroup lavu_math
+ * @{
+ */
+
+#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
+#ifndef ff_ctz
+#define ff_ctz(v) __builtin_ctz(v)
+#endif
+#endif
+
+#ifndef ff_ctz
+#define ff_ctz ff_ctz_c
+static av_always_inline av_const int ff_ctz_c(int v)
+{
+ int c;
+
+ if (v & 0x1)
+ return 0;
+
+ c = 1;
+ if (!(v & 0xffff)) {
+ v >>= 16;
+ c += 16;
+ }
+ if (!(v & 0xff)) {
+ v >>= 8;
+ c += 8;
+ }
+ if (!(v & 0xf)) {
+ v >>= 4;
+ c += 4;
+ }
+ if (!(v & 0x3)) {
+ v >>= 2;
+ c += 2;
+ }
+ c -= v & 0x1;
+
+ return c;
+}
+#endif
+
+/**
+ * Trailing zero bit count.
+ *
+ * @param v input value. If v is 0, the result is undefined.
+ * @return the number of trailing 0-bits
+ */
+int av_ctz(int v);
+
+/**
+ * @}
+ */
#endif /* AVUTIL_INTMATH_H */