Is there a way to tell clang to unroll a specific loop?
Googling for an answer gives me command-line options which will affect the whole compilant and not a single loop.
There is a similar question for GCC --- Tell gcc to specifically unroll a loop --- but the answer provided there does not work with clang.
Option 1 suggested there:
#pragma GCC optimize ("unroll-loops")
seems to be silently ignored. In fact
#pragma GCC akjhdfkjahsdkjfhskdfhd
is also silently ignored.
Option 2:
__attribute__((optimize("unroll-loops")))
results in a warning:
warning: unknown attribute 'optimize' ignored [-Wattributes]
Update
joshuanapoli provides a nice solution how to iterate via template metaprogramming and C++11 without creating a loop. The construct will be resolved at compile-time resulting in a repeatedly inlined body. While it is not exactly an answer to the question, it essentially achieves the same thing.
That is why I am accepting the answer. However, if you happen to know how to use a standard C loop (for
, while
) and force an unroll it - please share the knowledge with us!