1
0
Fork 0
forked from len0rd/rockbox

A better count_leading_zeros() function, courtesy of Jens Arnold

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8577 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Chapman 2006-02-05 09:12:57 +00:00
parent f9df934d90
commit 1a03c37947

View file

@ -184,50 +184,40 @@ static inline void unreadbits(alac_file *alac, int bits)
alac->input_buffer_bitaccumulator *= -1; alac->input_buffer_bitaccumulator *= -1;
} }
static const unsigned char bittab[16] ICONST_ATTR = {
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4
};
static inline int count_leading_zeros(int input) static inline int count_leading_zeros(int input)
{ {
int output = 0; int output = 32;
int curbyte = 0;
curbyte = input >> 24; #if 0
if (curbyte) goto found; /* Experimentation has shown that the following test is always false,
output += 8; so we don't bother to perform it. */
if (input & 0xffff0000)
curbyte = input >> 16;
if (curbyte & 0xff) goto found;
output += 8;
curbyte = input >> 8;
if (curbyte & 0xff) goto found;
output += 8;
curbyte = input;
if (curbyte & 0xff) goto found;
output += 8;
return output;
found:
if (!(curbyte & 0xf0))
{ {
output += 4; input >>= 16;
output -= 16;
} }
else #endif
curbyte >>= 4; if (input & 0xff00)
{
if (curbyte & 0x8) input >>= 8;
output -= 8;
}
if (input & 0xf0)
{
input >>= 4;
output -= 4;
}
output -= bittab[input];
return output; return output;
if (curbyte & 0x4)
return output + 1;
if (curbyte & 0x2)
return output + 2;
if (curbyte & 0x1)
return output + 3;
/* shouldn't get here: */
return output + 4;
} }
void basterdised_rice_decompress(alac_file *alac, void basterdised_rice_decompress(alac_file *alac,
int32_t *output_buffer, int32_t *output_buffer,
int output_size, int output_size,