Chapter 4 The Processor CprE 381 Computer Organization and Assembly Level Programming, Fall 2013 Zhao Zhang Iowa State University Revised from original.

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.
Instruction-Level Parallelism compiler techniques and branch prediction prepared and Instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University March.
Pipelining and Control Hazards Oct
Advanced Pipelining Optimally Scheduling Code Optimally Programming Code Scheduling for Superscalars (6.9) Exceptions (5.6, 6.8)
EECC551 - Shaaban #1 Fall 2003 lec# Pipelining and Exploiting Instruction-Level Parallelism (ILP) Pipelining increases performance by overlapping.
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.
The Pipelined CPU Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Revised 9/22/2013.
1 Lecture 10: Static ILP Basics Topics: loop unrolling, static branch prediction, VLIW (Sections 4.1 – 4.4)
CPE432 Chapter 4C.1Dr. W. Abu-Sufah, UJ Chapter 4C: The Processor, Part C Read Section 4.10 Parallelism and Advanced Instruction-Level Parallelism Adapted.
Pipeline Hazards Pipeline hazards These are situations that inhibit that the next instruction can be processed in the next stage of the pipeline. This.
Instruction Level Parallelism Chapter 4: CS465. Instruction-Level Parallelism (ILP) Pipelining: executing multiple instructions in parallel To increase.
Chapter 4 CSF 2009 The processor: Instruction-Level Parallelism.
Real Processors Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 19 - Pipelined.
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania Computer Organization Pipelined Processor Design 3.
 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.
