Question: Problem 2: Suppose we recompile the C/C++ code fragment with an optimizing compiler, and get the following new MIPS code (note that the variable sum

Problem 2:

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

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?Problem 2: Suppose we recompile the C/C++ code fragment with an optimizing

CSC 656-Computer Organization Iustructor: Dr. Vidhyacharan Bhaskar Homework 1: (Due: September 17, 2018 before 3.30 pm) Problem 2: Suppose we recompile the CiC++ 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 bave to be loaded from and stored to memory in each loop iteration): Problem 1: Performance and MIPS ISA Consider this CC++ code fragment Optimized MIPS code or $16,S16,$0 ,i 1-0 # load sum # load x[1] sum-sum-x[1] loop:Ly $19 S18) int i, sum-0, xI10] for 4-0; 10; 1++) Add $21,521,519 Addi $16.S16.1 Addi, $18.S18.4 Slti $17S16.10 um-sumx The code fragment is translated to MIPS assembly language. I is allocated to $16. $18 is a pointer for referencing the array x: $18 has already been initialized to contain &x] The variable sum is also allocated in memory: $20 contains &sum. # store sum We Dow un the optimized MIPS code on CPU base from Problem la. Calculate the instruction count and CPI for each instruction type, and also the total instruction count and the umber of cycles it takes the optimized MIPS code to nun. How much faster is the optimized code than the The MIPS code: or $16,S0,$0 ocigi inal code? lo:$19, (S18) x [1] surm sum=sum + x[1] load load LW $21,1520) Add $21:21, $19 SM $21, ($20) Addi, $16 $16,1 Addi $18,18,4 Slti, $17, $16,10 Bre $ 17, so, loop Problem 3: Exercise 1.5 on pagel55 # store sun BEE++ if1

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!