The Processor Lecture 3.6: Control Hazards

Slides:



Advertisements
Similar presentations
Morgan Kaufmann Publishers The Processor
Advertisements

Pipeline Control Hazards: Detection and Circumvention Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly.
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 ( )
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
CS 152 L12 RAW Hazards, Interrrupts (1)Fall 2004 © UC Regents CS152 – Computer Architecture and Engineering Lecture 12 – Pipeline Wrap up: Control Hazards,
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.
Computer ArchitectureFall 2007 © October 24nd, 2007 Majd F. Sakr CS-447– Computer Architecture.
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.
ENGS 116 Lecture 51 Pipelining and Hazards Vincent H. Berk September 30, 2005 Reading for today: Chapter A.1 – A.3, article: Patterson&Ditzel Reading for.
1 Stalls and flushes  So far, we have discussed data hazards that can occur in pipelined CPUs if some instructions depend upon others that are still executing.
Chapter 4B: The Processor, Part B. Review: Why Pipeline? For Performance! I n s t r. O r d e r Time (clock cycles) Inst 0 Inst 1 Inst 2 Inst 4 Inst 3.
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.
CSE 340 Computer Architecture Summer 2014 Basic MIPS Pipelining Review.
CS.305 Computer Architecture Enhancing Performance with Pipelining Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from.
CMPE 421 Parallel Computer Architecture
Computer Architecture and Design – ELEN 350 Part 8 [Some slides adapted from M. Irwin, D. Paterson. D. Garcia and others]
CMPE 421 Parallel Computer Architecture Part 2: Hardware Solution: Forwarding.
CECS 440 Pipelining.1(c) 2014 – R. W. Allison [slides adapted from D. Patterson slides with additional credits to M.J. Irwin]
CSIE30300 Computer Architecture Unit 04: Basic MIPS Pipelining Hsin-Chou Chi [Adapted from material by and
CSE431 L07 Overcoming Data Hazards.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 07: Overcoming Data Hazards Mary Jane Irwin (
CSIE30300 Computer Architecture Unit 05: Overcoming Data Hazards Hsin-Chou Chi [Adapted from material by and
CSE431 L06 Basic MIPS Pipelining.1Irwin, PSU, 2005 MIPS Pipeline Datapath Modifications  What do we need to add/modify in our MIPS datapath? l State registers.
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.
CSIE30300 Computer Architecture Unit 06: Containing Control Hazards
Designing a Pipelined Processor
CPE432 Chapter 4B.1Dr. W. Abu-Sufah, UJ Chapter 4B: The Processor, Part B-1 Read Sections 4.7 Adapted from Slides by Prof. Mary Jane Irwin, Penn State.
CSE 340 Computer Architecture Spring 2016 Overcoming Data Hazards.
Computer Organization
Exceptions Another form of control hazard Could be caused by…
Stalling delays the entire pipeline
Mary Jane Irwin ( ) [Adapted from Computer Organization and Design,
CDA 3101 Spring 2016 Introduction to Computer Organization
Lecture 08: Control Hazards
Single Clock Datapath With Control
Appendix C Pipeline implementation
Chapter 4 The Processor Part 4
ECS 154B Computer Architecture II Spring 2009
ECS 154B Computer Architecture II Spring 2009
ECE232: Hardware Organization and Design
Processor Design: Pipeline Handling Hazards
Chapter 4 The Processor Part 3
Review: MIPS Pipeline Data and Control Paths
Morgan Kaufmann Publishers The Processor
Peng Liu Lecture 9 Pipeline Peng Liu
Morgan Kaufmann Publishers The Processor
EI 209 Computer Organization Fall 2017
Pipelining review.
Pipelining Chapter 6.
Pipelining in more detail
Data Hazards Data Hazard
Pipeline control unit (highly abstracted)
The Processor Lecture 3.4: Pipelining Datapath and Control
The Processor Lecture 3.5: Data Hazards
Instruction Execution Cycle
Pipeline control unit (highly abstracted)
CSC3050 – Computer Architecture
Pipeline Control unit (highly abstracted)
Pipelining (II).
Control unit extension for data hazards
Introduction to Computer Organization and Architecture
Control unit extension for data hazards
Pipelining - 1.
Stalls and flushes Last time, we discussed data hazards that can occur in pipelined CPUs if some instructions depend upon others that are still executing.
MIPS Pipelined Datapath
ELEC / Computer Architecture and Design Spring 2015 Pipeline Control and Performance (Chapter 6) Vishwani D. Agrawal James J. Danaher.
Presentation transcript:

The Processor Lecture 3.6: Control Hazards Be aware that this first part of new chapter 4 is review for this class, so doesn’t go into detail. If your students are learning computer organization for the first time, this set of slides needs to be expanded greatly.

Learning Objectives Move branch decision hardware into the decode stage Resolve data hazards for branch instruction

Coverage Chapter 4.8

MIPS Pipeline Control Path Modifications 1 The width of each pipeline registers. IF/ID: 32+32=64 bits ID/EX:32*4+5*2+9=147 bits EX/MEM: 32*3+5+5+1=107 bits MEM/WB: 32*2+5+2=71 bits.

Control Hazards When the flow of instruction addresses is not sequential (i.e., PC ≠ PC + 4); incurred by change of flow instructions Unconditional branches (j, jal, jr) Conditional branches (beq, bne) Exceptions Possible approaches Stall (impacts CPI) Move decision point as early in the pipeline as possible, thereby reducing the number of stall cycles Predict and hope for the best! Delay decision (requires compiler support) Control hazards occur less frequently than data hazards, but there is nothing as effective against control hazards as forwarding is for data hazards

Branch Instr’s Cause Control Hazards Dependencies backward in time cause hazards beq ALU IM Reg DM I n s t r. O r d e ALU IM Reg DM lw ALU IM Reg DM Inst 3 ALU IM Reg DM Inst 4

One Way to “Fix” a Branch Control Hazard Fix branch hazard by waiting – flush – but affects CPI ALU IM Reg DM beq I n s t r. O r d e ALU IM Reg DM flush ALU IM Reg DM flush ALU IM Reg DM flush beq target ALU IM Reg DM Inst

Another Way to “Fix” a Branch Control Hazard Move branch decision hardware as early in the pipeline as possible, i.e., during the decode cycle ALU IM Reg DM beq I n s t r. O r d e ALU IM Reg DM flush beq target ALU IM Reg DM Inst Another “solution” is to put in enough extra hardware so that we can test registers, calculate the branch address, and update the PC during the second stage of the pipeline. That would reduce the number of stalls to only one.

Reducing the Delay of Branches Add hardware to compute the branch target address and evaluate the branch decision to the ID stage Reduces the number of stall (flush) cycles to one (like with jumps) But now need to add forwarding hardware in ID stage Comparing and updating the PC adds 2 muxes, a comparator, and an and gate to the ID stage Computing branch target address can be done in parallel with RegFile read (done for all instructions – only used when needed) Comparing the registers can be done in the same clock cycle as RegFile read For deeper pipelines, branch decision points can be even later in the pipeline, incurring more stalls Want a small branch penalty. Need more forwarding and hazard detection hardware for second option (one stall implementation) since a branch depended on a result still in the pipeline (that is one of the source operands for the comparison logic) must be forwarded from the EX/MEM or MEM/WB pipeline latches.

Supporting ID Stage Branches PCSrc Branch Hazard Unit ID/EX IF.Flush 1 EX/MEM IF/ID Control Add MEM/WB 4 Shift left 2 Add Compare Read Addr 1 Instruction Memory Data Memory RegFile Read Addr 2 Read Address PC Read Data 1 Read Data Write Addr ALU Address ReadData 2 Write Data Write Data ALU cntrl Now IF.Flush is generated by the Hazard Unit for both jumps and for taken branches. Book claims that you have to forward from the MEM/WB pipeline latch, but with RegFile write before read, I don’t think that is the case!! No need to forward from MEM/WB pipeline register. IF.Flush will change the value of the IF/ID to zero to flush the instruction The write signals to PC, IF/ID, and the multiplexor to change the value before the ID/EX pipeline register is to stall the Branch instruction itself. 16 Sign Extend 32 Forward Unit Forward Unit

Example: Branch Taken Example 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 ... 68: add $1, $2, $3 72: lw $4, 50($7) 76: and $3, $1, $2

Example: Branch Taken

Example: Branch Taken 72 should be 48. 48 is latched into the pipeline register.

Data Hazards for Branches If a comparison register is a destination of 2nd preceding ALU instruction Can resolve using forwarding IF ID EX MEM WB add $1, $2, $3 IF ID EX MEM WB add $4, $5, $6 IF ID EX MEM WB Inst 3 Which is forwarding, which is not forwarding? $4 is forwarding, $1 does not need forwarding. IF ID EX MEM WB beq $1, $4, target

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 Again, $4 needs forwarding, $1 does not need forwarding beq $1, $4, target ID EX MEM WB

Data Hazards for Branches If a comparison register is a destination of immediately preceding load instruction Need 2 stall cycles But no data forwarding IF ID EX MEM WB lw $1, addr beq stalled IF ID beq stalled ID No forwarding is needed. beq $1, $0, target ID EX MEM WB