diff options
author | Andrew Mahone <andrew.mahone@gmail.com> | 2009-02-06 05:43:00 +0000 |
---|---|---|
committer | Andrew Mahone <andrew.mahone@gmail.com> | 2009-02-06 05:43:00 +0000 |
commit | 79c25649b740ad2ac1dce80b5303b2b98470495c (patch) | |
tree | f560ea2c3067ba780eac085a0890b035bfe42afe /apps | |
parent | a7738a352641d2697e1cccb21342ec901485200c (diff) |
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
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/pictureflow.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/apps/plugins/pictureflow.c b/apps/plugins/pictureflow.c index cd7e54ce35..0e48a64e2d 100644 --- a/apps/plugins/pictureflow.c +++ b/apps/plugins/pictureflow.c @@ -346,11 +346,50 @@ static inline int clz(uint32_t v) } /* 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 static const char clz_lut[16] = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; /* This clz is based on the log2(n) implementation at * 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) { |