Enabling loop unrolling in small sections of code.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux