diff mbox

[FFmpeg-devel] Don't use _tzcnt instrinics with clang for windows w/o BMI.

Message ID CAPUDrwdV-vTgjFXjuyALZp-E_DY_4f+vKCpbTFHkmeuzg4LrxA@mail.gmail.com
State New
Headers show

Commit Message

Dale Curtis Oct. 24, 2017, 8:15 p.m. UTC
Technically _tzcnt* intrinsics are only available when the BMI
instruction set is present. However the instruction encoding
degrades to "rep bsf" on older processors.

Clang for Windows debatably restricts the _tzcnt* instrinics behind
the __BMI__ architecture define, so check for its presence or
exclude the usage of these intrinics when clang is present.

See also:
https://ffmpeg.org/pipermail/ffmpeg-devel/2015-November/183404.html
https://bugs.llvm.org/show_bug.cgi?id=30506
http://lists.llvm.org/pipermail/cfe-dev/2016-October/051034.html

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>

Comments

Matt Oliver Oct. 25, 2017, 4:39 p.m. UTC | #1
On 25 October 2017 at 07:15, Dale Curtis <dalecurtis@chromium.org> wrote:

> Technically _tzcnt* intrinsics are only available when the BMI
> instruction set is present. However the instruction encoding
> degrades to "rep bsf" on older processors.
>
> Clang for Windows debatably restricts the _tzcnt* instrinics behind
> the __BMI__ architecture define, so check for its presence or
> exclude the usage of these intrinics when clang is present.
>
> See also:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2015-November/183404.html
> https://bugs.llvm.org/show_bug.cgi?id=30506
> http://lists.llvm.org/pipermail/cfe-dev/2016-October/051034.html
>
> Signed-off-by: Dale Curtis <dalecurtis@chromium.org


LGTM
Michael Niedermayer Oct. 25, 2017, 5:53 p.m. UTC | #2
On Thu, Oct 26, 2017 at 03:39:57AM +1100, Matt Oliver wrote:
> On 25 October 2017 at 07:15, Dale Curtis <dalecurtis@chromium.org> wrote:
> 
> > Technically _tzcnt* intrinsics are only available when the BMI
> > instruction set is present. However the instruction encoding
> > degrades to "rep bsf" on older processors.
> >
> > Clang for Windows debatably restricts the _tzcnt* instrinics behind
> > the __BMI__ architecture define, so check for its presence or
> > exclude the usage of these intrinics when clang is present.
> >
> > See also:
> > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-November/183404.html
> > https://bugs.llvm.org/show_bug.cgi?id=30506
> > http://lists.llvm.org/pipermail/cfe-dev/2016-October/051034.html
> >
> > Signed-off-by: Dale Curtis <dalecurtis@chromium.org
> 
> 
> LGTM

will apply

thanks

[...]
diff mbox

Patch

From 123a60bdcf99cab6b6e6bd31a463a29bc49598f0 Mon Sep 17 00:00:00 2001
From: Dale Curtis <dalecurtis@chromium.org>
Date: Tue, 24 Oct 2017 13:03:59 -0700
Subject: [PATCH] Don't use _tzcnt instrinics with clang for windows w/o BMI.

Technically _tzcnt* intrinsics are only available when the BMI
instruction set is present. However the instruction encoding
degrades to "rep bsf" on older processors.

Clang for Windows debatably restricts the _tzcnt* instrinics behind
the __BMI__ architecture define, so check for its presence or
exclude the usage of these intrinics when clang is present.

See also:
https://ffmpeg.org/pipermail/ffmpeg-devel/2015-November/183404.html
https://bugs.llvm.org/show_bug.cgi?id=30506
http://lists.llvm.org/pipermail/cfe-dev/2016-October/051034.html

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
---
 libavutil/x86/intmath.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h
index e83971c084..40743fd13e 100644
--- a/libavutil/x86/intmath.h
+++ b/libavutil/x86/intmath.h
@@ -47,7 +47,8 @@  static av_always_inline av_const int ff_log2_x86(unsigned int v)
 #   endif
 #   define ff_log2_16bit av_log2
 
-#if defined(__INTEL_COMPILER) || (defined(_MSC_VER) && (_MSC_VER >= 1700))
+#if defined(__INTEL_COMPILER) || (defined(_MSC_VER) && (_MSC_VER >= 1700) && \
+                                  (defined(__BMI__) || !defined(__clang__)))
 #   define ff_ctz(v) _tzcnt_u32(v)
 
 #   if ARCH_X86_64
-- 
2.15.0.rc0.271.g36b669edcc-goog