Processor Design: How to Implement MIPS. Simplicity favors regularity

Similar documents
Review: MIPS Addressing Modes/Instruction Formats

Computer organization

(Refer Slide Time: 00:01:16 min)

Let s put together a Manual Processor

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Addressing The problem. When & Where do we encounter Data? The concept of addressing data' in computations. The implications for our machine design(s)

Solutions. Solution The values of the signals are as follows:

Computer Organization and Components

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Reduced Instruction Set Computer (RISC)

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University

16-bit ALU, Register File and Memory Write Interface

MICROPROCESSOR AND MICROCOMPUTER BASICS

A s we saw in Chapter 4, a CPU contains three main sections: the register section,

Pipeline Hazards. Structure hazard Data hazard. ComputerArchitecture_PipelineHazard1

WEEK 8.1 Registers and Counters. ECE124 Digital Circuits and Systems Page 1

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

Digital Logic Design. Basics Combinational Circuits Sequential Circuits. Pu-Jen Cheng

Microprocessor & Assembly Language

Pipeline Hazards. Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. Based on the material prepared by Arvind and Krste Asanovic

Instruction Set Architecture

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

Introducción. Diseño de sistemas digitales.1

Instruction Set Design

Memory Elements. Combinational logic cannot remember

Design of Digital Circuits (SS16)

Take-Home Exercise. z y x. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

The 104 Duke_ACC Machine

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

Systems I: Computer Organization and Architecture

Binary Adders: Half Adders and Full Adders

Latches, the D Flip-Flop & Counter Design. ECE 152A Winter 2012

CS 61C: Great Ideas in Computer Architecture Finite State Machines. Machine Interpreta4on

CPU Organisation and Operation

TIMING DIAGRAM O 8085

l C-Programming l A real computer language l Data Representation l Everything goes down to bits and bytes l Machine representation Language

CS311 Lecture: Sequential Circuits

Chapter 9 Computer Design Basics!

Central Processing Unit (CPU)

Chapter 2 Logic Gates and Introduction to Computer Architecture

A New Paradigm for Synchronous State Machine Design in Verilog

In the Beginning The first ISA appears on the IBM System 360 In the good old days

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December :59

Sequential Logic. (Materials taken from: Principles of Computer Hardware by Alan Clements )

Systems I: Computer Organization and Architecture

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

An Introduction to the ARM 7 Architecture

Counters and Decoders

ECE410 Design Project Spring 2008 Design and Characterization of a CMOS 8-bit Microprocessor Data Path

MACHINE ARCHITECTURE & LANGUAGE

DEPARTMENT OF INFORMATION TECHNLOGY

Module 3: Floyd, Digital Fundamental

CHAPTER 7: The CPU and Memory

CHAPTER 3 Boolean Algebra and Digital Logic

Chapter 5 Instructor's Manual

İSTANBUL AYDIN UNIVERSITY

CHAPTER 11: Flip Flops

CPU Organization and Assembly Language

Instruction Set Architecture (ISA)

CSE 141L Computer Architecture Lab Fall Lecture 2

To design digital counter circuits using JK-Flip-Flop. To implement counter using 74LS193 IC.

Understanding Verilog Blocking and Non-blocking Assignments

CS352H: Computer Systems Architecture

CS:APP Chapter 4 Computer Architecture. Wrap-Up. William J. Taffe Plymouth State University. using the slides of

Lecture-3 MEMORY: Development of Memory:

Design of Pipelined MIPS Processor. Sept. 24 & 26, 1997

PROBLEMS #20,R0,R1 #$3A,R2,R4

PART B QUESTIONS AND ANSWERS UNIT I

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

EC 362 Problem Set #2

on an system with an infinite number of processors. Calculate the speedup of

Assembly Language Programming

Q. Consider a dynamic instruction execution (an execution trace, in other words) that consists of repeats of code in this pattern:

Lecture 5: Gate Logic Logic Optimization

Introduction to CMOS VLSI Design (E158) Lecture 8: Clocking of VLSI Systems

Central Processing Unit

Computer Organization. and Instruction Execution. August 22

CHAPTER IX REGISTER BLOCKS COUNTERS, SHIFT, AND ROTATE REGISTERS

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 OUTCOME 3 PART 1

Generating MIF files

Flip-Flops, Registers, Counters, and a Simple Processor

BINARY CODED DECIMAL: B.C.D.

1 Classical Universal Computer 3

Summary of the MARIE Assembly Language

ARM Cortex-M3 Assembly Language

Lecture 7: Clocking of VLSI Systems

Memory ICS 233. Computer Architecture and Assembly Language Prof. Muhamed Mudawar

COMBINATIONAL and SEQUENTIAL LOGIC CIRCUITS Hardware implementation and software design

Instruction Set Architecture. Datapath & Control. Instruction. LC-3 Overview: Memory and Registers. CIT 595 Spring 2010

EECS 427 RISC PROCESSOR

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

