LECTURE 5. Single-Cycle Datapath and Control

Similar documents
COMPUTER ORGANIZATION AND DESIGN. The Hardware/Software Interface. Chapter 4. The Processor: A Based on P&H

Processor (I) - datapath & control. Hwansoo Han

CPE 335 Computer Organization. Basic MIPS Architecture Part I

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 4: Datapath and Control

Chapter 4. The Processor. Computer Architecture and IC Design Lab

CENG 3420 Lecture 06: Datapath

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.

Systems Architecture

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

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

CENG 3420 Computer Organization and Design. Lecture 06: MIPS Processor - I. Bei Yu

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

Chapter 4. The Processor

COMP303 - Computer Architecture Lecture 8. Designing a Single Cycle Datapath

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

The Processor: Datapath and Control. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

LECTURE 6. Multi-Cycle Datapath and Control

CSEN 601: Computer System Architecture Summer 2014

ECE232: Hardware Organization and Design

The MIPS Processor Datapath

Chapter 4. The Processor

Chapter 4. The Processor Designing the datapath

Chapter 4. The Processor. Instruction count Determined by ISA and compiler. We will examine two MIPS implementations

Topic #6. Processor Design

Review: Abstract Implementation View

EECS150 - Digital Design Lecture 10- CPU Microarchitecture. Processor Microarchitecture Introduction

CC 311- Computer Architecture. The Processor - Control

Lecture Topics. Announcements. Today: Single-Cycle Processors (P&H ) Next: continued. Milestone #3 (due 2/9) Milestone #4 (due 2/23)

ECE260: Fundamentals of Computer Engineering

Data paths for MIPS instructions

CPE 335. Basic MIPS Architecture Part II

The Processor: Datapath & Control

CPU Organization (Design)

RISC Processor Design

CSE 2021 COMPUTER ORGANIZATION

Design of the MIPS Processor

EECS150 - Digital Design Lecture 9- CPU Microarchitecture. Watson: Jeopardy-playing Computer

CS Computer Architecture Spring Week 10: Chapter

CO Computer Architecture and Programming Languages CAPL. Lecture 18 & 19

Introduction. Datapath Basics

Full Datapath. CSCI 402: Computer Architectures. The Processor (2) 3/21/19. Fengguang Song Department of Computer & Information Science IUPUI

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

CS3350B Computer Architecture Quiz 3 March 15, 2018

Inf2C - Computer Systems Lecture Processor Design Single Cycle

Lecture 8: Control COS / ELE 375. Computer Architecture and Organization. Princeton University Fall Prof. David August

Chapter 5: The Processor: Datapath and Control

ﻪﺘﻓﺮﺸﻴﭘ ﺮﺗﻮﻴﭙﻣﺎﻛ يرﺎﻤﻌﻣ MIPS يرﺎﻤﻌﻣ data path and ontrol control

Chapter 5 Solutions: For More Practice

Design of Digital Circuits 2017 Srdjan Capkun Onur Mutlu (Guest starring: Frank K. Gürkaynak and Aanjhan Ranganathan)

Single Cycle CPU Design. Mehran Rezaei

Lecture 5 and 6. ICS 152 Computer Systems Architecture. Prof. Juan Luis Aragón

Multiple Cycle Data Path

Single Cycle Data Path

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

The Processor: Datapath & Control

The overall datapath for RT, lw,sw beq instrucution

CSCI 402: Computer Architectures. Fengguang Song Department of Computer & Information Science IUPUI. Today s Content

Systems Architecture I

Design of the MIPS Processor (contd)

Computer Hardware Engineering

ENGN1640: Design of Computing Systems Topic 04: Single-Cycle Processor Design

Chapter 4. The Processor

CpE242 Computer Architecture and Engineering Designing a Single Cycle Datapath

Laboratory 5 Processor Datapath

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

Mark Redekopp and Gandhi Puvvada, All rights reserved. EE 357 Unit 15. Single-Cycle CPU Datapath and Control

The Big Picture: Where are We Now? EEM 486: Computer Architecture. Lecture 3. Designing a Single Cycle Datapath

Processor: Multi- Cycle Datapath & Control

Lecture 10: Simple Data Path

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Data Paths and Microprogramming

