History

avutil/intmath: use AV_HAS_BUILTIN to detect builtin availability

Fixes use of bultins on clang x86_64-pc-windows-msvc which does not define any __GNUC__. Also on other targets __GNUC__ is defined to 4 by default, so any feature testing based on version is not really valid.

Kacper Michajłow committed 1 year ago

Commit 43dc4431 parent f019dd62 files · +7 −9Browse files

Unified · Split

2 files
  1. libavutil/intmath.h +5 −7
  2. libavutil/x86/intmath.h +2 −2
libavutil/intmath.h+5−7
@@ -35,7 +35,7 @@ · 34 unmodified lines
3535 #endif
3636
3737 #if HAVE_FAST_CLZ
38−#if AV_GCC_VERSION_AT_LEAST(3,4)
38+#if AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_clz)
3939 #ifndef ff_log2
4040 # define ff_log2(x) (31 - __builtin_clz((x)|1))
4141 # ifndef ff_log2_16bit
@@ -90,18 +90,16 @@ static av_always_inline av_const int ff_log2_16bit_c(unsigned int v) · 48 unmodified lines
9090 */
9191
9292 #if HAVE_FAST_CLZ
93−#if AV_GCC_VERSION_AT_LEAST(3,4)
94−#ifndef ff_ctz
93+#if !defined(ff_ctz) && (AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_ctz))
9594 #define ff_ctz(v) __builtin_ctz(v)
9695 #endif
97−#ifndef ff_ctzll
96+#if !defined(ff_ctzll) && (AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_ctzll))
9897 #define ff_ctzll(v) __builtin_ctzll(v)
9998 #endif
100−#ifndef ff_clz
99+#if !defined(ff_clz) && (AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_clz))
101100 #define ff_clz(v) __builtin_clz(v)
102101 #endif
103102 #endif
104−#endif
105103
106104 #ifndef ff_ctz
107105 #define ff_ctz ff_ctz_c
@@ -154,7 +152,7 @@ static av_always_inline av_const unsigned ff_clz_c(unsigned x) · 46 unmodified lines
154152 }
155153 #endif
156154
157−#if AV_GCC_VERSION_AT_LEAST(3,4)
155+#if AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_parity)
158156 #ifndef av_parity
159157 #define av_parity __builtin_parity
160158 #endif
libavutil/x86/intmath.h+2−2
@@ -66,7 +66,7 @@ static av_always_inline av_const int ff_ctzll_x86(long long v) · 65 unmodified lines
6666
6767 #endif /* HAVE_FAST_CLZ */
6868
69−#if defined(__GNUC__)
69+#if defined(__GNUC__) || defined(__clang__)
7070
7171 /* Our generic version of av_popcount is faster than GCC's built-in on
7272 * CPUs that don't support the popcnt instruction.
@@ -81,7 +81,7 @@ static av_always_inline av_const int ff_ctzll_x86(long long v) · 8 unmodified lines
8181
8282 #if defined(__BMI2__)
8383
84−#if AV_GCC_VERSION_AT_LEAST(5,1)
84+#if AV_GCC_VERSION_AT_LEAST(5,1) || AV_HAS_BUILTIN(__builtin_ia32_bzhi_si)
8585 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
8686 #define av_zero_extend av_zero_extend_bmi2
8787 static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsigned p)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t