Chapter 7. Registers & Register Transfers. J.J. Shann. J. J. Shann

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Chapter 4 Lecture 5 The Microarchitecture Level Integer JAVA Virtual Machine

AC : A PROCESSOR DESIGN PROJECT FOR A FIRST COURSE IN COMPUTER ORGANIZATION

An Overview of Stack Architecture and the PSC 1000 Microprocessor

CHAPTER 4 MARIE: An Introduction to a Simple Computer

Execution Cycle. Pipelining. IF and ID Stages. Simple MIPS Instruction Formats

Computer Organization and Architecture

Transcription:

ECE468 Computer Organization and Architecture Designing a Single Cycle Datapath Processor Design: How to Implement MIPS Simplicity favors regularity ECE468 Datapath.1 22-4-1 Start: X:4

The Big Picture: Where are We Now? The Five Classic Components of a Computer Processor Control Memory Input Datapath Output Today s Topic: Datapath Design What is data? What is datapath? ECE468 Datapath.2 22-4-1 Before we go any further, let s step back for a second and take a look at the big picture. All computer consist of five components: (1) Input and (2) output devices. (3) The Memory System. And the (4) Control and (5) Datapath of the Processor. Today s lecture covers the datapath design. In the next lecture, I will show you how to design the processor s control unit. +1 = 5 min. (X:45)

The Big Picture: The Performance Perspective Performance of a machine was determined by: Instruction count Clock cycle time Clock cycles per instruction Processor design (datapath and control) will determine: Clock cycle time Clock cycles per instruction In the next two lectures: Single cycle processor: - Advantage: One clock cycle per instruction - Disadvantage: long cycle time ECE468 Datapath.3 22-4-1 This slide shows how the next two lectures fit into the overall performance picture. Recall from one of your earlier lectures that the performance of a machine is determined by 3 factors: (a) Instruction count, (b) Clock cycle time, and (c) Clock cycles per instruction. Instruction count is controlled by the Instruction Set Architecture and the compiler design so the computer engineer has very little control over it (Instruction Count). What you as a computer engineer can control, while you are designing a processor, are the Clock Cycle Time and Instruction Count per cycle. More specifically, in the next two lectures, you will be designing a single cycle processor which by definition takes one clock cycle to execute every instruction. The disadvantage of this single cycle processor design is that it has a long cycle time. +2 = 7 min. (X:47)

The MIPS Instruction Formats All MIPS instructions are bits long. The three instruction formats: 31 26 21 11 6 R-type op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits I-type 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits J-type 31 26 op target address 6 bits 26 bits The different fields are: op: operation of the instruction rs, rt, rd: the source and destination register specifiers shamt: shift amount funct: selects the variant of the operation in the op field address / immediate: address offset or immediate value target address: target address of the jump instruction ECE468 Datapath.4 22-4-1 One of the most important thing you need to know before you start designing a processor is how the instructions look like. Or in more technical term, you need to know the instruction format. One good thing about the MIPS instruction set is that it is very simple. First of all, all MIPS instructions are bits long and there are only three instruction formats: (a) R- type, (b) I-type, and (c) J-type. The different fields of the R-type instructions are: (a) OP specifies the operation of the instruction. (b) Rs, Rt, and Rd are the source and destination register specifiers. (c) Shamt specifies the amount you need to shift for the shift instructions. (d) Funct selects the variant of the operation specified in the op field. For the I-type instruction, bits to 15 are used as an immediate field. I will show you how this immediate field is used differently by different instructions. Finally for the J-type instruction, bits to 25 become the target address of the jump. +3 = 1 min. (X:5)

The MIPS Subset ADD and subtract add rd, rs, rt sub rd, rs, rt OR Immediate: ori rt, rs, imm LOAD and STORE lw rt, rs, imm sw rt, rs, imm BRANCH: beq rs, rt, imm 31 31 26 21 11 6 op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits JUMP: 31 26 j target op target address 6 bits 26 bits ECE468 Datapath.5 22-4-1 In today s lecture, I will show you how to implement the following subset of MIPS instructions: add, subtract, or immediate, load, store, branch, and the jump instruction. The Add and Subtract instructions use the R format. The Op together with the Func fields together specified all the different kinds of add and subtract instructions. Rs and Rt specifies the source registers. And the Rd field specifies the destination register. The Or immediate instruction uses the I format. It only uses one source register, Rs. The other operand comes from the immediate field. The Rt field is used to specified the destination register. Both the load and store instructions use the I format and both add the Rs and the immediate filed together to form the memory address. The difference is that the load instruction will load the data from memory into Rt while the store instruction will store the data in Rt into the memory. The branch on equal instruction also uses the I format. Here Rs and Rt are used to specified the registers we need to compare. If these two registers are equal, we will branch to a location specified by the immediate field. Finally, the jump instruction uses the J format and always causes the program to jump to a memory location specified in the address field. I know I went over this rather quickly and you may have missed something. But don t worry, this is just an overview. You will keep seeing these (point to the format) all day today. +3 = 13 min. (X:53)

An Abstract View of the Implementation Two types of functional units Operational element that operate on data (combinational State element that contain data (sequential) PC Ideal Instruction Memory Instruction Address Rd 5 Instruction Rs 5 Rt 5 Imm Generic Implementation: use PC to supply instruction address get the instruction from memory read registers use the instruction to decide exactly what to do All instructions use the ALU after reading the registers Why? memory-reference? arithmetic? control flow? Rw Ra Rb -bit Registers ALU Data Address Data In Ideal Data Memory DataOut Next step: to fill in the details: more units, more connections, and control unit ECE468 Datapath.6 22-4-1 One thing you may noticed from our last slide is that almost all instructions, except Jump, require reading some registers, do some computation, and then do something else. Therefore our datapath will look something like this. For example, if we have an add instruction (points to the output of Instruction Memory), we will read the registers from the register file (Ra, Rb and then busa and busb). Add the two numbers together (ALU) and then write the result back to the register file. On the other hand, if we have a load instruction, we will first use the ALU to calculate the memory address. Once the address is ready, we will use it to access the Data Memory. And once the data is available on Data Memory s output bus, we will write the data to the register file. Well, this is simple enough. But if it is this simple, you probably won t need to take this class. So in today s lecture, I will show you how to turn this abstract datapath into a real datapath by making it slightly (JUST slightly) more complicated so it can do real work for you. But before we do that, let s do a quick review of the clocking methodology +3 = (X:56)

Clocking Methodology Setup Hold Don t Care Setup Hold............ All storage elements are clocked by the same clock edge Edge-trigged: all stored values are updated on a clock edge Cycle Time = Latch Prop + Longest Delay Path + Setup + Clock Skew (Latch Prop + Shortest Delay Path - Clock Skew) > Hold Time ECE468 Datapath.7 22-4-1 Remember, we will be using a clocking methodology where all storage elements are clocked by the same clock edge. Consequently, our cycle time will be the sum of: (a) The Clock-to-Q ( or latch propagation) time of the input registers. (b) The longest delay path through the combinational logic block. (c) The set up time of the output register. (d) And finally the clock skew. In order to avoid hold time violation, you have to make sure this inequality is fulfilled. +2 = 18 min. (X:58)

An Abstract View of the Critical Path Register file and ideal memory: The CLK input is a factor ONLY during write operation During read operation, behave as combinational logic: - Address valid => Output valid after access time. PC Ideal Instruction Memory Instruction Address Rd 5 Instruction Rs 5 Rt 5 Imm Critical Path (Load Operation) = PC s prop time + Instruction Memory s Access Time + Register File s Access Time + ALU to Perform a -bit Add + Data Memory Access Time + Setup Time for Register File Write + Clock Skew Rw Ra Rb -bit Registers ALU Data Address Data In Ideal Data Memory DataOut ECE468 Datapath.8 22-4-1 Now with the clocking methodology back in your mind, we can think about how the critical path of our abstract datapath may look like. One thing to keep in mind about the Register File and Ideal Memory (points to both Instruction and Data) is that the Clock input is a factor ONLY during the write operation. For read operation, the CLK input is not a factor. The register file and the ideal memory behave as if they are combinational logic. That is you apply an address to the input, then after certain delay, which we called access time, the output is valid. We will come back to these points (point to the behave bullets) later in this lecture. But for now, let s look at this abstract datapath s critical path which occurs when the datapath tries to execute the Load instruction. The time it takes to execute the load instruction are the sum of: (a) The PC s clock-to-q time. (b) The instruction memory access time. (c) The time it takes to read the register file. (d) The ALU delay in calculating the Data Memory Address. (e) The time it takes to read the Data Memory. (f) And finally, the setup time for the register file and clock skew. +3 = 21 (Y:1)

The Steps of Designing a Processor Instruction Set Architecture => Register Transfer Language Register Transfer Language (RTL) => Datapath components Datapath interconnect Datapath components => Control signals Control signals => Control logic Element < component ECE468 Datapath.9 22-4-1 So let s design a processor. How and where do we start? Well, the best place to start is the processor s instruction set architecture. After all, the goal of your design is to execute the instructions in the instruction set correctly. What you need to do is to describe each instruction s operation in register transfer language. By looking at the Register Transfer Language description of the instruction, you can figure out the datapath components you need and how to connect these components together. As I will show you, each datapath component will have its own set of control signals. And the last step of the processor design task is to design the control unit that generates the control signals for the datapath. So what do we mean by Register Transfer Language? +2 = 27 min. (Y:7)

What is RTL: The ADD Instruction add rd, rs, rt Register Transfer Language mem[pc] Fetch the instruction from memory R[rd] <- R[rs] + R[rt] The ADD operation PC <- PC + 4 Calculate the next instruction s address ECE468 Datapath.1 22-4-1 Here is an example. In terms of Register Transfer Language, this is what the Add instruction need to do. First, you need to fetch the instruction from memory. Then you perform the actual add operation. And finally, you need to update the program counter to point to the next instruction. +1 = 28 min. (Y:8)

What is RTL: The Load Instruction lw rt, rs, imm mem[pc] Fetch the instruction from memory Addr <- R[rs] + SignExt(imm) Calculate the memory address R[rt] <- Mem[Addr] Load the data into the register PC <- PC + 4 Calculate the next instruction s address ECE468 Datapath.11 22-4-1 Here is another example. The load instruction also starts off by fetching the instruction from Instruction Memory. Then you calculate the memory address, use the address to fetch the data from memory (Mem(Addr)), and then load the data into the register. Finally, you need to update the PC to point to the next sequential instruction. +1 = 29 min (Y:9)

Combinational Logic Elements Adder MUX (p.b-9,b-19) ALU A B A B A Select OP MUX Adder Y B ALU CarryIn Sum Carry Result Zero Decoder 3 Decoder out out1 out2 out7 ECE468 Datapath.12 22-4-1 Based on the Register Transfer Language examples we have so far, we know we will need the following combinational logic elements. We will need an adder to update the program counter. A MUX to select the results. And finally, an ALU to do various arithmetic and logic operation. +1 = 3 min. (Y:1)

Storage Element: Register (p.b22-b25) Register Write Enable Similar to the D Flip Flop except - N-bit input and output Data In - Write Enable input N Write Enable: - : Data Out will not change - 1: Data Out will become Data In Array of logical elements(see register file on next 2 slides) Data Out N The content is updated at the clock tick ONLY if the Write Enable signal is set to 1. ECE468 Datapath.13 22-4-1 As far as storage elements are concerned, we will need a N-bit register that is similar to the D flipflop I showed you in class. The significant difference here is that the register will have a Write Enable input. That is the content of the register will NOT be updated if Write Enable is zero. The content is updated at the clock tick ONLY if the Write Enable signal is set to 1. +1 = 31 min. (Y:11)

Storage Element: Register File Register File consists of registers: Two -bit output busses: busa and busb One -bit input bus: busw Register is selected by: RA selects the register to put on busa RB selects the register to put on busb RW selects the register to be written via busw when Write Enable is 1 RW RA RB Write Enable 5 5 5 busw -bit Registers busa busb Clock input (CLK) The CLK input is a factor ONLY during write operation During read operation, behaves as a combinational logic block: - RA or RB valid => busa or busb valid after access time. ECE468 Datapath.14 22-4-1 We will also need a register file that consists of -bit registers with two output busses (busa and busb) and one input bus. The register specifiers Ra and Rb select the registers to put on busa and busb respectively. When Write Enable is 1, the register specifier Rw selects the register to be written via busw. In our simplified version of the register file, the write operation will occurs at the clock tick. Keep in mind that the clock input is a factor ONLY during the write operation. During read operation, the register file behaves as a combinational logic block. That is if you put a valid value on Ra, then bus A will become valid after the register file s access time. Similarly if you put a valid value on Rb, bus B will become valid after the register file s access time. In both cases (Ra and Rb), the clock input is not a factor. +2 = 33 min. (Y:13)

Storage Element: Register File -- Detailed diagram RW RA RB Write Enable 5 5 5 Write Enable RA RB busw -bit Registers busa busb RW 1 -to-1 Decoder 3 31 C Register D C Register 1 D M U busa busw C Register 3 D C Register 31 D X M U busb X ECE468 Datapath.15 22-4-1 We will also need a register file that consists of -bit registers with two output busses (busa and busb) and one input bus. The register specifiers Ra and Rb select the registers to put on busa and busb respectively. When Write Enable is 1, the register specifier Rw selects the register to be written via busw. In our simplified version of the register file, the write operation will occurs at the clock tick. Keep in mind that the clock input is a factor ONLY during the write operation. During read operation, the register file behaves as a combinational logic block. That is if you put a valid value on Ra, then bus A will become valid after the register file s access time. Similarly if you put a valid value on Rb, bus B will become valid after the register file s access time. In both cases (Ra and Rb), the clock input is not a factor. +2 = 33 min. (Y:13)

Storage Element: Idealized Memory Write Enable Address Memory (idealized) One input bus: Data In Data In DataOut One output bus: Data Out Memory word is selected by: Address selects the word to put on Data Out Write Enable = 1: address selects the memory memory word to be written via the Data In bus Clock input (CLK) The CLK input is a factor ONLY during write operation During read operation, behaves as a combinational logic block: - Address valid => Data Out valid after access time. ECE468 Datapath. 22-4-1 The last storage element you will need for the datapath is the idealized memory to store your data and instructions. This idealized memory block has just one input bus (DataIn) and one output bus (DataOut). When Write Enable is, the address selects the memory word to put on the Data Out bus. When Write Enable is 1, the address selects the memory word to be written via the DataIn bus at the next clock tick. Once again, the clock input is a factor ONLY during the write operation. During read operation, it behaves as a combinational logic block. That is if you put a valid value on the address lines, the output bus DataOut will become valid after the access time of the memory. +2 = 35 min. (Y:15)

Overview of the Instruction Fetch Unit (Fig. 5.5) The common RTL operations Fetch the Instruction: mem[pc] Update the program counter: - Sequential Code: PC <- PC + 4 - Branch and Jump PC <- something else PC Next Address Logic Address Instruction Memory Instruction Word ECE468 Datapath.17 22-4-1 Now let s take a look at the first major component of the datapath: the instruction fetch unit. The common RTL operations for all instructions are: (a) Fetch the instruction using the Program Counter (PC) at the beginning of an instruction s execution (PC -> Instruction Memory -> Instruction Word). (b) Then at the end of the instruction s execution, you need to update the Program Counter (PC -> Next Address Logic -> PC). More specifically, you need to increment the PC by 4 if you are executing sequential code. For Branch and Jump instructions, you need to update the program counter to something else other than plus 4. I will show you what is inside this Next Address Logic block when we talked about the Branch and Jump instructions. For now, let s focus our attention to the Add and Subtract instructions. +2 = 37 min. (Y:17)

RTL: The ADD Instruction 31 26 21 11 6 op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits add rd, rs, rt mem[pc] Fetch the instruction from memory R[rd] <- R[rs] + R[rt] The actual operation PC <- PC + 4 Calculate the next instruction s address ECE468 Datapath.18 22-4-1 The Add instruction is a R-type instruction. The Instruction Fetch Unit I just showed you will take care of the instruction fetch (mem[pc]) and PC update (PC <- PC + 4). The thing we need to take care of now is the actual operation: add the contents of the registers specified by the Rs and the Rt fields (Rs and Rt of the format diagram). And then write the results to the register specified by the Rd field. +1 = 38 min. (Y:18)

RTL: The Subtract Instruction 31 26 21 11 6 op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits sub rd, rs, rt mem[pc] Fetch the instruction from memory R[rd] <- R[rs] - R[rt] The actual operation PC <- PC + 4 Calculate the next instruction s address ECE468 Datapath.19 22-4-1 The Subtract instruction is also a R-type instruction. Here we need to subtract the the contents of the register specified by Rt from the contents of the register specified by the Rs field (Rs and Rt of the format diagram). And then write the results back to the register specified by the Rd field. +1 = 39 min. (Y:19)

Datapath for Register-Register Operations R[rd] <- R[rs] op R[rt] Example: add rd, rs, rt Ra, Rb, and Rw comes from instruction s rs, rt, and rd fields ALUctr and RegWr: control logic after decoding the instruction 31 26 21 11 6 op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits RegWr busw Rd Rs 5 5 5 Rw Ra Rb -bit Registers Rt busa busb ALUctr ALU Result ECE468 Datapath.2 22-4-1 And here is the datapath that can do the trick. First of all, we connect the register file s Ra, Rb, and Rw input to the Rd, Rs, and Rt fields of the instruction bus (points to the format diagram). Then we need to connect busa and busb of the register file to the ALU. Finally, we need to connect the output of the ALU to the input bus of the register file. Conceptually, this is how it works. The instruction bus coming out of the Instruction memory will set the Ra and Rb to the register specifiers Rs and Rt. This causes the register file to put the value of register Rs onto busa and the value of register Rt onto busb, respectively. But setting the ALUctr appropriately, the ALU will perform either the Add and Subtract for us. The result is then fed back to the register file where the register specifier Rw should already be set to the instruction bus s Rd field. Since the control, which we will design in our next lecture, should have already set the RegWr signal to 1, the result will be written back to the register file at the next clock tick (points to the input). +3 = 42 min. (Y:22)

Register-Register Timing PC Rs, Rt, Rd, Op, Func ALUctr Old Value -to-q New Value Old Value Old Value Instruction Memory Access Time New Value Delay through Control Logic New Value RegWr Old Value New Value Register File Access Time busa, B Old Value New Value ALU Delay busw Old Value New Value RegWr busw Rd Rs Rt 5 5 5 Rw Ra Rb -bit Registers busa busb ALUctr ALU Result Register Write Occurs Here ECE468 Datapath.21 22-4-1 Let s take a more quantitative picture of what is happening. At each clock tick, the Program Counter will present its latest value to the Instruction memory after -to-q time. After a delay of the Instruction Memory Access time, the Opcode, Rd, Rs, Rt, and Function fields will become valid on the instruction bus. Once we have the new instruction, that is the Add or Subtract instruction, on the instruction bus, two things happen in parallel. First of all, the control unit will decode the Opcode and Func field and set the control signals ALUctr and RegWr accordingly. We will cover this in the next lecture. While this is happening (points to Control Delay), we will also be reading the register file (Register File Access Time). Once the data is valid on busa and busb, the ALU will perform the Add or Subtract operation based on the ALUctr signal. Hopefully, the ALU is fast enough that it will finish the operation (ALU Delay) before the next clock tick. At the next clock tick, the output of the ALU will be written into the register file because the RegWr signal will be equal to 1. +3 = 45 min. (Y:25)

RTL: The OR Immediate Instruction 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits ori rt, rs, imm mem[pc] Fetch the instruction from memory R[rt] <- R[rs] or ZeroExt(imm) The OR operation PC <- PC + 4 Calculate the next instruction s address 31 bits 15 immediate bits ECE468 Datapath.22 22-4-1 The or immediate is a I-type instruction. The immediate field of the instruction (Imm of the format diagram) is zero extended to bits before it is operated with the other operand. The other operand is selected by the Rs field of the instruction. The destination register of this instruction will be selected by the Rt field. +2 = 57 min. (Y:27)

Datapath for Logical Operations with Immediate R[rt] <- R[rs] op ZeroExt[imm]] Example: ori rt, rs, imm 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits Rd Rt RegDst Mux Don t Care Rs RegWr (Rt) 5 5 5 busw imm Rw Ra Rb -bit Registers busb ZeroExt busa ALUctr Result ECE468 Datapath.23 22-4-1 Mux Newly added parts are in blue color. ALUSrc ALU Here is the datapath for the Or immediate instructions. We cannot use the Rd field here (Rw) because in this instruction format, we don t have a Rd field. The Rd field in the R-type is used here as part of the immediate field. For this instruction type, Rw input of the register file, that is the address of the register to be written, comes from the Rt field of the instruction. Recalled from earlier slide that for R-type instruction, the Rw comes from the Rd field. That s why we need a MUX here to put Rd onto Rw for R-type instructions and to put Rt onto Rw for the I-type instruction. Since the second operation of this instruction will be the immediate field zero extended to bits, we also need a MUX here to block off bus B from the register file. Since bus B is blocked off by the MUX, the value on bus B is don t care. Therefore we do not have to worry about what ends up on the register file s Rb register specifier. To keep things simple, we may just as well keep it the same as the R-type instruction and put the Rt field here. So to summarize, this is how this datapath works. With Rs on Register File s Ra input, bus A will get the value of Rs as the first ALU operand. The second operand will come from the immediate field of the instruction. Once the ALU complete the OR operation, the result will be written into the register specified by the instruction s Rt field. +3 = 5 min. (Y:3)

