ECE473 Computer Architecture and Organization. Pipeline: Data Hazards

Similar documents
ECE260: Fundamentals of Computer Engineering

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

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

Processor (II) - pipelining. Hwansoo Han

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

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

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

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

Full Datapath. Chapter 4 The Processor 2

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

Outline Marquette University

CSEE 3827: Fundamentals of Computer Systems

Chapter 4. The Processor

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

COMPUTER ORGANIZATION AND DESIGN

Design a MIPS Processor (2/2)

ECS 154B Computer Architecture II Spring 2009

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

COMPUTER ORGANIZATION AND DESIGN

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

Full Datapath. Chapter 4 The Processor 2

LECTURE 9. Pipeline Hazards

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

Thomas Polzer Institut für Technische Informatik

ECE154A Introduction to Computer Architecture. Homework 4 solution

DEE 1053 Computer Organization Lecture 6: Pipelining

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

LECTURE 3: THE PROCESSOR

ELE 655 Microprocessor System Design

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

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

Chapter 4. The Processor

Pipeline Data Hazards. Dealing With Data Hazards

DLX Unpipelined Implementation

ECE473 Computer Architecture and Organization. Pipeline: Control Hazard

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

EIE/ENE 334 Microprocessors

Chapter 4. The Processor

CENG 3420 Lecture 06: Pipeline

Chapter 4. The Processor

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

14:332:331 Pipelined Datapath

CS 251, Winter 2018, Assignment % of course mark

Chapter 4. The Processor

CS/CoE 1541 Exam 1 (Spring 2019).

CPE 335 Computer Organization. Basic MIPS Pipelining Part I

ECE232: Hardware Organization and Design

COSC121: Computer Systems. ISA and Performance

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

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

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

Chapter 6 Exercises with solutions

Chapter 4. The Processor. Jiang Jiang

University of Jordan Computer Engineering Department CPE439: Computer Design Lab

ECE260: Fundamentals of Computer Engineering

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

CS 251, Winter 2019, Assignment % of course mark

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

ECE331: Hardware Organization and Design

Computer Organization and Structure

(Basic) Processor Pipeline

ECE Exam II - Solutions November 8 th, 2017

Lecture 9. Pipeline Hazards. Christos Kozyrakis Stanford University

CISC 662 Graduate Computer Architecture Lecture 6 - Hazards

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

Basic Instruction Timings. Pipelining 1. How long would it take to execute the following sequence of instructions?

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

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

Instruction Pipelining

ECE/CS 552: Pipeline Hazards

MIPS An ISA for Pipelining

Computer Architecture

The Processor Pipeline. Chapter 4, Patterson and Hennessy, 4ed. Section 5.3, 5.4: J P Hayes.

Chapter 4 (Part II) Sequential Laundry

Instruction Level Parallelism. Appendix C and Chapter 3, HP5e

ECEC 355: Pipelining

Pipeline Overview. Dr. Jiang Li. Adapted from the slides provided by the authors. Jiang Li, Ph.D. Department of Computer Science

Very Simple MIPS Implementation

COSC 6385 Computer Architecture - Pipelining

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

Very Simple MIPS Implementation

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

Designing a Pipelined CPU

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

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

Pipelining. Maurizio Palesi

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

RISC Pipeline. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter 4.6

Pipelining. Pipeline performance

ECE331: Hardware Organization and Design

CS2100 Computer Organisation Tutorial #10: Pipelining Answers to Selected Questions

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier

Lecture 05: Pipelining: Basic/ Intermediate Concepts and Implementation

Pipelining: Hazards Ver. Jan 14, 2014

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

Lecture 3. Pipelining. Dr. Soner Onder CS 4431 Michigan Technological University 9/23/2009 1

Codeword[1] Codeword[0]

Instruction Pipelining

MIPS Pipelining. Computer Organization Architectures for Embedded Computing. Wednesday 8 October 14

Transcription:

Computer Architecture and Organization Pipeline: Data Hazards Lecturer: Prof. Yifeng Zhu Fall, 2015 Portions of these slides are derived from: Dave Patterson UCB Lec 14.1

Pipelining Outline Introduction Defining Pipelining Pipelining Instructions Hazards Structural hazards Data Hazards \ Control Hazards Performance Controller implementation Lec 14.2

Data Hazard Review Three types of data hazards RAW (MIPS) WAW (not in MIPS) WAR (not in MIPS) Forwarding Lec 14.3

Review: Data Hazards & Forwarding SUB $s0, $t0, $t1 ;$s0 = $t0 - $t1 ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 SUB ADD 1 2 3 4 5 6 EX Hazard: SUB result not written until its WB, ready at end of its EX, needed at start of ADD s EX EX/MEM Forwarding: forward $s0 from EX/MEM to ALU input in ADD EX stage (CC4) Note: can occur in sequential instructions Lec 14.4

