Re: how to ensure loop unrolling with template programming

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

 



You can look into expression templates.  Basically, you can make recursive
template instantiations that effectively provide an unrolled loop.  Google
should be able to provide further instruction.
   Brian

> On Jul 9, 2010 2:29 AM, "Frank Winter" <frank.winter@xxxxxxx> wrote:
>
> Is there a way to make sure, that the compiler does loop unrolling
> quantized by a template paramter? The standard says that the compiler "may"
> unroll the loop. How does G++ behave here?
>
> A tricky thing in my case might be, that the loop to be unrolled contains a
> function call. There is no way around that at the moment. The function is
> declared inline tough.
>
>
> template<typename T>
> inline
> void part( const T & a )
> {
>        // some code
> }
>
>
> template<typename T, int n>
> void func( const T & a )
> {
>        for ( int i = 0 ; i < n ; ++i )   // loop to unroll
>          part(a);
> }
>
>
> Function part() should be inlined n times so that after the loop unrolling
> the compiler can do optimizations on the temporaries created in part() and
> interleaf code.
>
> 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?
>
>
> Frank Winter
>
>



[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