ENE 334 Microprocessors

MIPS-Lite Single-Cycle Control

EECS 151/251A Fall 2017 Digital Design and Integrated Circuits. Instructor: John Wawrzynek and Nicholas Weaver. Lecture 13 EE141

Major CPU Design Steps

Lecture 5: The Processor

Computer Hardware Engineering

COMP303 Computer Architecture Lecture 9. Single Cycle Control

ECE369. Chapter 5 ECE369

361 datapath.1. Computer Architecture EECS 361 Lecture 8: Designing a Single Cycle Datapath

CS 351 Exam 2 Mon. 11/2/2015

Lets Build a Processor

361 control.1. EECS 361 Computer Architecture Lecture 9: Designing Single Cycle Control

ECE 313 Computer Organization FINAL EXAM December 14, This exam is open book and open notes. You have 2 hours.

TDT4255 Computer Design. Lecture 4. Magnus Jahre. TDT4255 Computer Design

Processor Design Pipelined Processor (II) Hung-Wei Tseng

University of Jordan Computer Engineering Department CPE439: Computer Design Lab

COMP2611: Computer Organization. The Pipelined Processor

CSE 378 Midterm 2/12/10 Sample Solution

Computer Science 141 Computing Hardware

4. What is the average CPI of a 1.4 GHz machine that executes 12.5 million instructions in 12 seconds?

Chapter 4. The Processor

Mapping Control to Hardware

Inf2C - Computer Systems Lecture 12 Processor Design Multi-Cycle

CSE Computer Architecture I Fall 2009 Lecture 13 In Class Notes and Problems October 6, 2009

Lecture 12: Single-Cycle Control Unit. Spring 2018 Jason Tang

Computer Architecture, IFE CS and T&CS, 4 th sem. Single-Cycle Architecture

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

CSE 2021 COMPUTER ORGANIZATION

Transcription:

LECTURE 5 Single-Cycle Datapath and Control

PROCESSORS In lecture 1, we reminded ourselves that the datapath and control are the two components that come together to be collectively known as the processor. Datapath consists of the functional units of the processor. Elements that hold data. Program Counter, Register File, Instruction Memory, etc. Elements that operate on data. ALU, adders, etc. Buses for transferring data between elements. Control commands the datapath regarding when and how to route and operate on data.

MIPS To showcase the process of creating a datapath and designing a control, we will be using a subset of the MIPS instruction set. Our available instructions include: add, sub, and, or, slt lw, sw beq, j

DATAPATH To start, we will look at the datapath elements needed by every instruction. First, we have instruction memory. Instruction memory is a state element that provides read-access to the instructions of a program and, given an address as input, supplies the corresponding instruction at that address.

DATAPATH Next, we have the program counter or PC. The PC is a state element that holds the address of the current instruction. Essentially, it is just a 32-bit register which holds the instruction address and is updated at the end of every clock cycle. The arrows on either side indicate that the PC state element is both readable and writeable.

DATAPATH Lastly, we have the adder. The adder is responsible for incrementing the PC to hold the address of the next instruction. It takes two input values, adds them together and outputs the result.

DATAPATH So now we have instruction memory, PC, and adder datapath elements. Now, we can talk about the general steps taken to execute a program. Use the address in the PC to fetch the current instruction from instruction memory. Determine the fields within the instruction (decode the instruction). Perform the operation indicated by the instruction. Update the PC to hold the address of the next instruction.

DATAPATH Use the address in the PC to fetch the current instruction from instruction memory. Determine the fields within the instruction (decode the instruction). Perform the operation indicated by the instruction. Update the PC to hold the address of the next instruction. Note: we perform PC+4 because instructions are word-aligned.

R-FORMAT INSTRUCTIONS Now, let s consider R-format instructions. In our limited MIPS instruction set, these are add, sub, and, or and slt. All R-format instructions read two registers, rs and rt, and write to a register rd. Name Fields Field Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits R format op rs rt rd shamt funct op instruction opcode. rs first register source operand. rt second register source operand. rd register destination operand. shamt shift amount. funct additional opcodes.

DATAPATH To support R-format instructions, we ll need to add a state element called a register file. A register file is a collection readable/writeable registers. Read register 1 first source register. 5 bits wide. Read register 2 second source register. 5 bits wide. Write register destination register. 5 bits wide. Write data data to be written to a register. 32 bits wide.