Lecture 15: Pipelining and Hazards CS 2011 Fall 2014, Dr. Rozier.
University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell CS352H: Computer Systems Architecture Topic 8: MIPS Pipelined.
Chapter 4 CSF 2009 The processor: Pipelining. Performance Issues Longest delay determines clock period – Critical path: load instruction – Instruction.
Instruction Level Parallelism Pipeline with data forwarding and accelerated branch Loop Unrolling Multiple Issue -- Multiple functional Units Static vs.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Chapter 6 Pipelined CPU Design. Spring 2005 ELEC 5200/6200 From Patterson/Hennessey Slides Pipelined operation – laundry analogy Text Fig. 6.1.
Superscalar - summary Superscalar machines have multiple functional units (FUs) eg 2 x integer ALU, 1 x FPU, 1 x branch, 1 x load/store Requires complex.
Branch Hazards and Static Branch Prediction Techniques
University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell CS352H: Computer Systems Architecture Topic 9: MIPS Pipeline.
COMPSYS 304 Computer Architecture Speculation & Branching Morning visitors - Paradise Bay, Bay of Islands.
Lecture 9. MIPS Processor Design – Pipelined Processor Design #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System.
LECTURE 10 Pipelining: Advanced ILP. EXCEPTIONS An exception, or interrupt, is an event other than regular transfers of control (branches, jumps, calls,
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.
Exceptions and Interrupts “Unexpected” events requiring change in flow of control – Different ISAs use the terms differently Exception – Arises within.
Use of Pipelining to Achieve CPI < 1
CS 352H: Computer Systems Architecture
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
Pipeline Architecture since 1985
Pipeline Implementation (4.6)
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers The Processor
Pipelining: Advanced ILP
The processor: Exceptions and Interrupts
Morgan Kaufmann Publishers The Processor
Chapter 4 The Processor Part 6
Morgan Kaufmann Publishers The Processor
Xiang Lian The University of Texas-Pan American
The processor: Pipelining and Branching
Computer Architecture
Morgan Kaufmann Publishers The Processor
Control unit extension for data hazards
Morgan Kaufmann Publishers The Processor
CSC3050 – Computer Architecture
The Processor (2/3) Chapter 4 (2/3)
Morgan Kaufmann Publishers The Processor
ECE 445 – Computer Organization
CSC3050 – Computer Architecture
Dynamic Hardware Prediction
Wackiness Algorithm A: Algorithm B:
Pipelined Datapath Lecture notes from MKP, H. H. Lee and S. Yalamanchili.
Lecture 5: Pipeline Wrap-up, Static ILP
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers The Processor
Presentation transcript:

Chapter 4 The Processor CprE 381 Computer Organization and Assembly Level Programming, Fall 2013 Zhao Zhang Iowa State University Revised from original slides provided by MKP

Week 11 Overview Dynamic branch prediction Exception handling Multi-issue pipeline Exam 2 review Chapter 1 — Computer Abstractions and Technology — 2

Announcements Exam 2 will be held on Monday Nov. 11 Open book, open notes Coverage: Ch. 4, The Processor Datapath and control MIPS pipeline Data hazards and forwarding Load-use hazard and pipeline stall Control hazards Exception handling Chapter 1 — Computer Abstractions and Technology — 3

Delayed Branch Delayed branch may remove the one-cycle stall The instruction right after the beq is executed no matter the branch is taken or not Alternatingly saying, the execution of beq is delayed by one cycle sub $10, $4, $8 beq $1, $3, 7 beq $1, $3, 7 => sub $10, $4, $8 and $12, $2, $5 and $12, $2, $5 Must find an independent instruction, otherwise May have to fill in a nop instruction, or Need two variants of beq, delayed and not delayed Chapter 1 — Computer Abstractions and Technology — 4

Chapter 4 — The Processor — 5 Branch Prediction We’ve actually studied one form of branch prediction Longer pipelines can’t readily determine branch outcome early Stall penalty becomes unacceptable Predict outcome of branch Only stall if prediction is wrong In MIPS pipeline Can predict branches not taken Fetch instruction after branch, with no delay

Chapter 4 — The Processor — 6 MIPS with Predict Not Taken Prediction correct Prediction incorrect

Chapter 4 — The Processor — 7 More-Realistic Branch Prediction Static branch prediction Based on typical branch behavior Example: loop and if-statement branches Predict backward branches taken Predict forward branches not taken Dynamic branch prediction Hardware measures actual branch behavior e.g., record recent history of each branch Assume future behavior will continue the trend When wrong, stall while re-fetching, and update history

Chapter 4 — The Processor — 8 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 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 2-Bit Predictor Only change prediction on two successive mispredictions

Chapter 4 — The Processor — 11 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 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

Chapter 4 — The Processor — 13 An Alternate Mechanism Vectored Interrupts Handler address determined by the cause Example: Undefined opcode:C Overflow:C …:C Instructions either Deal with the interrupt, or Jump to real handler

Chapter 4 — The Processor — 14 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 — 15 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 — 16 Pipeline with Exceptions

Chapter 4 — The Processor — 17 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 — 18 Exception Example Exception on add in 40sub $11, $2, $4 44and $12, $2, $5 48or $13, $2, $6 4Cadd $1, $2, $1 50slt $15, $6, $7 54lw $16, 50($7) … Handler sw $25, 1000($0) sw $26, 1004($0) …

Chapter 4 — The Processor — 19 Exception Example

Chapter 4 — The Processor — 20 Exception Example

Chapter 4 — The Processor — 21 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 — 22 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

Example Which exception should be recognized first in this sequence? add $1, $2, $1 # arithmetic overflow XXX $1, $2, $1 # undefined instruction sub $1, $2, $1 # hardware error Which exception should be report to the OS? i.e. with the offending instruction recorded in EPC Chapter 1 — Computer Abstractions and Technology — 23

Chapter 4 — The Processor — 24 Instruction-Level Parallelism (ILP) Pipelining: executing multiple instructions in parallel To increase ILP Deeper pipeline Less work per stage  shorter clock cycle Multiple issue Replicate pipeline stages  multiple pipelines Start multiple instructions per clock cycle CPI < 1, so use Instructions Per Cycle (IPC) E.g., 4GHz 4-way multiple-issue 16 BIPS, peak CPI = 0.25, peak IPC = 4 But dependencies reduce this in practice §4.10 Parallelism and Advanced Instruction Level Parallelism

Chapter 4 — The Processor — 25 Multiple Issue Static multiple issue Compiler groups instructions to be issued together Packages them into “issue slots” Compiler detects and avoids hazards Dynamic multiple issue CPU examines instruction stream and chooses instructions to issue each cycle Compiler can help by reordering instructions CPU resolves hazards using advanced techniques at runtime

Chapter 4 — The Processor — 26 Speculation “Guess” what to do with an instruction Start operation as soon as possible Check whether guess was right If so, complete the operation If not, roll-back and do the right thing Common to static and dynamic multiple issue Examples Speculate on branch outcome Roll back if path taken is different Speculate on load Roll back if location is updated

Chapter 4 — The Processor — 27 Compiler/Hardware Speculation Compiler can reorder instructions e.g., move load before branch Can include “fix-up” instructions to recover from incorrect guess Hardware can look ahead for instructions to execute Buffer results until it determines they are actually needed Flush buffers on incorrect speculation

Chapter 4 — The Processor — 28 Speculation and Exceptions What if exception occurs on a speculatively executed instruction? e.g., speculative load before null-pointer check Static speculation Can add ISA support for deferring exceptions Dynamic speculation Can buffer exceptions until instruction completion (which may not occur)

Chapter 4 — The Processor — 29 Static Multiple Issue Compiler groups instructions into “issue packets” Group of instructions that can be issued on a single cycle Determined by pipeline resources required Think of an issue packet as a very long instruction Specifies multiple concurrent operations  Very Long Instruction Word (VLIW)

Chapter 4 — The Processor — 30 Scheduling Static Multiple Issue Compiler must remove some/all hazards Reorder instructions into issue packets No dependencies with a packet Possibly some dependencies between packets Varies between ISAs; compiler must know! Pad with nop if necessary

Chapter 4 — The Processor — 31 MIPS with Static Dual Issue Two-issue packets One ALU/branch instruction One load/store instruction 64-bit aligned ALU/branch, then load/store Pad an unused instruction with nop AddressInstruction typePipeline Stages nALU/branchIFIDEXMEMWB n + 4Load/storeIFIDEXMEMWB n + 8ALU/branchIFIDEXMEMWB n + 12Load/storeIFIDEXMEMWB n + 16ALU/branchIFIDEXMEMWB n + 20Load/storeIFIDEXMEMWB

Chapter 4 — The Processor — 32 MIPS with Static Dual Issue

Chapter 4 — The Processor — 33 Hazards in the Dual-Issue MIPS More instructions executing in parallel EX data hazard Forwarding avoided stalls with single-issue Now can’t use ALU result in load/store in same packet add $t0, $s0, $s1 load $s2, 0($t0) Split into two packets, effectively a stall Load-use hazard Still one cycle use latency, but now two instructions More aggressive scheduling required

Chapter 4 — The Processor — 34 Scheduling Example Schedule this for dual-issue MIPS Loop: lw $t0, 0($s1) # $t0=array element addu $t0, $t0, $s2 # add scalar in $s2 sw $t0, 0($s1) # store result addi $s1, $s1,–4 # decrement pointer bne $s1, $zero, Loop # branch $s1!=0 ALU/branchLoad/storecycle Loop:noplw $t0, 0($s1)1 addi $s1, $s1,–4nop2 addu $t0, $t0, $s2nop3 bne $s1, $zero, Loopsw $t0, 4($s1)4 IPC = 5/4 = 1.25 (c.f. peak IPC = 2)

Chapter 4 — The Processor — 35 Loop Unrolling Replicate loop body to expose more parallelism Reduces loop-control overhead Use different registers per replication Called “register renaming” Avoid loop-carried “anti-dependencies” Store followed by a load of the same register Aka “name dependence” Reuse of a register name

Chapter 4 — The Processor — 36 Loop Unrolling Example IPC = 14/8 = 1.75 Closer to 2, but at cost of registers and code size ALU/branchLoad/storecycle Loop:addi $s1, $s1,–16lw $t0, 0($s1)1 noplw $t1, 12($s1)2 addu $t0, $t0, $s2lw $t2, 8($s1)3 addu $t1, $t1, $s2lw $t3, 4($s1)4 addu $t2, $t2, $s2sw $t0, 16($s1)5 addu $t3, $t4, $s2sw $t1, 12($s1)6 nopsw $t2, 8($s1)7 bne $s1, $zero, Loopsw $t3, 4($s1)8