Vishwani D. Agrawal James J. Danaher Professor

Slides:



Advertisements
Similar presentations
Microprocessor Design Multi-cycle Datapath Nia S. Bradley Vijay.
Advertisements

1 Chapter Five The Processor: Datapath and Control.
VHDL Development for ELEC7770 VLSI Project Chris Erickson Graduate Student Department of Electrical and Computer Engineering Auburn University, Auburn,
Chapter 5 The Processor: Datapath and Control Basic MIPS Architecture Homework 2 due October 28 th. Project Designs due October 28 th. Project Reports.
1 5.5 A Multicycle Implementation A single memory unit is used for both instructions and data. There is a single ALU, rather than an ALU and two adders.
©UCB CS 161Computer Architecture Chapter 5 Lecture 11 Instructor: L.N. Bhuyan Adapted from notes by Dave Patterson (http.cs.berkeley.edu/~patterson)
Preparation for Midterm Binary Data Storage (integer, char, float pt) and Operations, Logic, Flip Flops, Switch Debouncing, Timing, Synchronous / Asynchronous.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Advanced Computer Architecture 5MD00 / 5Z033 MIPS Design data path and control Henk Corporaal TUEindhoven 2007.
331 W10.1Spring :332:331 Computer Architecture and Assembly Language Spring 2005 Week 10 Building a Multi-Cycle Datapath [Adapted from Dave Patterson’s.
1 The Processor: Datapath and Control We will design a microprocessor that includes a subset of the MIPS instruction set: –Memory access: load/store word.
CSE431 L05 Basic MIPS Architecture.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 05: Basic MIPS Architecture Review Mary Jane Irwin.
Dr. Iyad F. Jafar Basic MIPS Architecture: Multi-Cycle Datapath and Control.
CMPE 421 Advanced Computer Architecture Supplementary material for Pipelining PART1.
COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections
Computer Architecture Chapter 5 Fall 2005 Department of Computer Science Kent State University.
Datapath and Control: MultiCycle Implementation. Performance of Single Cycle Machines °Assume following operation times: Memory units : 200 ps ALU and.
CPE232 Basic MIPS Architecture1 Computer Organization Multi-cycle Approach Dr. Iyad Jafar Adapted from Dr. Gheith Abandah slides
1 CS/COE0447 Computer Organization & Assembly Language Multi-Cycle Execution.
C HAPTER 5 T HE PROCESSOR : D ATAPATH AND C ONTROL M ULTICYCLE D ESIGN.
1 Processor: Datapath and Control Single cycle processor –Datapath and Control Multicycle processor –Datapath and Control Microprogramming –Vertical and.
1 Processor: Datapath and Control Single cycle processor –Datapath and Control Multicycle processor –Datapath and Control Microprogramming –Vertical and.
Multicycle Implementation
LECTURE 6 Multi-Cycle Datapath and Control. SINGLE-CYCLE IMPLEMENTATION As we’ve seen, single-cycle implementation, although easy to implement, could.
ECE-C355 Computer Structures Winter 2008 The MIPS Datapath Slides have been adapted from Prof. Mary Jane Irwin ( )
Datapath and Control AddressInstruction Memory Write Data Reg Addr Register File ALU Data Memory Address Write Data Read Data PC Read Data Read Data.
Fall 2015, Sep ELEC / Lecture 5 1 ELEC / Computer Architecture and Design Fall 2015 Datapath and Control (Chapter.
Datapath and Control AddressInstruction Memory Write Data Reg Addr Register File ALU Data Memory Address Write Data Read Data PC Read Data Read Data.
RegDst 1: RegFile destination No. for the WR Reg. comes from rd field. 0: RegFile destination No. for the WR Reg. comes from rt field.
Chapter 4 From: Dr. Iyad F. Jafar Basic MIPS Architecture: Multi-Cycle Datapath and Control.
Computer Architecture Lecture 6.  Our implementation of the MIPS is simplified memory-reference instructions: lw, sw arithmetic-logical instructions:
Design a MIPS Processor (II)
CSE 331 Computer Organization and Design Fall 2007 Week 10 & 11
Multi-Cycle Datapath and Control
Chapter 5: A Multi-Cycle CPU.
Exceptions Another form of control hazard Could be caused by…
IT 251 Computer Organization and Architecture
/ Computer Architecture and Design
ECE/CS 552: Multicycle Data Path
Systems Architecture I
Multi-Cycle CPU.
Extensions to the Multicycle CPU
Single Cycle Processor
D.4 Finite State Diagram for the Multi-cycle processor
Multi-Cycle CPU.
Basic MIPS Architecture
CS/COE0447 Computer Organization & Assembly Language
Multiple Cycle Implementation of MIPS-Lite CPU
MIPS processor continued
Chapter Five The Processor: Datapath and Control
The Multicycle Implementation
Vishwani D. Agrawal James J. Danaher Professor
Chapter Five The Processor: Datapath and Control
Rocky K. C. Chang 6 November 2017
Composing the Elements
The Multicycle Implementation
Systems Architecture I
The Processor Lecture 3.2: Building a Datapath with Control
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
Processor: Multi-Cycle Datapath & Control
Multi-Cycle Datapath Lecture notes from MKP, H. H. Lee and S. Yalamanchili.
Chapter Four The Processor: Datapath and Control
5.5 A Multicycle Implementation
Systems Architecture I
The Processor: Datapath & Control.
Processor: Datapath and Control
CS161 – Design and Architecture of Computer Systems
ELEC / Computer Architecture and Design Spring 2015 Pipeline Control and Performance (Chapter 6) Vishwani D. Agrawal James J. Danaher.
CS/COE0447 Computer Organization & Assembly Language
Presentation transcript:

ELEC 5200-001/6200-001 Computer Architecture and Design Fall 2014 Datapath and Control (Chapter 4) Vishwani D. Agrawal James J. Danaher Professor Department of Electrical and Computer Engineering Auburn University, Auburn, AL 36849 http://www.eng.auburn.edu/~vagrawal vagrawal@eng.auburn.edu Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Von Neumann Kitchen ALU Start Control My choice PC Registers Processor Program Data Input Memory Output Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Where Does It All Begin? In a register called program counter (PC). PC contains the memory address of the next instruction to be executed. In the beginning, PC contains the address of the memory location where the program begins. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Where is the Program? Processor Memory Program counter (register) Machine code of program Start address Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

How Does It Run? Start PC has memory address where program begins Fetch instruction word from memory address in PC and increment PC ← PC + 4 to point to next instruction Decode instruction Execute instruction Save result in register or memory No Program complete? Yes STOP Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Datapath and Control Datapath: Memory, registers, adders, ALU, and communication buses. Each step (fetch, decode, execute, save result) requires communication (data transfer) paths between memory, registers and ALU. Control: Datapath for each step is set up by control signals that set up dataflow directions on communication buses and select ALU and memory functions. Control signals are generated by a control unit consisting of one or more finite-state machines. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Datapath for Instruction Fetch Add 4 Instruction Memory PC Instruction word to control unit and registers Address Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Register File: A Datapath Component 5 32 Registers (reg. file) reg 1 32 Read registers reg 1 data 5 reg 2 Write register 5 32 reg 2 data Write data 32 RegWrite from control Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Multi-Operation ALU Operation select from control 3 zero ALU result Operation select ALU function 000 AND 001 OR 010 Add 110 Subtract 111 Set on less than 3 zero ALU result overflow zero = 1, when all bits of result are 0 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

R-Type Instructions Also known as arithmetic-logical instructions add, sub, slt Example: add $t0, $s1, $s2 Machine instruction word 000000 10001 10010 01000 00000 100000 opcode $s1 $s2 $t0 function Read two registers Write one register Opcode and function code go to control unit that generates RegWrite and ALU operation code. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Datapath for R-Type Instruction 000000 10001 10010 01000 00000 100000 opcode $s1 $s2 $t0 function (add) Operation select from control (add) 5 32 Registers (reg. file) 10001 $s1 Read register numbers 3 32 zero 5 10010 $s2 ALU result 32 overflow Write reg. number 5 01000 $t0 Write data 32 RegWrite from control activated Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Load and Store Instructions I-type instructions lw $t0, 1200 ($t1) # incr. in bytes 100011 01001 01000 0000 0100 1011 0000 opcode $t1 $t0 1200 sw $t0, 1200 ($t1) # incr. in bytes 101011 01001 01000 0000 0100 1011 0000 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Datapath for lw Instruction 100011 01001 01000 0000 0100 1011 0000 opcode $t1 $t0 1200 MemWrite Operation select from control (add) 32 Registers (reg. file) 5 01001 $t1 Read register numbers 3 32 Read data 5 zero result ALU Addr. Data memory overflow Write reg. number 5 01000 $t0 Write data Write data 32 32 RegWrite from control activated Sign extend MemRead activated 0000 0100 1011 0000 16 mem. data to $t0 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Datapath for sw Instruction 101011 01001 01000 0000 0100 1011 0000 opcode $t1 $t0 1200 MemWrite activated Operation select from control (add) 32 Registers (reg. file) 5 01001 $t1 Read register numbers 3 32 Read data 5 zero 01000 $t0 result ALU Addr. Data memory overflow Write reg. number 5 32 Write data Write data $t0 data to mem. 32 32 Sign extend RegWrite from control MemRead 0000 0100 1011 0000 16 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Branch Instruction (I-Type) beq $s1, $s2, 25 # if $s1 = $s2, advance PC through 25 instructions 16-bits 000100 10001 10010 0000 0000 0001 1001 opcode $s1 $s2 25 Note: Can branch within ± 215 words from the current instruction address in PC. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Datapath for beq Instruction 16-bits 000100 10001 10010 0000 0000 0001 1001 opcode $s1 $s2 25 Operation select from control (subtract) 32 Registers (reg. file) 5 10001 $s1 Read register numbers 32 ALU 3 5 10010 $s2 To branch control logic zero result 5 32 Write reg. number overflow Write data Add PC+4 Branch target 32 RegWrite from control From instruction fetch datapath 32 Sign extend Shift left 2 0000 0000 0001 1001 16 32 32 32 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

J-Type Instruction j 2500 # jump to instruction 2,500 26-bits 000010 0000 0000 0000 0010 0111 0001 00 opcode 2,500 32-bit jump address 0000 0000 0000 0000 0010 0111 0001 0000 bits 28-31 from PC+4 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Datapath for Jump Instruction Branch Jump Add Branch addr. 4 1 mux 32 32 mux 1 32 PC+4 4 Shift left 2 28 Instruction Memory 32 PC 26 opcode (bits 26-31) to control 32 6 Address 32 Instruction word to control and registers Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

ALU ALU Data mem. Combined Datapaths 0 mux 1 Add 1 mux 0 opcode Jump 0-25 Shift left 2 0 mux 1 4 Add 1 mux 0 ALU Branch opcode MemtoReg CONTROL RegDst 26-31 21-25 zero MemWrite MemRead ALU Instr. mem. PC Reg. File Data mem. 16-20 1 mux 0 0 mux 1 1 mux 0 Combined Datapaths 11-15 ALU Cont. Sign ext. Shift left 2 0-15 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Control RegDst Jump Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Instruction bits 26-31 opcode Control Logic 2 Instruction bits 0-5 funct. ALU Control to ALU Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Control Logic: Truth Table Instr type Inputs: instr. opcode bits Outputs: control signals 31 30 29 28 27 26 RegDst Jump ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALOOp1 ALUOp2 R 1 lw sw X beq j Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

How Long Does It Take? Assume control logic is fast and does not affect the critical timing. Major time delay components are ALU, memory read/write, and register read/write. Arithmetic-type (R-type) Fetch (memory read) 2ns Register read 1ns ALU operation 2ns Register write 1ns Total 6ns Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Time for lw and sw (I-Types) ALU (R-type) 6ns Load word (I-type) Fetch (memory read) 2ns Register read 1ns ALU operation 2ns Get data (mem. Read) 2ns Register write 1ns Total 8ns Store word (no register write) 7ns Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Time for beq (I-Type) ALU (R-type) 6ns Load word (I-type) 8ns Store word (I-type) 7ns Branch on equal (I-type) Fetch (memory read) 2ns Register read 1ns ALU operation 2ns Total 5ns Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Time for Jump (J-Type) ALU (R-type) 6ns Load word (I-type) 8ns Store word (I-type) 7ns Branch on equal (I-type) 5ns Jump (J-type) Fetch (memory read) 2ns Total 2ns Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

How Fast Can Clock Run? If every instruction is executed in one clock cycle, then: Clock period must be at least 8ns to perform the longest instruction, i.e., lw. This is a single cycle machine. It is slower because many instructions take less than 8ns but are still allowed that much time. Method of speeding up: Use multicycle datapath. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

A Single Cycle Example Delay of 1-bit full adder = 1ns Clock period ≥ 32ns a31 . a2 a1 a0 c32 1-b full adder s31 . s2 s1 s0 1-b full adder b31 . b2 b1 b0 1-b full adder 1-b full adder Time of adding words ~ 32ns Time of adding bytes ~ 32ns Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

A Multicycle Implementation . a2 a1 a0 Delay of 1-bit full adder = 1ns Clock period ≥ 1ns Time of adding words ~ 32ns Time of adding bytes ~ 8ns Shift 1-b full adder b31 . b2 b1 b0 s31 . s2 s1 s0 c32 FF Shift Shift Initialize to 0 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

ALU ALU Data mem. Single-cycle Datapaths 0 mux 1 Add 1 mux 0 opcode Jump 0-25 Shift left 2 0 mux 1 4 Add 1 mux 0 ALU Branch opcode MemtoReg CONTROL RegDst 26-31 21-25 zero MemWrite MemRead ALU Instr. mem. PC Reg. File Data mem. 16-20 1 mux 0 0 mux 1 1 mux 0 Single-cycle Datapaths 11-15 ALU Cont. Sign ext. Shift left 2 0-15 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Multicycle Datapath Memory ALU Instr. reg. (IR) A Reg. PC Addr. Memory Register file ALU ALUOut Reg. Data 4 Mem. Data (MDR) B Reg. One-cycle data transfer paths (need registers to hold data) Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Multicycle Datapath Requirements Only one ALU, since it can be reused. Single memory for instructions and data. Five registers added: Instruction register (IR) Memory data register (MDR) Three ALU registers, A and B for inputs and ALUOut for output Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Multicycle Datapath Memory ALU Instr. reg. (IR) A Reg. PC PCSource PCWrite etc. Shift left 2 26-31 to Control FSM 0-25 RegWrite 21-25 28-31 16-20 PC Instr. reg. (IR) A Reg. Addr. Memory 11-15 Register file ALU ALUSrcA ALUSrcB ALUOut Reg. IorD Data Mem. Data (MDR) B Reg. out RegDst MUX control IRWrite 4 in1 in2 MemRead Sign extend Shift left 2 MemtoReg 0-15 MemWrite ALU control ALUOp 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

3 to 5 Cycles for an Instruction Step R-type (4 cycles) Mem. Ref. (4 or 5 cycles) Branch type (3 cycles) J-type Instruction fetch IR ← Memory[PC]; PC ← PC+4 Instr. decode/ Reg. fetch A ← Reg(IR[21-25]); B ← Reg(IR[16-20]) ALUOut ← PC + {(sign extend IR[0-15]) << 2} Execution, addr. Comp., branch & jump completion ALUOut ← A op B A+sign extend (IR[0-15]) If (A= =B) then PC←ALUOut PC←PC[28-31] || (IR[0-25]<<2) Mem. Access or R-type completion Reg(IR[11-15]) ← ALUOut MDR←M[ALUout] or M[ALUOut]←B Memory read completion Reg(IR[16-20]) ← MDR Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Cycle 1 of 5: Instruction Fetch (IF) Read instruction into IR, M[PC] → IR Control signals used: IorD = 0 select PC MemRead = 1 read memory IRWrite = 1 write IR Increment PC, PC + 4 → PC ALUSrcA = 0 select PC into ALU ALUSrcB = 01 select constant 4 ALUOp = 00 ALU adds PCSource = 00 select ALU output PCWrite = 1 write PC Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Cycle 2 of 5: Instruction Decode (ID) 31-26 25-21 20-16 15-11 10-6 5-0 R I J opcode | reg 1 | reg 2 | reg 3 | shamt | fncode opcode | reg 1 | reg 2 | word address increment opcode | word address jump Control unit decodes instruction Datapath prepares for execution R and I types, reg 1→ A reg, reg 2 → B reg No control signals needed Branch type, compute branch address in ALUOut ALUSrcA = 0 select PC into ALU ALUSrcB = 11 Instr. Bits 0-15 shift 2 into ALU ALUOp = 00 ALU adds Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Cycle 3 of 5: Execute (EX) R type: execute function on reg A and reg B, result in ALUOut Control signals used: ALUSrcA = 1 A reg into ALU ALUsrcB = 00 B reg into ALU ALUOp = 10 instr. Bits 0-5 control ALU I type, lw or sw: compute memory address in ALUOut ← A reg + sign extend IR[0-15] ALUSrcB = 10 Instr. Bits 0-15 into ALU ALUOp = 00 ALU adds Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Cycle 3 of 5: Execute (EX) I type, beq: subtract reg A and reg B, write ALUOut to PC Control signals used: ALUSrcA = 1 A reg into ALU ALUsrcB = 00 B reg into ALU ALUOp = 01 ALU subtracts If zero = 1, PCSource = 01 ALUOut to PC If zero = 1, PCwriteCond =1 write PC Instruction complete, go to IF J type: write jump address to PC ← IR[0-25] shift 2 and four leading bits of PC PCSource = 10 PCWrite = 1 write PC Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Cycle 4 of 5: Reg Write/Memory R type, write destination register from ALUOut Control signals used: RegDst = 1 Instr. Bits 11-15 specify reg. MemtoReg = 0 ALUOut into reg. RegWrite = 1 write register Instruction complete, go to IF I type, lw: read M[ALUOut] into MDR IorD = 1 select ALUOut as mem adr. MemRead = 1 read memory to MDR I type, sw: write M[ALUOut] from B reg MemWrite = 1 write memory Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Cycle 5 of 5: Reg Write I type, lw: write MDR to reg[IR(16-20)] Control signals used: RegDst = 0 instr. Bits 16-20 are write reg MemtoReg = 1 MDR to reg file write input RegWrite = 1 write reg. file Instruction complete, go to IF For an alternative method of designing datapath, see N. Tredennick, Microprocessor Logic Design, the Flowchart Method, Digital Press, 1987. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

1-bit Control Signals Signal name Value = 0 Value =1 RegDst Write reg. # = bit 16-20 Write reg. # = bit 11-15 RegWrite No action Write reg. ← Write data ALUSrcA First ALU Operand ← PC First ALU Operand←Reg. A MemRead Mem.Data Output←M[Addr.] MemWrite M[Addr.]←Mem. Data Input MemtoReg Reg.File Write In←ALUOut Reg.File Write In←MDR IorD Mem. Addr. ← PC Mem. Addr. ← ALUOut IRWrite IR ← Mem.Data Output PCWrite PC is written PCWriteCond PC is written if zero(ALU)=1 zero(ALU) PCWriteCond PCWrite etc. PCWrite Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

2-bit Control Signals Signal name Value Action ALUOp 00 ALU performs add 01 ALU performs subtract 10 Funct. field (0-5 bits of IR ) determines ALU operation ALUSrcB Second input of ALU ← B reg. Second input of ALU ← 4 (constant) Second input of ALU ← 0-15 bits of IR sign ext. to 32b 11 Second input of ALU ← 0-15 bits of IR sign ext. and left shift 2 bits PCSource ALU output (PC +4) sent to PC ALUOut (branch target addr.) sent to PC Jump address IR[0-25] shifted left 2 bits, concatenated with PC+4[28-31], sent to PC Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Control: Finite State Machine Start State 0 Clock cycle 1 Instruction fetch State 1 Clock cycle 2 Instruction decode and register fetch FSM-M Memory access instr. FSM-R FSM-B FSM-J Clock cycles 3-5 R-type instr. Branch instr. Jump instr. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 0: Instruction Fetch (CC1) PCSource=00 PCWrite etc.=1 Shift left 2 26-31 to Control FSM 0-25 RegWrite 21-25 28-31 16-20 PC Instr. reg. (IR) A Reg. Addr. Memory Register file ALU ALUSrcA=0 ALUSrcB=01 ALUOut Reg. IorD=0 Data Mem. Data (MDR) B Reg. out RegDst MUX control IRWrite =1 4 Add in1 in2 MemRead = 1 Sign extend Shift left 2 MemtoReg 0-15 MemWrite ALUOp =00 ALU control 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 0 Control FSM Outputs Start State 1 Instruction decode/ Register fetch/ Branch addr. State0 Instruction fetch MemRead =1 ALUSrcA = 0 IorD = 0 IRWrite = 1 ALUSrcB = 01 ALUOp = 00 PCWrite = 1 PCSource = 00 Outputs? Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 1: Instr. Decode/Reg. Fetch/ Branch Address (CC2) PCSource PCWrite etc. Shift left 2 26-31 to Control FSM 0-25 RegWrite 21-25 28-31 16-20 PC Instr. reg. (IR) A Reg. Addr. Memory Register file ALUSrcA=0 ALU ALUSrcB=11 ALUOut Reg. IorD Data Mem. Data (MDR) B Reg. out RegDst MUX control Add IRWrite 4 in1 in2 MemRead Sign extend Shift left 2 MemtoReg 0-15 MemWrite ALUOp = 00 ALU control 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 1 Control FSM Outputs Start State 1 Instruction decode (ID) / Register fetch / Branch addr. State0 Instruction fetch (IF) MemRead =1 ALUSrcA = 0 IorD = 0 IRWrite = 1 ALUSrcB = 01 ALUOp = 00 PCWrite = 1 PCSource = 00 ALUSrcA = 0 ALUSrcB = 11 ALUOp = 00 Opcode = lw, sw Opcode = R-type Opcode = BEQ Opcode = J-type FSM-M FSM-R FSM-B FSM-J Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 1 (Opcode = lw) → FSM-M (CC3-5) PCSource CC4 PCWrite etc. Shift left 2 26-31 to Control FSM 0-25 RegWrite=1 21-25 28-31 16-20 CC3 PC Instr. reg. (IR) A Reg. Addr. Memory Register file ALUSrcA=1 ALU ALUSrcB=10 ALUOut Reg. IorD=1 Data Mem. Data (MDR) B Reg. out CC5 MUX control Add IRWrite 4 RegDst=0 in1 in2 MemRead=1 Sign extend Shift left 2 MemtoReg=1 0-15 MemWrite ALUOp = 00 ALU control 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 1 (Opcode= sw)→FSM-M (CC3-4) PCSource PCWrite etc. Shift left 2 26-31 to Control FSM 0-25 RegWrite 21-25 28-31 16-20 CC3 PC Instr. reg. (IR) A Reg. Addr. Memory Register file ALUSrcA=1 ALU ALUSrcB=10 ALUOut Reg. IorD=1 Data Mem. Data (MDR) B Reg. out RegDst=0 MUX control Add IRWrite 4 CC4 in1 in2 MemRead Sign extend Shift left 2 MemtoReg 0-15 MemWrite=1 ALUOp = 00 ALU control 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

FSM-M (Memory Access) From state 1 Opcode = “lw” or “sw” Opcode = “lw” Compute mem addrress ALUSrcA =1 ALUSrcB = 10 ALUOp = 00 Opcode = “lw” Opcode = “sw” Read Memory data Write memory MemRead = 1 IorD = 1 MemWrite = 1 IorD = 1 Write register To state 0 (Instr. Fetch) RegWrite = 1 MemtoReg = 1 RegDst = 0 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 1(Opcode=R-type)→FSM-R (CC3-4) PCSource PCWrite etc. Shift left 2 26-31 to Control FSM 0-25 RegWrite 21-25 28-31 16-20 PC Instr. reg. (IR) A Reg. Addr. Memory Register file ALU CC3 ALUSrcA=1 ALUSrcB=00 ALUOut Reg. 11-15 IorD Data Mem. Data (MDR) B Reg. out RegDst=0 MUX control IRWrite 4 “funct. code” CC4 in1 in2 MemRead Sign extend Shift left 2 MemtoReg=0 0-15 MemWrite ALUOp = 10 ALU control 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

FSM-R (R-type Instruction) From state 1 Opcode = R-type ALU operation ALUSrcA =1 ALUSrcB = 00 ALUOp = 10 Write register To state 0 (Instr. Fetch) RegWrite = 1 MemtoReg = 0 RegDst = 1 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 1 (Opcode = beq ) → FSM-B (CC3) If(zero) PCSource 01 PCWrite etc.=1 Shift left 2 26-31 to Control FSM 0-25 RegWrite 21-25 28-31 16-20 PC Instr. reg. (IR) A Reg. Addr. Memory Register file ALUSrcA=1 ALU CC3 ALUSrcB=00 ALUOut Reg. 11-15 IorD Data Mem. Data (MDR) B Reg. zero out RegDst MUX control IRWrite 4 subtract in1 in2 MemRead Sign extend Shift left 2 MemtoReg 0-15 MemWrite ALUOp = 01 ALU control 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Write PC on “zero” zero=1 PCWriteCond=1 PCWrite etc.=1 PCWrite PCWrite = 1, unconditionally write PC Cycle 1, fetch Cycle 3, jump Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

FSM-B (Branch) From state 1 Opcode = “beq” To state 0 (Instr. Fetch) Write PC on branch condition Branch condition: If A – B=0 zero = 1 ALUSrcA =1 ALUSrcB = 00 ALUOp = 01 PCWriteCond=1 PCSource=01 To state 0 (Instr. Fetch) Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

State 1 (Opcode = j) → FSM-J (CC3) PCSource 10 PCWrite etc. Shift left 2 26-31 to Control FSM 0-25 RegWrite 21-25 28-31 16-20 PC Instr. reg. (IR) A Reg. Addr. Memory Register file ALU ALUSrcA ALUOut Reg. 11-15 IorD ALUSrcB Data Mem. Data (MDR) B Reg. zero out RegDst MUX control IRWrite 4 in1 in2 MemRead Sign extend Shift left 2 MemtoReg 0-15 MemWrite ALUOp ALU control 0-5 Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Write PC zero PCWriteCond PCWrite etc.=1 PCWrite=1 PCWrite = 1, unconditionally write PC Cycle 1, fetch Cycle 3, jump Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

FSM-J (Jump) From state 1 Opcode = “jump” To state 0 (Instr. Fetch) Write jump addr. In PC PCWrite=1 PCSource=10 To state 0 (Instr. Fetch) Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Control FSM Start State 0 1 Instr. fetch/ adv. PC lw or sw J R B 3 2 decode/reg. fetch/branch addr. lw or sw J R B 3 2 Read memory data Compute memory addr. ALU operation Write jump addr. to PC Write PC on branch condition lw 6 8 9 sw 4 5 Write register Write memory data 7 Write register Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Control FSM (Controller) 6 inputs (opcode) 16 control outputs Combinational logic Present state Next state Reset Clock FF FF FF FF Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Designing the Control FSM Encode states; need 4 bits for 10 states, e.g., State 0 is 0000, state 1 is 0001, and so on. Write a truth table for combinational logic: Opcode Present state Control signals Next state 000000 0000 0001000110000100 0001 . . . . . . . . . . . . . . . . Synthesize a logic circuit from the truth table. Connect four flip-flops between the next state outputs and present state inputs. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Block Diagram of a Processor MemWrite MemRead Controller (Control FSM) ALU control ALUOp 2-bits Opcode 6-bits PCSource 2-bits funct. [0,5] ALUOp 3-bits zero ALUSrcA ALUSrcB 2-bits RegWrite IorD Overflow RegDst MemtoReg IRWrite PCWrite PCWriteCond Reset Clock Datapath (PC, register file, registers, ALU) Mem. Addr. Mem. write data Mem. data out Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Exceptions or Interrupts Conditions under which the processor may produce incorrect result or may “hang”. Illegal or undefined opcode. Arithmetic overflow, divide by zero, etc. Out of bounds memory address. EPC: 32-bit register holds the affected instruction address. Cause: 32-bit register holds an encoded exception type. For example, 0 for undefined instruction 1 for arithmetic overflow Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Implementing Exceptions PCSource 11 8000 0180(hex) PCWrite etc.=1 26-31 to Control FSM PC Instr. reg. (IR) EPCWrite=1 ALUSrcA=0 ALU ALUSrcB=01 EPC CauseWrite=1 Overflow to Control FSM out MUX control 4 Cause 1 Subtract in1 in2 32-bit register ALUOp =01 ALU control Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

How Long Does It Take? Again Assume control logic is fast and does not affect the critical timing. Major time components are ALU, memory read/write, and register read/write. Time for hardware operations, suppose Memory read or write 2ns Register read 1ns ALU operation 2ns Register write 1ns Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Single-Cycle Datapath R-type 6ns Load word (I-type) 8ns Store word (I-type) 7ns Branch on equal (I-type) 5ns Jump (J-type) 2ns Clock cycle time = 8ns Each instruction takes one cycle Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Performance Parameters Average cycles per instruction (CPI) Cycle time (clock period, T) Execution time of a program For single-cycle datapath: CPI = 1 T = hardware time for lw instruction = T × CPI × (Total instructions executed) Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Multicycle Datapath Clock cycle time is determined by the longest operation, ALU or memory: Clock cycle time = 2ns Cycles per instruction: lw 5 (10ns) sw 4 (8ns) R-type 4 (8ns) beq 3 (6ns) j 3 (6ns) Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

CPI of a Multicycle Computer ∑k (Instructions of type k) × CPIk CPI = —————————————— ∑k (instructions of type k) where CPIk = Cycles for instruction of type k Note: CPI is dependent on the instruction mix of the program being run. Standard benchmark programs are used for specifying the performance of CPUs. Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Example Consider a program containing: loads 25% stores 10% branches 11% jumps 2% Arithmetic 52% CPI = 0.25×5 + 0.10×4 + 0.11×3 + 0.02×3 + 0.52×4 = 4.12 for multicycle datapath CPI = 1.00 for single-cycle datapath Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Multicycle vs. Single-Cycle Performance ratio = Single cycle time / Multicycle time (CPI × cycle time) for single-cycle = ——————————————— (CPI × cycle time) for multicycle 1.00 × 8ns = ————— = 0.97 4.12 × 2ns Single cycle is faster in this case, but is it always so? Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Consider Another Example For this program: loads 5% stores 5% branches 30% jumps 10% Arithmetic 50% CPI = 0.05×5 + 0.05×4 + 0.30×3 + 0.10×3 + 0.50×4 = 3.65 for multicycle datapath CPI = 1.00 for single-cycle datapath Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Multicycle vs. Single-Cycle Performance ratio = Single cycle time / Multicycle time (CPI × cycle time) for single-cycle = ——————————————— (CPI × cycle time) for multicycle 1.00 × 8ns = ————— = 1.096 3.65 × 2ns Multicycle is faster in this case, so the performance ratio depends on the instruction mix. Can we do better? Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5

Next: Pipelining https://www.youtube.com/watch?v=IjarLbD9r30 https://www.youtube.com/watch?v=ANXGJe6i3G8 https://www.youtube.com/watch?v=5lp4EbfPAtI Fall 2014, Sep 15 . . . ELEC 5200-001/6200-001 Lecture 5