ECE260: Fundamentals of Computer Engineering

Similar documents
Lecture Topics. Announcements. Today: Data and Control Hazards (P&H ) Next: continued. Exam #1 returned. Milestone #5 (due 2/27)

Processor (II) - pipelining. Hwansoo Han

The Processor (3) Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Pipelining Analogy. Pipelined laundry: overlapping execution. Parallelism improves performance. Four loads: Non-stop: Speedup = 8/3.5 = 2.3.

Pipeline Hazards. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 4 The Processor 1. Chapter 4B. The Processor

Full Datapath. Chapter 4 The Processor 2

zhandling Data Hazards The objectives of this module are to discuss how data hazards are handled in general and also in the MIPS architecture.

ECE473 Computer Architecture and Organization. Pipeline: Data Hazards

Pipelined datapath Staging data. CS2504, Spring'2007 Dimitris Nikolopoulos

CSEE 3827: Fundamentals of Computer Systems

Chapter 4. The Processor

COMPUTER ORGANIZATION AND DESIGN

COMPUTER ORGANIZATION AND DESIGN

Full Datapath. Chapter 4 The Processor 2

Department of Computer and IT Engineering University of Kurdistan. Computer Architecture Pipelining. By: Dr. Alireza Abdollahpouri

LECTURE 9. Pipeline Hazards

Outline Marquette University

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. 5 th. Edition. Chapter 4. The Processor

Lecture 3: The Processor (Chapter 4 of textbook) Chapter 4.1

ECE260: Fundamentals of Computer Engineering

Pipeline Data Hazards. Dealing With Data Hazards

EE557--FALL 1999 MIDTERM 1. Closed books, closed notes

ECS 154B Computer Architecture II Spring 2009

LECTURE 3: THE PROCESSOR

Chapter 4 The Processor 1. Chapter 4A. The Processor

Computer Architecture Computer Science & Engineering. Chapter 4. The Processor BK TP.HCM

Determined by ISA and compiler. We will examine two MIPS implementations. A simplified version A more realistic pipelined version

Thomas Polzer Institut für Technische Informatik

EIE/ENE 334 Microprocessors

ECE154A Introduction to Computer Architecture. Homework 4 solution

Chapter 4. The Processor

Chapter 4. The Processor

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

14:332:331 Pipelined Datapath

CENG 3420 Lecture 06: Pipeline

Chapter 4. The Processor

Chapter 6 Exercises with solutions

ECE Exam II - Solutions November 8 th, 2017

Computer Architecture Computer Science & Engineering. Chapter 4. The Processor BK TP.HCM

CS 251, Winter 2018, Assignment % of course mark

Chapter 4. The Processor

ELE 655 Microprocessor System Design

DEE 1053 Computer Organization Lecture 6: Pipelining

Design a MIPS Processor (2/2)

Chapter 4. The Processor. Jiang Jiang

ECE260: Fundamentals of Computer Engineering

CS 251, Winter 2019, Assignment % of course mark

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition. Chapter 4. The Processor

CS 2506 Computer Organization II Test 2. Do not start the test until instructed to do so! printed

COMP2611: Computer Organization. The Pipelined Processor

COSC121: Computer Systems. ISA and Performance

Pipelined Datapath. Reading. Sections Practice Problems: 1, 3, 8, 12

Pipelined Datapath. Reading. Sections Practice Problems: 1, 3, 8, 12 (2) Lecture notes from MKP, H. H. Lee and S.

Midnight Laundry. IC220 Set #19: Laundry, Co-dependency, and other Hazards of Modern (Architecture) Life. Return to Chapter 4

Unresolved data hazards. CS2504, Spring'2007 Dimitris Nikolopoulos

ECE Exam II - Solutions October 30 th, :35 pm 5:55pm

Processor Design Pipelined Processor (II) Hung-Wei Tseng

CS232 Final Exam May 5, 2001

CPE 335 Computer Organization. Basic MIPS Pipelining Part I

Pipelining. Ideal speedup is number of stages in the pipeline. Do we achieve this? 2. Improve performance by increasing instruction throughput ...

