Skip to main content

IAR Embedded Workbench for RL78 5.20

unroll

In this section:
Syntax
#pragma unroll=n
Parameters

n

The number of loop bodies in the unrolled loop, a constant integer. #pragma unroll = 1 will prevent the unrolling of a loop.

Description

Use this pragma directive to specify that the loop following immediately after the directive should be unrolled and that the unrolled loop should have n copies of the loop body. The pragma directive can only be placed immediately before a for, do, or while loop, whose number of iterations can be determined at compile time.

Normally, unrolling is most effective for relatively small loops. However, in some cases, unrolling larger loops can be beneficial if it exposes opportunities for further optimizations between the unrolled loop iterations, for example, common subexpression elimination or dead code elimination.

The #pragma unroll directive can be used to force a loop to be unrolled if the unrolling heuristics are not aggressive enough. The pragma directive can also be used to reduce the aggressiveness of the unrolling heuristics.

Example
#pragma unroll=4
for (i = 0; i < 64; ++i)
{
  foo(i * k, (i + 1) * k);
}
See also

Loop unrolling