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?
Asked
Active
Viewed 182 times
1 Answers
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
-
1`#pragma GCC unroll 4` may be closer to what the OP was looking for. – Marc Glisse Nov 11 '18 at 07:54
-
@MarcGlisse: I see that's new in GCC 8. Thanks for pointing it out, I had no idea (and by the way it appears to be undocumented). – John Zwinck Nov 11 '18 at 08:19