CSSE232 Computer Architecture I Excep4ons in Pipelines - - PowerPoint PPT Presentation

csse232 computer architecture i
SMART_READER_LITE
LIVE PREVIEW

CSSE232 Computer Architecture I Excep4ons in Pipelines - - PowerPoint PPT Presentation

CSSE232 Computer Architecture I Excep4ons in Pipelines Outline Review: excep4ons and interrupts Excep4ons in mul4cycle datapaths Excep4ons in pipelined


slide-1
SLIDE 1

CSSE232 ¡ Computer ¡Architecture ¡I ¡

Excep4ons ¡in ¡Pipelines ¡

slide-2
SLIDE 2

Outline ¡

  • Review: ¡excep4ons ¡and ¡interrupts ¡
  • Excep4ons ¡in ¡mul4cycle ¡datapaths ¡
  • Excep4ons ¡in ¡pipelined ¡
slide-3
SLIDE 3

What ¡are ¡Excep4ons ¡and ¡Interrupts ¡

  • “Unexpected” ¡events ¡requiring ¡change ¡

in ¡flow ¡of ¡control ¡

– Different ¡ISAs ¡use ¡the ¡terms ¡differently ¡

  • Excep4on ¡

– Arises ¡within ¡the ¡CPU ¡

  • e.g., ¡undefined ¡opcode, ¡overflow, ¡syscall, ¡… ¡
  • Interrupt ¡

– From ¡an ¡external ¡I/O ¡controller ¡

  • Dealing ¡with ¡them ¡without ¡sacrificing ¡performance ¡is ¡

hard ¡

slide-4
SLIDE 4

How ¡do ¡we ¡Handle ¡Excep4ons ¡

  • In ¡MIPS, ¡excep4ons ¡managed ¡by ¡a ¡System ¡Control ¡

Coprocessor ¡(CP0) ¡

  • Save ¡PC ¡of ¡offending ¡(or ¡interrupted) ¡instruc4on ¡

– In ¡MIPS: ¡Excep4on ¡Program ¡Counter ¡(EPC) ¡

  • Save ¡indica4on ¡of ¡the ¡problem ¡

– In ¡MIPS: ¡Cause ¡register ¡

  • Jump ¡to ¡handler ¡at ¡8000 ¡00180 ¡
  • Status[1] ¡= ¡1 ¡
slide-5
SLIDE 5

What ¡is ¡the ¡difference ¡between ¡ excep4on ¡level ¡and ¡interrupt ¡ enable? ¡

  • Interrupt ¡enable ¡– ¡turns ¡on ¡and ¡off ¡interrupts ¡
  • Excep4on ¡level ¡– ¡when ¡its ¡1 ¡excep4on ¡is ¡being ¡
  • handled. ¡Further ¡interrupts ¡are ¡disabled ¡

(excep4on ¡level ¡overrides ¡interrupt ¡enable) ¡

slide-6
SLIDE 6

Types ¡of ¡excep4ons ¡

  • We ¡will ¡look ¡at ¡2 ¡excep4ons ¡

– Undefined ¡instruc4on ¡ – Overflow ¡

  • Mul4-­‑cycle ¡first ¡
  • Where ¡do ¡these ¡happen? ¡
  • What ¡can ¡cause ¡them? ¡
slide-7
SLIDE 7

Mul4cycle ¡RTL ¡

