unroll

Option Type Default Value #pragma options C C++
-qoption see below - x x

Syntax

-qunroll=n | -qnounroll 

Purpose
Unrolls inner loops in the program by a factor of n. By default, the optimizer selects the best value for each loop.

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.

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 Batch Compiler Options and Their Defaults
Options that Specify the Compiler Object Code Produced
Equivalent Batch Compile-Link and Incremental Build Options