Top Banner
In the name of Allah who is most beneficial and most merciful
21

Data Hazard and Solution for Data Hazard

Aug 07, 2015

Download

Education

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data Hazard and Solution for Data Hazard

In the name of Allah who is most beneficial and most merciful

Page 2: Data Hazard and Solution for Data Hazard

Rules• You can ask question after completion of

topics.

• Your questions should be according to topic.

•Any misbehave during presentation would lead you to some serious actions like asked to leave the class room.

Page 3: Data Hazard and Solution for Data Hazard

Topic Outline

• What is Pipelining?

• Types of Pipelining.

• What is Data Hazard?

• Types of Data Hazard.

• Solutions for Data Hazards.

Page 4: Data Hazard and Solution for Data Hazard

Pipelining

• A technique used in advanced microprocessors where the microprocessor begins executing a second instruction before the first has been completed.

• That is, several instructions are in the pipeline simultaneously, each at a different processing stage.

Page 5: Data Hazard and Solution for Data Hazard

Types of Pipelining

CONTROL HAZARD

DATAHAZARD

STRUCTURE

HAZARD

Pipelining

Page 6: Data Hazard and Solution for Data Hazard

• A situation that prevent the starting next instruction in the next cycle

• They reduce speedup of pipeline execution

• Hazards can always be resolved by waiting

HAZARD

Page 7: Data Hazard and Solution for Data Hazard

• Attempt to use item before it is ready

• Instruction depends on result of prior instruction still in the pipeline

DATA HAZARD@@

Page 8: Data Hazard and Solution for Data Hazard

Any Questions???

Page 9: Data Hazard and Solution for Data Hazard

Types of Data Hazard

RAW WAR WAW

DATA HAZARD

Page 10: Data Hazard and Solution for Data Hazard

RAW(Read After Write)

• It is also known as TRUE DEPENDENCY .

• An instruction modifies a register or memory location

• Succeeding instruction reads data in that location

• Hazard if read takes place before write complete

Page 11: Data Hazard and Solution for Data Hazard

Write After Read (RAW)

• It is also known as Anti dependency

• An instruction reads a register or memory location

• Succeeding instruction writes to location

• Hazard if write completes before read takes place

Page 12: Data Hazard and Solution for Data Hazard

Write After Write (RAW)

• Two instructions both write to same location

•Hazard if writes take place in reverse of order intended sequence

Page 13: Data Hazard and Solution for Data Hazard

Any Questions???

Page 14: Data Hazard and Solution for Data Hazard

Problem with Data Hazard

Problem

Page 15: Data Hazard and Solution for Data Hazard

• All the instructions after the ADD use the result of the ADD instruction (in R1). The ADD instruction writes the value of R1 in the WB stage .

• SUB instruction reads the value during ID stage (IDsub). This problem is called a data hazard

Page 16: Data Hazard and Solution for Data Hazard

Two instruction with add and Sub using three register $sO(in addition) and $t2(in subtraction) =Destination Register

$tO , $t1 and $t3 are Read /Write RegisterWhile $sO is read/write register in Subtraction instruction

ID

0 2 4 6 8 10 12

IF ID EX MEM

16

add $s0 ,$t0,$t1

18

sub $t2, $s0 ,$t3 IF EX MEM

Ws0

WBRs0

new value of s0

Data hazard occur at this stage

Page 17: Data Hazard and Solution for Data Hazard

Solution of Data Hazard

Solution

Page 18: Data Hazard and Solution for Data Hazard

Data Hazards – Forwarding

• Key idea: connect new value directly to next stage

• Still read s0, but ignore in favor of new result

Page 19: Data Hazard and Solution for Data Hazard

Forwarding-Data HazardA instruction goes into four state

Let two instruction Add $sO, $tO , $t1 Sub $t2, $sO ,$t3

How to avoid data hazard?

$sO registe

r

If we use this path as shown by arrow then we left the $sO register for

instruction SUB

Page 20: Data Hazard and Solution for Data Hazard

Solution

• Usually solved by data or register forwarding (bypassing or short-circuiting). This is based on the fact that the data selected is not really used in ID but in the next stage: ALU.

• Forwarding works as follows: ALU result from EX/MEM buffer is always fed back to the ALU input keys. If the forwarding hardware detects that its source operand has a new value, the logic selects the newer result rather than the value read from the register file.

Page 21: Data Hazard and Solution for Data Hazard

Any Question???