Question
Suppose we recompile the C/C++ code fragment with an optimizing compiler, and get the following new MIPS code (note that the variable sum is now
Suppose we recompile the C/C++ code fragment with an optimizing compiler, and get the following new MIPS code (note that the variable sum is now allocated to a register for the duration of the loop, and does not have to be loaded from and stored to memory in each loop iteration):
Optimized MIPS code:
Or $16,$16,$0 # I=0
Lw $21,($20) # load sum
loop:Lw $19,($18) # load x[I]
Add $21,$21,$19 # sum = sum + x[I]
Addi $16,$16,1 # I++
Addi $18,$18,4 # ptr++
Slti $17,$16,10
Bne $17,$0,loop # if (I<10) goto loop
Sw $21,($20) # store sum
We now run the optimized MIPS code on CPU_base from Problem 1a. Calculate the instruction count and CPI for each instruction type, and also the total instruction count and the number of cycles it takes the optimized MIPS code to run. How much faster is the optimized code than the original code?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started