RTL: The Load Instruction lw rt, rs, imm 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits mem[pc] Fetch the instruction from memory Addr <- R[rs] + SignExt(imm) Calculate the memory address R[rt] <- Mem[Addr] Load the data into the register PC <- PC + 4 Calculate the next instruction s address 31 15 bits 31 15 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 bits immediate bits immediate bits ECE468 Datapath.24 22-4-1 Like the OR immediate instruction I just showed you, the load instruction also uses the I format (point to the format diagram). But unlike the OR immediate instruction, the immediate field (Imm of the format diagram) is sign extended instead of zero extended. That is we will duplicate the most significant bit of times to the left to form a -bit value. This sign extended value (SignExt) is then added to the register selected by the Rs field of the instruction to form the memory address. The memory address is then used to load the value into the register specified by the Rt field of the instruction (Rt of the format diagram). +2 = 57 min. (Y:37)

Datapath for Load Operations R[rt] <- Mem[R[rs] + SignExt[imm]] Example: lw rt, rs, imm 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits Rd Rt RegDst Mux Don t Care Rs RegWr (Rt) 5 5 5 busw imm Rw Ra Rb -bit Registers busb Extender busa Mux ALUSrc ALUctr ALU Data In MemWr WrEn Adr Data Memory MemtoReg Mux ExtOp ECE468 Datapath.25 22-4-1 Once again we cannot use the instruction s Rd field for the Register File s Rw input because load is a I-type instruction and there is no such thing as the Rd field in the I format. So instead of Rd, the Rt field is used to specify the destination register through this two to one multiplexor. The first operand of the ALU comes from busa of the register file which contains the value of Register Rs (points to the Ra input of the register file). The second operand, on the other hand, comes from the immediate field of the instruction. Instead of using the Zero Extender I used in datapath for the or immediate datapath, I have to use a more general purpose Extender that can do both Sign Extend and Zero Extend. The ALU then adds these two operands together to form the memory address. Consequently, the output of the ALU has to go to two places: (a) First the address input of the data memory. (b) And secondly, also to the input of this two-to-one multiplexer. The other input of this multiplexer comes from the output of the data memory so we can place the output of the data memory onto the register file s input bus for the load instruction. For Add, Subtract, and the Or immediate instructions, the output of the ALU will be selected to be placed on the input bus of the register file. In either case, the control signal RegWr should be asserted so the register file will be written at the end of the cycle. +3 = 6 min. (Y:4)

