Question: The following C code generates a double precision floating point Fibonacci sequence: D [ 0 ] = 1 . 0 ; D [ 1 ]
The following C code generates a double precision floating point Fibonacci sequence: D;
D;
for j ; j ; j
Dj Dj Dj ;
The MIPS code corresponding to the above fragment is:
lid $f
sd $f$a
sd $f$a
li $s
add $s $a $s
addi $s $a
loop: ld $f$s
ld $f$s
add.d $f $f $f
sd $f$s
addi $s $s
bne $s $s loop
Instructions taking more than cycle have the following associated added latencies in cycles: add.d: lid:ALU delayshazards ld:data read buffer delayhazard sd:data write buffer delayhazard for double precision processing.
a How many cycles does it take to execute this code if every hazard stalls the next instruction?
b Reorder the code to reduce stalls. Now, how many cycles does it take to execute this code?
c When an instruction in a later iteration of a loop depends upon a data value produced in an earlier iteration of the same loop, we say that there is a loop carried dependence between iterations of the loop. Identify the loopcarried dependences in the above code. Identify the dependent program variable and assemblylevel registers. You can ignore the loop induction variable j
d Rewrite the code by using registers to carry the data between iterations of the loop as opposed to storing and reloading the data from main memory Show where this code stalls and calculate the number of cycles required to execute. Note that for this problem you will need to use the assembler pseudo instruction "move.d rd rs which writes the value of floatingpoint register rs into floatingpoint register rd Assume that mov, d executes in a single cycle.
e Unroll and optimize the loop above so that each unrolled loop handles three iterations of the original loop. Show where this code stalls and calculate the number of cycles required to execute.
f Unrolling from works nicely because we happen to want a multiple of four iterations. What happens if the number of iterations is not known at compile time? How can we efficiently handle a number of iterations that is not a multiple of the number of iterations per unrolled loop?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
