edited by
5,592 views
14 votes
14 votes

An instruction pipeline consists of following 5 stages:
IF = Instruction Fetch, ID = Instruction Decode, EX = Execute, MA = Memory Access and WB = Register Write Back.
Now consider the following code:


1. LOAD            R8, 0(R5);               R8 = memory [R5]
2. LOAD            R9, 4(R5);               R9 = memory [R5 + 4]
3. ADD              R7, R8, R9;             R7 = R8 + R9
4. SUB              R6, R7, R8;             R6 = R7 – R8


Assume that each stage takes 1 clock cycle for all the instructions. How many cycles are required to execute the code, without operand forwarding over a bypass network?

  1. 9
  2. 10
  3. 11
  4. 14
edited by

2 Answers

Best answer
31 votes
31 votes
  1 2 3 4 5 6 7 8 9 10 11 12
I1 IF ID EX MA WB              
I2   IF ID EX MA WB            
I3     IF X X ID EX MA WB      
I4       X X IF X X ID EX MA WB

WB and ID can go together in 1 cycle- WB writes to register file in first half of a cycle and ID reads it from the second half. This is a common technique and need not be explicitly given in question. So, answer is 12 cycles without operand forwarding. (Suppose this answer is not there in choice for GATE, we can do WB and ID in separate cycles and get the answer in choice. But for previous GATE questions this was never the case). 

With operand forwarding:

  1 2 3 4 5 6 7 8 9
I1 IF ID EX MA WB        
I2   IF ID EX MA WB      
I3     IF ID X EX MA WB  
I4       IF X ID EX MA WB
edited by
0 votes
0 votes
I1 IF ID EX MA WB                  
I2   IF ID x x EX MA WB            
I3     IF ID x x x x EX MA WB      
I4       IF ID x x x x x x EX MA WB

Total required cycle is 14.

Related questions

2 votes
2 votes
1 answer
1
Satbir asked Jan 16, 2019
893 views
5 stage pipeline → 3,6,5,8,4 latencies(in ns).What is average CPI of non pipelined CPU when speed up achieved by to pipeline is 4 ? (ans = 1.23)