Chapter 7 Digital Design and Computer Architecture, 2 nd Edition Chapter 7 David Money Harris and Sarah L. Harris.

Slides:



Advertisements
Similar presentations
COMP541 Datapath & Single-Cycle MIPS
Advertisements

1 Chapter Five The Processor: Datapath and Control.
The Processor: Datapath & Control
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
©UCB CS 162 Computer Architecture Lecture 3: Pipelining Contd. Instructor: L.N. Bhuyan
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.
331 Lec 14.1Fall 2002 Review: Abstract Implementation View  Split memory (Harvard) model - single cycle operation  Simplified to contain only the instructions:
Computer Structure - Datapath and Control Goal: Design a Datapath  We will design the datapath of a processor that includes a subset of the MIPS instruction.
Copyright 1998 Morgan Kaufmann Publishers, Inc. All rights reserved. Digital Architectures1 Machine instructions execution steps (1) FETCH = Read the instruction.
The Processor: Datapath & Control. Implementing Instructions Simplified instruction set memory-reference instructions: lw, sw arithmetic-logical instructions:
Dr. Iyad F. Jafar Basic MIPS Architecture: Multi-Cycle Datapath and Control.
Chapter 4 Sections 4.1 – 4.4 Appendix D.1 and D.2 Dr. Iyad F. Jafar Basic MIPS Architecture: Single-Cycle Datapath and Control.
COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections
1 Pipelining Reconsider the data path we just did Each instruction takes from 3 to 5 clock cycles However, there are parts of hardware that are idle many.
Lecture 9. MIPS Processor Design – Instruction Fetch Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education &
Automobile Manufacturing 1. Build frame. 60 min. 2. Add engine. 50 min. 3. Build body. 80 min. 4. Paint. 40 min. 5. Finish.45 min. 275 min. Latency: Time.
Lec 15Systems Architecture1 Systems Architecture Lecture 15: A Simple Implementation of MIPS Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
1 COMP541 Multicycle MIPS Montek Singh Apr 4, 2012.
COMP541 Multicycle MIPS Montek Singh Apr 8, 2015.
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
COMP541 Datapaths II & Single-Cycle MIPS
CDA 3101 Fall 2013 Introduction to Computer Organization
1 COMP541 Pipelined MIPS Montek Singh Mar 30, 2010.
Computer Architecture and Design – ECEN 350 Part 6 [Some slides adapted from A. Sprintson, M. Irwin, D. Paterson and others]
1 A single-cycle MIPS processor  An instruction set architecture is an interface that defines the hardware operations which are available to software.
1 COMP541 Datapaths II & Control I Montek Singh Mar 22, 2010.
Another Example: MIPS From the Harris/Weste book Based on the MIPS-like processor from the Hennessy/Patterson book.
COMP541 Multicycle MIPS Montek Singh Mar 25, 2010.
1 COMP541 Pipelined MIPS Montek Singh Apr 9, 2012.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Datapath and Control AddressInstruction Memory Write Data Reg Addr Register File ALU Data Memory Address Write Data Read Data PC Read Data Read Data.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
1 Chapter 5: Datapath and Control (Part 2) CS 447 Jason Bakos.
Lecture 9. MIPS Processor Design – Single-Cycle Processor Design Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System.
Chapter 4 From: Dr. Iyad F. Jafar Basic MIPS Architecture: Multi-Cycle Datapath and Control.
Pipelining: Implementation CPSC 252 Computer Organization Ellen Walker, Hiram College.
Lecture 5. MIPS Processor Design
Computer Architecture Lecture 6.  Our implementation of the MIPS is simplified memory-reference instructions: lw, sw arithmetic-logical instructions:
Chapter 7 Digital Design and Computer Architecture, 2 nd Edition Chapter 7 David Money Harris and Sarah L. Harris.
Chapter 7 :: Microarchitecture
Microarchitecture.
CS161 – Design and Architecture of Computer Systems
Electrical and Computer Engineering University of Cyprus
Computer Organization
Exceptions Another form of control hazard Could be caused by…
IT 251 Computer Organization and Architecture
Morgan Kaufmann Publishers
Performance of Single-cycle Design
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
MIPS processor continued
Chapter 7 Digital Design and Computer Architecture, 2nd Edition
Morgan Kaufmann Publishers The Processor
Single-Cycle CPU DataPath.
Lecture 9. MIPS Processor Design – Pipelined Processor Design #2
Rocky K. C. Chang 6 November 2017
Lecture 5. MIPS Processor Design
The Processor Lecture 3.2: Building a Datapath with Control
Lecture 9. MIPS Processor Design – Decoding and Execution
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
COMP541 Datapaths I Montek Singh Mar 18, 2010.
Chapter Four The Processor: Datapath and Control
The Processor: Datapath & Control.
COMS 361 Computer Organization
Processor: Datapath and Control
ELEC / Computer Architecture and Design Spring 2015 Pipeline Control and Performance (Chapter 6) Vishwani D. Agrawal James J. Danaher.
Presentation transcript:

