Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.

Slides:



Advertisements
Similar presentations
ILP: IntroductionCSCE430/830 Instruction-level parallelism: Introduction CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
Advertisements

Pipeline Exceptions & ControlCSCE430/830 Pipelining in MIPS MIPS architecture was designed to be pipelined –Simple instruction format (makes IF, ID easy)
COMP 4211 Seminar Presentation Based On: Computer Architecture A Quantitative Approach by Hennessey and Patterson Presenter : Feri Danes.
CIS429/529 Winter 2007 Pipelining II- 1 Additional pipelining topics Why pipelining is so hard: exception handling ILP techniques: loop unrolling.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Pipelined Processor.
1 Chapter Five The Processor: Datapath and Control.
Computer Organization
The Processor: Datapath & Control
ECE 232 L15.Microprog.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 15 Microprogrammed.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 18 - Pipelined.
Part 4 - Exception Hazards – one last kicker 3/24/04 Similar problem as the conditional branch An exception is an involuntary branch from a non-branching.
Chapter Six Enhancing Performance with Pipelining
CSCE 212 Chapter 5 The Processor: Datapath and Control Instructor: Jason D. Bakos.
CSCE 212 Quiz 9 – 3/30/11 1.What is the clock cycle time based on for single-cycle and for pipelining? 2.What two actions can be done to resolve data hazards?
Chapter 6 Pipelining to Increase Effective Computer Speed.
Control Hazards.1 Review: Datapath with Data Hazard Control Read Address Instruction Memory Add PC 4 Write Data Read Addr 1 Read Addr 2 Write Addr Register.
The Processor Data Path & Control Chapter 5 Part 4 – Exception Handling N. Guydosh 3/1/04+
ECE 232 L23.Exceptions.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 23 Exceptions.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections
Lecture 5: Pipelining Implementation Kai Bu
1 A single-cycle MIPS processor  An instruction set architecture is an interface that defines the hardware operations which are available to software.
University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell CS352H: Computer Systems Architecture Topic 9: MIPS Pipeline.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 16 - Multi-Cycle.
Introduction to Computer Organization Pipelining.
LECTURE 10 Pipelining: Advanced ILP. EXCEPTIONS An exception, or interrupt, is an event other than regular transfers of control (branches, jumps, calls,
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
ECE/CS 552: Pipeline Hazards © Prof. Mikko Lipasti Lecture notes based in part on slides created by Mark Hill, David Wood, Guri Sohi, John Shen and Jim.
Pipelining: Implementation CPSC 252 Computer Organization Ellen Walker, Hiram College.
Exceptions and Interrupts “Unexpected” events requiring change in flow of control – Different ISAs use the terms differently Exception – Arises within.
Computer Architecture Lecture 6.  Our implementation of the MIPS is simplified memory-reference instructions: lw, sw arithmetic-logical instructions:
CS161 – Design and Architecture of Computer Systems
Interrupts and exceptions
CS 230: Computer Organization and Assembly Language
Exceptions Another form of control hazard Could be caused by…
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.
Note how everything goes left to right, except …
CSCI206 - Computer Organization & Programming
/ Computer Architecture and Design
Extensions to the Multicycle CPU
\course\cpeg323-08F\Topic6b-323
Exceptions & Multi-cycle Operations
Pipelining: Advanced ILP
Forwarding Now, we’ll introduce some problems that data hazards can cause for our pipelined processor, and show how to handle them with forwarding.
The processor: Exceptions and Interrupts
CSCE 212 Chapter 5 The Processor: Datapath and Control
Computer Architecture
Single-cycle datapath, slightly rearranged
Pipelining Chapter 6.
The processor: Pipelining and Branching
Lecture 9. MIPS Processor Design – Pipelined Processor Design #2
Systems Architecture II
CSCI206 - Computer Organization & Programming
\course\cpeg323-05F\Topic6b-323
Lecture 5. MIPS Processor Design
Composing the Elements
The Processor Lecture 3.2: Building a Datapath with Control
Project Instruction Scheduler Assembler for DLX
Chapter Four The Processor: Datapath and Control
ECE 445 – Computer Organization
Control Hazards Branches (conditional, unconditional, call-return)
Datapath and Control Exceptions
ECE/CS 552: Pipelining and Exceptions
Introduction to Computer Organization and Architecture
Interrupts and exceptions
©2003 Craig Zilles (derived from slides by Howard Huang)
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:

Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng Zhu, U. of Maine Fall, 2006 Portions of these slides are derived from: Dave Patterson © UCB

Pipeline Exceptions & ControlCSCE430/830 Pipelining Outline Introduction –Defining Pipelining –Pipelining Instructions Hazards –Structural hazards –Data Hazards –Control Hazards Exceptions  Performance Controller implementation

Pipeline Exceptions & ControlCSCE430/830 Exceptions - “Stuff Happens” Exceptions definition: “unexpected change in control flow” Another form of control hazard. For example: add $1, $2, $1; causing an arithmetic overflow sw $3, 400($1); add $5, $1, $2; Invalid $1 contaminates other registers or memory locations!

Pipeline Exceptions & ControlCSCE430/830 Two Types of Exceptions: Interrupts and Traps Interrupts –Caused by external events: »Network, Keyboard, Disk I/O, Timer »Page fault - virtual memory »System call - user request for OS action –Asynchronous to program execution –May be handled between instructions –Simply suspend and resume user program Traps –Caused by internal events »Exceptional conditions (overflow) »Undefined Instruction »Hardware malfunction –Usually Synchronous to program execution –Condition must be remedied by the handler –Instruction may be retried or simulated and program continued or program may be aborted

Pipeline Exceptions & ControlCSCE430/830 Synchronous vs Asynchronous Definition: If the event occurs at the same place every time the program is executed with the same data and memory allocation, the event is synchronous. Otherwise asynchronous. Except for hardware malfunctions, asynchronous events are caused by devices external to the CPU and memory. Asynchronous events usually are easier to handled because asynchronous events can be handled after the completion of the current instruction.

Pipeline Exceptions & ControlCSCE430/830 Exceptions in Simple five-stage pipeline Instruction Fetch, & Memory stages –Page fault on instruction/data fetch –Misaligned memory access –Memory-protection violation Instruction Decode stage –Undefined/illegal opcode Execution stage –Arithmetic exception Write-Back stage –No exceptions!

Pipeline Exceptions & ControlCSCE430/830 What happens during an exception In The Hardware The pipeline has to 1)stop executing the offending instruction in midstream, 2)let all preceding instructions complete, 3)flush all succeeding instructions, 4)set a register to show the cause of the exception, 5)save the address of the offending instruction, and 6)then jump to a prearranged address (the address of the exception handler code) In The Software The software (OS) looks at the cause of the exception and “deals” with it Normally OS kills the program