Review: Data Hazards & Forwarding SUB $s0, $t0, $t1 ;$s0 = $t0 - $t1 ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 1 2 3 4 5 6 SUB ADD EX Hazard Detection - EX/MEM Forwarding Conditions: If ((EX/MEM.RegWrite = 1) & (EX/MEM.RegRD = ID/EX.RegRS)) If ((EX/MEM.RegWrite = 1) & (EX/MEM.RegRD = ID/EX.RegRT)) Then forward EX/MEM result to EX stage Note: In PH3, also check that EX/MEM.RegRD 0 Lec 14.5

Review: Data Hazards & Forwarding SUB ADD OR SUB $s0, $t4, $s3 ;$s0 = $t4 + $s3 ADD $t2, $s1, $t1 ;$t2 = $s0 + $t1 OR $s2, $t3, $s0 ;$s2 = $t3 OR $s0 1 2 3 4 5 6 MEM Hazard: SUB result not written until its WB, stored in MEM/WB, needed at start of OR s EX MEM/WB Forwarding: forward $s0 from MEM/WB to ALU input in OR EX stage (CC5) Note: can occur in instructions I n, I n+2 Lec 14.6

Review: Data Hazards & Forwarding SUB $s0, $t4, $s3 ;$s0 = $t4 + $s3 ADD $t2, $s1, $t1 ;$t2 = $s0 + $t1 OR $s2, $t3, $s0 ;$s2 = $t3 OR $s0 1 2 3 4 5 6 SUB ADD OR MEM Hazard Detection - MEM/WB Forwarding Conditions: If ((MEM/WB.RegWrite = 1) & (MEM/WB.RegRD = ID/EX.RegRS)) If ((EX/MEM.RegWrite = 1) & (EX/MEM.RegRD = ID/EX.RegRT)) Then forward MEM/WB result to EX stage Note: In PH3, also check that MEM/WB.RegRD 0 Lec 14.7

Forwarding How to implement forwarding? Lec 14.8

Forwarding Lec 14.9

Forwarding 00 01 10 00 01 10 Add hardware to feed back ALU and MEM results to both ALU inputs Lec 14.10

Read after Write Data Hazard Detection in MIPS Time (in clock cycles) Value of register $2: Program execution order (in instructions) sub $2, $1, $3 CC 1 CC 2 CC 3 CC 4 CC 5 CC 6 IM Reg CC 7 CC 8 CC 9 10 10 10 10 10/ 20 20 20 20 20 IF/ID ID/EX EX/MEM MEM/WB DM Reg and $12, $2, $5 IM Reg DM Reg or $13, $6, $2 IM Reg DM Reg add $14, $2, $2 IM Reg DM Reg sw $15, 100($2) IM Reg DM Reg 1a: EX/MEM.RegisterRd = ID/EX.RegisterRs 1b: EX/MEM.RegisterRd = ID/EX.RegisterRt 2a: MEM/WB.RegisterRd = ID/EX.RegisterRs 2b: MEM/WB.RegisterRd = ID/EX.RegisterRt Problem? Some instructions does not write register. EX/MEM.RegWrite must be asserted! EX hazard MEM hazard Lec 14.11

Controlling Forwarding Need to test when register numbers match in rs, rt, and rd fields stored in pipeline registers "EX" hazard: EX/MEM - test whether instruction writes register file and examine rd register ID/EX - test whether instruction reads rs or rt register and matches rd register in EX/MEM "MEM" hazard: MEM/WB - test whether instruction writes register file and examine rd (rt) register ID/EX - test whether instruction reads rs or rt register and matches rd (rt) register in EX/MEM Lec 14.12

Forwarding Unit Detail - EX Hazard if (EX/MEM.RegWrite) and (EX/MEM.RegisterRd 0) and (EX/MEM.RegisterRd = ID/EX.RegisterRs)) ForwardA = 10 if (EX/MEM.RegWrite) and (EX/MEM.RegisterRd 0) and (EX/MEM.RegisterRd = ID/EX.RegisterRt)) ForwardB = 10 Lec 14.13

Forwarding Unit Detail - MEM Hazard if (MEM/WB.RegWrite) and (MEM/WB.RegisterRd 0) and (MEM/WB.RegisterRd = ID/EX.RegisterRs)) ForwardA = 01 if (MEM/WB.RegWrite) and (MEM/WB.RegisterRd 0) and (MEM/WB.RegisterRd = ID/EX.RegisterRt)) ForwardB = 01 Lec 14.14

Forwarding Unit Detail - MEM Hazard Add $1, $1, $2 Add $1, $1, $3 Add $1, $1, $4 Lec 14.15

