COMP226 Tutorial 6

Hand-in questions

In these hand-in questions we will look at pipeline issues.

Read about forwarding, and then attempt the questions.

  1. Identify all of the data dependencies in the following code. Which dependencies are data hazards that can be resolved by forwarding? Assuming one cycle per pipeline stage and full forwarding, which registers are being read and which registers are being written during the fifth cycle of execution?
    	add %r5, %r4, %r2
    	add %r2, %r5, %r4
    	st  %r5, [%r2+4]
    	add %r2, %r4, %r3
    	add %r3, %r5, %r5
    
  2. Consider the pipelined execution of the following code on a processor with 5 pipeline stages identical to the one presented in lectures. Assume that the processor supports all reasonable data forwarding (again as discussed in lectures or in the link above). Suppose that the hardware also supports register write at the first half and register read at the second half of a cycle.
    add  %r1, %r4, %r3
    ld   [%r3], %r2
    add  %r1, %r2, %r4
    sub  %r4, %r2, %r2
    add  %r1, %r4, %r2
    

    How many cycles will it take to execute this code?

  3. Is the following code conversion correct? Why?

    The original code

      top:	add %r4, %r3, %r4
    	subcc %r2, 1, %r2
    	bg top
    	nop
    
    The converted code
      top:	subcc %r2, 1, %r2
    	bg top
    	add %r4, %r3, %r4
    
  4. The following code contains data hazards.
    loop:	ld [%r1], %r3
    	add %r3, %i2, %r3
    	st %r3, [%r1]
    	ld [%r1-4], %r4
    	add %r4, %r2, %r4
    	st %r4, [%r1-4]
    	add %r1, -8, %r1
    	subcc %r1, %r0, %r0
    	bne loop
    	nop
    
    Assume that forwarding is available, and reorder the code so that it has the same semantics (the same effect on the machine including all data registers and memory locations), but so that it will run faster on the standard pipeline.

Discussion questions

  1. What do we mean when we say that two different things are "syntactically identical"? (You may like to consider the call instruction discussed below for a concrete example.)
  2. Look at the isem reference card. There are two syntactically identical call instructions (one is a real instruction and the other is a synthetic instruction). But according to the reference card they are different. This must be a mistake right? Discuss.
  3. "Call" is not a very good name for these instuctions. We often talk about "calling" subroutines, but that's not what they do. What would be a better name that more accurately describes what they do?
  4. Whatever you think about question 2, the SPARC designers had a good reason for introducing the real call instruction. What was it? What is the big advantage of that instruction? What can it do that no other single instruction can do?

Kate and Mike, 2013. COMP226 home page