Pipeline Exceptions & ControlCSCE430/830 Exceptions Exception = non-programmed control transfer –system takes action to handle the exception »must record the address of the offending instruction »record any other information necessary to return afterwards –returns control to user –must save & restore user state user program normal control flow: sequential, jumps, branches, calls, returns System Exception Handler Exception: return from exception

Pipeline Exceptions & ControlCSCE430/830 Additions to MIPS ISA to support Exceptions EPC (Exceptional Program Counter) –A 32-bit register –Hold the address of the offending instruction Cause –A 32-bit register in MIPS (some bits are unused currently.) –Record the cause of the exception Status - interrupt mask and enable bits and determines what exceptions can occur. Control signals to write EPC, Cause, and Status Be able to write exception address into PC, increase mux set PC to exception address (MIPS uses hex ). May have to undo PC = PC + 4, since want EPC to point to offending instruction (not its successor); PC = PC – 4 What else? flush all succeeding instructions in pipeline

Pipeline Exceptions & ControlCSCE430/830 Flush instructions in Branch Hazard 36sub $10, $4, $8 40beq$1, $3, 7 # taget = *4 = 72 44and $12, $2, $5 48or $13, $2, $6 52 …. …. 72 lw $4, 50($7)

Pipeline Exceptions & ControlCSCE430/830 Flush instructions at IF stage in Branch Hazard Turn the instructions at IF stage into nop.

Pipeline Exceptions & ControlCSCE430/830 Flush instructions at IF stage in Branch Hazard 2 zero control signals

Pipeline Exceptions & ControlCSCE430/830 Additions to MIPS ISA to support Exceptions

Pipeline Exceptions & ControlCSCE430/830 Exceptions Example 40 hex sub $11, $2, $4 44 hex and$12, $2, $5 48 hex or $13, $2, $6 4C hex add$1, $2, $1; // arithmetic overflow 50 hex stl$15,%6,$7 54 hex lw $16, 50($7) hex sw $25, 1000($0) hex sw$12, 1004($0) Exception handling program:

Pipeline Exceptions & ControlCSCE430/830 Exceptions Example

Pipeline Exceptions & ControlCSCE430/830 Exceptions Example

Pipeline Exceptions & ControlCSCE430/830 Summary Exceptions –Interrupts –Traps Exceptions in five-stage pipeline Exception detection (not covered) Exception handling –Stop the offending instruction –Flush instructions following the offending instructions –Save the address of the offending instruction, and –Jump to a prearranged exception handler code

