Loop Unwinding - Dynamic Unrolling

Dynamic Unrolling

Since the benefits of loop unrolling are frequently dependent on the size of an array - that may often not be known until run time, JIT compilers (for example) can determine whether to invoke a "standard" loop sequence or instead generate a (relatively short) sequence of individual instructions for each element. This flexibility is one of the advantages of just-in-time techniques versus static or manual optimization in the context of loop unrolling. In this situation, it is often with relatively small values of 'n' where the savings are still useful - requiring quite small (if any) overall increase in program size (that might be included just once, as part of a standard library).

Assembly language programmers (including optimizing compiler writers) are also able to benefit from the technique of dynamic loop unrolling, using a method similar to that used for efficient branch tables. Here the advantage is greatest where the maximum offset of any referenced field in a particular array is less than the maximum offset that can be specified in a machine instruction (which will be flagged by the assembler if exceeded). The example below is for IBM/360 or Z/Architecture assemblers and assumes a field of 100 bytes (at offset zero) is to be copied from array 'FROM' to array 'TO' - both having element lengths of 256 bytes with 50 entries

Read more about this topic:  Loop Unwinding

Famous quotes containing the word dynamic:

    Imagination is always the fabric of social life and the dynamic of history. The influence of real needs and compulsions, of real interests and materials, is indirect because the crowd is never conscious of it.
    Simone Weil (1909–1943)