Low overhead looping support

Michael Hayes m.hayes@elec.canterbury.ac.nz
Sun Mar 7 21:28:00 GMT 1999


Jeffrey A Law writes:

 > My gut tells me this is a bad thing to do.  Either the compiler figures out
 > that it is safe, or it does not generate these instructions.  Having the
 > user use pragmas and such to specify this stuff is gross.

For the compiler to tell that this is safe, it will need to perform
range tracking and the user would have to use assert statements.
In the interim, I still think that a compiler option is best.

For those folks who haven't followed this thread, the problem concerns
optimizing loops like the following to use special low-overhead
looping instructions.  The problem is that some machines treat the
iteration count as a signed variable and thus the following loop would
be rejected since it is possible for someone to call the function with
a value for size that would appear to be negative.  Now I can
guarantee that none of my DSP code would ever iterate that many times
and thus I think that a compiler option is the natural thing to convey
this fact to the compiler.

To put some figures on the performance loss, on the c4x, the
following loop would takes 5 times longer without the optimisation.

double foo(const double *a, const double *b, unsigned int size)
{
    unsigned int i;
    double result = 0;
    
    for (i = 0; i < size; i++)
	result += a[i] * b[i];
    return result;
}

Michael.


More information about the Gcc-patches mailing list