summaryrefslogtreecommitdiff
path: root/libavutil/x86/intmath.h
diff options
context:
space:
mode:
authorMatt Oliver <protogonoi@gmail.com>2015-10-16 16:58:43 +1100
committerMatt Oliver <protogonoi@gmail.com>2015-10-19 13:40:27 +1100
commit216cc1f6fe33b256ce708fade5e6638b2bb54d2b (patch)
treea56398adcfccb6570101a460375265e1c15e2dee /libavutil/x86/intmath.h
parentce0a117ed4f99c5eac2fd365cbdebba568a0ead8 (diff)
lavu/intmath.h: Add msvc/icl ctzll optimisations.
Signed-off-by: Matt Oliver <protogonoi@gmail.com>
Diffstat (limited to 'libavutil/x86/intmath.h')
-rw-r--r--libavutil/x86/intmath.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h
index fefad205e6..3ba5ed072c 100644
--- a/libavutil/x86/intmath.h
+++ b/libavutil/x86/intmath.h
@@ -24,6 +24,41 @@
#include <stdint.h>
#include "config.h"
+#if HAVE_FAST_CLZ
+#if defined(__INTEL_COMPILER)
+# define ff_ctzll ff_ctzll_x86
+static av_always_inline av_const int ff_ctzll_x86(long long v)
+{
+# if ARCH_X86_64
+ uint64_t c;
+ __asm__("bsfq %1,%0" : "=r" (c) : "r" (v));
+ return c;
+# else
+ return ((uint32_t)v == 0) ? _bit_scan_forward((uint32_t)(v >> 32)) + 32 : _bit_scan_forward((uint32_t)v);
+# endif
+}
+#elif defined(_MSC_VER)
+# define ff_ctzll ff_ctzll_x86
+static av_always_inline av_const int ff_ctzll_x86(long long v)
+{
+ unsigned long c;
+# if ARCH_X86_64
+ _BitScanForward64(&c, v);
+# else
+ if ((uint32_t)v == 0) {
+ _BitScanForward(&c, (uint32_t)(v >> 32));
+ c += 32;
+ } else {
+ _BitScanForward(&c, (uint32_t)v);
+ }
+# endif
+ return c;
+}
+
+#endif /* __INTEL_COMPILER */
+
+#endif /* HAVE_FAST_CLZ */
+
#if defined(__GNUC__)
/* Our generic version of av_popcount is faster than GCC's built-in on