Exceptions Another form of control hazard Could be caused by…

Slides:



Advertisements
Similar presentations
Pipeline Example: cycle 1 lw R10,9(R1) sub R11,R2, R3 and R12,R4, R5 or R13,R6, R7.
Advertisements

Microprocessor Design Multi-cycle Datapath Nia S. Bradley Vijay.
Review: MIPS Pipeline Data and Control Paths
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Chapter 5 The Processor: Datapath and Control Basic MIPS Architecture Homework 2 due October 28 th. Project Designs due October 28 th. Project Reports.
Multicycle Review Performance Examples. Single Cycle MIPS Implementation All instructions take the same amount of time Signals propagate along longest.
©UCB CS 162 Computer Architecture Lecture 3: Pipelining Contd. Instructor: L.N. Bhuyan
Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
331 Lec18.1Fall :332:331 Computer Architecture and Assembly Language Fall 2003 Lecture 18 Introduction to Pipelined Datapath [Adapted from Dave.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Spring W :332:331 Computer Architecture and Assembly Language Spring 2005 Week 11 Introduction to Pipelined Datapath [Adapted from Dave Patterson’s.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
CMPE 421 Advanced Computer Architecture Supplementary material for Pipelining PART1.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
Pipeline Data Hazards: Detection and Circumvention Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly.
CPE432 Chapter 4B.1Dr. W. Abu-Sufah, UJ Chapter 4B: The Processor, Part B-2 Read Section 4.7 Adapted from Slides by Prof. Mary Jane Irwin, Penn State University.
C HAPTER 5 T HE PROCESSOR : D ATAPATH AND C ONTROL M ULTICYCLE D ESIGN.
CECS 440 Pipelining.1(c) 2014 – R. W. Allison [slides adapted from D. Patterson slides with additional credits to M.J. Irwin]
1 Processor: Datapath and Control Single cycle processor –Datapath and Control Multicycle processor –Datapath and Control Microprogramming –Vertical and.
ECE-C355 Computer Structures Winter 2008 The MIPS Datapath Slides have been adapted from Prof. Mary Jane Irwin ( )
CSIE30300 Computer Architecture Unit 05: Overcoming Data Hazards Hsin-Chou Chi [Adapted from material by and
Datapath and Control AddressInstruction Memory Write Data Reg Addr Register File ALU Data Memory Address Write Data Read Data PC Read Data Read Data.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 16 - Multi-Cycle.
LECTURE 10 Pipelining: Advanced ILP. EXCEPTIONS An exception, or interrupt, is an event other than regular transfers of control (branches, jumps, calls,
Chapter 4 From: Dr. Iyad F. Jafar Basic MIPS Architecture: Multi-Cycle Datapath and Control.
Spr 2016, Mar 9... ELEC / Lecture 7 1 ELEC / Computer Architecture and Design Spring 2016 Pipeline Control and Performance.
CSE 340 Computer Architecture Spring 2016 Overcoming Data Hazards.
Computer Architecture Lecture 6.  Our implementation of the MIPS is simplified memory-reference instructions: lw, sw arithmetic-logical instructions:
Access the Instruction from Memory
Multi-Cycle Datapath and Control
Electrical and Computer Engineering University of Cyprus
Computer Organization
Computer Organization CS224
Handling Exceptions In MIPS, exceptions managed by a System Control Coprocessor (CP0) Save PC of offending (or interrupted) instruction In MIPS: Exception.
Stalling delays the entire pipeline
Computer Architecture
IT 251 Computer Organization and Architecture
/ Computer Architecture and Design
ELEN 468 Advanced Logic Design
Multi-Cycle CPU.
Extensions to the Multicycle CPU
Single Cycle Processor
D.4 Finite State Diagram for the Multi-cycle processor
Multi-Cycle CPU.
ECS 154B Computer Architecture II Spring 2009
Multiple Cycle Implementation of MIPS-Lite CPU
Pipelining: Advanced ILP
Review: MIPS Pipeline Data and Control Paths
CSCE 212 Chapter 5 The Processor: Datapath and Control
Computer Architecture
Pipelining review.
Single-cycle datapath, slightly rearranged
The processor: Pipelining and Branching
A pipeline diagram Clock cycle lw $t0, 4($sp) IF ID
Lecture 9. MIPS Processor Design – Pipelined Processor Design #2
Pipelining in more detail
Systems Architecture II
Lecture 5. MIPS Processor Design
The Processor Lecture 3.6: Control Hazards
Vishwani D. Agrawal James J. Danaher Professor
The Processor Lecture 3.5: Data Hazards
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
Processor: Multi-Cycle Datapath & Control
Introduction to Computer Organization and Architecture
The Processor: Datapath & Control.
COMS 361 Computer Organization
Single Cycle MIPS Implementation
Processor: Datapath and Control
ELEC / Computer Architecture and Design Spring 2015 Pipeline Control and Performance (Chapter 6) Vishwani D. Agrawal James J. Danaher.
Presentation transcript:

Exceptions Another form of control hazard Could be caused by… Arithmetic overflow (how do we know?) Divide by 0 Undefined opcode in instruction Illegal memory address Syscall

Handling an exception What the system must do: Save address of offending instruction Transfer control to OS at some address that will handle the exception OS takes appropriate action OS can terminate execution, or continue using the address saved in 1. How this is done depends on processor implementation (datapath, etc.)

MIPS support for exceptions EPC = exception program counter contains address of instruction that caused the exception Cause = 32-bit register used to record cause of exception. mfc0 = instruction to put EPC into one of general-purpose regs. E.g. mfc0 $s1, $epc so that we can return from exception handler using jr.

Exceptions in pipelined datapath Could have exceptions in different stages: IF: fetching instruction from memory causes page fault ID: illegal opcode EX: division by 0, overflow MEM: fetching data causes page fault; illegal address (protection violation) WB: no exceptions possible!

Exceptions in pipelined datapath Say you execute: lw $1, 4($3) add $2, $3, $4 # causes overflow!!! or $3, $1, $2 bne $1, $3, L

Exception in stage EX IF ID EX MEM WB EPC Cause bne $1, $3, L Instruction memory Register file ALU CLK SE PC Data Memory 0x1240 Overflow detected add $2, $3, $4 or $3, $1, $2 lw $1, 4($3) Clock: We need to continue executing lw, but kill the add, or, and bne instructions – and start executing the exception handler instead 1 2 3 4

Exception in EX – next cycle IF ID EX MEM WB EPC Cause exc. instr 1 Instruction memory Register file ALU CLK SE PC Data Memory address of Interrupt handling routine nop nop nop lw $1, 4($3) Clock: Still in pipeline! 1 2 3 4 5

Review and summary 1 Performance CPI: cycles per instruction. Average CPI based on instruction mixes Execution time = IC * CPI * C Where IC = instruction count; C = clock cycle time Performance: inverse of execution time MIPS = million instructions per second Higher is better Amdahl’s Law:

Review and summary 2 Differences between single-cycle, multi-cycle, and pipelined datapaths. CPI for single-cycle is 1. Inefficient. Multicycle: instructions take different # of cycles to execute. CPI is 3,4, or 5 depending on instruction type. Pipeline: fixed CPI = 5 , but best throughput and performance. Multicycle: share resources across cycles (e.g. have one ALU for everything); not so in single cycle and pipeline (e.g. have at least 3 ALUs).

Functional units Many units used the same in all datapaths (single, multi, pipeline): - has address of current instr. Sign-extend: for I-type instructions (e.g. addi), takes a 16-bit immediate field from instruction and sign-extends it to 32 bits. Shift-left-by-2: - used for adjusting addresses to be word-aligned. Branch address calculation: (sign_ext(imm)) << 2) + (PC+4) PC SE << 2

Controls Basic controls for some functional units: Register file Write enable: only 1 when writing a register Memory MemRead – want to read data MemWrite – want to write data (must be off by default!) ALU Operation to be performed PC PCWrite – set to 1 when want to write PC. Only exists in multicycle datapath. We write PC on every cycle in pipelined/single cycle versions!

Controls continued Decisions to be made in the datapath (i.e. mux controls): ALUSrcA, ALUSrcB: choose ALU inputs from: register (read from register file) Immediate (sign-extended, zero-extended, etc.) Forwarded data (in pipelined design) PCSource: select between PC+4, branch address, and jump address RegDst: select between rd and rt for destination register MemtoReg: in pipeline, select between memory output and ALU output to write back to register file. IorD: in multicycle, select whether we use memory to read instruction or data.

Pipelining Time IM Reg DM IM Reg DM IM Reg DM IM Reg DM Clock Cycle 1 instr1 IM Reg DM instr2 IM Reg DM IM Reg DM instr3 IM Reg DM instr4 Instructions

Pipeline hazards Data hazards Structural hazards Control hazards Instruction dependent on another instruction still in pipeline. E.g.: add $1, $2 $3; or $3, $1, $1 Resolve by forwarding and/or stalling Structural hazards where two instructions at different stages want to use the same resource. Resolve by adding more hardware Control hazards Branches, interrupts, exceptions Wrong instruction in pipeline following branch, because branch address/condition not ready in time Fixes: stall, redesign pipeline, specify delay slots, branch prediction