The processor: Pipelining and Branching

Slides:



Advertisements
Similar presentations
Morgan Kaufmann Publishers The Processor
Advertisements

Chapter 4 The Processor. Chapter 4 — The Processor — 2 The Main Control Unit Control signals derived from instruction 0rsrtrdshamtfunct 31:265:025:2120:1615:1110:6.
Pipelining and Control Hazards Oct
COMP 4211 Seminar Presentation Based On: Computer Architecture A Quantitative Approach by Hennessey and Patterson Presenter : Feri Danes.
Pipeline Computer Organization II 1 Hazards Situations that prevent starting the next instruction in the next cycle Structural hazards – A required resource.
Lecture Objectives: 1)Define pipelining 2)Calculate the speedup achieved by pipelining for a given number of instructions. 3)Define how pipelining improves.
Chapter 4 The Processor CprE 381 Computer Organization and Assembly Level Programming, Fall 2013 Zhao Zhang Iowa State University Revised from original.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
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.
1  2004 Morgan Kaufmann Publishers Chapter Six. 2  2004 Morgan Kaufmann Publishers Pipelining The laundry analogy.
1 Chapter Six - 2nd Half Pipelined Processor Forwarding, Hazards, Branching EE3055 Web:
1 Stalling  The easiest solution is to stall the pipeline  We could delay the AND instruction by introducing a one-cycle delay into the pipeline, sometimes.
Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
 The actual result $1 - $3 is computed in clock cycle 3, before it’s needed in cycles 4 and 5  We forward that value to later instructions, to prevent.
