]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/intmath.h
x86: lpc: fix a segfault in av_evaluate_lls_sse2()
[ffmpeg] / libavutil / intmath.h
index b4b87e605932e8dd32df20b7f2b5ee54d05674bc..a5ee6525ee31436586970b924191795a7630ae18 100644 (file)
 #include "config.h"
 #include "attributes.h"
 
+#if ARCH_ARM
+#   include "arm/intmath.h"
+#endif
+
 /**
  * @addtogroup lavu_internal
  * @{
@@ -81,6 +85,61 @@ static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
 #define av_log2       ff_log2
 #define av_log2_16bit ff_log2_16bit
 
+/**
+ * @}
+ */
+
+/**
+ * @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);
+
 /**
  * @}
  */