#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcpy(), memset() */
#include "private/bitbuffer.h"
+#include "private/bitmath.h"
#include "private/crc.h"
static const unsigned FLAC__BITBUFFER_DEFAULT_CAPACITY = 65536; /* bytes */
#endif
#define max(x,y) ((x)>(y)?(x):(y))
-static unsigned ilog2_(unsigned v)
-{
- unsigned l = 0;
- assert(v > 0);
- while(v >>= 1)
- l++;
- return l;
-}
-
-static unsigned silog2_(int v)
-{
- while(1) {
- if(v == 0) {
- return 0;
- }
- else if(v > 0) {
- unsigned l = 0;
- while(v) {
- l++;
- v >>= 1;
- }
- return l+1;
- }
- else if(v == -1) {
- return 2;
- }
- else {
- v = -(++v);
- }
- }
-}
-
static bool bitbuffer_resize_(FLAC__BitBuffer *bb, unsigned new_capacity)
{
byte *new_buffer;
else
uval = (unsigned)(val << 1);
- k = ilog2_(parameter);
+ k = FLAC__bitmath_ilog2(parameter);
if(parameter == 1u<<k) {
assert(k <= 30);
assert(parameter > 0);
- k = ilog2_(parameter);
+ k = FLAC__bitmath_ilog2(parameter);
if(parameter == 1u<<k) {
assert(k <= 30);
assert(bb->buffer != 0);
assert(parameter <= 31);
- val_bits = silog2_(val);
+ val_bits = FLAC__bitmath_silog2(val);
total_bits = 2 + parameter + 5 + val_bits;
if(total_bits <= 32) {
else
uval = (unsigned)(val << 1);
- k = ilog2_(parameter);
+ k = FLAC__bitmath_ilog2(parameter);
if(parameter == 1u<<k) {
unsigned pattern;
assert(bb->buffer != 0);
assert(parameter > 0);
- k = ilog2_(parameter);
+ k = FLAC__bitmath_ilog2(parameter);
if(parameter == 1u<<k) {
unsigned pattern;
assert(bb != 0);
assert(bb->buffer != 0);
- k = ilog2_(parameter);
+ k = FLAC__bitmath_ilog2(parameter);
/* read the unary MSBs and end bit */
while(1) {
assert(bb != 0);
assert(bb->buffer != 0);
- k = ilog2_(parameter);
+ k = FLAC__bitmath_ilog2(parameter);
/* read the unary MSBs and end bit */
while(1) {