mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 18:47:39 -04:00
use a table-free clz on coldfire, where it benchmarks a bit faster
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19933 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a7738a3526
commit
79c25649b7
1 changed files with 39 additions and 0 deletions
|
@ -346,11 +346,50 @@ static inline int clz(uint32_t v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Otherwise, use our clz, which can be inlined */
|
/* Otherwise, use our clz, which can be inlined */
|
||||||
|
#elif defined(CPU_COLDFIRE)
|
||||||
|
/* This clz is based on the log2(n) implementation at
|
||||||
|
* http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
|
||||||
|
* A clz benchmark plugin showed this to be about 14% faster on coldfire
|
||||||
|
* than the LUT-based version.
|
||||||
|
*/
|
||||||
|
static inline int clz(uint32_t v)
|
||||||
|
{
|
||||||
|
int r = 32;
|
||||||
|
if (v >= 0x10000)
|
||||||
|
{
|
||||||
|
v >>= 16;
|
||||||
|
r -= 16;
|
||||||
|
}
|
||||||
|
if (v & 0xff00)
|
||||||
|
{
|
||||||
|
v >>= 8;
|
||||||
|
r -= 8;
|
||||||
|
}
|
||||||
|
if (v & 0xf0)
|
||||||
|
{
|
||||||
|
v >>= 4;
|
||||||
|
r -= 4;
|
||||||
|
}
|
||||||
|
if (v & 0xc)
|
||||||
|
{
|
||||||
|
v >>= 2;
|
||||||
|
r -= 2;
|
||||||
|
}
|
||||||
|
if (v & 2)
|
||||||
|
{
|
||||||
|
v >>= 1;
|
||||||
|
r -= 1;
|
||||||
|
}
|
||||||
|
r -= v;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
static const char clz_lut[16] = { 4, 3, 2, 2, 1, 1, 1, 1,
|
static const char clz_lut[16] = { 4, 3, 2, 2, 1, 1, 1, 1,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0 };
|
0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
/* This clz is based on the log2(n) implementation at
|
/* This clz is based on the log2(n) implementation at
|
||||||
* http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
|
* http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
|
||||||
|
* It is not any faster than the one above, but trades 16B in the lookup table
|
||||||
|
* for a savings of 12B per each inlined call.
|
||||||
*/
|
*/
|
||||||
static inline int clz(uint32_t v)
|
static inline int clz(uint32_t v)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue