PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Unrolling loops

Is there any magical compiler pre-processor commands that would make it easier for me to keep up with unrolled loop changes?

For instance, it would be really cool if I could do something like:

#REPEAT=8

*(display++) = *(source + (u += du) + (v += dv)<<5);

#ENDREPEAT

Instead of having to change all 8 lines of code.

Even better if I could increment a constant value in the process...

BTW, I know for a fact that this helped my FPS with the only downside of having to keep the size a multiple of 8...
Templates with specialization would be best for this I think. I'm really not an expert on templates, but I think this is one thing templates do pretty well.

Check this out:

http://www.codeproject.com/cpp/crc_meta.asp

--Eric
fast_rx wrote:Is there any magical compiler pre-processor commands that would make it easier for me to keep up with unrolled loop changes?


A simply use a macro like this:

Code:

#define DO_STUFF *(display++) = *(source + (u += du) + (v += dv)<<5);

DO_STUFF
DO_STUFF
DO_STUFF
DO_STUFF
DO_STUFF
DO_STUFF
DO_STUFF
DO_STUFF

#undef DO_STUFF


It ain't perfect, but I only need to update the code in one place. And face it: you don't unroll that many loops anyways.
Doh! I didn't even think of doing it like that Thierry... Of course, my main use would be on several lines of code, not just the one... But it could still work.

And thanks for the article, Eric. I would have never know to look for it (since I didn't know what to call it).
fast_rx wrote:Doh! I didn't even think of doing it like that Thierry... Of course, my main use would be on several lines of code, not just the one... But it could still work.

And thanks for the article, Eric. I would have never know to look for it (since I didn't know what to call it).

Otherwise you could try using Intel's compiler, which seems to be pretty good at doing this kind of transformations for you if you set the right options. The eval version (I think 60 days or so) is free, so you might want to give it a try.

- HM