0
$\begingroup$

i have read about data hazards and then came across that mips architecture doesn't allow WAR AND WAW hazards can someone please help me understand it? the reason is not given in the book the MIPS pipeline is divided into :

1.IF(instruction fetch) 2.ID(decode the instruction) 3.EX(execute instruction) 4.MEM(write or read from the memory) 5.WB(write back to the register file) for eg in case of WAW hazards :

I1: LOAD R1,0(R2)

I2: ADD R1, R2, R3

I1:  |IF|ID|EX|MEM|WB |
I2      |IF|ID|EX |MEM|WB|

The above is expected way in which the instructions execute without data hazards
but here the second instruction has to wait till the WB phase of the instruction I1 for getting the value of R1 hence it will stall till the value of R1 is available in register file i.e till WB phase of the I1. here what my doubt is in case I2 Takes less number of clock cycles than I1 for completion then can I2 access the register file going to WB phase directly in case it has nothing to do in the phase of MEM will this give rise to a hazard?

$\endgroup$
7
  • $\begingroup$ Where have you read that? What are your thoughts about the matter? $\endgroup$
    – Raphael
    Jan 4, 2018 at 12:23
  • 1
    $\begingroup$ I find your post very hard to understand. Please take some care splitting your narrative into proper English sentences. Also, use Markdown formatting for lists and code. (You're still missing a reference: which book?) $\endgroup$
    – Raphael
    Jan 4, 2018 at 17:50
  • $\begingroup$ I have read the concept from my class notes but saw this in a video course youtube.com/watch?v=9mpOG9YtSLc&t=1242s not i dont know which standard book that professor referred to $\endgroup$
    – venkat
    Jan 4, 2018 at 18:05
  • $\begingroup$ please see this video at 17:58 youtube.com/watch?v=9mpOG9YtSLc&t=1242s $\endgroup$
    – venkat
    Jan 4, 2018 at 18:06
  • $\begingroup$ Please include those references in the questions, comments may vanish. :) (If your prof quotes a book without saying why a) check the syllabus or similar, and if you find nothing b) ask them to please credit their sources. $\endgroup$
    – Raphael
    Jan 4, 2018 at 19:22

3 Answers 3

3
$\begingroup$

in case I2 Takes less number of clock cycles than I1 for completion then can I2 access the register file going to WB phase directly in case it has nothing to do in the phase of MEM will this give rise to a hazard?

I2 reads the register R1 at its ID phase. Therefore, if implemented directly, we must have time(I2.ID)>time(I1.WB). A more sophisticated solution would bypass the register file and take the values directly from the Memory output. In this case we need time(I2.ID)>time(I1.MEM) and the controller becomes more involved.

If I understand your question correctly, you ask whether I2 must take 5 clocks although it doesn't use the MEM phase. The answer is YES or otherwise, it may conflict with other instructions that would try to use MEM at the same time (unless the pipeline controller stalls them when congestion appears).

$\endgroup$
0
0
$\begingroup$

The actually executed codes are:

lw $R1, 0($R2)
nop
add $R1, $R2, $R3

Therefore the space diagram should be:

|IF |ID |EX |MEM|WB |   |   |
|   |   |IF |ID |EX |MEM|WB |

With forwarding from MEM of I1 to EX of I2, the hazard would be eliminated

$\endgroup$
0
$\begingroup$

The answer is that, in MIPS, the data is not written to the actual register $R1 until the WB phase for each instruction.

You are confusing what is in the register with what data is available to be forwarded. So while an add function may have its data available to be forwarded after the EX stage, it doesn't write to the register until the WB stage. It does forward the data to the phase registers to be used, but that also requires a control on whether or not they are used.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.