Data Hazards Compiler Scheduling Pipeline scheduling or instruction scheduling: Compiler generates code to eliminate hazard

Instruction word R0 R1 R2 R3 R4 R5 R6 R8 R12 R31

The Processor. Z. Jerry Shi Department of Computer Science and Engineering University of Connecticut. CSE3666: Introduction to Computer Architecture

Pipelining. Pipeline performance

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

PS Midterm 2. Pipelining

EE2011 Computer Organization Lecture 10: Enhancing Performance with Pipelining ~ Pipelined Datapath

Perfect Student CS 343 Final Exam May 19, 2011 Student ID: 9999 Exam ID: 9636 Instructions Use pencil, if you have one. For multiple choice

Pipelining. CSC Friday, November 6, 2015

Comp 303 Computer Architecture A Pipelined Datapath Control. Lecture 13

ECEC 355: Pipelining

Designing a Pipelined CPU

ECE260: Fundamentals of Computer Engineering

Pipelining. lecture 15. MIPS data path and control 3. Five stages of a MIPS (CPU) instruction. - factory assembly line (Henry Ford years ago)

Outline. A pipelined datapath Pipelined control Data hazards and forwarding Data hazards and stalls Branch (control) hazards Exception

TDT4255 Friday the 21st of October. Real world examples of pipelining? How does pipelining influence instruction

Lecture 4: Review of MIPS. Instruction formats, impl. of control and datapath, pipelined impl.

CS/CoE 1541 Exam 1 (Spring 2019).

1 Hazards COMP2611 Fall 2015 Pipelined Processor

Question 1: (20 points) For this question, refer to the following pipeline architecture.

高雄大學資訊工程系計算機組織期末考. and (MEM/WB.RegRd=ID/EX.RegRt))

Virtual memory. Hung-Wei Tseng

Lecture 8: Data Hazard and Resolution. James C. Hoe Department of ECE Carnegie Mellon University

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

Chapter 4. Instruction Execution. Introduction. CPU Overview. Multiplexers. Chapter 4 The Processor 1. The Processor.

Chapter Six. Dataı access. Reg. Instructionı. fetch. Dataı. Reg. access. Dataı. Reg. access. Dataı. Instructionı fetch. 2 ns 2 ns 2 ns 2 ns 2 ns

CS232 Final Exam May 5, 2001

Chapter 4 (Part II) Sequential Laundry

3/12/2014. Single Cycle (Review) CSE 2021: Computer Organization. Single Cycle with Jump. Multi-Cycle Implementation. Why Multi-Cycle?

University of Jordan Computer Engineering Department CPE439: Computer Design Lab

Computer and Information Sciences College / Computer Science Department Enhancing Performance with Pipelining

Virtual memory. Hung-Wei Tseng

ECE331: Hardware Organization and Design

ECE 552 / CPS 550 Advanced Computer Architecture I. Lecture 6 Pipelining Part 1

Lecture 9. Pipeline Hazards. Christos Kozyrakis Stanford University

Improve performance by increasing instruction throughput

CS 2506 Computer Organization II Test 2

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

CS3350B Computer Architecture Quiz 3 March 15, 2018

Transcription:

Data Hazards in a Pipelined Datapath James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy

Data Hazards in ALU Instructions Next instruction needs to wait for previous instruction to complete its data read/write A data dependency exists between the result of one instruction and the next Extremely common! Consider the following sequence: sub $2, $1, $3 and $12, $2, $5 or $13, $6, $2 add $14, $2, $2 sw $15, 100($2) the and instruction requires $2 as input the sub instruction will not yet have executed WB stage to write result Register file will contain stale data for $2 when and requests it the or instruction has a similar issue Data hazards can be resolved with forwarding Need a way to determine when forwarding should happen Need a hardware support to enable forwarding 2

Data Hazards in ALU Instructions (continued) A multi-cycle pipeline diagram illustrates the data dependencies Red lines in the diagram cannot be satisfied without pipeline stalls or forwarding support Green lines need no extra hardware support or pipeline stalls required 3

