Question: Perform loop unrolling and code optimization to speed up the following operation. Be sure to report: (i) the number of clock-cycles it takes for unrolled,
Perform loop unrolling and code optimization to speed up the following operation. Be sure to report: (i) the number of clock-cycles it takes for unrolled, un-optimized code, and (ii) the number of clock-cycles it will take after loop unrolling and code optimization are in place.
The high level code that needs to be optimized is as follows:
double scalar = 5;
for (int I = 0; I < 2000; i++) {
arr[i] = arr[8] + scalar;
}
MIPS assemble language initialization for this snippet (performed prior to loop-unrolling is as follows:
- Initialize in R2 the address of the last element
- Initialize variable scalar in F2 as 5
- Initialize in R1 the address of the first array element, or arr[0]
With the above in place, the core MIPS code for performing the loop computation is as follows:
Loop: L.D F0, 0(R1) ;F0 = arr[0]
ADDD F4, F0, F2 ;F4 = result
S.D F4, O(R1) ;store arr[i]
DADDUI R1, R1, #8 ;loop i++
BNE R1, R2, Loop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
