Re: [LAU] OT(ish): Strange coding problem (audio related)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: linux-audio-user <linux-audio-user@...>
Date: Saturday, January 29, 2011 - 12:22 pm

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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[LAU] OT(ish): Strange coding problem (audio related), James Stone, (Fri Jan 28, 12:35 am)
Re: [LAU] OT(ish): Strange coding problem (audio related), Gabriel M. Beddingfield, (Fri Jan 28, 3:01 am)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Fri Jan 28, 11:29 am)
Re: [LAU] OT(ish): Strange coding problem (audio related), Peter Nelson, (Fri Jan 28, 12:04 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Fri Jan 28, 1:02 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sat Jan 29, 11:07 am)
Re: [LAU] OT(ish): Strange coding problem (audio related), Peter Nelson, (Sat Jan 29, 12:47 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sun Jan 30, 1:29 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sun Feb 13, 3:30 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sat Jan 29, 12:22 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Peter Nelson, (Sat Jan 29, 12:54 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sun Jan 30, 1:46 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Gabriel M. Beddingfield, (Fri Jan 28, 2:40 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Gabriel Beddingfield, (Fri Jan 28, 12:28 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Peter Nelson, (Fri Jan 28, 12:41 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Gabriel M. Beddingfield, (Fri Jan 28, 2:31 pm)