[music-dsp] Frequncy smear? (fwd)

Ian Lewis ILewis at acclaim.com
Fri Jan 12 12:15:21 EST 2001


You need to replace "asm (..." with "asm __volatile__ (...." Otherwise the
gcc optimizer discards the assembly you've written.
Ian

-----Original Message-----
From: Steve Harris [mailto:S.W.Harris at ecs.soton.ac.uk]
Sent: Friday, January 12, 2001 5:16 AM
To: music-dsp at shoko.calarts.edu
Subject: Re: [music-dsp] Frequncy smear? (fwd)


On Thu, Jan 11, 2001 at 05:00:21PM -0800, Jon Watte wrote:
> You can, however, often write an inline function which expands to an
inline 
> assembly instruction which does the "common" conversion without changing 
> the bits; this will speed up some C code quite dramatically.

Yes, it does, but I couldn't get this to work under gcc, I could hack it
to work if I didn't use any optimisation, but as soon as the compiler
inlined the function it all went to pot.

Anyone know how to do it in gcc?

I think what I ended up with was:

	static const float _truncate_half = 0.5f;

	int truncate(float flt) {
			int i;

			asm (
					"flds 8(%ebp)\n"
					"\tfsubs _truncate_half\n"
					"\tfistpl -4(%ebp)\n"
			);

			return i;
	}

I'm afriad I know *nothing* about x86 assembly code, this was all just
from guesswork and other peoples examples. I think I was relying on the
compiler sticking the arguments in the right places, which was why it
didn't work when inlined.

I tried using some compiler dependent stuff to prevent inlining (the
function call is faster than the FPU jiggery) but it didn't seem to work,
I think the optimisation had higher precedence.

Also, whats a good set of flags for gcc? I'm using "-O3 -ffast-math -fPIC
-DPIC -mcpu=i686 -march=i686" which seems quite good, but I'm not sure if
-O2 with some explict exotic stuff might be better.

- Steve

dupswapdrop -- the music-dsp mailing list and website: subscription info,
FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp/

dupswapdrop -- the music-dsp mailing list and website: subscription info,
FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp/




More information about the music-dsp mailing list