Option Type | Default Value | #pragma options | C | C++ |
-qoption | unroll=4* | - | x | x |
Syntax
-qunroll=n | -qnounroll
Purpose
Unrolls inner loops in the program by a factor of n.
Notes
When -qunroll is specified, the bodies of
inner loops will be duplicated n-1 times, creating a
loop with n original bodies. The loop control may be
modified in some cases to avoid unnecessary branching.
The maximum value for n is 8.
Default
The compiler will perform automatic unrolling of inner loops
by a factor of 4 at an optimization level of 2 or higher (for
example, when the -O3
optimizing option is specified). This will be disabled, however,
if -qnounroll is specified at the same time.
Example
In the following example, loop control is not modified:
while (*s != 0) { *p++ = *s++; }
Unrolling this by a factor of 2 gives:
while (*s) { *p++ = *s++; if (*s == 0) break; *p++ = *s++; }
In this example, loop control is modified:
for (i=0; i<n; i++) { a[i]=b[i] * c[i]; }
Unrolling by 3 gives:
i=0; if (i>n-2) goto remainder; for (; i<n-2; i+=3) { a[i]=b[i] * c[i]; a[i+1]=b[i+1] * c[i+1]; a[i+2]=b[i+2] * c[i+2]; } if (i<n) { remainder: for (; i<n; i++) { a[i]=b[i] * c[i]; } }
List of Compiler Options and Their
Defaults
Options that Specify the Compiler Object
Code Produced