Enabling loop unrolling in small sections of code.

Ted Byers r.ted.byers@rogers.com
Tue May 6 06:50:00 GMT 2008


--- Jason Cipriani <jason.cipriani@gmail.com> wrote:
> Is it possible to enable -funroll-loops only for
> small sections of
> code, maybe with some #pragma or something?

I do not know about this.  When dealing with code that
must squeeze the maximum performance out of my
hardware, I use the most aggressive optimization the
compiler can give me.  But that is the very last
consideration to make when producing high performance
code.

For example, creative use of template metaprogramming
can provide big gains, not only with loop unrolling,
but also with elimination of temporaries, reduced
copying, &c., &c., &c.

> I have a
> situation where I
> have a template class similar to this defined in a
> header:
> 
> template <int N> class A {
>   double data[N];

Take a look at Alexandrescu's book "Modern C++ Design"
or Vandevorde & Josuttis' book on templates.  It seems
to me that extending your template to include policy
classes may be one of your better options.  With well
defined policy classes, you may well do with template
metaprogramming what you asked about doing with
possibly a pragma or a compiler option.

You may well find that the compiler will do a better
job optimizing code that is well designed/optimized to
begin with than it could be with code that has not yet
been optimally designed.  Template metaprogramming is
your friend in this case.

HTH

Ted



More information about the Gcc-help mailing list