retagged by
2,078 views
3 votes
3 votes
Indicate the type of data hazards (RAW, WAR, and WAW) that exist between the following instructions:
I1:ADD R1, R2, R3        ; R1 = R2 + R3
I2:ADD R4, R1, R4        ; R4 = R1 + R4
I3:ADD R3, R1, R2        ; R3 = R1 + R2
I4:ADD R1, R1, R4        ; R1 = R1 + R4
 
Soln: Between I1 and I2 RAW(w.r.t. R1),
In I2 WAW (w.r.t R4 but I am not sure if this has WAR too)
Between I3 and I4 WAR (w.r.t. R1)
In I4 WAW (w.r.t R1 but I am not sure if this has WAR too)
Please correct me and My doubts, as follows:
i)Whether hazards can exist in single instruction?(as in I2 and I4)
ii)Do we have to consider only consecutive instructions? (as in I1 and I2) or can it be (I1 and I3) too?
 
retagged by

3 Answers

2 votes
2 votes
According to me ,no hazards can not exists in single instruction. As we can change the sequence the of instructions but we can not change sequence of instruction cycle (e.g you can not perform execute before fetch  )

Also hazards need not be in consecutive instructions.It can be I1 and I3 also
0 votes
0 votes

RAW (I1,I2): (This hazards are called true or adjacent hazard so only can be done in adjacent instructions)

WAR (I3,I4) 

WAW (NIL): [I1,I4] is not WAR. First instruction will not constitute to WAW becz we cant change its order other wise Data loss                          problem can come

edited by
0 votes
0 votes
Q. Whether hazards can exist in single instruction?(as in I2 and I4) ADD R4, R1, R4        ; R4 = R1 + R4

Data hazards arises due to concurrent operation  on a single data item. Here in I2 or I4 , the data is read in ID stage and is update in WB stage. The only operation is done here in I2 is to add R1 value to the value of R4.

Done confuse yourself with the acronym of WAR here.

Q. Do we have to consider only consecutive instructions? (as in I1 and I2) or can it be (I1 and I3) too?

Yes. to check for WAR we need to check more than one instruction as single instruction does not suffer from any data hazards. Data hazards occurs if a set of  instructions are working on same data in concurrent environment ( eg. in pipelining) . These set of instructions may or may not be consecutive .

Related questions

2 votes
2 votes
2 answers
1
1 votes
1 votes
1 answer
3
Tuhin Dutta asked Dec 3, 2017
2,111 views
J1: R1 = 100J2: R1 = R2 + R4J3: R2 = R4 + 25J4: R4 = R1 + R3J5: R1 = R1 + 30Give the no of RAW, WAR and WAW hazards