This is the mail archive of the
mailing list for the GCC project.
Re: Low overhead looping support
- To: law at cygnus dot com
- Subject: Re: Low overhead looping support
- From: Michael Hayes <m dot hayes at elec dot canterbury dot ac dot nz>
- Date: Mon, 08 Mar 1999 18:28:34 +1300 (NZDT)
- Cc: Michael Hayes <m dot hayes at elec dot canterbury dot ac dot nz>, dje at watson dot ibm dot com, egcs-patches at cygnus dot com
- References: <"14033.58029.474241.22783"@ongaonga.elec.canterbury.ac.nz><email@example.com>
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];