[LAD] gcc and pointer aliasing... missing optimizations in some cases

torbenh torbenh at gmx.de
Tue Dec 22 16:55:08 UTC 2009


hi...

i discovered yesterday, that gcc cant optimize something like:

-----------------------------------------------------------------------
class Ramp
{
    private:
	float _phase;
	float _omega;
    public:
	Ramp();
	float process()
	{
	    _phase += _omega;
	    return  _phase;
	}
};

Ramp osc_block;


int process( jack_nframes_t nframes, void *arg )
{
    int i;

    float * __restrict__ buf = (float *) jack_port_get_buffer( out_port, nframes );

    for( i=0; i<nframes; i++ ) {
	buf[i] = osc_block.process(); 
    }
}
-----------------------------------------------------------------------

the __restrict__ on buf is not enough to convince gcc that writing to
buf[i] doesnt clobber _phase or _omega;

i am trying to make a case here, that something stronger than
__restrict__ is needed which allows the programmer to state that a
pointer really doesnt alias to anything.

of course the gcc guys say "wont happen" ... 
so the question is whether we have enough need for this in the dsp
scene... and maybe some political power ?

am i totally wrong and such idioms arent of much use ?



-- 
torben Hohn



More information about the Linux-audio-dev mailing list