Excerpts from fons's message of 2011-01-29 12:46:49 +0100:
The glibc package seems to own it on my system. Anyway, I was searching
the web for libm, then looking for a header and so on, but it's pretty
clear now, it's installed by default and the header for C is math.h.
> > > k = (int)(log2(x) + 1e-6)
I thought that log2() might use a different routine if the argument is a
power of 2. I guess that even if it does it's nothing to rely on because
another libm implementation might not do the same thing.
Why did you choose 1e-6 specifically?
> > > int m, k;
Really nice, but I wonder whether it really matters at the end of the
day, simply because of optimisation. I tried to compare your variant
with the one from Peter Nelson using a nice little line I got from
Torben Hohn at some point. Without optimisation the output is quite
different, but beginning with -O2 the machine code appears all the same.
# simple variant using *= 2
echo "void a() { int m, k, j = 2048; for (k = 0, m = 1; m < j; k++, m *=
2); }" | gcc -O2 -xc -S - -o -
# Fons's variant
echo "void a() { int m, k, j = 2048; for (k = 0, m = 1; m < j; k++, m
<<= 1); }" | gcc -O2 -xc -S - -o -
# Peter Nelsons variant
echo "void a() { int m, k, j = 2048; for (k = 0; (1 << k) < j; k++); }"
| gcc -O2 -xc -S - -o -
To be honest I don't know what the line does exactly and hence whether
this is a valid comparison. Also, my knowledge of assembly is so minimal
that I have no idea where the computation takes place at all in the
optimised versions.
If the optimised code really is the same is it worth it to use funky bit
shifting operations? Especially Peter Nelsons version is non-obvious to
me (although it's probably the most efficient out of the three if no
optimisation is used).
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@lists.linuxaudio.org
http://lists.linuxaudio.org/listinfo/linux-audio-user
LINUX® is a registered trademark of Linus Torvalds in the USA and other countries.
Linuxaudio.org logo copyright Thorsten Wilms © 2006.
Hosting provided by the Virginia Tech Department of Music and DISIS.