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:
parent
f9df934d90
commit
1a03c37947
1 changed files with 27 additions and 37 deletions
|
@ -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;
|
||||||
return output;
|
output -= 8;
|
||||||
if (curbyte & 0x4)
|
}
|
||||||
return output + 1;
|
if (input & 0xf0)
|
||||||
if (curbyte & 0x2)
|
{
|
||||||
return output + 2;
|
input >>= 4;
|
||||||
if (curbyte & 0x1)
|
output -= 4;
|
||||||
return output + 3;
|
}
|
||||||
|
output -= bittab[input];
|
||||||
/* shouldn't get here: */
|
return output;
|
||||||
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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue