CSCI341 Lecture 36, Pipelining & Hazards RECALL... RECALL... - - PowerPoint PPT Presentation

csci341
SMART_READER_LITE
LIVE PREVIEW

CSCI341 Lecture 36, Pipelining & Hazards RECALL... RECALL... - - PowerPoint PPT Presentation

CSCI341 Lecture 36, Pipelining & Hazards RECALL... RECALL... HAZARDS Data Hazards Control Hazards Dukes of Hazzard DATA HAZARD Hardware solution: Include forwarding paths in the machines datapath. Even though results have not


slide-1
SLIDE 1

CSCI341

Lecture 36, Pipelining & Hazards

slide-2
SLIDE 2

RECALL...

slide-3
SLIDE 3

RECALL... HAZARDS

  • Data Hazards
  • Control Hazards

Dukes of Hazzard

slide-4
SLIDE 4

DATA HAZARD

Hardware solution: Include forwarding paths in the machine’s datapath. Even though results have not yet reached the writeback stage, the needed information is forwarded from a pipeline register to the input of the ALU (for example).

slide-5
SLIDE 5

HAZARD “DETECTION”

  • Control logic inspects instruction registers used by

neighboring stages.

  • eg, “If EX/MEM’s Rd = ID/EX’s Rs and EX/MEM’s Rd = ID/

EX’s Rt”

slide-6
SLIDE 6

HAZARD

slide-7
SLIDE 7

FORWARDING

slide-8
SLIDE 8

“FORWARDING UNIT”

slide-9
SLIDE 9

DATA HAZARD

Can’t always solve this w/ hardware. For example: lw followed by add

slide-10
SLIDE 10

DATA HAZARD

slide-11
SLIDE 11

DATA HAZARD

One solution: Rearrange the assembly instructions so the instruction following a load is not one that uses the value fetched from memory. (Pipelined loads are often called “delayed loads.”)

slide-12
SLIDE 12

DATA HAZARD

What if the instructions can’t be rearranged? Then we insert a nop instruction. (“No Operation”)

slide-13
SLIDE 13

NOP

0000 0000 0000 0000 0000 0000 0000 0000 (sll $0, $0, 0)

slide-14
SLIDE 14

STALLING

slide-15
SLIDE 15

HAZARD DETECTION

slide-16
SLIDE 16

CONTROL HAZARDS

Associated with every branch/jump instruction.

slide-17
SLIDE 17

ONE SOLUTION

Assume the branch is not taken. (If it is, then we must flush the instructions that have already begun flowing through the pipeline.)

slide-18
SLIDE 18

AN IMPROVED SOLUTION

Determine the branch condition earlier (using additional logic circuitry.) The goal is to slightly reduce the number of “wasted” instructions (and cycles) that have entered the pipeline.

slide-19
SLIDE 19

DELAY SLOT

At the assembly level, organize the instructions such that the instruction immediately following a branch instruction is a useful one.

Loop: add $t0, $t0, $v0 addi $v0, $v0, -1 bnez $v0, Loop li $v0, 4 ... Loop: addi $v0, $v0, -1 bnez $v0, Loop add $t0, $t0, $v0 li $v0, 4 ...

slide-20
SLIDE 20

DYNAMIC BRANCH PREDICTION

In a nutshell: Keeping track of branch instruction histories, and consulting previous branch decisions to best predict the current one.

slide-21
SLIDE 21

EXCEPTIONS

aka “Interrupts” Important when considering pipelined architectures! I/O device request Invoke the OS Overflow HW Malfunction

slide-22
SLIDE 22

WHAT HAPPENS?

Save the address of the exceptional instruction (in the EPC, exception program counter). Transfer control to the OS at some specified address. OS can terminate the program or continue.

slide-23
SLIDE 23

OS EXCEPTION HANDLING

  • What was the reason? (MIPS uses a “cause register”)
  • Which instruction was the culprit? (EPC)
slide-24
SLIDE 24

EXCEPTIONS & PIPELINING

In essence, an exception is treated like a control hazard.

slide-25
SLIDE 25
slide-26
SLIDE 26

NEXT....

Parallelism

slide-27
SLIDE 27

HOMEWORK

  • Reading 30
  • Project 8: “Flip

Ya!”

Flip it good!