in CO and Architecture retagged by
2,444 views
4 votes
4 votes
Consider following program is executed on a 5 stage RISC pipeline and stages are IF, ID, EX, MA, WB.

IF = Instruction Fetch

ID = Instruction Decode and fetch register

EX  = Execution Stage

MA = Memory Access

WB = Write back register file

Program:-

I1) ADD R0, R1 R2

I2) ADD R3, R0 R4

I3) ADD R10, R0 R5

I4) ADD R11, R0 R6

I5) ADD R12, R0 R7

I6) ADD R13, R0 R8

I7) ADD R14, R0 R9

Calculate the number of RAW dependency and Hazards.(There is no Structural Dependency)

My Answers -> Dependencies = 6, hazards = 3.

Someone verify these answer.
in CO and Architecture retagged by
2.4k views

25 Comments

correct..
1
1
Thanks !!!!
1
1

@joshi_nitish So, Every RAW, WAR, WAW hazards question should also contain information about stages.then only it is possible to get the exact solution. ryt??

1
1
yes, hazard can be found only by drawing pipeling diagram..
2
2
For RAW hazards we can know through the pipeline diagram but for WAR and WAW hazards which occur out of order so this information needs to be mentioned whether instruction reordering is allowed or not..

For finding dependencies we can simply do so by using Bernstein's conditions..
1
1
How hazards are calculated?

and what if pipeline info not given for dependency calculation. Does it matters?
0
0
Can someone please explain how we got 3 RAW hazards ??
0
0
Prateek if u draw it's cycle state diagram, then in that I1 will execute from C1 TO C5.

Now I2 is dependent on I1, I2 enter into the pipeline at C2 because we are not using Operator Forwarding so I2 must wait for I1 to produce result r0 and I1 will complete in C5 and from C3 to C5 i2 have to remain in IF stage and this cause hazards or stalls. Thus we have 3 hazards.
3
3

@  Shubhanshu thank you so much sir for nicely explanation .if we use operand forwarding ,then i think zero RAW hazards we will get .right ??

1
1
Yeah. From Ex to ID.
2
2

@Prateek Raghuvanshi @Shubhanshu 

There are stalls in $I2$ because we are waiting for $I1$ to writeback then only $I2$ can start execute phase.

But we can do $execute(I1)$ and $decode(I2)$ in same clock cycle(c3)?

0
0
we cannot ex(I1) and decode(I2) in cycle 3.
0
0

@ayush.5 why not?

we can do operand forwarding from EX(I1) to EX(I2). Right?

 

0
0
We cannot use operand forwarding here because it isn't mentioned. Anyway, if we use it then no. of hazards will be zero.
0
0
Hazards means no. of stalls ??
0
0

please tell the number of RAW dependencies in above?

0
0
SUB R1,R2,R3;

ADD R2,R1,R3;

ADD R3,R1,R2;

SUB R1,R2,R2;

number of raw dependencies here?
0
0
@harshit, 4 raw dependencies
0
0
@ayush ,but made easy has given the ans 2
0
0

They have counted dependencies between adjacent instructions only. It is a misconception that dependency is only between adjacent instructions. Dont trust test series answer. Go through best answer and the comments under it :- https://gateoverflow.in/29896/number-of-war-dependencies

1
1
Okk @ayush, and what about number of raw hazards??
0
0

@harshit, in your example:-

1)If we use operand forwarding then no. of RAW hazards will be zero.

2)Without operand forwarding, you will need to draw pipeline diagram:-

  F  D  E  M  W

      F   –   –  D  E  M  W

           F   –  –   –   –  D   E  M  W

                F  –   –   –  –    D  E  M  W

No. of hazards=10

Note: I have overlapped W and D stage. But it can also be the case that you put decode stage of I2 in the next cycle after W stage of I1. In this case hazards will be 12. But you should always overlap unless told in question that you have to non-overlap. Go through this link :- https://gateoverflow.in/1391/gate2005-68?show=95441

1
1
@ayush, so for hazards we need to draw the diagram
0
0
yep!
0
0
@ayush.5 link given by you.. best answer say 9 , arjun sir answer say 11... I also think arjun sir answer is correct.. and yes ME test COA is kind of worst.. instructor have also some of the concepts wrong about cache.
0
0

1 Answer

2 votes
2 votes

Is it right please verify it

4 Comments

@Ram Swaroop How can you say that I1 and I3 have RAW dependency? I mean we go for immediate next instruction. There is only one RAW dependency. 

0
0

dependency doesn't need to be consecutive you can see here : question 3

https://cseweb.ucsd.edu/classes/wi12/cse141-a/solutions/assignment5-soln.pdf

0
0

@ @

why are we not using "split phase" concept for Instruction2 at cycle 5?

0
0
yeah, there will be 2 hazard and by default split phase should be used
0
0

Related questions

0 votes
0 votes
0 answers
1
Na462 asked in CO and Architecture Nov 14, 2018
775 views
Na462 asked in CO and Architecture Nov 14, 2018
by Na462
775 views