RTL: The Store Instruction 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits sw rt, rs, imm mem[pc] Fetch the instruction from memory Addr <- R[rs] + SignExt(imm) Calculate the memory address Mem[Addr] <- R[rt] Store the register into memory PC <- PC + 4 Calculate the next instruction s address ECE468 Datapath.26 22-4-1 Just like the load instruction: (a) The store instruction also uses the I format. (b) And the store instruction also forms the memory address by adding the contents of the register selected by the Rs field to the sign extended immediate field. However, unlike the load instruction, which gets data from memory and put the data into the the register file, the store instruction: (a) Get the register selected by the Rt field of the instruction (R[rt]). (b) And then write this register into the data memory. +2 = 62 min. (Y:42)

Datapath for Store Operations Mem[R[rs] + SignExt[imm] <- R[rt]] Example: sw rt, rs, imm 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits Rd Rt RegDst Mux Rs Rt RegWr 5 5 5 busw imm Rw Ra Rb -bit Registers busb Extender busa Mux ALUSrc ALUctr ALU Data In MemWr WrEn Adr Data Memory MemtoReg Mux ExtOp ECE468 Datapath.27 22-4-1 And here is the datapath for the store instruction. The Register File, the ALU, and the Extender are the same as the datapath for the load instruction because the memory address has to be calculated the exact same way: (a) Put the register selected by Rs onto bus A and sign extend the bit immediate field. (b) Then make the ALU (ALUctr) adds these two (busa and output of Extender) together. The new thing we added here is busb extension (DataIn). More specifically, in order to send the register selected by the Rt field (Rb of the register file) to data memory, we need to connect bus B to the data memory s Data In bus. Finally, the store instruction is the first instruction we encountered that does not do any register write at the end. Therefore the control unit must make sure RegWr is zero for this instruction. +2 = 64 min. (Y:44)