Forwarding Unit Detail - MEM Hazard if (MEM/WB.RegWrite) and (MEM/WB.RegisterRd 0) and (MEM/WB.RegisterRd = ID/EX.RegisterRs) and (EX/MEM.RegisterRd ID/EX.RegisterRs)) ForwardA = 01 if (MEM/WB.RegWrite) and (MEM/WB.RegisterRd 0) and (MEM/WB.RegisterRd = ID/EX.RegisterRt) and (EX/MEM.RegisterRd ID/EX.RegisterRt)) ForwardB = 01 Lec 14.16

Data Hazards and Stalls So far, we ve only addressed potential data hazards, in that the forwarding unit was able to detect and resolve them without affecting the performance of the pipeline. There are also true data hazards, which the forwarding unit cannot resolve, and whose resolution does affect pipeline performance. We thus add a (true) hazard detection unit, which detects them and introduces stalls to resolve them. Lec 14.17

Data Hazards & Stalls Identify the true data hazard in this sequence: LW $s0, 100($t0) ;$s0 = memory value ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 1 2 3 4 5 6 LW ADD Lec 14.18

Data Hazards & Stalls Identify the true data hazard in this sequence: LW $s0, 100($t0) ;$s0 = memory value ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 1 2 3 4 5 6 LW ADD LW doesn t write $s0 to Reg File until the end of CC5, but ADD reads $s0 from Reg File in CC3 Lec 14.19

Data Hazards & Stalls LW $s0, 100($t0) ;$s0 = memory value ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 1 2 3 4 5 6 LW ADD EX/MEM forwarding won t work, because the data isn t loaded from memory until CC4 (so it s not in EX/MEM register) Lec 14.20

Data Hazards & Stalls LW $s0, 100($t0) ;$s0 = memory value ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 1 2 3 4 5 6 LW ADD MEM/WB forwarding won t work either, because ADD executes in CC4 Lec 14.21

Data Hazards & Stalls: implementation LW $s0, 100($t0) ;$s0 = memory value ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 1 2 3 4 5 6 LW ADD IF bubble ID EX MEM WB We must handle this hazard by stalling the pipeline for 1 Clock Cycle (bubble) Lec 14.22

Data Hazards & Stalls: implementation LW $s0, 100($t0) ;$s0 = memory value ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 1 2 3 4 5 6 LW ADD IF bubble ID EX MEM WB We can then use MEM/WB forwarding, but of course there is still a performance loss Lec 14.23

Data Hazards & Stalls: implementation Stall Implementation #1: Compiler detects hazard and inserts a NOP (no reg changes (SLL $0, $0, 0)) LW $s0, 100($t0) ;$s0 = memory value NOP ;dummy instruction ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 1 2 3 4 5 6 LW NOP ADD bubble bubble bubble bubble bubble Problem: we have to rely on the compiler Lec 14.24

Data Hazards & Stalls: implementation Stall Implementation #2: Add a hazard detection unit to stall current instruction for 1 CC if: ID-Stage Hazard Detection and Stall Condition: If ((ID/EX.MemRead = 1) & ;only a LW reads mem ((ID/EX.RegRT = IF/ID.RegRS) ;RS will read load dest (RT) (ID/EX.RegRT = IF/ID.RegRT))) ;RT will read load dest LW $s0, 100($t0) ;$s0 = memory value ADD $t2, $s0, $t3 ;$t2 = $s0 + $t3 LW ADD Lec 14.25

Data Hazards & Stalls: implementation The effect of this stall will be to repeat the ID Stage of the current instruction. Then we do the MEM/WB forwarding on the next Clock Cycle LW ADD IF ID ID EX MEM WB We do this by preserving the current values in IF/ID for use on the next Clock Cycle Lec 14.26

Data Hazards: Class Example Identify the data dependencies in the following code. Which of them can be resolved through forwarding? SUB $2, $1, $3 OR $12, $2, $5 SW $13, 100($2) ADD $14, $2, $2 LW $15, 100($2) ADD $4, $7, $15 Lec 14.27

Data Hazards Reordering Instructions Assuming we have data forwarding, what are the hazards in this code? lw $t0, 0($t1) lw $t2, 4($t1) sw $t2, 0($t1) sw $t0, 4($t1) Reorder instructions to remove hazard: lw $t0, 0($t1) lw $t2, 4($t1) sw $t0, 4($t1) sw $t2, 0($t1) Lec 14.28

Data Hazard Summary Three types of data hazards RAW (MIPS) WAW (not in MIPS) WAR (not in MIPS) Solution to RAW in MIPS Stall Forwarding» Detection & Control EX hazard MEM hazard» A stall is needed if read a register after a load instruction that writes the same register. Reordering Lec 14.29

Pipelining Outline Next class Introduction Defining Pipelining Pipelining Instructions Hazards Structural hazards Data Hazards Control Hazards \ Performance Lec 14.30