Reputation: 1157
I know that consecutive R-Type instructions can cause a hazard, for example:
add $2, $2, $1
add $2, $2, $3
but can consecutive I-Type instructions? For example:
addi $2, $0, 10
addi $2, $0, 5
Upvotes: 0
Views: 1646
Reputation: 951
given your case of:
addi $2, $0, 10
addi $2, $0, 5
you will never encounter a data hazard because you are never reading a value after it is being written (read after write)
maybe think of it like this:
$2 = $0 + 10
$2 = $0 + 5
you can see that $2 is not being used in the second calculation and $0 is not being changed, so there is no data hazard.
if you were to do this:
addi $2, $0, 10 # $2 = $0 + 10
addi $3, $2, 5 # $3 = $2 + 5
pipelining will not guarantee that $2 is the expected value when it is read during the second calculation.
consider that lw and sw are also I-type instructions;
RAW
A Read After Write hazard occurs when, in the code as written, one instruction
reads a location after an earlier instruction writes new data to it, but in the
pipeline the write occurs after the read (so the instruction doing the read gets stale data).
WAR
A Write After Read hazard is the reverse of a RAW: in the code a write occurs after a read,
but the pipeline causes write to happen first.
WAW
A Write After Write hazard is a situation in which two writes occur out of order. We normally
only consider it a WAW hazard when there is no read in between; if there is, then we have a RAW
and/or WAR hazard to resolve, and by the time we've gotten that straightened out the WAW has
likely taken care of itself.
http://www.cs.nmsu.edu/~pfeiffer/classes/473/notes/hazards.html
given that the operations for reading and writing data are I-type instructions and given the definition of these potential data hazards, yes, I-type instructions can still have a hazard.
Upvotes: 3