From 5289b309cfc0a36c02077810cd37deb0038c865f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 7 May 2012 13:00:12 +0200 Subject: [PATCH] Optimize COUNT_ZERO_MSBS macro Reorder the conditions according to the expected distribution of input signal. This seems to make it almost as fast as the clz builtin using the bsr instruction. Signed-off-by: Erik de Castro Lopo --- src/libFLAC/bitreader.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c index ae515a07..dcd9e426 100644 --- a/src/libFLAC/bitreader.c +++ b/src/libFLAC/bitreader.c @@ -68,9 +68,11 @@ COUNT_ZERO_MSBS (uint32_t word) #else /* counts the # of zero MSBs in a word */ #define COUNT_ZERO_MSBS(word) ( \ - (word) <= 0xffff ? \ - ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \ - ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \ + (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 \ ) #endif