DATAPATH At the bottom, we have the RegWrite input. A writing operation only occurs when this bit is set. The two output ports are: Read data 1 contents of source register 1. Read data 2 contents of source register 2.

DATAPATH To actually perform R-format instructions, like add for example, we need to include the ALU element. The ALU performs the operation indicated by the instruction. It takes two inputs, the operands to perform the operation on, as well as a 4-bit wide operation selector value. The result of the operation is the output value. We have an additional output specifically for branching we will cover this in a minute.

DATAPATH Here is our datapath for R-format instructions. 1. Grab instruction address from PC.

DATAPATH Here is our datapath for R-format instructions. 2. Fetch instruction from instruction memory. 3. Decode instruction.

DATAPATH Here is our datapath for R-format instructions. 4. Pass rs, rt, and rd into read register and write register arguments.

DATAPATH Here is our datapath for R-format instructions. 5. Retrieve contents of read register 1 and read register 2 (rs and rt).

DATAPATH Here is our datapath for R-format instructions. 6. Pass contents of rs and rt into the ALU as operands of the operation to be performed.

DATAPATH Here is our datapath for R-format instructions. 7. Retrieve result of operation performed by ALU and pass back as the write data argument of the register file (with the RegWrite bit set).

DATAPATH Here is our datapath for R-format instructions. 8. Add 4 bytes to the PC value to obtain the word-aligned address of the next instruction.

I-FORMAT INSTRUCTIONS Now that we have a complete datapath for R-format instructions, let s add in support for I-format instructions. In our limited MIPS instruction set, these are lw, sw, and beq. The op field is used to identify the type of instruction. The rs field is the source register. The rt field is either the source or destination register, depending on the instruction. The immed field is zero-extended if it is a logical operation. Otherwise, it is signextended. Name Fields Field Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits I format op rs rt immed

DATA TRANSFER INSTRUCTIONS Let s start with accommodating the data transfer instructions we ll get to beq in a bit. For lw and sw, we have the following format: lw $rt, immed($rs) sw $rt, immed($rs) The memory address is computed by sign-extending the 16-bit immediate to 32-bits, which is added to the contents of $rs. In lw, $rt represents the register that will be assigned the memory value. In sw, $rt represents the register whose value will be stored in memory. Bottom line: we need to datapath elements to access memory and perform signextending.

DATAPATH The data memory element implements the functionality for reading and writing data to/from memory. There are two inputs. One for the address of the memory location to access, the other for the data to be written to memory if applicable. The output is the data read from the memory location accessed, if applicable. Reads and writes are signaled by MemRead and MemWrite, respectively, which must be asserted for the corresponding action to take place.

DATAPATH To perform sign-extending, we can add a sign extension element. The sign extension element takes as input a 16-bit wide value to be extended to 32-bits. To sign extend, we simply replicate the most-significant bit of the original field until we have reached the desired field width.

DATAPATH FOR LOAD WORD Here, we have modified the datapath to work only for the lw instruction. lw $rt, immed($rs) The registers have been added to the datapath for added clarity. rs rt immed

DATAPATH FOR STORE WORD Here, we have modified the datapath to work only for the sw instruction. sw $rt, immed($rs) The registers have been added to the datapath for added clarity. rs rt immed

DATAPATH FOR R-FORMAT AND MEMORY ACCESS Note: PC, adder, and instruction memory are omitted. add $rd, $rs, $rt lw $rt, immed($rs) sw $rt, immed($rs)

DATAPATH FOR R-FORMAT AND MEMORY ACCESS Note: PC, adder, and instruction memory are omitted. add $rd, $rs, $rt lw $rt, immed($rs) sw $rt, immed($rs)

DATAPATH FOR R-FORMAT AND MEMORY ACCESS Note: PC, adder, and instruction memory are omitted. add $rd, $rs, $rt lw $rt, immed($rs) sw $rt, immed($rs)

DATAPATH FOR R-FORMAT AND MEMORY ACCESS Note: PC, adder, and instruction memory are omitted. add $rd, $rs, $rt lw $rt, immed($rs) sw $rt, immed($rs)

