This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: how to ensure loop unrolling with template programming
- From: me22 <me22 dot ca at gmail dot com>
- To: Frank Winter <frank dot winter at desy dot de>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 9 Jul 2010 16:38:55 -0700
- Subject: Re: how to ensure loop unrolling with template programming
- References: <alpine.LRH.2.00.1007091105330.1773@pub1.ifh.de>
On 9 July 2010 02:29, Frank Winter <frank.winter@desy.de> wrote:
>
> How can I make sure the compiler unrolls the loop and inlines all function
> calls? Do I have to use the preprocessor in my case?
>
if you're *really* sure you know so much better than the heuristics, then:
- __attribute__((__force_inline__)) or something like that will inline the calls
- And change the loop to one at compile time using template specialization
template <unsigned I>
struct repeat {
template <typename F>
repeat(F f) { f(); repeat<I-1>(f); }
};
template <>
struct repeat<0> {
template <typename F>
repeat(F) {}
};
void bar();
void foo() {
repeat<4>(bar);
}
HTH,
~ Scott