1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
zbhhbz
  • 19
  • 2

1 Answers1

0

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.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436