4 msgExtracting all functions from C++ source code
2 msgForce GCC to unroll a loop?
5 msgSyslog fixes a bug?
2 msggcc 4.2.x large file support
2 msgWindows DEP problem with nested functions
8 msgPorting GCC to 8051 Microcontroller
2 msgCleanup for thread local storage?
3 msgGCC 4.3.2 Install into Cygwin
4 msggcno file doesn't include uncalled member funct...
3 msgGCC 4.3.0 configure failure: libgcc
2 msglex/yacc
1 msgBuilding trunk -- error msg instrucitons not qu...
2 msgMIPS atomic builtins

Enabling loop unrolling in small sections of code.
\ Jason Cipriani (6 May 2008)
. \ me22 (6 May 2008)
. \ Ted Byers (6 May 2008)

1 msg#pragma warning
2 msgProblems building gcc 4.3
8 msggcc 4.3.0 -- program search path issue
1 msgRe: WELCOME to gcc
2 msgInclude paths for cpp/g++ (gcc 4.3.0)
2 msgLinking a library and source file into another ...
Subject:Enabling loop unrolling in small sections of code.
Group:Gcc-help
From:Jason Cipriani
Date:6 May 2008


Is it possible to enable -funroll-loops only for small sections of
code, maybe with some #pragma or something? 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];
public:
void Multiply (const A<N> &a) {
for (int i = 0; i < N; ++ i)
data[i] *= a.data[i];
}
};

The values of N are small (between 2 and 20, say) and benchmarks show
the code does seem to benefit from loop unrolling. However, that
template header is #included by many source files where loop unrolling
is not appropriate; so I can't just enable it everywhere. I want to
keep the Multiply function inline so I don't want to put it in a
separate source file compiled with -funroll-loops and explicitly
instantiate all the A<N>'s. I also don't really feel like explicitly
specializing 19 copies of this function, and in my real application
there are many such member functions.

So without using -funroll-loops on every file, explicit instantiation
(to put code in its own source file), or explicit specialization (to
unroll loops by hand), can I do what I want to do here? That is, have
GCC automagically unroll these loops for me without affecting anything
else in any of the source files that #includes this template
definition?

Thanks,
Jason


© 2004-2008 readlist.com