From 7b37472a2f2a2ec6437a303d31fb828779f3dd92 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 28 Aug 2012 11:58:40 +0200 Subject: [PATCH] Add new clz function which works with input 0. Signed-off-by: Erik de Castro Lopo --- src/libFLAC/include/private/bitmath.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libFLAC/include/private/bitmath.h b/src/libFLAC/include/private/bitmath.h index d32b1a7..4e60f78 100644 --- a/src/libFLAC/include/private/bitmath.h +++ b/src/libFLAC/include/private/bitmath.h @@ -64,7 +64,6 @@ static inline unsigned int FLAC__clz_soft_uint32(unsigned int word) }; return (word) > 0xffffff ? byte_to_unary_table[(word) >> 24] : - !(word) ? 32 : (word) > 0xffff ? byte_to_unary_table[(word) >> 16] + 8 : (word) > 0xff ? byte_to_unary_table[(word) >> 8] + 16 : byte_to_unary_table[(word)] + 24; @@ -88,6 +87,14 @@ static inline unsigned int FLAC__clz_uint32(FLAC__uint32 v) #endif } +/* This one works with input 0 */ +static inline unsigned int FLAC__clz2_uint32(FLAC__uint32 v) +{ + if (!v) + return 32; + return FLAC__clz_uint32(v); +} + /* An example of what FLAC__bitmath_ilog2() computes: * * ilog2( 0) = undefined -- 2.7.4