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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!