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.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Kacper Michajłow 2025-03-31 14:02:36 +02:00 committed by Martin Storsjö
parent f019dd69f0
commit 43dc443446
2 changed files with 7 additions and 9 deletions

View File

@ -35,7 +35,7 @@
#endif #endif
#if HAVE_FAST_CLZ #if HAVE_FAST_CLZ
#if AV_GCC_VERSION_AT_LEAST(3,4) #if AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_clz)
#ifndef ff_log2 #ifndef ff_log2
# define ff_log2(x) (31 - __builtin_clz((x)|1)) # define ff_log2(x) (31 - __builtin_clz((x)|1))
# ifndef ff_log2_16bit # ifndef ff_log2_16bit
@ -90,18 +90,16 @@ static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
*/ */
#if HAVE_FAST_CLZ #if HAVE_FAST_CLZ
#if AV_GCC_VERSION_AT_LEAST(3,4) #if !defined(ff_ctz) && (AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_ctz))
#ifndef ff_ctz
#define ff_ctz(v) __builtin_ctz(v) #define ff_ctz(v) __builtin_ctz(v)
#endif #endif
#ifndef ff_ctzll #if !defined(ff_ctzll) && (AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_ctzll))
#define ff_ctzll(v) __builtin_ctzll(v) #define ff_ctzll(v) __builtin_ctzll(v)
#endif #endif
#ifndef ff_clz #if !defined(ff_clz) && (AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_clz))
#define ff_clz(v) __builtin_clz(v) #define ff_clz(v) __builtin_clz(v)
#endif #endif
#endif #endif
#endif
#ifndef ff_ctz #ifndef ff_ctz
#define ff_ctz ff_ctz_c #define ff_ctz ff_ctz_c
@ -154,7 +152,7 @@ static av_always_inline av_const unsigned ff_clz_c(unsigned x)
} }
#endif #endif
#if AV_GCC_VERSION_AT_LEAST(3,4) #if AV_GCC_VERSION_AT_LEAST(3,4) || AV_HAS_BUILTIN(__builtin_parity)
#ifndef av_parity #ifndef av_parity
#define av_parity __builtin_parity #define av_parity __builtin_parity
#endif #endif

View File

@ -66,7 +66,7 @@ static av_always_inline av_const int ff_ctzll_x86(long long v)
#endif /* HAVE_FAST_CLZ */ #endif /* HAVE_FAST_CLZ */
#if defined(__GNUC__) #if defined(__GNUC__) || defined(__clang__)
/* Our generic version of av_popcount is faster than GCC's built-in on /* Our generic version of av_popcount is faster than GCC's built-in on
* CPUs that don't support the popcnt instruction. * 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)
#if defined(__BMI2__) #if defined(__BMI2__)
#if AV_GCC_VERSION_AT_LEAST(5,1) #if AV_GCC_VERSION_AT_LEAST(5,1) || AV_HAS_BUILTIN(__builtin_ia32_bzhi_si)
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
#define av_zero_extend av_zero_extend_bmi2 #define av_zero_extend av_zero_extend_bmi2
static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsigned p) static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsigned p)