3.3k views

Consider a pipelined processor with the following four stages:

• IF: Instruction Fetch
• ID: Instruction Decode and Operand Fetch
• EX: Execute
• WB: Write Back

The IF, ID and WB stages take one clock cycle each to complete the operation. The number of clock cycles for the EX stage depends on the instruction. The ADD and SUB instructions need 1 clock cycle and the MUL instruction needs 3 clock cycles in the EX stage. Operand forwarding is used in the pipelined processor. What is the number of clock cycles taken to complete the following sequence of instructions?

 ADD R2, R1, R0 R2 $\leftarrow$ R1 + R0 MUL R4, R3, R2 R4 $\leftarrow$ R3 * R2 SUB R6, R5, R4 R6 $\leftarrow$ R5 - R4

1. 7
2. 8
3. 10
4. 14

retagged | 3.3k views

1.How do we really know about forwarding stages.

2.For the same question we can get ans 10 also if we take operator forwarding from EX to RD.

always take the best case unless told otherwise.
Thanks...

If question is given as numerical, then what should be our assumption? Split phase or Operand forwarding?

(Split phase will obviously give minimum answer.)

considering EX to EX data forwarding.

1 2 3 4 5 6 7 8
I1 IF ID EX WB
I2   IF ID EX EX EX WB
I3     IF ID     EX WB

EX to EX data Forwarding:

Image Source: COA by Carl Hamacher

edited
How can we make ID when prev instruction is executing?I'd is fetching operand ..how is it getting it before completion of execution
@uddipto Wrong value will be fetched during ID phase but will be overwritten by original value during EX phase as the result of the execution phase of previous instruction will be given as input immediately.
How wrong value will be updated before execution of 2 instruction?

How you are fetching R4 in 3 instruction before executing it in 2 statement?
@Uddipto @Mandeep
that is the case of operand forwarding occurs

@Arjun sir

here as you told in other questions, since split phase (2 stages in same clock-cycle) cannot be done for       Exe-Exe unlike WB-OF or Exe-OF, we are making Exe of I3 in the 7-th clock-cycle instead of 6-th clock-cycle right ??

yes, exactly
@Arjun sir : Although answer would be the same,we can do forwarding from EX->ID stage can't we?
This answer cleared up forwarding for me totally. Thanks!
@prayas if we do operand forwarding from ex to id then also it is taking same cycle.
Shouldn't ID of I3 be in the 6th cycle instead of 4th? Though the final answer would remain same.
I also think so. ID of I3 should be in 6th cycle as only when the next stage of previous instruction has started can a stage be used by current instruction.
+1 vote
Correct answer would be 8 cycles.

MUL:       |IF|ID|....EX........|WB|

SUB:           |IF|ID|            |EX|WB|