Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Fw: Log base 2

Fw: Log base 2

From: Paul Suade <paul.suade_at_laposte.net>
Date: Fri, 20 Sep 2002 23:40:41 +0200

Sorry it is not O(log2(n)) but O(log2(8)), that is O(4) instead of O(n) ! (n
is the MSB bit set to 1 in x)

----- Original Message -----
From: "Paul Suade" <paul.suade_at_laposte.net>
To: <rockbox_at_cool.haxx.se>
Sent: Friday, September 20, 2002 11:27 PM
Subject: Re: Log base 2

[...]


>
> dBfs = 20 * ( log(sample) - log(SAMPLE_RANGE) )
> = 20 * ( log2(sample) - log2(SAMPLE_RANGE) ) / ( log2(10) )
>

[...]


> int log2(short x) {
> short j = 8;
[...]


> // use an O(log2(n)) MSB bit scanner instead of an O(n) MSB bit scanner !
> // very good for PC, but for SH1 you really should unroll it
> while (j) {
> if (j >= (1<<i)) {
> j >>= i;
> } else {
> x <<= i;
> }
> i >>= 1;
> }


[...]


> SH1 has poor shift operations so you'd better use the following unrolled
> code which should be far faster as O(log2(n)) MSB bit scanner :
Received on 2002-09-20

Page template was last modified "Mon Jun 14 16:30:06 2021" The Rockbox Crew -- Privacy Policy