Chapter 7 Digital Design and Computer Architecture, 2 nd Edition Chapter 7 David Money Harris and Sarah L. Harris

Chapter 7 Chapter 7 :: Topics Introduction Performance Analysis Single-Cycle Processor Pipelined Processor Exceptions Advanced Microarchitecture

Chapter 7 Microarchitecture: the implementation of an architecture in hardware Processor: – Datapath: functional blocks – Control: control signals Introduction

Chapter 7 Multiple implementations for a single architecture: – Single-cycle: Each instruction executes in a single cycle – Multicycle: Instructions are broken into series of shorter steps Each instruction executes in n cycles, where n varys according to the instr. – Pipelined: Each instruction broken up into series of steps & multiple instructions execute at once (Note: AMD and Intel pipelines are different, for the same IA-32 architecture (a.k.a. x86 ISA) Microarchitecture

Chapter 7 Program execution time Execution Time = (#instructions)(cycles/instruction)(seconds/cycle) Definitions: – IC: Instruction Count (= #instructions) – CPI: Cycles/Instruction – clock period: seconds/cycle – IPC: Instructions/Cycle (= 1/CPI) Challenge is to satisfy constraints of: – Cost – Power – Performance Processor Performance

Chapter 7 Consider subset of MIPS instructions: – R-type instructions: and, or, add, sub, slt – Memory instructions: lw, sw – Branch instructions: beq MIPS Processor

Chapter 7 Determines everything about a processor: – PC and special registers – Register File – Memory Architectural State

Chapter 7 MIPS State Elements Plus the HI and LO registers

Chapter 7 Datapath—design it 1 st, to make the instruction actions possible Control—design it 2 nd, to make them happen Single-Cycle MIPS Processor

Chapter 7 STEP 1: Fetch instruction IM[PC] Single-Cycle Datapath: lw fetch

Chapter 7 STEP 2: Read source operands from RF RF[rs] or RF[Instr(25:21)] Single-Cycle Datapath: lw Register Read

Chapter 7 STEP 3: Sign-extend the immediate SignExt(immed) Single-Cycle Datapath: lw Immediate

Chapter 7 STEP 4: Compute the memory address addr = RF[rs] + SignExt(immed) Single-Cycle Datapath: lw address

Chapter 7 STEP 5: Read data from memory and write it back to register file: RF[rt]  DM[addr] Single-Cycle Datapath: lw Memory Read

Chapter 7 STEP 6: Determine address of next instruction PC  PC + 4 Single-Cycle Datapath: lw PC Increment

Chapter 7 IM[PC] RF[rt]  DM[RF[rs] + SignExt(immed)] PC  PC + 4 Full RTL Expression for lw

Chapter 7 Write data in rt to memory: DM[addr]  RF[rt] Single-Cycle Datapath: sw

Chapter 7 Read from rs and rt Write ALUResult to register file Write to rd (instead of rt ) RF[rd]  RF[rs] op RF[rt] Single-Cycle Datapath: R-Type

Chapter 7 Determine whether values in rs and rt are equal Calculate branch target address: BTA = PC SignExt(immed)<< 2 # <<2 = 4x Single-Cycle Datapath: beq

Chapter 7 IM[PC] if (RF[rs] - RF[rt] == 0) PC  BTA else PC  PC + 4 RTL Expression for beq

Chapter 7 Single-Cycle Processor

Chapter 7 Single-Cycle Control

Chapter 7 F 2:0 Function 000A & B 001A | B 010A + B 011not used 100A & ~B 101A | ~B 110A - B 111SLT Review: ALU

Chapter 7 Review: ALU

Chapter 7 ALUOp 1:0 Meaning 00Add (for lw, sw) 01Subtract (for beq) 10Look at funct (R-type) 11Not Used ALUOp 1:0 functALUControl 2:0 00X010 (Add) X1X110 (Subtract) 1X ( add ) 010 (Add) 1X ( sub ) 110 (Subtract) 1X ( and ) 000 (And) 1X ( or ) 001 (Or) 1X ( slt ) 111 (SLT) Control Unit: ALU Decoder

Chapter 7 InstructionOp 5:0 RegWriteRegDstAluSrcBranchMemWriteMemtoRegALUOp 1:0 R-type lw sw beq Control Unit: Main Decoder

Chapter 7 InstructionOp 5:0 RegWriteRegDstAluSrcBranchMemWriteMemtoRegALUOp 1:0 R-type lw sw X101X00 beq X010X01 Control Unit: Main Decoder

Chapter 7 Single-Cycle Datapath: or

Chapter 7 No change to datapath Extended Functionality: addi

Chapter 7 InstructionOp 5:0 RegWriteRegDstAluSrcBranchMemWriteMemtoRegALUOp 1:0 R-type lw sw X101X00 beq X010X01 addi Main Decoder table: addi

Chapter 7 InstructionOp 5:0 RegWriteRegDstAluSrcBranchMemWriteMemtoRegALUOp 1:0 R-type lw sw X101X00 beq X010X01 addi Main Decoder table: addi

Chapter 7 Extended Functionality: j

Chapter 7 InstructionOp 5:0 RegWriteRegDstAluSrcBranchMemWriteMemtoRegALUOp 1:0 Jump R-type lw sw X101X000 beq X010X010 j Main Decoder table: j

Chapter 7 InstructionOp 5:0 RegWriteRegDstAluSrcBranchMemWriteMemtoRegALUOp 1:0 Jump R-type lw sw X101X000 beq X010X010 j XXX0XXX1 Main Decoder table: j

Chapter 7 Program Execution Time = (#instructions)(cycles/instruction)(seconds/cycle) = IC x CPI x T C Review: Processor Performance

Chapter 7 T C limited by critical path ( lw ) Single-Cycle Performance

Chapter 7 Single-cycle critical path: T c = t pcq_PC + t mem + max(t RFread, t sext + t mux ) + t ALU + t mem + t mux + t RFsetup Typically, limiting paths are: –memory, ALU, register file –T c = t pcq_PC + 2t mem + t RFread + t mux + t ALU + t RFsetup Single-Cycle Performance

Chapter 7 ElementParameterDelay (ps) Register clock-to-Qt pcq_PC 30 Register setupt setup 20 Multiplexert mux 25 ALUt ALU 200 Memory readt mem 250 Register file readt RFread 150 Register file setupt RFsetup 20 T c = ? Single-Cycle Performance Example

Chapter 7 ElementParameterDelay (ps) Register clock-to-Qt pcq_PC 30 Register setupt setup 20 Multiplexert mux 25 ALUt ALU 200 Memory readt mem 250 Register file readt RFread 150 Register file setupt RFsetup 20 T c = t pcq_PC + 2t mem + t RFread + t mux + t ALU + t RFsetup = [30 + 2(250) ] ps = 925 ps [f clk = 1/0.925 GHz = 1.08 GHz] Single-Cycle Performance Example

Chapter 7 Program with IC = 100 billion instructions: Execution Time = IC x CPI x T C = (100 × 10 9 )(1)(925 × s) = 92.5 seconds Single-Cycle Performance Example

Chapter 7 Pros and cons of single-cycle implementation: + simple design + 1 cycle per every instruction - slow cycle time limited by longest instruction ( lw ) - HW: 2 adders + ALU; 2 memories Evaluation of Single-Cycle Processor

Chapter 7 Review: Single-Cycle Processor

Chapter 7 // // 9 November 2005 // Top level system including MIPS and memories // module top (input clk, reset, output [31:0] writedata, dataadr, output memwrite); wire [31:0] pc, instr, readdata; // instantiate processor and memories mips mips (clk, reset, pc, instr, memwrite, dataadr, writedata, readdata); imem imem (pc[7:2], instr); dmem dmem (clk, memwrite, dataadr, writedata, readdata); endmodule Verilog Model

Chapter 7 // // 23 October 2005 // External data memory used by MIPS single-cycle processor // module dmem (input clk, we, input [31:0] a, wd, output [31:0] rd); reg [31:0] RAM[63:0]; assign rd = RAM[a[31:2]]; // word-aligned read clk) if (we) RAM[a[31:2]] <= wd; // word-aligned write endmodule Verilog Model of Data Memory

Chapter 7 module imem (input [5:0] addr, output reg [31:0] instr); // imem is modeled as a lookup table, a stored-program byte-addressable ROM case ({addr, 2'b00}) //address instruction // 'h00: instr = 32'h ; 8'h04: instr = 32'h c; 8'h08: instr = 32'h2067fff7; 8'h0c: instr = 32'h00e22025; 8'h10: instr = 32'h ; 8'h14: instr = 32'h00a42820; 8'h18: instr = 32'h10a7000a; 8'h1c: instr = 32'h a; 8'h20: instr = 32'h ; default: instr = {32{1'bx}};// unknown instruction endcase endmodule Verilog Model of Instr. Memory

Chapter 7 module imem (input [5:0] addr, output [31:0] instr); reg [31:0] RAM[63:0]; // imem is RAM, loaded from memfile.dat file with hex values at startup initial begin $readmemh("memfile.dat", RAM); end assign instr = RAM[addr]; // instr at RAM[addr] is read out endmodule // imem can be created with CoreGen for Xilinx synthesis Alternate Model of Instr. Memory

Chapter 7 // single-cycle MIPS processor module mips (input clk, reset, output [31:0] pc, input [31:0] instr, output memwrite, output [31:0] aluout, writedata, input [31:0] readdata); wire memtoreg, pcsrc, zero, alusrc, regdst, regwrite, jump; wire [2:0] alucontrol; controller c (instr[31:26], instr[5:0], zero, memtoreg, memwrite, pcsrc, alusrc, regdst, regwrite, jump, alucontrol); datapath dp (clk, reset, memtoreg, pcsrc, alusrc, regdst, regwrite, jump, alucontrol, zero, pc, instr, aluout, writedata, readdata); endmodule Verilog Model of MIPS Processor

Chapter 7 module controller ( input [5:0] op, funct, input zero, output memtoreg, memwrite, output pcsrc, alusrc, output regdst, regwrite, output jump, output [2:0] alucontrol); wire [1:0] aluop; wire branch; maindec md (op, regwrite, regdst, alusrc, branch, memwrite, memtoreg, aluop, jump); aludec ad (funct, aluop, alucontrol); assign pcsrc = branch & zero; endmodule Verilog Model of Controller

Chapter 7 module maindec (input [5:0] op, output regwrite, regdst, alusrc, branch, output memwrite, memtoreg, output [1:0] aluop, output jump); reg [8:0] controls; assign {regwrite, regdst, alusrc, branch, memwrite, memtoreg, aluop, jump} = controls; case(op) 6'b000000: controls = 9'b ; //Rtype 6'b100011: controls = 9'b ; //LW 6'b101011: controls = 9'b ; //SW 6'b000100: controls = 9'b ; //BEQ 6'b001000: controls = 9'b ; //ADDI 6'b000010: controls = 9'b ; //J default: controls = 9'bxxxxxxxxx; //??? endcase endmodule Verilog Model of Main Decoder

Chapter 7 module aludec (input [5:0] funct, input [1:0] aluop, output reg [2:0] alucontrol); case(aluop) 2'b00: alucontrol = 3'b010; // add 2'b01: alucontrol = 3'b110; // sub default: case(funct) // RTYPE 6'b100000: alucontrol = 3'b010; // ADD 6'b100010: alucontrol = 3'b110; // SUB 6'b100100: alucontrol = 3'b000; // AND 6'b100101: alucontrol = 3'b001; // OR 6'b101010: alucontrol = 3'b111; // SLT default: alucontrol = 3'bxxx; // ??? endcase endmodule Verilog Model of ALU Decoder

Chapter 7 module datapath (input clk, reset, memtoreg, pcsrc, alusrc, regdst, input regwrite, jump, input [2:0] alucontrol, output zero, output [31:0] pc, input [31:0] instr, output [31:0] aluout, writedata, input [31:0] readdata); wire [4:0] writereg; wire [31:0] pcnext, pcnextbr, pcplus4, pcbranch; wire [31:0] signimm, signimmsh, srca, srcb, result; // next PC logic flopr #(32) pcreg(clk, reset, pcnext, pc); adder pcadd1(pc, 32'b100, pcplus4); sl2 immsh(signimm, signimmsh); adder pcadd2(pcplus4, signimmsh, pcbranch); mux2 #(32) pcbrmux(pcplus4, pcbranch, pcsrc, pcnextbr); mux2 #(32) pcmux(pcnextbr, {pcplus4[31:28], instr[25:0], 2'b00}, jump, pcnext); Verilog Model of Datapath

Chapter 7 // register file logic regfile rf (clk, regwrite, instr[25:21], instr[20:16], writereg, result, srca, writedata); mux2 #(5) wrmux (instr[20:16], instr[15:11], regdst, writereg); mux2 #(32) resmux (aluout, readdata, memtoreg, result); signext se (instr[15:0], signimm); // ALU logic mux2 #(32) srcbmux (writedata, signimm, alusrc, srcb); alu alu (srca, srcb, alucontrol, aluout, zero); endmodule Verilog Model of Datapath (con’t)

Chapter 7 module regfile (input clk, we3, input [4:0] ra1, ra2, wa3, input [31:0] wd3, output [31:0] rd1, rd2); reg [31:0] rf [31:0]; // three ported register file: read two ports combinationally // write third port on rising edge of clock. Register 0 hardwired to 0 clk) if (we3) rf [wa3] <= wd3; assign rd1 = (ra1 != 0) ? rf [ra1] : 0; assign rd2 = (ra2 != 0) ? rf[ ra2] : 0; endmodule Verilog Model of Register File

Chapter 7 module adder (input [31:0] a, b, output [31:0] y); assign y = a + b; endmodule module sl2 (input [31:0] a, output [31:0] y); // shift left by 2 assign y = {a[29:0], 2'b00}; endmodule module signext (input [15:0] a, output [31:0] y); assign y = {{16{a[15]}}, a}; endmodule Verilog Models of Other Parts

Chapter 7 module flopr #(parameter WIDTH = 8) (input clk, reset, input [WIDTH-1:0] d, output reg [WIDTH-1:0] q); clk, posedge reset) if (reset) q <= 0; else q <= d; endmodule module flopenr #(parameter WIDTH = 8) (input clk, reset, en, input [WIDTH-1:0] d, output reg [WIDTH-1:0] q); clk, posedge reset) if (reset) q <= 0; else if (en) q <= d; endmodule module mux2 #(parameter WIDTH = 8) (input [WIDTH-1:0] d0, d1, input s, output [WIDTH-1:0] y); assign y = s ? d1 : d0; endmodule Verilog for Parameterized Parts

Chapter 7 Unscheduled function call to exception handler Caused by: –Hardware, also called an interrupt, e.g. keyboard –Software, also called traps, e.g. undefined instruction When exception occurs, the processor: –Records cause of exception ( Cause register) –Jumps to exception handler (0x ) –Returns to program ( EPC register) Review: Exceptions

Chapter 7 Example Exception

Chapter 7 Not part of register file; in Coprocessor 0 – Cause Records cause of exception Coprocessor 0 register 13 – EPC (Exception PC) Records PC where exception occurred Coprocessor 0 register 14 Move from Coprocessor 0 – mfc0 $t0, Cause (=mfc0 $t0,$13) – Moves contents of Cause into $t0 Review: Exception Registers

Chapter 7 ExceptionCause Hardware Interrupt0x System Call0x Breakpoint / Divide by 00x Undefined Instruction0x Arithmetic Overflow0x Extend single-cycle MIPS processor to handle last two types of exceptions Review: Exception Causes

Chapter 7 Exception RTLs Undefined Instruction IM[PC]...# problem in decoding (bad op or func ) Cause  40 # = 0x28 EPC  PC PC  0x #Exception handler address Arithmetic Overflow IM[PC]...# ALU operation overflows Cause  48 # = 0x30 EPC  PC PC  0x #Exception handler address mfc0 instruction (e.g. mfc0 $t1, $13 ) IM[PC] RF[rt]  RFc0[rd] PC  PC + 4

Chapter 7 Exception Hardware: EPC & Cause Never mind the multi-cycle datapath, focus on the exception hardware.

Chapter 7 Exception Hardware: mfc0 Never mind the multi-cycle datapath, focus on the exception hardware.

Chapter 7 Temporal parallelism Divide single-cycle processor into 5 stages: –Fetch –Decode –Execute –Memory –Writeback Add pipeline registers between stages Pipelined MIPS Processor

Chapter 7 Single-Cycle vs. Pipelined

Chapter 7 Pipelined Processor Abstraction

Chapter 7 Single-Cycle & Pipelined Datapath

Chapter 7 WriteReg must arrive at same time as Result Corrected Pipelined Datapath

Chapter 7 Same control unit as single-cycle processor Control delayed to proper pipeline stage Pipelined Processor Control

Chapter 7 When an instruction depends on result from instruction that hasn’t completed Types: – Data hazard: register value not yet written back to register file – Control hazard: next instruction not decided yet (caused by branches) or target address not calculated yet (jumps and branches) Pipeline Hazards

Chapter 7 Data Hazard

Chapter 7 2 SW fixes Insert nop s in code at compile time Rearrange code at compile time 2 HW fixes Stall the processor at run time Forward data at run time Handling Data Hazards

Chapter 7 Insert enough nop s for result to be ready Or move independent useful instructions forward Compile-Time Hazard Elimination

Chapter 7 Data Forwarding

Chapter 7 Data Forwarding

Chapter 7 Forward to Execute stage from either: – Memory stage or – Writeback stage Forwarding logic for ForwardAE: if ((rsE != 0) AND (rsE == WriteRegM) AND RegWriteM) then ForwardAE = 10 else if ((rsE != 0) AND (rsE == WriteRegW) AND RegWriteW) then ForwardAE = 01 elseForwardAE = 00 Forwarding logic for ForwardBE same, but replace rsE with rtE Data Forwarding

Chapter 7 Stalling Forwarding on a load-use hazard isn’t possible!

Chapter 7 Stalling The HW solution is to stall the pipeline

Chapter 7 Stalling Hardware

Chapter 7 lwstall = ((rsD==rtE) OR (rtD==rtE)) AND MemtoRegE StallF = StallD = FlushE = lwstall By flushing the Execute stage, and stalling Fetch and Decode stages, the instruction flushed will simply be repeated in then next clock cycle, but this time with correct (forwarded) data! Stalling Logic

Chapter 7 beq : – branch not determined until 4 th stage of pipeline – Instructions after the branch are fetched before the branch occurs – These instructions must be flushed if branch happens Branch misprediction penalty – the # of instruction flushed, when branch is taken – may be reduced by determining branch earlier Control Hazards

Chapter 7 Control Hazards: Original Pipeline

Chapter 7 Control Hazards

Chapter 7 But: introduced another data hazard in Decode stage! Early Branch Resolution

Chapter 7 Early Branch Resolution

Chapter 7 Forwarding to Early-branch HW

Chapter 7 Forwarding logic: ForwardAD = (rsD !=0) AND (rsD == WriteRegM) AND RegWriteM ForwardBD = (rtD !=0) AND (rtD == WriteRegM) AND RegWriteM Stalling logic: branchstall = BranchD AND RegWriteE AND (WriteRegE == rsD OR WriteRegE == rtD) OR BranchD AND MemtoRegM AND (WriteRegM == rsD OR WriteRegM == rtD) StallF = StallD = FlushE = (lwstall OR branchstall) Control Forwarding & Stalling Logic

Chapter 7 Guess whether branch will be taken – Backward branches are usually taken (in bottom- tested loops) – Consider history to improve guess Good prediction significantly reduces fraction of branches requiring a flush Requires HW for history table, etc Branch Prediction

Chapter 7 SPECINT2000 benchmark: –25% loads –10% stores –11% branches –2% jumps –52% R-type Suppose: –40% of loads used by next instruction –25% of branches mispredicted –All jumps flush next instruction (JTA not ready) What is the average CPI? Pipelined Performance Example

Chapter 7 Average CPI is the weighted average of CPI lw, CPI sw, CPI beq, CPI j and CPI R-type For pipeline processors, CPI = 1 + # of stall cycles Load CPI = 1 when no stall, = 2 when load-use occurs (1 stall) –CPI lw = 1(0.6) + 2(0.4) = 1.4 –CPI sw = 1 Branch CPI = 1 when no stall, = 2 when it mispredicts and stalls –CPI beq = 1(0.75) + 2(0.25) = 1.25 Jump CPI = 2 since it always requires 1 stall –CPI j = 2 –CPI R-type = 1 Average CPI = (0.25)(1.4) + (0.1)(1) + (0.11)(1.25) + (0.02)(2) + (0.52)(1) = 1.15 Calculation of Average CPI

Chapter 7 Pipelined processor critical path: T c = max { t pcq + t mem + t setup 2(t RFread + t mux + t eq + t AND + t mux + t setup ) t pcq + t mux + t mux + t ALU + t setup t pcq + t memwrite + t setup 2(t pcq + t mux + t RFwrite ) } Pipelined Performance

Chapter 7 ElementParameterDelay (ps) Register clock-to-Qt pcq_PC 30 Register setupt setup 20 Multiplexert mux 25 ALUt ALU 200 Memory readt mem 250 Register file readt RFread 150 Register file setupt RFsetup 20 Equality comparatort eq 40 AND gatet AND 15 Memory writeT memwrite 220 Register file writet RFwrite 100 ps T c = 2(t RFread + t mux + t eq + t AND + t mux + t setup ) = 2[ ] ps = 550 ps Pipelined Performance Example

Chapter 7 Program with IC = 100 billion instructions Execution Time = IC × CPI × T c = (100 × 10 9 )(1.15)(550 × ) = 63 seconds Pipelined Performance Example

Chapter 7 Processor Execution Time (seconds) Speedup (single-cycle as baseline) Single-cycle92.51 Multicycle Pipelined Processor Performance Comparison

Chapter 7 Deep Pipelining Branch Prediction Superscalar Processors Out of Order Processors Register Renaming SIMD Multithreading Multiprocessors Advanced Microarchitecture

Chapter stages typical Number of stages limited by: – Pipeline hazards – Sequencing overhead – Power – Cost Deep Pipelining

Chapter 7 Ideal pipelined processor: CPI = 1 Branch misprediction increases CPI Static branch prediction: – Check direction of branch (forward or backward) – If backward, predict taken – Else, predict not taken Dynamic branch prediction: – Keep history of last (several hundred) branches in branch target buffer, record: Branch destination Whether branch was taken Branch Prediction

Chapter 7 add $s1, $0, $0 # sum = 0 add $s0, $0, $0 # i = 0 addi $t0, $0, 10 # $t0 = 10 for: beq $s0, $t0, done # if i == 10, branch add $s1, $s1, $s0 # sum = sum + i addi $s0, $s0, 1 # increment i j for done: Branch Prediction Example

Chapter 7 Remembers whether branch was taken the last time and does the same thing Mispredicts first and last branch of loop 1-Bit Branch Predictor

Chapter 7 Only mispredicts the last branch of the loop 2-Bit Branch Predictor

Chapter 7 Multiple copies of datapath execute multiple instructions at once Dependencies make it tricky to issue multiple instructions at once Superscalar

Chapter 7 lw $t0, 40($s0) add $t1, $t0, $s1 sub $t0, $s2, $s3 Ideal IPC: 2 and $t2, $s4, $t0 Actual IPC:2 or $t3, $s5, $s6 sw $s7, 80($t3) Superscalar Example

Chapter 7 lw $t0, 40($s0) add $t1, $t0, $s1 sub $t0, $s2, $s3 Ideal IPC: 2 and $t2, $s4, $t0 Actual IPC:6/5 = 1.17 or $t3, $s5, $s6 sw $s7, 80($t3) Superscalar with Dependencies

Chapter 7 Looks ahead across multiple instructions Issues as many instructions as possible at once Issues instructions out of order (as long as no dependencies) Dependencies: – RAW (read after write): one instruction writes, later instruction reads a register – WAR (write after read): one instruction reads, later instruction writes a register – WAW (write after write): one instruction writes, later instruction writes a register Out of Order Processor

Chapter 7 Instruction level parallelism (ILP): number of instruction that can be issued simultaneously (average < 3) Scoreboard: table that keeps track of: – Instructions waiting to issue – Available functional units – Dependencies Out of Order Processor

Chapter 7 lw $t0, 40($s0) add $t1, $t0, $s1 sub $t0, $s2, $s3 Ideal IPC: 2 and $t2, $s4, $t0 Actual IPC:6/4 = 1.5 or $t3, $s5, $s6 sw $s7, 80($t3) Out of Order Processor Example

Chapter 7 lw $t0, 40($s0) add $t1, $t0, $s1 sub $t0, $s2, $s3 Ideal IPC: 2 and $t2, $s4, $t0 Actual IPC:6/3 = 2 or $t3, $s5, $s6 sw $s7, 80($t3) Register Renaming

Chapter 7 Single Instruction Multiple Data (SIMD) – Single instruction acts on multiple pieces of data at once – Common application: graphics – Perform short arithmetic operations (also called packed arithmetic) For example, add four 8-bit elements SIMD

Chapter 7 Multithreading – Wordprocessor: thread for typing, spell checking, printing Multiprocessors – Multiple processors (cores) on a single chip Advanced Architecture Techniques

Chapter 7 Process: program running on a computer – Multiple processes can run at once: e.g., surfing Web, playing music, writing a paper Thread: part of a program – Each process has multiple threads: e.g., a word processor may have threads for typing, spell checking, printing Threading: Definitions

Chapter 7 One thread runs at once When one thread stalls (for example, waiting for memory): – Architectural state of that thread stored – Architectural state of waiting thread loaded into processor and it runs – Called context switching Appears to user like all threads running simultaneously Threads in Conventional Processor

Chapter 7 Multiple copies of architectural state Multiple threads active at once: – When one thread stalls, another runs immediately – If one thread can’t keep all execution units busy, another thread can use them Does not increase instruction-level parallelism (ILP) of single thread, but increases throughput Intel calls this “hyperthreading” Multithreading

Chapter 7 Multiple processors (cores) with a method of communication between them Types: – Homogeneous: multiple cores with shared memory – Heterogeneous: separate cores for different tasks (for example, DSP and CPU in cell phone) – Clusters: each core has own memory system Multiprocessors