Home /
Expert Answers /
Computer Science /
34-loop-unrolling-a-k-a-34-loop-iteration-merging-34-34-is-a-static-performance-optimization-loop-un-pa515
(Solved): "Loop unrolling (A.K.A. "loop-iteration merging")" is a static performance optimization. Loop unrol ...
"Loop unrolling (A.K.A. "loop-iteration merging")" is a static performance optimization. Loop unrolling tries to eliminate especially RAW data dependencies by merging multiple loop iterations into one iteration, when a loop structure repeats for a specific number of times. Thus, loop unrolling is often applied to "for" loops (because the number of the iterations in each for loop structure is known in the compile time), while loop unrolling is NOT applicable to "while" loops (because the number of the iterations is usually not known in the compile time). Assume the following loop-structure using "for": for (i=0;i<120;i++) \{ array_01[i] = array_01[i] +10 ; array_02[i] = array_02[i] - 50; \} which is translated into the following assembly instructions: END_LUUP: some instruction some instruction Assumptions: (a) The processor is a five-stage pipeline processors (b) "R" is performed in ID stage (at the 2nd stage) (c) "W" is performed in WB stage (at the 5 th stage) (d) Registers $a0 and $a1 are used as pointers, which point to the beginning of "array_01" and "array_02" respectively. (e) Each element in "array_01" and "array_02" is four bytes (see the figure in the next page) (f) This processor has infinite number of $ t registers (g) Before loop-unrolling, no code optimization is applied (a compiler generates instructions sequentially for each high-level programming language statement).