RTL: The Branch Instruction 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits beq rs, rt, imm mem[pc] Fetch the instruction from memory Cond <- R[rs] - R[rt] Calculate the branch condition if (COND eq ) Calculate the next instruction s address - PC <- PC + 4 + ( SignExt(imm) x 4 ) else - PC <- PC + 4 ECE468 Datapath.28 22-4-1 How does the branch on equal instruction work? Well it calculates the branch condition by subtracting the register selected by the Rt field from the register selected by the Rs field. If the result of the subtraction is zero, then these two registers are equal and we take a branch. Otherwise, we keep going down the sequential path (PC <- PC +4). +1 = 65 min. (Y:45)

Datapath for Branch Operations beq rs, rt, imm We need to compare Rs and Rt! 31 26 21 op rs rt immediate 6 bits 5 bits 5 bits bits Rd Rt RegDst Mux Rs Rt RegWr 5 5 5 busw imm Rw Ra Rb -bit Registers busb Extender busa Mux ALUSrc ALUctr ALU imm Branch Zero PC Next Address Logic To Instruction Memory ExtOp ECE468 Datapath.29 22-4-1 The datapath for calculating the branch condition is rather simple. All we have to do is feed the Rs and Rt fields of the instruction into the Ra and Rb inputs of the register file. Bus A will then contain the value from the register selected by Rs. And bus B will contain the value from the register selected by Rt. The next thing to do is to ask the ALU to perform a subtract operation and feed the output Zero to the next address logic. How does the next address logic block look like? Well, before I show you that, let s take a look at the binary arithmetics behind the program counter (PC). +2 = 67 min. (Y:47)

