Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist...

24
Forwarding and Hazards Member Role William Elliott Team Leader Jessica Tyler Shuler Wiki Specialist Tyler Kimsey Lead Engineer Cameron Carroll Engineer Danielle Turner PowerPoint Leader* Chris Smith Presentation Leader* Saeed Alshahrani PowerPoint Team* Matt Wood PowerPoint Team* *Roles change with Phase

Transcript of Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist...

Page 1: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Forwarding and Hazards

Member Role

William Elliott Team Leader

Jessica Tyler Shuler Wiki Specialist

Tyler Kimsey Lead Engineer

Cameron Carroll Engineer

Danielle Turner PowerPoint Leader*

Chris Smith Presentation Leader*

Saeed Alshahrani PowerPoint Team*

Matt Wood PowerPoint Team*

*Roles change with Phase

Page 2: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

OverviewWhat are Hazards?

Hazards are problems that occur within the instruction pipeline of the central processing unit (CPU) microarchitecture that can potentially result in an incorrect computation.

There are several types of hazards Structural Hazards Data Hazards Control Hazards

Page 3: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Block Diagram

Page 4: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Structural Hazards

When the current instruction cannot execute in the proper clock cycle because the hardware does not support the combination of instructions that are set to execute

These are not a problem in the MIPS architecture, as there is sufficient hardware to implement everything we need

The only solution, would they occur, would be to add more hardware

Page 5: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Data Hazards

When the current instruction cannot execute in the proper clock cycle because data that is needed to execute instruction is not available.

Load-use data hazard: a specific form of data hazard in which the data being loaded by a load instruction has not yet become available when it is needed by another instruction

Page 6: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Read-after-Read (RAR)

This is a false dependency Reading won’t alter the

contents of the register file, and the registers are read at different times

MIPS Pseudo-code

add $t0, $t1, $t2sub $t4, $t1, $t5

c = a + bd = a + e

Page 7: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

This is not a hazard to be concerned with

The output of the second operation in no way relies on the output of the first

Output is stored again in the next pipeline stage, overwriting the value from the first instruction

MIPS Pseudo-code

add $t1, $t2, $t3add $t1, $t4, $t5

c = a + bc = d + e

Write-after-Write (WAW)

Page 8: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

This is also not a hazard The “sub” instruction reads

in the value of $t3 five stages before it’s written into the register file

MIPS Pseudo-code

sub $t1, $t2, $t3add $t3, $t4, $t5

c = a + bb = d + e

Write-after-Read (WAR)

Page 9: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

This refers to a situation where a previous instruction has not finished writing a value to memory before it needs to be used

This can occur because of the pipelined nature of our processor. Data is written back to the register file two stages after the subsequent instruction needs this information.

This is known as a true-data dependency

MIPS Pseudo-code

add $t1, $t2, $t3add $t4, $t1, $t5

c = a + bd = c + e

Read-after-Write (RAW)

Page 10: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Data HazardsTrue-Data Dependencies

Stalling – inserts a bubble, or a nop (no operation) into the pipeline

Forwarding – Copies data from inside the pipeline before it is written back to the register.

Page 11: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Forwarding Example

add $t1, $t2, $t3

add $t4, $t1, $t5

Page 12: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Forwarding Logic

Page 13: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Selector MUXs

Mux Control Source Explanation

ForwardA = 00 ID/EX The first ALU operand comes from the register file

ForwardA = 10 EX/MEM The first ALU operand is forwarded from the prior ALU result

ForwardA = 01 MEM/WB The first ALU operand is forwarded from data memory or an earlier ALU result

ForwardB = 00 ID/EX The second ALU operand comes from the register file

ForwardB = 10 EX/MEM The second ALU operand is forwarded from the prior ALU result

ForwardB = 01 MEM/WB The second ALU operand is forwarded from data memory or an earlier ALU result

Page 14: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Data HazardsLoad-Use Hazard

There is a case where forwarding will not solve our problems, as the load will not resolve until the last clock cycle in the pipeline, while the subsequent instruction needs the information in the previous cycle.

Therefore, we must stall the pipeline in order to let the load instruction to “catch up”

Page 15: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Load-Use Example

Page 16: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Hazard Detection Unit

Page 17: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Bubble Control Flow Chart

Page 18: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Handling the Bubble

Page 19: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Inserting the Bubble

Page 20: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Control Hazards

Branch (beq) Two paths that can be taken, uses a statement that checks which

branch will be taken. (Think of an “if” statement in Java, or C.)

Jump (j) Always “jumps” to a different location in the code.

Page 21: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Control HazardsFlush Logic

Because there are two options in a branch, we assume the branch will not be taken. If the branch is taken we must remove the instructions that have entered the pipeline.

We do this with a “flush” where we turn all values in the pipeline into nop.

Page 22: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.
Page 23: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Flush Logic

Page 24: Forwarding and Hazards MemberRole William ElliottTeam Leader Jessica Tyler ShulerWiki Specialist Tyler KimseyLead Engineer Cameron CarrollEngineer Danielle.

Questions?