BRANCHING INSTRUCTIONS Now we ll turn out attention to a branching instruction. In our limited MIPS instruction set, we have the beq instruction which has the following form: beq $t1, $t2, offset This instruction compares the contents of $t1 and $t2 for equality and uses the 16-bit immediate field to compute the target address of the branch relative to the current address. Name Fields Field Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits I format op rs rt immed

BRANCHING INSTRUCTIONS Note that our immediate field is only 16-bits so we can t specify a full 32-bit target address. So we have to do a few things before jumping. The immediate field is left-shifted by two because the offset represents the number of words offset from PC+4, not the number of bytes (and we want to get it in number of bytes!). We sign-extend the immediate field to 32-bits. beq $t1, $t2, offset Name Fields Field Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits I format op rs rt immed

BRANCHING INSTRUCTIONS Note: the subscripts here indicate the number of bits. As an example, let s say PC is currently 0x64 = 0000 0000 0110 0100 32. The next instruction is beq $t1, $t2, 12.This instruction has us branch to an address 12 words away from the current address. The offset 12 in binary is 0000 0000 0000 1100 16. Now, we sign-extend our offset to get a 32-bit offset. This give us 0000... 0000 0000 1100 32. Then, we left-shift the offset by two to get the offset in number of bytes. This gives us 00 0000 0000 0011 0000 32. To get the target address, we simply add this offset to PC+4. (PC+4) + offset = 0110 1000 32 + 0011 0000 32 = 1001 1000 32

BRANCHING INSTRUCTIONS Besides computing the target address, a branching instruction also has to compare the contents of the source registers. As stated before, the ALU has an output line denoted as Zero. This output is specifically hardwired to be set when the result of an operation is zero. To test whether a and b are equal, we can set the ALU to perform a subtraction operation. The Zero output line is only set if a b is 0, indicating a and b are equal.

DATAPATH FOR BEQ Here, we have modified the datapath to work only for the beq instruction. beq $rs, $rt, immed rs rt The registers have been added to the datapath for added clarity. immed

DATAPATH FOR R AND I FORMAT Now we have a datapath which supports all of our R and I format instructions. add $rd, $rs, $rt lw $rt, immed($rs) sw $rt, immed($rs) beq $rs, $rt, immed

DATAPATH FOR R AND I FORMAT Now we have a datapath which supports all of our R and I format instructions. add $rd, $rs, $rt lw $rt, immed($rs) sw $rt, immed($rs) beq $rs, $rt, immed

J-FORMAT INSTRUCTIONS The last instruction we have to implement in our simple MIPS subset is the jump instruction. An example jump instruction is j L1. This instruction indicates that the next instruction to be executed is at the address of label L1. We have 6 bits for the opcode. We have 26 bits for the target address.

J-FORMAT INSTRUCTIONS Note, as in the branching example, we do not have enough space in the instruction to specify a full target address. Branching solves this problem by specifying an offset in words. Jump instructions solve this problem by specifying a portion of an absolute address, not an offset. We take the 26-bit target address field of the instruction, left-shift by two (because we are word-aligned), and concatenate the result with the upper 4 bits of PC+4.

J-FORMAT INSTRUCTIONS For example, let s say the current PC is 0x64 = 0000 0000 0110 0100 32. The next instruction is j L1. Let s say the pseudo-direct address of L1 is 0010 0110 26. To get the target address, we simply add the 28-bit left-shifted pseudo-direct address to the upper 4-bits of the PC+4. (PC + 4) 31 28 + Pseudo 27 0 = 0000 1001 1000 32

DATAPATH FOR J-FORMAT Here, we have modified the datapath to work only for the j instruction. j targaddr

SINGLE-CYCLE CONTROL Now we have a complete datapath for our simple MIPS subset we will show the whole diagram in just a couple of minutes. Before that, we will add the control. The control unit is responsible for taking the instruction and generating the appropriate signals for the datapath elements. Signals that need to be generated include Operation to be performed by ALU. Whether register file needs to be written. Signals for multiple intermediate multiplexors. Whether data memory needs to be written. For the most part, we can generate these signals using only the opcode and funct fields of an instruction.

