Hosting by Solid Eight Studios ,PhotoTangler Collage Maker

This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 Unrolling Loops With Meta-Programming   Submitted by

Tim Sweeney recently posted a great piece of code as a "code of the day". He presented a generic, n-dimensional template for vertor spaces.

Tim's code objective was more clarity than performance, but some people complained about the fact that vector operations were implemented as for loops, MSVCPP is not clever enought to unroll.

So I decided to post this trick based on meta-programming that can be used to unroll statement execution.

This way, you can write a vector/matrix class template that will be exactly the same as your hand-written Vect3 class.

In the following code you will find:
• the AssignOpLoopUnroller class which can be viewed as the "meta-program"
• a toy matrix class using this stuff
• a small foo-bar-main program using this class
• and finally, some assembly code showing the unrolled loops. a.k.a. the proof! :)

• Of course, this trick is not mine, I stole it to meta-programming gurus.

If you want to know more about meta-programming, check:
• The Blitz home-page: http://oonumerics.org/blitz/
• Todd Veldhuizen's expression templates: http://extreme.indiana.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html

• Enjoy your unrolling!

--
Xavier Lemaire
lemair_x@epita.fr

 ```//============================================================================] // The two following templated classes contain a static member function (doOperation) // performing assignation operation between two values(= or +=). // so T_lhs and T_rhs can be float, const float, double, a Complex class or whatever. //============================================================================] struct AssignOpAssign { template

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.