Data Hazards and Stalls Data hazards and forwarding

  • Slides: 33
Download presentation
Data Hazards and Stalls • Data hazards and forwarding • Data Hazards and Stalls

Data Hazards and Stalls • Data hazards and forwarding • Data Hazards and Stalls 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 1

An Example Assuming that register R 2 = 10 initially. And the sub instruction

An Example Assuming that register R 2 = 10 initially. And the sub instruction will result in R 2 = -20. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 2

Pipelined dependencies in a five instruction sequence using simplified datapaths to show the dependencies.

Pipelined dependencies in a five instruction sequence using simplified datapaths to show the dependencies. Note: only add and sw get the right value R 2 = - 20 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 3

An Example (cont’d) Hazard condition (between sub and at the indicated stages): EX/MEM. Register.

An Example (cont’d) Hazard condition (between sub and at the indicated stages): EX/MEM. Register. Rd = ID/EX. Register. Rs = $2 General 1 a. 1 b. 2 a. 2 b. EX/MEM. Register. Rd = ID/EX. Register. Rs EX/MEM. Register. Rd = ID/EX. Register. Rt MEM/WB. Register. Rd = ID/EX. Register. Rs MEM/WB. Register. Rd = ID/EX. Register. Rt Question: can you identify which of the 4 conditions Here captures the hazards condition between sub and or ? 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 4

Forwarding/Bypassing • ALUinputs can also from pipeline registers • Extra multiplexors • Hazard detection

Forwarding/Bypassing • ALUinputs can also from pipeline registers • Extra multiplexors • Hazard detection units 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 5

The dependencies between the pipeline registers move forward in time, so it is possible

The dependencies between the pipeline registers move forward in time, so it is possible to supply the inputs to the ALU needed by the and instruction and or instruction by forwarding the results found in the pipeline registers rather than stall. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 6

a. No forwarding the ALU and pipeline register before adding forwarding. 2021/9/25 coursecpeg 323

a. No forwarding the ALU and pipeline register before adding forwarding. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 7

b. With forwarding Forwarding control and the multiplexors are added 2021/9/25 coursecpeg 323 -05

b. With forwarding Forwarding control and the multiplexors are added 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 8

The control values for the forwarding multiplexors. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323.

The control values for the forwarding multiplexors. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 9

Forwarding Conditions 1. EX hazard: if(EX/MEM. Reg. Write and (EX/MEM. Register. Rd =/= 0)

Forwarding Conditions 1. EX hazard: if(EX/MEM. Reg. Write and (EX/MEM. Register. Rd =/= 0) and (EX/MEM. Register. Rd = ID/EX. Register. Rs)) Forward. A = 10 if (EX/MEM. Reg. Write and (EX/MEM. Register. Rd =/= 0) and (EX/MEM. Register. Rd = ID/EX. Register. Rt)) Forward. B = 10 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 10

Con’d 2. MEM hazard: if(MEM/WB. Reg. Write and (MEM/WB. Register. Rd =/= 0) and

Con’d 2. MEM hazard: if(MEM/WB. Reg. Write and (MEM/WB. Register. Rd =/= 0) and (MEM/WB. Register. Rd = ID/EX. Register. Rs)) Forward. A = 01 if(MEM/WB. Reg. Write and (MEM/WB. Register. Rd =/= 0) and (MEM/WB. Register. Rd = ID/EX. Register. Rt)) Forward. B = 01 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 11

Priority in Forwarding Add $1, $2 Add $1, $3 Add $1, $4 …. Note:

Priority in Forwarding Add $1, $2 Add $1, $3 Add $1, $4 …. Note: here both EX and MEM stages may have the exact hazard conditions. What should we do ? 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 12

Priority in Forwarding If (MEM/WB. Reg. Write and (MEM/WB. Register. Rd =/= 0) and

Priority in Forwarding If (MEM/WB. Reg. Write and (MEM/WB. Register. Rd =/= 0) and (EX/MEM. Register. Rd =/= ID/EX. Register. Rs) and (MEM/WB. Register. Rd = ID/EX. Register. Rs)) Forward A = 01 if (MEM/WB. Reg. Write and (MEM/WB. Register. Rd =/= 0) and (EX/MEM. Register. Rd =/= ID/EX. Register. Rt) and (MEM/WB. Register. Rd = ID/EX. Register. Rt)) Forward. B = 01 Note: 2021/9/25 When both EX and MEM stages may have the exact hazard conditions. coursecpeg 323 -05 FTopic 6 c-323. ppt 13

The datapath modified to resolve hazards via forwarding. 2021/9/25 coursecpeg 323 -05 FTopic 6

The datapath modified to resolve hazards via forwarding. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 14

The Snapshots of Our Example Through Forwarding 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323.

The Snapshots of Our Example Through Forwarding 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 15

Clock cycles 3 of the instruction sequence. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323.

Clock cycles 3 of the instruction sequence. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 16

add $9, $4, $2 or $4, $2 and $4, $2, $5 sub $2…… before

add $9, $4, $2 or $4, $2 and $4, $2, $5 sub $2…… before <1> Clock cycles 4 of the instruction sequence. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 17

Clock cycles 5 of the instruction sequence. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323.

Clock cycles 5 of the instruction sequence. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 18

after <2> after <1> add $9, $4, $2 or $4…… and $4…. . .

after <2> after <1> add $9, $4, $2 or $4…… and $4…. . . Clock cycles 6 of the instruction sequence. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 19

Hazards and Stalls 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 20

Hazards and Stalls 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 20

A pipelined sequence of instructions. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 21

A pipelined sequence of instructions. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 21

The way stalls are really inserted into the pipeline. 2021/9/25 coursecpeg 323 -05 FTopic

The way stalls are really inserted into the pipeline. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 22

Forwarding with Load and Stores • The problem • The solution 2021/9/25 coursecpeg 323

Forwarding with Load and Stores • The problem • The solution 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 23

A Hazard Detection Unit In the ID stage, the following should be checked by

A Hazard Detection Unit In the ID stage, the following should be checked by the hazard detection unit, so it can insert the stall between a load and its use. if (ID/EX. Mem. Read and ((ID/EX. Register. Rt = IF/ID. Register. Rs) or (ID/EX. Register. Rt = IF/ID. Register. Rt)) stall the pipeline 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 24

Pipelined control overview, showing the two multiplexors forwarding, the hazard detection unit, and the

Pipelined control overview, showing the two multiplexors forwarding, the hazard detection unit, and the forwarding unit. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 25

“Snapshots” of the running example through the pipeline 2021/9/25 coursecpeg 323 -05 FTopic 6

“Snapshots” of the running example through the pipeline 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 26

Clock cycles 2 of the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05

Clock cycles 2 of the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 27

Clock cycles 3 of the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05

Clock cycles 3 of the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 28

Clock cycles 4 the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05 FTopic

Clock cycles 4 the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 29

Clock cycles 5 of the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05

Clock cycles 5 of the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 30

Clock cycles 6 of the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05

Clock cycles 6 of the instruction sequence in the example. 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 31

Clock cycles 7 of the instruction sequence in the example. (note the forwarding of

Clock cycles 7 of the instruction sequence in the example. (note the forwarding of r 4) 2021/9/25 coursecpeg 323 -05 FTopic 6 c-323. ppt 32

Branch Hazards and Handling • Branch hazards • Branch hazard handling methods - 2021/9/25

Branch Hazards and Handling • Branch hazards • Branch hazard handling methods - 2021/9/25 Static Dynamic coursecpeg 323 -05 FTopic 6 c-323. ppt 33