Binary Arithmetics for the Next Address In theory, the PC is a -bit byte address into the instruction memory: Sequential operation: PC<31:> = PC<31:> + 4 Branch operation: PC<31:> = PC<31:> + 4 + SignExt[Imm] * 4 The magic number 4 always comes up because: The -bit PC is a byte address And all our instructions are 4 bytes ( bits) long In other words: The 2 LSBs of the -bit PC are always zeros There is no reason to have hardware to keep the 2 LSBs In practice, we can simplify the hardware by using a 3-bit PC<31:2>: Sequential operation: PC<31:2> = PC<31:2> + 1 Branch operation: PC<31:2> = PC<31:2> + 1 + SignExt[Imm] In either case: Instruction Memory Address = PC<31:2> concat ECE468 Datapath.3 22-4-1 In theory, the Program Counter (PC) is a -bit byte address into the Instruction memory. The Program Counter is increment by four after each sequential instruction. When a branch is taken, we need to sign extend the bit immediate field, multiply this sign extended value by four, and add it to the sequential instruction address (PC + 4). Why does this magic number 4 always come up? Well the reason is that the -bit PC is a byte address and all MIPS instructions are four bytes, or bits, long. In other words, if we keep a -bit Program Counter, then the two least significant bits of the Program Counter will always be zeros. And if these two bits are always zeros, there is no reason to have hardware to keep them. So in practice, we will simply the hardware by using a 3 bit program counter. That is, we will build a Program Counter that only keep tracks of the upper 3 bits (<31:2>) of the instruction address because we know the 2 least significant bits will always be s. Then instead of always increase the Program Counter by four for sequential operation, we only have to increase it by 1. And for branch operation, we don t need to multiply the sign extended immediate field by four before adding to the sequential PC (PC + 1). And when we apply the program counter to the address of the instruction memory, we need to attach two zeros to its least significant bits. +3 = 7 min. (Y:5)

