Add GCC specific optimisation for log base 2 operations.

Based on a patch from Cristian Rodríguez.
This commit is contained in:
Erik de Castro Lopo
2012-03-30 21:55:08 +11:00
parent 238b2676c2
commit 5c44cd7d0c
3 changed files with 45 additions and 5 deletions

View File

@@ -34,8 +34,30 @@
#include "FLAC/ordinals.h"
#if defined(__GNUC__)
static inline unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
{
if (v == 0)
return 0;
return sizeof(FLAC__uint32) * __CHAR_BIT__ - 1 - __builtin_clz(v);
}
static inline unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
{
if (v == 0)
return 0;
return sizeof(FLAC__uint64) * __CHAR_BIT__ - 1 - __builtin_clzll(v);
}
#else
unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
#endif
unsigned FLAC__bitmath_silog2(int v);
unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);