How to unroll a certain loop with certain params like max-unroll-times in GCC

198 Views Asked by At

How should I write my code if I want GCC to unroll one of loops in my code with certain params like max-unroll-times in GCC?

1

There are 1 best solutions below

2
John Zwinck On

Try this:

#pragma GCC push_options
#pragma GCC optimize ("O3", "unroll-loops")
void func()
{
    #pragma GCC unroll 4
    for (...)
    {
    }
}
#pragma GCC pop_options

The params like max-unroll-times don't seem to be controllable via #pragma; if you really need different values for different loops, move each loop to a function in a separate file and compile with exactly the options you need.