Pipeline Exceptions & ControlCSCE430/830 Pipelining Outline Introduction –Defining Pipelining –Pipelining Instructions Hazards –Structural hazards –Data Hazards –Control Hazards Exceptions Performance Controller implementation 

Pipeline Exceptions & ControlCSCE430/830 Pipelining in MIPS MIPS architecture was designed to be pipelined –Simple instruction format (makes IF, ID easy) »Single-word instructions »Small number of instruction formats »Common fields in same place (e.g., rs, rt) in different formats –Memory operations only in lw, sw instructions (simplifies EX) –Memory operands aligned in memory (simplifies MEM) –Single value for Write-Back (limits forwarding) Pipelining is harder in CISC architectures

Pipeline Exceptions & ControlCSCE430/830 Pipelined Datapath with Control Signals

Pipeline Exceptions & ControlCSCE430/830 Next Step: Adding Control Basic approach: build on single-cycle control –Place control unit in ID stage –Pass control signals to following stages Later: extra features to deal with: –Data forwarding –Stalls –Exceptions

Pipeline Exceptions & ControlCSCE430/830 Control for Pipelined Datapath RegDst ALUOp[1:0] ALUSrc MemRead MemWrite Branch RegWrite MemtoReg

Pipeline Exceptions & ControlCSCE430/830 Control for Pipelined Datapath

Pipeline Exceptions & ControlCSCE430/830 Datapath and Control Unit

Pipeline Exceptions & ControlCSCE430/830 Tracking Control Signals - Cycle 1 LW

Pipeline Exceptions & ControlCSCE430/830 Tracking Control Signals - Cycle 2 SWLW

Pipeline Exceptions & ControlCSCE430/830 Tracking Control Signals - Cycle 3 ADDSWLW

Pipeline Exceptions & ControlCSCE430/830 Tracking Control Signals - Cycle 4 SUBADD SW LW 1 0 0

Pipeline Exceptions & ControlCSCE430/ ADD Tracking Control Signals - Cycle 5 SUB SW LW

Pipeline Exceptions & ControlCSCE430/830 Class Exercise Consider the following code segment 1. LW R1, 0(R4) 2. LW R2, 0(R5) 3. ADD R3, R1, R2 4. BNZ R3, L 5. LW R4, 100(R1) 6. LW R5, 100(R2) 7. SUB R3, R4, R5 8.L: SW R3, 50(R1) Assuming that there is no forwarding, zero testing is being resolved during ID, and registers can be written in the first half of the WB cycle and also be read in the send half of the same WB cycle, Question: identify the resources of various hazards in the above code sequence.

Pipeline Exceptions & ControlCSCE430/830 Class Exercise Consider the following code segment 1. LW R1, 0(R4) 2. LW R2, 0(R5) 3. ADD R3, R1, R2 4. BNZ R3, L 5. LW R4, 100(R1) 6. LW R5, 100(R2) 7. SUB R3, R4, R5 8.L: SW R3, 50(R1) Assuming that there is no forwarding, zero testing is being resolved during ID, and registers can be written in the first of the WB cycle and also be read in the send half of the same WB cycle, Question: identify the resources of various hazards in the above code sequence.

Pipeline Exceptions & ControlCSCE430/830 Class Exercise Consider the following code segment 1. LW R1, 0(R4) 2. LW R2, 0(R5) 3. ADD R3, R1, R2 4. BNZ R3, L 5. LW R4, 100(R1) 6. LW R5, 100(R2) 7. SUB R3, R4, R5 8.L: SW R3, 50(R1) Use compiler techniques to reshuffle/rewrite the code (without changing the meaning of the program) as to minimize data hazards as far as possible. Assume that no other general purpose registers other than those used in the code, are available.

Pipeline Exceptions & ControlCSCE430/830 Class Exercise Consider the following code segment 1. LW R1, 0(R4) 2. LW R2, 0(R5) 3. ADD R3, R1, R2 4. BNZ R3, L 5. LW R4, 100(R1) 6. LW R5, 100(R2) 7. SUB R3, R4, R5 8.L: SW R3, 50(R1) Use compiler techniques to reshuffle/rewrite the code (without changing the meaning of the program) as to minimize data hazards as far as possible. Assume that no other general purpose registers other than those used in the code, are available. 1. LW R1, 0(R4) 2. LW R2, 0(R5) 3. LW R4, 100(R1) 4. LW R5, 100(R2) 5. ADD R3, R1, R2 6. BNZ R3, L 7. SUB R3, R4, R5 8.L: SW R3, 50(R1)