Questions tagged [cpu-hazard]

In [computer-architecture], data hazards, control hazards or structural hazards can exist between two nearby instructions. CPU pipelines need to handle them, or require software to avoid them, to correctly execute code.

Questions about hazards should usually also be tagged .

A pipelined CPU starts working on an instruction before completely finishing previous instructions. Maintaining correctness while doing this requires avoiding hazards, for example making sure that an instruction reading a value from a register actually gets the right value, even if it was only written by the previous instruction. (Read After Write (RAW) data hazard).

Data hazards, control hazards, and/or structural hazards can exist between two nearby instructions. CPU pipelines need to handle them, or require software to avoid them, otherwise execution could give wrong or unpredictable results.

See Wikipedia for details:


Things this tag is not about:

20 questions
2
votes
1 answer

a specific case of data hazard( when a R-Type instruction comes after two consecutive LW )

I am designing a MIPS-like CPU with Verilog and now I'm handling data hazards. I have these instructions: Ins[0] = LW r1 r0(100) Ins[1] = LW r2 r0(101) Ins[2] = ADD r3 r2 r1 I'm using pipeline and my dataPath is something like this: I have 5…
1
vote
1 answer

About data hazard and forwarding with beq in MIPS?

Why the first add needs forwarding? # stage: add $1, $2, $3 # WB add $4, $5, $6 # MEM nop # EX beq $1, $4, target # ID Since beq needs the $1, if the first add is about to execute WB-stage, isn't that…
Kindred
  • 1,229
  • 14
  • 41
1
vote
1 answer

PIPELINE - mem(memory) and if(instruction fetch)

In PIPELINE, MEM (memory) and IF (instruction fetch) are the same hardware element? If are the same memory then 2 instructions can't load or store in the same cycle clock, I'm right? MIPS processor diagram
vaniokmd
  • 59
  • 7
1
vote
0 answers

MIPS pipeline load use hazard with branch

Today I'm studying in the MIPS pipeline and finding out one interesting thing. Seeing the code below: I1: lw $s1, 0($s3) I2: add $s4, $s5, $zero I3: beq $s1, $s5, 8 In order to reduce penalty of branch, we make compare two register data in ID…
J.Hsieh
  • 11
  • 1
1
vote
1 answer

Static Hazard 1 and One Circuit Problems?

I read about Static Hazard. We know Static 1-hazard is: Input change causes output to go from 1 to 0 to 1. My note covers a Circuit as follows: My notes says: When B=C=D=1, for any changes in A values, it's probable to have Static Hazard 1. But I…
user5912880
0
votes
1 answer

I am confused as to which instructions in MIPS have a hazard

I have been looking at this problem, and upon my own attempt, I found 3 data hazards. However, other sources say otherwise. Find all hazards in the following instructions (MIPS Pipeline): add $t3, $t1, $t2 sub $t3, $t2, $t1 and $t4, $t3, $t1 or $t0,…
0
votes
1 answer

Multi-Cycle Pipeline implementation: why do we cancel the earlier WB when addressing the WAW hazard to handle the exception?

I learned 'Computer Organization and Design' RISC-V version by Patterson and Hennessy and searched 'Multi-Cycle Pipeline' on the internet and find this helpful doc chap3_6 I have some questions about the WAW hazard in the 'doc chap3_6' above: In the…
zg c
  • 113
  • 1
  • 1
  • 7
0
votes
0 answers

Questions about forwarding and data hazard in RISC-V CPU

I'm studying RISC-V (32-bit) computer architechture and I'm having a hard time understanding this type of data hazard. Suppose that we have instructions like this: or x4, x3, x4 bne x4, x4, error (not taken) addi x2, x0, 1060 sw x4, 0(x2) Suppose…
Hypernova
  • 103
  • 4
0
votes
0 answers

Why forwarding unit in MIPS processor does not store always data from WB stage to ID stage?

Hey to everyone I am trying to understand 5 stage pipeline MIPS with forwarding unit So I found a problem which has raw data hazards The problem is the following : Ι1 and $1, $1, $2 Ι2 add $2, $1, $2 Ι3 lw $2, –20($3) Ι4 sub $4, $2,…
up10388
  • 1
  • 3
0
votes
0 answers

MIPS: How to identify dependences in pipeline processor

1 lw $t2, 8($t1) 2 lw $s0, 0($t2) 3 add $t3, $t2, $t1 4 add $s1, $s0, $t3 Am I correct in saying there are 3 dependences? 2 depends on 1, 3 depends on 1, and 4 depends on 3.
0
votes
1 answer

Identifying all RAWs & inserting "nop"(s) in the MIPS code

This is the MIPS code : (1) Loop : lw $2, 0($1) (2) lw $3, 0($2) # $2 (3) add $4, $3, $2 # $3, $2 (4) sw $4, 4($2) # $4 (5) beq $4, $5, Loop # $4 For identifying all the RAW dependencies…
0
votes
1 answer

How many True dependencies does this code have?

LW t1, 0(t4) ; t1 ← address (0+t4) ADDI t1, t1, #8 ; t1 ← t1+8 MULT t3, t1, t1 ; t3 ← t1*t1 SW t3, 4(t2) ; address(4+t2) ← t3 I'm currently unable to tell how many true dependencies this code has. For me, there are two ways of looking at it.…
Helftmir
  • 1
  • 1
0
votes
1 answer

Assuming that you had a MIPS processer with PIPELINE but without hazard prevention nor forwarding, would this be the correct placement of NOP?

I would like to check my work and understanding of pipelines, unfortunately MARS doesn't accommodate this feature so it is hard to verify my hypothesis. I placed the instructions in a spreadsheet to help me understand what is going on and I would…
A P
  • 2,131
  • 2
  • 24
  • 36
0
votes
1 answer

Arguing whether a situation leads to data hazard or not

I was going through the section of pipelining from the text Computer Organization [5e] by Hamacher et. al.. There I came across a situation which the authors claim causes data hazard. The situation is shown below: For example, stage E in the…
Abhishek Ghosh
  • 597
  • 7
  • 18
0
votes
1 answer

Reading and writing the register bank at the same clock cycle in the pipeline. There will be a data hazard in this situation?

I’m studying computer architecture through the book “Computer Organization and Design, The Hardware Software Interface ARM Edition by David A. Patterson and John L. Hennessy” and while I was reading the Chapter 4 (The Processor), I came across some…
1
2