From 0dd8a3d71e2c01d42e868d6c6b8974fadfcc529e Mon Sep 17 00:00:00 2001 From: Ganesh Ajjanagadde Date: Wed, 16 Dec 2015 13:28:39 -0500 Subject: [PATCH] lavu/intmath: add faster clz support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This should be useful for the sofalizer filter. Reviewed-by: Kieran Kunhya Reviewed-by: Clément Bœsch Signed-off-by: Ganesh Ajjanagadde --- libavutil/intmath.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libavutil/intmath.h b/libavutil/intmath.h index 20167230dfb..82193a6d7c6 100644 --- a/libavutil/intmath.h +++ b/libavutil/intmath.h @@ -96,6 +96,9 @@ static av_always_inline av_const int ff_log2_16bit_c(unsigned int v) #ifndef ff_ctzll #define ff_ctzll(v) __builtin_ctzll(v) #endif +#ifndef ff_clz +#define ff_clz(v) __builtin_clz(v) +#endif #endif #endif @@ -135,6 +138,21 @@ static av_always_inline av_const int ff_ctzll_c(long long v) } #endif +#ifndef ff_clz +#define ff_clz ff_clz_c +static av_always_inline av_const unsigned ff_clz_c(unsigned x) +{ + unsigned i = sizeof(x) * 8; + + while (x) { + x >>= 1; + i--; + } + + return i; +} +#endif + /** * @} */ -- 2.39.2