The Gateway to Computer Science Excellence
+21 votes

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?
$$\begin{array}{ll} \textbf{ADD} & \text{R2, R1, R0} &&& \text{R2 $\leftarrow$ R1$+$R0} \\  \textbf{MUL} & \text{R4, R3, R2} &&& \text{R4 $\leftarrow$ R3$*$R2} \\   \textbf{SUB} & \text{R6, R5, R4} &&& \text{R6 $\leftarrow$ R5$-$R4} \\   \end{array}$$

  1. $7$
  2. $8$
  3. $10$
  4. $14$
in CO and Architecture by Veteran (52.2k points)
edited by | 5.4k 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.

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

(Split phase will obviously give minimum answer.)

Sir there is no relationship between following stages,why we use forwarding

2 Answers

+42 votes
Best answer

Answer: option B.
Considering EX to EX data forwarding.

$$\small \begin{array}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|} \hline

EX to EX data Forwarding:

by Boss (33.9k points)
edited by
How can we make ID when prev instruction is executing?I'd is fetching operand 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.
@Arjun Sir, ID of I3 will be in the 6th cycle or 4th cycle? Please clarify this.
In 4th cycle
@Abhishek, This is because we are considering EX to EX operand forwarding? What happened in EX to ID operand forwarding?
You are always consider best case .
should this mean if nothing is given specific about operand forwarding that will be considered as EX to EX forwarding?
Implementing split phase here from EX to ID gives the same answer. But what should be the strategy here?

Op. forwarding EX --> EX or op forwarding with split phase EX --> ID?

@ ,always consider with the best case if not mentioned which one is giving less number of clock cycle consider that one.

+2 votes
Correct answer would be 8 cycles.


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

SUB:           |IF|ID|            |EX|WB|
by Loyal (6.1k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,382 answers
105,321 users