Next Address Logic: Expensive and Fast Solution Using a 3-bit PC: Sequential operation: PC<31:2> = PC<31:2> + 1 Branch operation: PC<31:2> = PC<31:2> + 1 + SignExt[Imm] In either case: Instruction Memory Address = PC<31:2> concat PC 3 1 imm Instruction<15:> SignExt Adder 3 3 3 3 Adder 3 Mux 1 Addr<31:2> Addr<1:> Instruction Memory Instruction<31:> Branch Zero ECE468 Datapath.31 22-4-1 So let s see how we can put all these theories (point to the equations) into practice. The PC plus one is implemented by this first adder here. For branch operation, we need to sign extend the immediate field of the instruction and then add it to the output of the first adder to implement this equation (PC + 1 + SignExt(imm)). For sequential operation, the output of the first adder is selected by the two-to-one mux so it will be saved into the PC register at the next clock tick. For a taken branch, that is we have a branch_on_equal and the condition Zero is true, the output of the second adder is selected. In all cases, the 3 bit Program Counter is used as instruction address bit 31 to bit 2. The two least significant bits of the instruction address will always be zeroes. One question you may want to ask is: Do we really need an adder just to add 1? Well may be not. +2 = 72 min. (Y:52)

Next Address Logic: Cheap and Slow Solution Why is this slow? Cannot start the address add until Zero (output of ALU) is valid Does it matter that this is slow in the overall scheme of things? Probably not here. Critical path is the load operation. 3 PC imm Instruction<15:> 3 SignExt 3 Mux 1 3 1 Carry In Adder 3 Addr<31:2> Addr<1:> Instruction Memory Instruction<31:> Branch Zero ECE468 Datapath. 22-4-1 One way to simplify the implementation is to use the CarryIn input of the adder to implement the PC<31:2> = PC<31:2> plus 1 operation. Then we can put a MUX in front of the adder to add the branch offset if the branch is taken. If the branch is not taken, we simply set the 2nd output of the ALU to zeros so we only add one through the CarryIn input. Why is this implementation slow? Well because we cannot start the address add until the Zero input is valid. And when will the Zero input become valid? Not until we have performed a -bit subtract in the main datapath. But does it matter that this is slow in the overall scheme of things? Well, probably not in this single cycle implementation. The critical path of this single cycle implementation will be the load instruction s memory access so the extra time it takes to calculate the PC can be hidden behind the critical path. +3 = 75 min (Y:55)

RTL: The Jump Instruction 31 26 op target address 6 bits 26 bits j target mem[pc] Fetch the instruction from memory PC<31:2> <- PC<31:28> concat target<25:> Calculate the next instruction s address ECE468 Datapath.33 22-4-1 Finally, let s take a look at the jump instruction which uses the J format. The effect of the jump instruction is to change the lower 26 bits of the Program Counter to the value specified in the address field of the instruction. +1 = 76 min. (Y:46)

Instruction Fetch Unit j target PC<31:2> <- PC<31:28> concat target<25:> 3 PC<31:28> Target 4 Instruction<25:> 26 3 3 1 Mux Addr<31:2> Addr<1:> Instruction Memory PC 3 1 imm Instruction<15:> Adder SignExt 3 Adder 3 3 Mux 1 Jump Instruction<31:> Branch Zero ECE468 Datapath.34 22-4-1 Well this (points to the equation) is easy to implement. All we have to do is grab the four most significant bits of the PC and put them right next to the 26 bits target, and we will have the next PC for the jump (point to the feedback path). If we are running Powerview, what we will do now is to create a symbol called Instruction Fetch Unit. The output of this symbol is the -bit instruction word. The input to the Instruction Fetch Unit are two control signals, Branch and Jump, and one conditional input Zero from the datapath. Using this new symbol, we can complete our single cycle datapath. +2 = 78 min. (Y:58)

Putting it All Together: A Single Cycle Datapath We have everything except control signals (underline) RegDst busw 1 Mux Rs Rt RegWr 5 5 5 Rd imm Rt Rw Ra Rb -bit Registers busb Extender Branch Jump busa ExtOp Mux 1 ALUSrc Instruction Fetch Unit ALUctr Data In ECE468 Datapath.35 22-4-1 ALU Zero Instruction<31:> Rt <21:25> Rs <:2> MemWr WrEn Adr Data Memory Rd <11:15> <:15> Imm Mux 1 MemtoReg So here is the single cycle datapath we just built. If you push into the Instruction Fetch Unit, you will see the last slide showing the PC, the next address logic, and the Instruction Memory. Here I have shown how we can get the Rt, Rs, Rd, and Imm fields out of the -bit instruction word. The Rt, Rs, and Rd fields will go to the register file as register specifiers while the Imm field will go to the Extender where it is either Zero and Sign extended to bits. The signals ExtOp, ALUSrc, ALUctr, MemWr, MemtoReg, RegDst, RegWr, Branch, and Jump are control signals. And I will show you how to generate them in the next class.. +2 = 8 min. (Z:)

Where to get more information? To be continued... ECE468 Datapath.36 22-4-1 So that s all for today. See you guys Thursday.