Dependencies & Forwarding Desired data is available at end of EX stage during clock cycle 3 Desired behavior is shown as green lines on the multi-cycle pipeline diagram Forward data from output registers of EX and MEM stages to input of ALU Forward data to either input of ALU (maybe even both) No need to forward from WB stage 4

Detecting the Need to Forward Must pass register numbers along pipeline and store in pipeline registers Register numbers for Rs and Rt are passed from ID stage to EX stage Register number for Rd is passed through entire pipeline Were already passing this value down pipeline anyway to store result of instruction in register file In MEM and WB, the Rd field may have come from the Rt field of the instruction (recall that the I-Type instructions use the Rt field as their destination register!) New notation is used to identify register numbers at different stages of pipeline ID/EX.RegisterRs = the register number for the Rs register that is stored in the ID/EX register ID/EX.RegisterRt = the register number for the Rt register that is stored in the ID/EX register EX/MEM.RegisterRd = the register number for the Rd register that is stored in the EX/MEM register MEM/WB.RegisterRd = the register number for the Rd register that is stored in the EX/MEM register 5

Detecting the Need to Forward (continued) Data hazards might exist when: 1a. EX/MEM.RegisterRd = ID/EX.RegisterRs Maybe forward data from EX/MEM pipeline register to 1 st input of ALU 1b. EX/MEM.RegisterRd = ID/EX.RegisterRt Maybe forward data from EX/MEM pipeline register to 2 nd input of ALU 2a. MEM/WB.RegisterRd = ID/EX.RegisterRs Maybe forward data from MEM/WB pipeline register to 1 st input of ALU 2b. MEM/WB.RegisterRd = ID/EX.RegisterRt Maybe forward data from MEM/WB pipeline register to 2 nd input of ALU Not all instructions write the Rd register, so forwarding may not be necessary Example: the sw instruction does not write the register file 6

Detecting the Need to Forward (continued) Only forward data if the forwarding instruction will write to the register file Check the control signals that are in the pipeline to determine if instruction will write pipeline If the RegWrite control signal is asserted for an instruction: it will write the register file during the WB stage forward data from EX/MEM or MEM/WB as needed Do NOT forward data if the destination register Rd is register $0! Recall that register $0 ($zero) is read-only Setting $0 as a destination register will not actually write the register file 7

Forwarding Paths NOTE: Forwarding unit can pass EX/MEM.RegisterRd to either input of the ALU NOTE 2: Forwarding unit can pass MEM/WB.RegisterRd to either input of the ALU NOTE 3: The EX/MEM.RegisterRd field can come from either ID/EX.RegisterRd OR from ID/EX.RegisterRt NOTE 4: The forwarding unit simply compares the Rd field at the MEM and WB stages to the ALU input registers in the EX stage 8

Forwarding Conditions EX hazard: Forward EX/MEM.RegisterRd to ALU input 1 MEM hazard: Forward MEM/WB.RegisterRd to ALU input 1 if (EX/MEM.RegWrite and (EX/MEM.RegisterRd 0) and (EX/MEM.RegisterRd = ID/EX.RegisterRs)) ForwardA = 10 if (MEM/WB.RegWrite and (MEM/WB.RegisterRd 0) and (MEM/WB.RegisterRd = ID/EX.RegisterRs)) ForwardA = 01 Forward EX/MEM.RegisterRd to ALU input 2 if (EX/MEM.RegWrite and (EX/MEM.RegisterRd 0) and (EX/MEM.RegisterRd = ID/EX.RegisterRt)) ForwardB = 10 Forward MEM/WB.RegisterRd to ALU input 2 if (MEM/WB.RegWrite and (MEM/WB.RegisterRd 0) and (MEM/WB.RegisterRd = ID/EX.RegisterRt)) ForwardB = 01 9

