diff options
author | Cristian RodrÃguez <crrodriguez@opensuse.org> | 2012-05-08 23:58:19 -0400 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2012-06-08 19:58:29 +1000 |
commit | 387b72731dbf79450050987b9b36bf70f286b098 (patch) | |
tree | 45eaca7bb2325b0419fc5904d3b7719fd8b5bf3c /src/libFLAC/bitreader.c | |
parent | 605f9208165e9da36753bc22d2b0ae75c90cc3dd (diff) | |
download | flac-387b72731dbf79450050987b9b36bf70f286b098.tar.gz |
bitmath: Finish up optimizations
This patch adds support for other compilers and systems
including MSVC, Intel C compiler etc..
Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Diffstat (limited to 'src/libFLAC/bitreader.c')
-rw-r--r-- | src/libFLAC/bitreader.c | 54 |
1 files changed, 7 insertions, 47 deletions
diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c index dcd9e426..9e15db0c 100644 --- a/src/libFLAC/bitreader.c +++ b/src/libFLAC/bitreader.c @@ -43,7 +43,7 @@ #include "share/endswap.h" /* Things should be fastest when this matches the machine word size */ -/* WATCHOUT: if you change this you must also change the following #defines down to COUNT_ZERO_MSBS below to match */ +/* WATCHOUT: if you change this you must also change the following #defines down to FLAC__clz_uint32 below to match */ /* WATCHOUT: there are a few places where the code will not work unless uint32_t is >= 32 bits wide */ /* also, some sections currently only have fast versions for 4 or 8 bytes per word */ #define FLAC__BYTES_PER_WORD 4 /* sizeof uint32_t */ @@ -56,27 +56,6 @@ #define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x) #endif -#if defined(__GNUC__) -/* "int __builtin_clz (unsigned int x) If x is 0, the result is undefined" */ -static inline uint32_t -COUNT_ZERO_MSBS (uint32_t word) -{ - if (word == 0) - return 32; - return __builtin_clz (word); -} -#else -/* counts the # of zero MSBs in a word */ -#define COUNT_ZERO_MSBS(word) ( \ - (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 - - /* * This should be at least twice as large as the largest number of words * required to represent any 'number' (in any encoding) you are going to @@ -93,25 +72,6 @@ COUNT_ZERO_MSBS (uint32_t word) */ static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */ -static const unsigned char byte_to_unary_table[] = { - 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */ #ifdef _MSC_VER #define FLAC__U64L(x) x @@ -679,7 +639,7 @@ FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *va while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */ uint32_t b = br->buffer[br->consumed_words] << br->consumed_bits; if(b) { - i = COUNT_ZERO_MSBS(b); + i = FLAC__clz_uint32(b); *val += i; i++; br->consumed_bits += i; @@ -709,7 +669,7 @@ FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *va const unsigned end = br->bytes * 8; uint32_t b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits; if(b) { - i = COUNT_ZERO_MSBS(b); + i = FLAC__clz_uint32(b); *val += i; i++; br->consumed_bits += i; @@ -800,7 +760,7 @@ FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[ mov i, eax } #else - i = COUNT_ZERO_MSBS(b); + i = FLAC__clz_uint32(b); #endif uval += i; bits = parameter; @@ -832,7 +792,7 @@ FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[ const unsigned end = br->bytes * 8; uint32_t b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits; if(b) { - i = COUNT_ZERO_MSBS(b); + i = FLAC__clz_uint32(b); uval += i; bits = parameter; i++; @@ -984,7 +944,7 @@ break2: : "r"(b) ); #else - i = COUNT_ZERO_MSBS(b); + i = FLAC__clz_uint32(b); #endif uval += i; cbits += i; @@ -1015,7 +975,7 @@ break2: const unsigned end = br->bytes * 8; uint32_t b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits; if(b) { - i = COUNT_ZERO_MSBS(b); + i = FLAC__clz_uint32(b); uval += i; cbits += i; cbits++; /* skip over stop bit */ |