ALU CONTROL LINES Note here that the ALU has a 4-bit control line called ALU operation. The first two bits indicate whether a and b need to be inverted, respectively. The last two bits indicate the operation. ALU Control Lines Function 0000 AND 0001 OR 0010 Add 0110 Subtract 0111 Set on less than 1100 NOR

ALU CONTROL LINES How do we set these control lines? Consider the control unit below. The 2-bit ALUop input indicates whether an operation should be add (00) for loads and stores, subtract (01) for beq, or determined by the funct input (10). The 6-bit Funct input corresponds to the funct field of R-format instructions. Each unique funct field corresponds to a unique set of ALU control input lines. 2 ALUop 6 Funct Control Unit 4 ALU Operation Control Input

ALU CONTROL LINES Opcode ALU op Operation Funct ALU action ALU Control Input lw 00 Load word N/A add 0010 sw 00 Store word N/A add 0010 2 beq 01 Branch equal N/A subtract 0110 R-type 10 Add 100000 add 0010 R-type 10 Subtract 100010 subtract 0110 R-type 10 AND 100100 AND 0000 ALUop 6 Funct Control Unit 4 ALU Control Input R-type 10 OR 100101 OR 0001 R-type 10 Set on less than 101010 slt 0111

Here, we have modified the datapath to work with every instruction except the jump instruction. Notice the added element for determining the ALU control input from the funct field for R-types.

CONTROL SIGNALS As we can see from the previous slide, we also need to use the instruction to set control signals other than the ALU. Signal Name Effect when not set Effect when set RegDst Destination register comes from rt field. Destination register comes from the rd field. RegWrite None. Write Register is written to with Write Data. ALUSrc Second ALU operand is Read Data 2. Second ALU operand is immediate field. PCSrc PC PC + 4 PC Branch target MemRead None. Contents of Address input are copied to Read Data. MemWrite None. Write Data is written to Address. MemToReg Value of register Write Data is from ALU. Value of register Write Data is memory Read Data.

Here, we have modified the datapath to work with every instruction except the jump instruction. Notice how most of the control decisions can be decided using only the upper 6 bits of the instruction (opcode).

CONTROL SIGNALS From the previous slide, we can see that the control signals are chosen based on the upper 6 bits of the instruction. That is, the opcode is used to set the control lines. Instr. RegDst ALUSrc MemToReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOp2 R 1 0 0 1 0 0 0 1 0 lw 0 1 1 1 1 0 0 0 0 sw X 1 X 0 0 1 0 0 0 beq X 0 X 0 0 0 1 0 1 Furthermore, as we saw before, the ALU control input lines are also dictated by the funct fields of applicable instructions.

Here we add in an additional control line for jump instructions.

Quiz Time! What are the relevant datapath lines for the add instruction and what are the values of each of the control lines? add $rd, $rs, $rt

Quiz Time! What are the relevant datapath lines for the add instruction and what are the values of each of the control lines? add $rd, $rs, $rt Datapath shown in yellow. Relevant control lines in green.

Quiz Time! What are the relevant datapath lines for the add instruction and what are the values of each of the control lines? add $rd, $rs, $rt Datapath shown in yellow. Relevant control lines in green.

Quiz Time! What are the relevant datapath lines for the beq instruction and what are the values of each of the control lines? beq $rs, $rt, imm

Quiz Time! What are the relevant datapath lines for the beq instruction and what are the values of each of the control lines? beq $rs, $rt, imm

RELATIVE CYCLE TIME Type What is the longest path (slowest instruction) assuming 4ns for instruction and data memory, 3ns for ALU and adders, and 1ns for register reads or writes? Assume negligible delays for muxes, control unit, sign extend, PC access, shift left by 2, routing, etc Instruction Memory Register Read ALU Operation Data Memory Register Write R-format 4 1 3 0 1 9 lw 4 1 3 4 1 13 sw 4 1 3 4 0 12 beq 4 1 3 0 0 8 j 4 0 0 0 0 4 Total

SINGLE-CYCLE IMPLEMENTATION The advantage of single cycle implementation is that it is simple to implement. Disadvantages The clock cycle will be determined by the longest possible path, which is not the most common instruction. This type of implementation violates the idea of making the common case fast. May be wasteful with respect to area since some functional units, such as adders, must be duplicated since they cannot be shared during a single clock cycle