Double Data Hazard (seriously?) Consider the sequence: add $1, $1, $2 add $1, $1, $3 add $1, $1, $4 Both hazards occur when the third add instruction is in the EX stage Forwarding conditions suggest that data should be forward from EX/MEM stage Forwarding conditions ALSO suggest that data should be forward from MEM/WB stage Can t forward data to ALU input two different places Definitely want to use the most recent result (i.e. the result in the EX/MEM register) Revise MEM hazard condition, only forward if EX hazard condition isn t true i.e. forwarding from EX/MEM takes precedence over forwarding from MEM/WB 10

Revised Forwarding Conditions EX hazard: (same as before) MEM hazard: Forward MEM/WB.RegisterRd to ALU input 1 if (MEM/WB.RegWrite and (MEM/WB.RegisterRd 0) and not (EX/MEM.RegWrite and (EX/MEM.RegisterRd 0) and (EX/MEM.RegisterRd = ID/EX.RegisterRs)) and (MEM/WB.RegisterRd = ID/EX.RegisterRs)) ForwardA = 01 Forward MEM/WB.RegisterRd to ALU input 2 Addition to MEM forwarding rule is shown in blue Additional basically says, And NOT forwarding from EX/MEM if (MEM/WB.RegWrite and (MEM/WB.RegisterRd 0) and not (EX/MEM.RegWrite and (EX/MEM.RegisterRd 0) and (EX/MEM.RegisterRd = ID/EX.RegisterRt)) and (MEM/WB.RegisterRd = ID/EX.RegisterRt)) ForwardB = 01 11

Datapath Showing Forwarding Components NOTE: This datapath does NOT show all the components of the datapath, just the additions made for forwarding 12

Load-Use Data Hazard Forwarding works very well in many cases, but not all Consider when a lw instruction precedes an instruction that uses the value being loaded Cannot forward data backwards in time!!! Loaded data is not available in MEM/WB until AFTER the next instruction needs it Need to stall for one clock cycle Example code: lw $2, 20($1) and $4, $2, $5 or $8, $2, $6 add $9, $4, $2 slt $1, $6, $7 13

Detecting a Load-Use Hazard Load-use hazard occurs under following condition: Instruction is a load instruction as indicated by the MemRead control signal Next instruction specifies a source operand register that is being written by the load instruction ID/EX.MemRead and ((ID/EX.RegisterRt = IF/ID.RegisterRs) or (ID/EX.RegisterRt = IF/ID.RegisterRt)) Check for hazard when using instruction is decoded in the ID stage Is there a load in the EX stage that is loading a source operand register? If load-use hazard is detected, stall the pipeline and insert a bubble 14

How to Stall the Pipeline Force control line values in ID/EX register to 0 Effectively results in a nop (no-operation) in the EX, MEM and WB stages (i.e. a bubble) Prevent update of PC and IF/ID register Contents of PC and IF/ID will not change for that clock cycle that the pipeline is stalled Using instruction is decoded again since it still exists in the IF/ID register Instruction after the using instruction is fetched again (a second time) A 1-cycle stall allows MEM stage to read data for the lw instruction Can subsequently forward data to the EX stage for the using instruction 15

Stalling the Pipeline (Inserting a Bubble) Example code: lw $2, 20($1) and $4, $2, $5 or $8, $2, $6 add $9, $4, $2 slt $1, $6, $7 Load-use hazard detected at clock cycle 3 when and instruction is decoded Rs register for and instruction requires result of previous lw instruction Stall pipeline at clock cycle 4 to insert nop Loaded data can then be forward to and instruction (green line) 16

Stalling the Pipeline (Inserting a Bubble) (continued) Example code: lw $2, 20($1) and $4, $2, $5 or $8, $2, $6 add $9, $4, $2 slt $1, $6, $7 Slightly more accurate depiction shows: and instruction is fetched at CC2, decoded at CC3, then decoded AGAIN in CC4 or instruction is fetched in CC3 and then fetched AGAIN in CC4 17

Datapath with Hazard Detection NOTE: Hazard detection unit detects load-use hazards NOTE: PCWrite is used to prevent PC from being written when pipeline is stalled NOTE: IF/IDWrite is used to prevent PC from being written when pipeline is stalled 18