The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+24 votes

A $5-$stage pipelined processor has Instruction Fetch (IF), Instruction Decode (ID), Operand Fetch (OF), Perform Operation (PO) and Write Operand (WO) stages. The IF, ID, OF and WO stages take $1$ clock cycle each for any instruction. The PO stage takes $1$ clock cycle for ADD and SUB instructions, $3$ clock cycles for MUL instruction and $6$ clock cycles for DIV instruction respectively. Operand forwarding is used in the pipeline. What is the number of clock cycles needed to execute the following sequence of instructions?

$$\begin{array}{|c|l||} \hline  \textbf {Instruction} &  \textbf{Meaning of instruction}  \\\hline  \text{$t _0$: MUL $R _2$,$R _0$,$R _1$} & \text{R}_2  \gets \text{R}_0*\text{R}_1\\\hline  \text{$t _1$: DIV $R _5,R _3,R _4$} & \text{R}_5 \gets \text{R}_3 / \text{R}_4\\\hline   \text{$t _2$: ADD $R _2,R _5,R _2$} & \text{R}_2 \gets \text{R}_5 + \text{R}_2 \\\hline t_3: \text{SUB} \:\text{R}_5,\text{R}_2,\text{R}_6 & \text{R}_5 \gets \text{R}_2 - \text{R}_6  \\\hline\end{array}$$

  1. $13$
  2. $15$
  3. $17$
  4. $19$
asked in CO & Architecture by Veteran (96.1k points)
edited by | 6.6k views
Can anybody could explain, why are we not considering WAW dependency between t1 and t3 (due to R5). Untill t1 WO operation performed how can t3 perform OF operation, as it could lead to wrong result.

I understand the Operand forwarding for t1 - t2.Also operand forwarding for t2- t3. Why are we ignoring WAW between t1 and t3

2 Answers

+47 votes
Best answer

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

Operand forwarding allows an output to be passed for the next instruction. Here from the output of PO stage of DIV instruction operand is forwarded to the PO stage of ADD instruction and similarly between ADD and SUB instructions. Hence, $15$cycles required.

Correct Answer: $B$

answered by Veteran (407k points)
edited by
Operand forwarding is used. Generally operand is forwarded in EX-EX stage (unless stated otherwise), so the pipeline here is deliberately letting (OF) of T2 fetch the wrong value because the updated value will be automatically provided after the (PO) of T1.

So operand forwarding is done from t12 to t13. I get it!

But is it wrong to say OF (of instruction t2) takes place at t12? If so why? And, is this the default behavior when operand forwarding is mentioned? Because I remember a certain similar problem of previous GATE, where the selected answer had shown the stage (similar to the image attached in this comment) at the end of the previous stage of the previous instruction, (though I don't remember the year and question number).

OF at t7 or at t12 will not affect the final answer, but I wonder which one would be more appropriate and why.
Are you sure that question of yours had OF stage at t12 (assume)? It may be that stage was in use by previous process till t11. You should check out that question again.

Going by the operand forwarding logic, ID of I3 should have been in C4 instead of C6, but C4 and C5 have been shown as stalls.


It is given in that question that operand forwarding is being done in EX-ID stage. The result of MUL is produced in 6th cycle, that is why ID is present at 6th cycle instead of 4th.


This the design issue. It will be more appropriate to say t6 of MUL and t12 ADD are OF because OF may be in use by previous instruction for EX OR It is a possibility too that OF before would alter them.

So, this follow solution from G4G would be more appropriate


@Arjun sir

what about WAW dependency between t1(DIV) and t3(SUB) the question haven't mentioned anything about register renaming.

Can we take register renaming by default !?

Am I missing something? 

What is the issue with WAW dependency - it only matters if we do out of order execution.
sorry sir i was mistaken. thanks sir.
+6 votes

Let IF=F, ID=D, OF=O, PO=P, WO=W




I3 HHFD-------OPW   

I4 HHHFD-------OPW

(I3 depends upon R5 n R2, n using operator forwarding we can use R5 value directly when PO of I2 completes). Same happens for I4. So the total time taken until I4 completion is 15. (B) would be correct answer

answered by Active (2.4k points)
reshown by

Why PO of I2 and OF of I3 in the same column???

 OF stage of i3 has to wait till PO stage of i2 is finished to get its input nah??

moral of the story ::

when in pipelining the dependency in previous cycle and upcoming cycle is remain till thn put stall .

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
49,530 questions
54,139 answers
71,068 users