CSSE232 Computer Architecture I Control Hazards Pipelining - - PowerPoint PPT Presentation

csse232 computer architecture i
SMART_READER_LITE
LIVE PREVIEW

CSSE232 Computer Architecture I Control Hazards Pipelining - - PowerPoint PPT Presentation

CSSE232 Computer Architecture I Control Hazards Pipelining From last =me Data Hazards: Create units to help with Forward data Detect when


slide-1
SLIDE 1

CSSE232 ¡ Computer ¡Architecture ¡I ¡

Control ¡Hazards ¡

slide-2
SLIDE 2

Pipelining ¡

  • From ¡last ¡=me… ¡
  • Data ¡Hazards: ¡

– Create ¡units ¡to ¡help ¡with ¡

  • Forward ¡data ¡
  • Detect ¡when ¡stalls ¡are ¡needed ¡
slide-3
SLIDE 3

Datapath ¡with ¡Hazard ¡Detec=on ¡

slide-4
SLIDE 4

Branching ¡

  • Previous ¡datapaths ¡had ¡no ¡issues ¡with ¡

branching ¡

  • Pipeline ¡datapath ¡

– Execu=ng ¡several ¡instruc=ons ¡in ¡parallel ¡ – Processing ¡branch ¡and ¡subsequent ¡instruc=ons! ¡

slide-5
SLIDE 5

Branch ¡Hazards ¡

Flush ¡these ¡ instruc=ons ¡ (Set ¡control ¡ values ¡to ¡0) ¡

slide-6
SLIDE 6

Flushing ¡

  • Stall ¡

– Stopped ¡updates ¡to ¡IF, ¡ID ¡ – Cancelled ¡EX ¡for ¡current ¡instruc=on ¡

  • Flush ¡

– Cancel ¡all ¡instruc=ons! ¡ – Set ¡control ¡to ¡zero ¡in ¡for ¡3 ¡instruc=ons ¡in ¡flight ¡

slide-7
SLIDE 7

Reducing ¡Flushed ¡Instruc=ons ¡

  • How ¡to ¡reduce ¡wasted ¡instruc=ons? ¡
slide-8
SLIDE 8

Reducing ¡Branch ¡Flushing ¡

  • Move ¡hardware ¡to ¡determine ¡outcome ¡to ¡ID ¡stage ¡

– Target ¡address ¡adder ¡ – Register ¡comparator ¡

  • ALUs ¡are ¡slow ¡

– Subtac=on ¡is ¡slow ¡

  • Equal ¡is ¡much ¡easier ¡

– Just ¡use ¡XOR ¡gates ¡

slide-9
SLIDE 9
slide-10
SLIDE 10

Detec=ng ¡Control ¡Hazard ¡

  • Hazard ¡unit ¡can ¡detect ¡branch ¡instruc=ons, ¡and ¡

automa=cally ¡flush ¡next ¡instruc=on ¡

  • MIPS ¡does ¡not ¡detect ¡control ¡hazards ¡

– Does ¡not ¡flush! ¡ – Will ¡execute ¡1 ¡instruc=on ¡aZer ¡branch ¡ – Require ¡noop ¡aZer ¡all ¡branches? ¡

  • Lets ¡programmer ¡choose ¡to ¡use ¡the ¡'delay ¡slot' ¡

– Can ¡increment ¡loop ¡counter ¡(or ¡something ¡else) ¡

slide-11
SLIDE 11

Other ¡Control ¡Hazards ¡

  • Jump ¡and ¡link ¡

– Greencard ¡says ¡PC+8 ¡ – Assumes ¡a ¡delay ¡slot ¡ – Return ¡to ¡instruc=on ¡aZer ¡delay ¡slot ¡

slide-12
SLIDE 12

Other ¡complica=ons ¡

  • Flushing ¡is ¡ ¡one ¡problem ¡

– MIPS ¡solu=on ¡is ¡to ¡reduce ¡to ¡single ¡delay ¡slot ¡

  • What ¡about ¡ge`ng ¡branch ¡ready? ¡
slide-13
SLIDE 13
  • If ¡a ¡comparison ¡register ¡is ¡a ¡des=na=on ¡of ¡2nd ¡
  • r ¡3rd ¡preceding ¡ALU ¡instruc=on ¡

IF ¡ ID ¡ EX ¡ MEM ¡ WB ¡ IF ¡ ID ¡ EX ¡ MEM ¡ WB ¡ IF ¡ ID ¡ EX ¡ MEM ¡ WB ¡ IF ¡ ID ¡ EX ¡ MEM ¡ WB ¡

add $4, $5, $6 add $1, $2, $3 beq $1, $4, target

n Can ¡resolve ¡using ¡forwarding ¡

slide-14
SLIDE 14
  • If ¡a ¡comparison ¡register ¡is ¡a ¡des=na=on ¡of ¡

preceding ¡ALU ¡instruc=on ¡or ¡2nd ¡preceding ¡ load ¡instruc=on ¡

– Need ¡1 ¡stall ¡cycle ¡

beq stalled

IF ¡ ID ¡ EX ¡ MEM ¡ WB ¡ IF ¡ ID ¡ EX ¡ MEM ¡ WB ¡ IF ¡ ID ¡ ID ¡ EX ¡ MEM ¡ WB ¡

add $4, $5, $6 lw $1, addr beq $1, $4, target

slide-15
SLIDE 15
  • If ¡a ¡comparison ¡register ¡is ¡a ¡des=na=on ¡of ¡

immediately ¡preceding ¡load ¡instruc=on ¡

– Need ¡2 ¡stall ¡cycles ¡

beq stalled

IF ¡ ID ¡ EX ¡ MEM ¡ WB ¡ IF ¡ ID ¡ ID ¡ ID ¡ EX ¡ MEM ¡ WB ¡

beq stalled lw $1, addr beq $1, $0, target

slide-16
SLIDE 16

Dynamic ¡Branch ¡Predic=on ¡

  • In ¡deeper ¡and ¡superscalar ¡pipelines, ¡branch ¡penalty ¡

is ¡more ¡significant ¡

  • Use ¡dynamic ¡predic=on ¡

– Branch ¡predic=on ¡buffer ¡(aka ¡branch ¡history ¡table) ¡ – Indexed ¡by ¡recent ¡branch ¡instruc=on ¡addresses ¡ – Stores ¡outcome ¡(taken/not ¡taken) ¡ – To ¡execute ¡a ¡branch ¡

  • Check ¡table, ¡expect ¡the ¡same ¡outcome ¡
  • Start ¡fetching ¡from ¡fall-­‑through ¡or ¡target ¡
  • If ¡wrong, ¡flush ¡pipeline ¡and ¡flip ¡predic=on ¡
slide-17
SLIDE 17

Review ¡and ¡Ques=ons ¡

  • Hazards ¡

– Data ¡ – Control ¡ – Structural ¡

  • Hazard ¡detec=on ¡
  • Hazard ¡preven=on ¡