Pipelined Datapath and Control (Lecture #15) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Chapter 6 Pipelined CPU Design. Spring 2005 ELEC 5200/6200 From Patterson/Hennessey Slides Pipelined operation – laundry analogy Text Fig. 6.1.
Winter 2002CSE Topic Branch Hazards in the Pipelined Processor.
University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell CS352H: Computer Systems Architecture Topic 9: MIPS Pipeline.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 13: Branch prediction (Chapter 4/6)
CMPE 421 Parallel Computer Architecture Part 3: Hardware Solution: Control Hazard and Prediction.
PROCESSOR PIPELINING YASSER MOHAMMAD. SINGLE DATAPATH DESIGN.
LECTURE 10 Pipelining: Advanced ILP. EXCEPTIONS An exception, or interrupt, is an event other than regular transfers of control (branches, jumps, calls,
Exceptions and Interrupts “Unexpected” events requiring change in flow of control – Different ISAs use the terms differently Exception – Arises within.
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.
Morgan Kaufmann Publishers The Processor Dr. Hussein Al-Zoubi
Morgan Kaufmann Publishers
Morgan Kaufmann Publishers The Processor
Instructor: Justin Hsia
Single Clock Datapath With Control
Pipeline Implementation (4.6)
Morgan Kaufmann Publishers The Processor
Chapter 4 The Processor Part 4
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers The Processor
Pipelining: Advanced ILP
Chapter 4 The Processor Part 3
Morgan Kaufmann Publishers The Processor
Peng Liu Lecture 9 Pipeline Peng Liu
The processor: Exceptions and Interrupts
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers The Processor
Pipelining review.
Xiang Lian The University of Texas-Pan American
Morgan Kaufmann Publishers Enhancing Performance with Pipelining
Lecture 9. MIPS Processor Design – Pipelined Processor Design #2
Morgan Kaufmann Publishers The Processor
Lecture 5. MIPS Processor Design
The Processor Lecture 3.6: Control Hazards
Control unit extension for data hazards
Morgan Kaufmann Publishers The Processor
CS203 – Advanced Computer Architecture
CSC3050 – Computer Architecture
The Processor (2/3) Chapter 4 (2/3)
Morgan Kaufmann Publishers The Processor
ECE 445 – Computer Organization
Control Hazards Branches (conditional, unconditional, call-return)
Pipelining (II).
Morgan Kaufmann Publishers The Processor
Wackiness Algorithm A: Algorithm B:
Control unit extension for data hazards
Pipelined Datapath Lecture notes from MKP, H. H. Lee and S. Yalamanchili.
Interrupts and exceptions
Morgan Kaufmann Publishers The Processor
ELEC / Computer Architecture and Design Spring 2015 Pipeline Control and Performance (Chapter 6) Vishwani D. Agrawal James J. Danaher.
Morgan Kaufmann Publishers The Processor
Presentation transcript:

The processor: Pipelining and Branching Morgan Kaufmann Publishers 17 November, 2018 CSF 2009 The processor: Pipelining and Branching Chapter 4 Chapter 4 — The Processor 1

Morgan Kaufmann Publishers 17 November, 2018 Branch Hazards If branch outcome determined in MEM Flush these instructions (Set control values to 0) PC Chapter 4 — The Processor — 2 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Reducing Branch Delay Move hardware to determine outcome to ID stage Target address adder Register comparator Example: branch taken 36: sub $10, $4, $8 40: beq $1, $3, 7 44: and $12, $2, $5 48: or $13, $2, $6 52: add $14, $4, $2 56: slt $15, $6, $7 ... 72: lw $4, 50($7) Chapter 4 — The Processor — 3 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Example: Branch Taken Chapter 4 — The Processor — 4 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Example: Branch Taken Chapter 4 — The Processor — 5 Chapter 4 — The Processor

Data Hazards for Branches Morgan Kaufmann Publishers 17 November, 2018 Data Hazards for Branches If a comparison register is a destination of 2nd or 3rd preceding ALU instruction IF ID EX MEM WB add $1, $2, $3 IF ID EX MEM WB add $4, $5, $6 IF ID EX MEM WB … IF ID EX MEM WB beq $1, $4, target Can resolve using forwarding Chapter 4 — The Processor — 6 Chapter 4 — The Processor

Data Hazards for Branches Morgan Kaufmann Publishers 17 November, 2018 Data Hazards for Branches If a comparison register is a destination of preceding ALU instruction or 2nd preceding load instruction Need 1 stall cycle IF ID EX MEM WB lw $1, addr IF ID EX MEM WB add $4, $5, $6 beq stalled IF ID beq $1, $4, target ID EX MEM WB Chapter 4 — The Processor — 7 Chapter 4 — The Processor

Data Hazards for Branches Morgan Kaufmann Publishers 17 November, 2018 Data Hazards for Branches If a comparison register is a destination of immediately preceding load instruction Need 2 stall cycles IF ID EX MEM WB lw $1, addr beq stalled IF ID beq stalled ID beq $1, $0, target ID EX MEM WB Chapter 4 — The Processor — 8 Chapter 4 — The Processor

Dynamic Branch Prediction Morgan Kaufmann Publishers 17 November, 2018 Dynamic Branch Prediction In deeper and superscalar pipelines, branch penalty is more significant Use dynamic prediction Branch prediction buffer (aka branch history table) Indexed by recent branch instruction 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 prediction Chapter 4 — The Processor — 9 Chapter 4 — The Processor

1-Bit Predictor: Shortcoming Morgan Kaufmann Publishers 17 November, 2018 1-Bit Predictor: Shortcoming Inner loop branches mispredicted twice! outer: … … inner: … … beq …, …, inner … beq …, …, outer Mispredict as taken on last iteration of inner loop Then mispredict as not taken on first iteration of inner loop next time around Chapter 4 — The Processor — 10 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 2-Bit Predictor Only change prediction on two successive mispredictions Chapter 4 — The Processor — 11 Chapter 4 — The Processor

Calculating the Branch Target Morgan Kaufmann Publishers 17 November, 2018 Calculating the Branch Target Even with predictor, still need to calculate the target address 1-cycle penalty for a taken branch Branch target buffer Cache of target addresses Indexed by PC when instruction fetched If hit and instruction is branch predicted taken, can fetch target immediately Chapter 4 — The Processor — 12 Chapter 4 — The Processor

The processor: Exceptions and Interrupts Morgan Kaufmann Publishers 17 November, 2018 CSF 2009 The processor: Exceptions and Interrupts Chapter 4 Chapter 4 — The Processor 13

Exceptions and Interrupts Morgan Kaufmann Publishers 17 November, 2018 Exceptions and Interrupts “Unexpected” events requiring change in flow of control Different ISAs use the terms differently Exception 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 Chapter 4 — The Processor — 14 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Handling Exceptions In MIPS, exceptions managed by a System Control Coprocessor (CP0) Save PC of offending (or interrupted) instruction In MIPS: Exception Program Counter (EPC) Save indication of the problem In MIPS: Cause register We’ll assume 1-bit 0 for undefined opcode, 1 for overflow Jump to handler at 8000 00180 Chapter 4 — The Processor — 15 Chapter 4 — The Processor

An Alternate Mechanism Morgan Kaufmann Publishers 17 November, 2018 An Alternate Mechanism Vectored Interrupts Handler address determined by the cause Example: Undefined opcode: C000 0000 Overflow: C000 0020 …: C000 0040 Instructions either Deal with the interrupt, or Jump to real handler Chapter 4 — The Processor — 16 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Handler Actions Read cause, and transfer to relevant handler Determine action required If restartable Take corrective action use EPC to return to program Otherwise Terminate program Report error using EPC, cause, … Chapter 4 — The Processor — 17 Chapter 4 — The Processor

Exceptions in a Pipeline Morgan Kaufmann Publishers 17 November, 2018 Exceptions 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 instructions Flush add and subsequent instructions Set Cause and EPC register values Transfer control to handler Similar to mispredicted branch Use much of the same hardware Chapter 4 — The Processor — 18 Chapter 4 — The Processor

Pipeline with Exceptions Morgan Kaufmann Publishers 17 November, 2018 Pipeline with Exceptions Chapter 4 — The Processor — 19 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Exception Properties Restartable exceptions Pipeline can flush the instruction Handler executes, then returns to the instruction Refetched and executed from scratch PC saved in EPC register Identifies causing instruction Actually PC + 4 is saved Handler must adjust Chapter 4 — The Processor — 20 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Exception Example Exception 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) … Chapter 4 — The Processor — 21 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Exception Example Chapter 4 — The Processor — 22 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Exception Example Chapter 4 — The Processor — 23 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Multiple Exceptions Pipelining overlaps multiple instructions Could have multiple exceptions at once Simple approach: deal with exception from earliest instruction Flush subsequent instructions “Precise” exceptions In complex pipelines Multiple instructions issued per cycle Out-of-order completion Maintaining precise exceptions is difficult! Chapter 4 — The Processor — 24 Chapter 4 — The Processor

Morgan Kaufmann Publishers 17 November, 2018 Imprecise Exceptions Just stop pipeline and save state Including exception cause(s) Let the handler work out Which instruction(s) had exceptions Which to complete or flush May require “manual” completion Simplifies hardware, but more complex handler software Not feasible for complex multiple-issue out-of-order pipelines Chapter 4 — The Processor — 25 Chapter 4 — The Processor