Let it roll - or not?
bbalk 1200006543 Visits (1973)
One of the new options introduced in the new 4.2 release of Enterprise PL/I is the UNROLL option. However, to understand it, you first need to understand what the compiler does with loops.
Usually, the compiler turns a DO loop into a sequence of instructions which is followed by a test and then a conditional branch back to repeat those instructions with some updated values (and the sequence of instructions may be preceded by a conditional test to see if the loop should be run at all).
In some situations, the optimizer can make this generated code run faster by "unrolling" the loop. This means that instead of generating the instructions described above, the optimizer will eliminate the conditional branches (which are relatively expensive) and instead duplicate the loop body with the updated values (or it may do some of both).
The UNROLL option lets you control this. For example, given this code
dcl a(10) fixed bin(31) connected;
dcl jx fixed bin(31);
dcl sum fixed bin(31);
sum = 0;
do jx = 1 to 10;
sum += a(jx);end;
Under UNROLL(NO), the compiler will not unroll the loop, and the code generated would look like
But under UNROLL(AUTO), it would generate the longer, but faster
This is a very simple example, and the code under the default setting of UNROLL(AUTO) is probably better.
But note that even here the unrolled code is larger (if only by a bit). If the code needed inside the loop were bigger, unrolling the loop could significantly increase the object deck size.
There is no one correct setting for this option. You will have to decide what is best for your code: do you want the optimizer to decide which loops to unroll (that's what the default setting does and what all the previous releases did) or do you want to turn off all loop unrolling?