Loop Unrolling Support

unroll Directive

The unroll directive (unroll(n)|nounroll) tells the compiler how many times to unroll a counted loop. The syntax for this directive is:

#pragma unroll

#pragma unroll(n)

#pragma nounroll

where n is an integer constant from 0 through 255. The unroll directive must precede the for statement for each for loop it affects. If n is specified, the optimizer unrolls the loop n times. If n is omitted, or if it is outside the allowed range, the optimizer assigns the number of times to unroll the loop. The unroll directive overrides any setting of loop unrolling from the command line. The directive can be applied only for the innermost nested loop. If applied to the outer loops, it is ignored. The compiler generates correct code by comparing n and the loop count.

Example of unroll Directive

#pragma unroll(4)

 

for(i=1; i<m; i++)

{

   b[i]=a[i]+1;

   d[i]=c[i]+1;

}