diff options
author | James Almer <jamrial@gmail.com> | 2024-06-11 13:44:37 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2024-06-13 20:36:09 -0300 |
commit | 4b57ea8fc74aefb0eaba90ae4b73931a217f8f33 (patch) | |
tree | 787e0ab7bc6007d6dc18121f67ef0d66099d8c2e /libavutil/x86/intmath.h | |
parent | 39c90d6466a675fb363746a6b0f3b09906ca1f0e (diff) | |
download | ffmpeg-4b57ea8fc74aefb0eaba90ae4b73931a217f8f33.tar.gz |
avutil/common: assert that bit position in av_zero_extend is valid
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavutil/x86/intmath.h')
-rw-r--r-- | libavutil/x86/intmath.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h index 821a06ab66..4893a1f1b4 100644 --- a/libavutil/x86/intmath.h +++ b/libavutil/x86/intmath.h @@ -82,7 +82,16 @@ static av_always_inline av_const int ff_ctzll_x86(long long v) #if defined(__BMI2__) #if AV_GCC_VERSION_AT_LEAST(5,1) +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 +#define av_zero_extend av_zero_extend_bmi2 +static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsigned p) +{ + if (p > 31) abort(); + return __builtin_ia32_bzhi_si(a, p); +} +#else #define av_zero_extend __builtin_ia32_bzhi_si +#endif #elif HAVE_INLINE_ASM /* GCC releases before 5.1.0 have a broken bzhi builtin, so for those we * implement it using inline assembly @@ -90,8 +99,11 @@ static av_always_inline av_const int ff_ctzll_x86(long long v) #define av_zero_extend av_zero_extend_bmi2 static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsigned p) { +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 + if (p > 31) abort(); +#endif if (av_builtin_constant_p(p)) - return a & ((1 << p) - 1); + return a & ((1U << p) - 1); else { unsigned x; __asm__ ("bzhi %2, %1, %0 \n\t" : "=r"(x) : "rm"(a), "r"(p)); |