From 79c25649b740ad2ac1dce80b5303b2b98470495c Mon Sep 17 00:00:00 2001 From: Andrew Mahone Date: Fri, 6 Feb 2009 05:43:00 +0000 Subject: 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 --- apps/plugins/pictureflow.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) 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) { -- cgit v1.2.3