Step ¡ R-­‑Type ¡ lw/sw ¡ beq/bne ¡ j ¡ IF ¡ IR ¡= ¡Mem[PC] ¡ PC ¡= ¡PC ¡+ ¡4 ¡ ID ¡ A ¡= ¡Reg[IR[25-­‑21]] ¡ B ¡= ¡Reg[IR[20-­‑16]] ¡ ALUOut ¡= ¡PC ¡+ ¡(SE(IR[15-­‑0]) ¡<< ¡2) ¡ EX ¡ ALUOut ¡= ¡A ¡op ¡B ¡ ALUOut ¡= ¡ ¡ A ¡+SE(IR[15-­‑0]) ¡ If ¡(A==B) ¡ then ¡ ¡ PC ¡= ¡ALUOut ¡ PC ¡= ¡PC[31-­‑28] ¡ || ¡ ¡(IR[25-­‑0]<<2 ¡ MEM ¡ Reg[IR[15-­‑11]] ¡= ¡ ALUOut ¡ MDR=Mem[ALUOut] ¡ Mem[ALUOut] ¡= ¡B ¡ WB ¡ Reg[IR[20-­‑16]] ¡= ¡MDR ¡

slide-8
SLIDE 8

Types ¡of ¡excep4ons ¡

  • Undefined ¡instruc4on ¡

– Happens ¡in ¡Decode ¡ – Can ¡be ¡caused ¡by ¡any ¡invalid ¡instruc4on ¡

  • Overflow ¡

– Happens ¡in ¡Execute ¡ – Not ¡caused ¡by ¡jumps, ¡branches, ¡lw/sw ¡ – Only ¡R-­‑type ¡add/sub ¡

slide-9
SLIDE 9

Types ¡of ¡excep4ons ¡

  • Decode ¡stage ¡

– Undefined ¡instruc4on ¡

  • Execu4on ¡stage ¡

– Overflow ¡

  • Cause ¡= ¡0 ¡– ¡undefined ¡excep4on ¡
  • Cause ¡= ¡1 ¡-­‑ ¡overflow ¡
slide-10
SLIDE 10

Undefined ¡instruc4on ¡

  • What ¡happens? ¡
slide-11
SLIDE 11

Undefined ¡instruc4on ¡

  • Cause ¡gets ¡0 ¡
  • EPC ¡= ¡PC ¡– ¡4 ¡
  • Exc. ¡Level ¡= ¡1 ¡(in ¡status ¡register) ¡
  • PC ¡= ¡Address ¡of ¡excep4on ¡handler ¡
slide-12
SLIDE 12

Overflow ¡excep4on ¡

  • Almost ¡same ¡thing ¡

– Cause ¡gets ¡1 ¡ – EPC ¡= ¡PC ¡– ¡4 ¡ – Exc. ¡Level ¡= ¡1 ¡(in ¡status ¡register) ¡ – PC ¡= ¡Address ¡of ¡excep4on ¡handler ¡

slide-13
SLIDE 13

RTL ¡with ¡Excep4ons ¡(overflow) ¡

Step ¡ R-­‑Type ¡ lw/sw ¡ beq/bne ¡ j ¡ Excep5on ¡ IF ¡ IR ¡= ¡Mem[PC] ¡ PC ¡= ¡PC ¡+ ¡4 ¡ ID ¡ A ¡= ¡Reg[IR[25-­‑21]] ¡ B ¡= ¡Reg[IR[20-­‑16]] ¡ ALUOut ¡= ¡PC ¡+ ¡(SE(IR[15-­‑0]) ¡<< ¡2) ¡ EX ¡ ALUOut ¡= ¡A ¡op ¡B ¡ ALUOut ¡= ¡ ¡ A ¡+SE(IR[15-­‑0]) ¡ If ¡(A==B) ¡ then ¡ ¡ PC ¡= ¡ALUOut ¡ PC ¡= ¡PC[31-­‑28] ¡ || ¡ ¡(IR[25-­‑0]<<2 ¡ PC ¡= ¡0x8000 ¡ 0180 ¡ EPC ¡= ¡PC ¡– ¡4 ¡ Cause ¡= ¡0 ¡or ¡1 ¡ Status ¡= ¡? ¡ MEM ¡ Reg[IR[15-­‑11]] ¡= ¡ ALUOut ¡ MDR=Mem[ALUOut] ¡ Mem[ALUOut] ¡= ¡B ¡ WB ¡ Reg[IR[20-­‑16]] ¡= ¡MDR ¡

The ¡excep4on ¡steps ¡are ¡done ¡in ¡one ¡clock ¡cycle. ¡

slide-14
SLIDE 14

Datapath ¡changes ¡

Shift left 2 PC M u x 1 Registers Write register Write data Read data 1 Read data 2 Read register 1 Read register 2 Instruction [15– 11] M u x 1 M u x 1 4 Instruction [15– 0] Sign extend 32 16 Instruction [25– 21] Instruction [20– 16] Instruction [15– 0] Instruction register ALU control ALU result ALU Zero Memory data register

  • A

B

IorD MemRead MemWrite MemtoReg PCWriteCond PCWrite IRWrite ALUOp ALUSrcB ALUSrcA RegDst PCSource RegWrite Control Outputs Op [5– 0]

Instruction [31-26] Instruction [5– 0]

M u x 2 Jump address [31-0]

Instruction [25– 0] 26 28

Shift left 2 PC [31-28]

1 1 M u x 3 2 M u x 1 ALUOut Memory MemData Write data Address

slide-15
SLIDE 15

Datapath ¡changes ¡

  • Add ¡special ¡cause ¡register ¡
  • Add ¡special ¡status ¡register ¡
  • Add ¡logic ¡to ¡set ¡cause ¡register ¡
  • Add ¡excep4on ¡handler ¡address ¡as ¡input ¡PC ¡
slide-16
SLIDE 16

Control ¡changes ¡

  • Add ¡excep4on ¡control ¡stage ¡

– Set ¡ALU ¡to ¡subtract ¡PC ¡values ¡ – Update ¡excep4on ¡registers ¡ – Update ¡PC ¡

  • Can ¡arrive ¡at ¡excep4on ¡stage ¡from ¡

– Decode ¡– ¡undefined ¡instruc4on ¡ – Excecute ¡– ¡overflow ¡

  • Transi4on ¡back ¡to ¡fetch ¡stage ¡

– Run ¡excep4on ¡handler ¡

slide-17
SLIDE 17

What ¡if ¡we ¡ditched ¡the ¡cause ¡register? ¡

  • Vectored ¡Interrupts ¡

– Jump ¡to ¡different ¡address ¡based ¡on ¡the ¡cause ¡

  • Example: ¡

– Undefined ¡opcode: ¡0x8000 ¡0180 ¡ – Overflow: ¡0x8000 ¡0280 ¡

  • MIPS ¡

– Cause ¡register ¡(with ¡a ¡few ¡excep4ons) ¡

  • X86 ¡

– Uses ¡vectored ¡interrupts ¡

slide-18
SLIDE 18

Excep4ons ¡in ¡a ¡Pipeline ¡

  • Possible ¡excep4on ¡

– Invalid ¡instruc4on ¡ – Overflow ¡ – Invalid ¡memory ¡address ¡ – Invalid ¡instruc4on ¡address ¡

slide-19
SLIDE 19

Excep4ons ¡in ¡a ¡Pipeline ¡

slide-20
SLIDE 20

Excep4ons ¡in ¡a ¡Pipeline ¡

  • Possible ¡excep4on ¡

– Invalid ¡instruc4on ¡(ID) ¡ – Overflow ¡(EX) ¡ – Invalid ¡memory ¡address ¡(MEM) ¡ – Invalid ¡instruc4on ¡address ¡(IF) ¡

  • Could ¡generate ¡4 ¡excep4on ¡in ¡one ¡cycle! ¡
slide-21
SLIDE 21

Mul4ple ¡Excep4ons ¡

  • Pipelining ¡overlaps ¡mul4ple ¡instruc4ons ¡

– Could ¡have ¡mul4ple ¡excep4ons ¡at ¡once ¡

  • Simple ¡approach: ¡deal ¡with ¡excep4on ¡from ¡earliest ¡

instruc4on ¡

– Flush ¡subsequent ¡instruc4ons ¡ – “Precise” ¡excep4ons ¡

  • In ¡complex ¡pipelines ¡

– Mul4ple ¡instruc4ons ¡issued ¡per ¡cycle ¡ – Out-­‑of-­‑order ¡comple4on ¡ – Maintaining ¡precise ¡excep4ons ¡is ¡difficult! ¡

slide-22
SLIDE 22

Excep4ons ¡in ¡a ¡Pipeline ¡

  • Another ¡form ¡of ¡control ¡hazard ¡
  • Consider ¡overflow ¡on ¡add ¡in ¡EX ¡stage ¡

add $1, $2, $1 – Prevent ¡$1 ¡from ¡being ¡clobbered ¡ – Complete ¡previous ¡instruc4ons ¡ – Flush ¡add ¡and ¡subsequent ¡instruc4ons ¡ – Set ¡Cause ¡and ¡EPC ¡register ¡values ¡ – Transfer ¡control ¡to ¡handler ¡

  • Similar ¡to ¡mispredicted ¡branch ¡

– Use ¡much ¡of ¡the ¡same ¡hardware ¡

slide-23
SLIDE 23

Pipeline ¡with ¡Excep4ons ¡

slide-24
SLIDE 24

Pipeline ¡with ¡Excep4ons ¡

  • Diagram ¡doesn't ¡show ¡EPC=PC-­‑4 ¡
  • Possible ¡solu4ons ¡

– Add ¡an ¡ALU ¡ – Pass ¡original ¡PC ¡along ¡

slide-25
SLIDE 25

Excep4on ¡Example ¡

  • Excep4on ¡on ¡add ¡in ¡

40 sub $11, $2, $4 44 and $12, $2, $5 48 or $13, $2, $6 4C add $1, $2, $1 50 slt $15, $6, $7 54 lw $16, 50($7) …

  • Handler ¡

80000180 sw $25, 1000($0) 80000184 sw $26, 1004($0) …

slide-26
SLIDE 26

Excep4on ¡Example ¡

slide-27
SLIDE 27

Excep4on ¡Example ¡

slide-28
SLIDE 28

Imprecise ¡Excep4ons ¡

  • Just ¡stop ¡pipeline ¡and ¡save ¡state ¡

– Including ¡excep4on ¡cause(s) ¡

  • Let ¡the ¡handler ¡work ¡out ¡

– Which ¡instruc4on(s) ¡had ¡excep4ons ¡ – Which ¡to ¡complete ¡or ¡flush ¡

  • May ¡require ¡“manual” ¡comple4on ¡
  • Simplifies ¡hardware, ¡but ¡more ¡complex ¡handler ¡

sosware ¡

  • Not ¡feasible ¡for ¡complex ¡mul4ple-­‑issue ¡
  • ut-­‑of-­‑order ¡pipelines ¡
slide-29
SLIDE 29

Mul4cycle ¡Interrupts ¡

  • Are ¡interrupts ¡very ¡different ¡from ¡excep4ons? ¡
  • What ¡modifica4ons ¡would ¡you ¡make ¡for ¡an ¡

interrupt? ¡

slide-30
SLIDE 30

Mul4cycle ¡Interrupts ¡

  • Are ¡interrupts ¡very ¡different ¡from ¡excep4ons? ¡

– Basically ¡the ¡same ¡thing ¡ – Show ¡that ¡interrupt ¡happened ¡(cause ¡register) ¡

  • What ¡modifica4ons ¡would ¡you ¡make ¡for ¡an ¡

interrupt? ¡

– Check ¡before ¡each ¡new ¡instruc4on ¡

slide-31
SLIDE 31

Check ¡for ¡ interrupts ¡ before ¡ fetching ¡ next ¡ instruc4on ¡

slide-32
SLIDE 32

Pipeline ¡interrupt ¡

  • Any ¡changes ¡from ¡pipeline ¡excep4ons? ¡
slide-33
SLIDE 33

Pipeline ¡with ¡Excep4ons ¡

slide-34
SLIDE 34

Pipeline ¡interrupt ¡

  • Any ¡changes ¡from ¡pipeline ¡excep4ons? ¡

– Don't ¡flush ¡ – Finish ¡current ¡instruc4ons ¡ – Go ¡to ¡handler ¡ – Return ¡to ¡PC+4 ¡

slide-35
SLIDE 35

Review ¡and ¡Ques4ons ¡

  • Review: ¡excep4ons ¡and ¡interrupts ¡
  • Excep4ons ¡in ¡mul4cycle ¡datapaths ¡
  • Excep4ons ¡in ¡pipelined ¡
  • Interrupts ¡

¡