cosc 3430 l08 basic mips architecture.1 cosc 3430 computer architecture lecture 08 processors single...

28
COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

Upload: esmond-joseph

Post on 01-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.1

COSC 3430 Computer Architecture

Lecture 08

Processors

Single cycle Datapath

PH 3: Sections 5.1-5.4

Page 2: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.2

Introduction

CPU performance factors Instruction count

- Determined by ISA and compiler CPI and Cycle time

- Determined by CPU hardware

We will examine two MIPS implementations in this chapter A simplified single cycle version A multicycle implementation In the next chapter we will see a more realistic

pipelined version

Page 3: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.3

Review: THE Performance Equation The basic performance equation is

CPU time = Instruction_count x CPI x clock_cycle

Instruction_count x CPI

clock_rate CPU time = -----------------------------------------------

or

These equations separate the three key factors that affect performance

Can measure the CPU execution time by running the program The clock rate is usually given in the documentation Can measure instruction count by using profilers/simulators

without knowing all of the implementation details CPI varies by instruction type and ISA implementation for which

we must know the implementation details

Page 4: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.4

Our implementation of the MIPS is simplified memory-reference instructions: lw, sw arithmetic-logical instructions: add, sub, and, or, slt control flow instructions: beq, j

Generic implementation use the program counter (PC) to supply

the instruction address and fetch the instruction from memory (and update the PC)

decode the instruction (and read registers) execute the instruction

All instructions (except j) use the ALU after reading the registers

How? memory-reference? arithmetic? control flow?

The Processor: Datapath & Control

FetchPC = PC+4

DecodeExec

Page 5: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.5

Instruction Execution

PC instruction memory, fetch instruction

Register numbers register file, read registers

Depending on instruction class Use ALU to calculate

- Arithmetic result

- Memory address for load/store

- Branch target address Access data memory for load/store PC target address or PC + 4

Page 6: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.6

Clocking Methodologies The clocking methodology defines when signals can be

read and when they are written An edge-triggered methodology

Typical execution read contents of state elements send values through combinational logic write results to one or more state elements

Stateelement

1

Stateelement

2

Combinationallogic

clock

one clock cycle

Assumes state elements are written on every clock cycle; if not, need explicit write control signal write occurs only when both the write control is asserted and the

clock edge occurs

Page 7: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.7

Clocking Methodology

Combinational logic transforms data during clock cycles Between clock edges Input from state elements, output to state element Longest delay determines clock period

Page 8: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.8

CPU Overview (Simplified example circuit)

Page 9: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.9

Multiplexers

Can’t just join wires together Use multiplexers

Page 10: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.10

Building a Datapath

Datapath Elements that process data and addresses

in the CPU- Registers, ALUs, mux’s, memories, …

We will build a MIPS datapath incrementally Refining the overview design

Page 11: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.11

Fetching Instructions Fetching instructions involves

reading the instruction from the Instruction Memory updating the PC to hold the address of the next instruction

ReadAddress

Instruction

InstructionMemory

Add

PC

4

PC is updated every cycle, so it does not need an explicit write control signal

Instruction Memory is read every cycle, so it doesn’t need an explicit read control signal

Page 12: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.12

Decoding Instructions Decoding instructions involves

sending the fetched instruction’s opcode and function field bits to the control unit

Instruction

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ControlUnit

reading two values from the Register File- Register File addresses are contained in the instruction

Page 13: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.13

Executing R Format Operations R format operations (add, sub, slt, and, or)

perform the (op and funct) operation on values in rs and rt store the result back into the Register File (into location rd)

Instruction

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

overflowzero

ALU controlRegWrite

R-type:

31 25 20 15 5 0

op rs rt rd functshamt

10

The Register File is not written every cycle (e.g. sw), so we need an explicit write control signal for the Register File

Page 14: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.14

Executing Load and Store Operations Load and store operations involves

compute memory address by adding the base register (read from the Register File during decode) to the 16-bit signed-extended offset field in the instruction

store value (read from the Register File during decode) written to the Data Memory

load value, read from the Data Memory, written to the Register File

Instruction

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

overflowzero

ALU controlRegWrite

DataMemory

Address

Write Data

Read Data

SignExtend

MemWrite

MemRead

16 32

Page 15: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.15

Executing Branch Operations Branch operations involves

compare the operands read from the Register File during decode for equality (zero ALU output)

compute the branch target address by adding the updated PC to the 16-bit signed-extended offset

field in the instr

Instruction

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

zero

ALU control

SignExtend16 32

Shiftleft 2

Add

4 Add

PC

Branchtargetaddress

(to branch control logic)

Page 16: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.16

Executing Jump Operations Jump operation involves

replace the lower 28 bits of the PC with the lower 26 bits of the fetched instruction shifted left by 2 bits

ReadAddress

Instruction

InstructionMemory

Add

PC

4

Shiftleft 2

Jumpaddress

26

4

28

Page 17: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.17

Creating a Single Datapath from the Parts

Assemble the datapath segments and add control lines and multiplexors as needed

Single cycle design – fetch, decode and execute each instructions in one clock cycle

no datapath resource can be used more than once per instruction, so some must be duplicated (e.g., separate Instruction Memory and Data Memory, several adders)

multiplexors needed at the input of shared elements with control lines to do the selection

write signals to control writing to the Register File and Data Memory

Cycle time is determined by length of the longest path

Page 18: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.18

Fetch, R-type, and Memory Access Portions

MemtoReg

ReadAddress

Instruction

InstructionMemory

Add

PC

4

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

ovfzero

ALU controlRegWrite

DataMemory

Address

Write Data

Read Data

MemWrite

MemReadSign

Extend16 32

ALUSrc

Page 19: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.19

Adding the Control Selecting the operations to perform (ALU, Register File

and Memory read/write) Controlling the flow of data (multiplexor inputs)

I-Type: op rs rt address offset

31 25 20 15 0

R-type:

31 25 20 15 5 0

op rs rt rd functshamt

10

Observations op field always

in bits 31-26

addr of registers to be read are always specified by the rs field (bits 25-21) and rt field (bits 20-16); for lw and sw rs is the base register

addr. of register to be written is in one of two places – in rt (bits 20-16) for lw; in rd (bits 15-11) for R-type instructions

offset for beq, lw, and sw always in bits 15-0

J-type:31 25 0

op target address

Page 20: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.20

Single Cycle Datapath with Control Unit

ReadAddress

Instr[31-0]

InstructionMemory

Add

PC

4

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

ovf

zero

RegWrite

DataMemory

Address

Write Data

Read Data

MemWrite

MemRead

SignExtend16 32

MemtoReg

ALUSrc

Shiftleft 2

Add

PCSrc

RegDst

ALUcontrol

1

1

1

00

0

0

1

ALUOp

Instr[5-0]

Instr[15-0]

Instr[25-21]

Instr[20-16]

Instr[15 -11]

ControlUnit

Instr[31-26]

Branch

Page 21: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.21

R-type Instruction Data/Control Flow

ReadAddress

Instr[31-0]

InstructionMemory

Add

PC

4

Write Data

Read Addr 1Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

ovf

zero

RegWrite

DataMemory

Address

Write Data

Read Data

MemWrite

MemRead

SignExtend16 32

MemtoReg

ALUSrc

Shiftleft 2

Add

PCSrc

RegDst

ALUcontrol

1

1

1

00

0

0

1

ALUOp

Instr[5-0]

Instr[15-0]

Instr[25-21]

Instr[20-16]

Instr[15 -11]

ControlUnit

Instr[31-26]

Branch

Page 22: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.23

Load Word Instruction Data/Control Flow

ReadAddress

Instr[31-0]

InstructionMemory

Add

PC

4

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

ovf

zero

RegWrite

DataMemory

Address

Write Data

Read Data

MemWrite

MemRead

SignExtend16 32

MemtoReg

ALUSrc

Shiftleft 2

Add

PCSrc

RegDst

ALUcontrol

1

1

1

00

0

0

1

ALUOp

Instr[5-0]

Instr[15-0]

Instr[25-21]

Instr[20-16]

Instr[15 -11]

ControlUnit

Instr[31-26]

Branch

Page 23: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.25

Branch Instruction Data/Control Flow

ReadAddress

Instr[31-0]

InstructionMemory

Add

PC

4

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

ovf

zero

RegWrite

DataMemory

Address

Write Data

Read Data

MemWrite

MemRead

SignExtend16 32

MemtoReg

ALUSrc

Shiftleft 2

Add

PCSrc

RegDst

ALUcontrol

1

1

1

00

0

0

1

ALUOp

Instr[5-0]

Instr[15-0]

Instr[25-21]

Instr[20-16]

Instr[15 -11]

ControlUnit

Instr[31-26]

Branch

Page 24: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.26

Adding the Jump Operation

ReadAddress

Instr[31-0]

InstructionMemory

Add

PC

4

Write Data

Read Addr 1

Read Addr 2

Write Addr

Register

File

Read Data 1

Read Data 2

ALU

ovf

zero

RegWrite

DataMemory

Address

Write Data

Read Data

MemWrite

MemRead

SignExtend16 32

MemtoReg

ALUSrc

Shiftleft 2

Add

PCSrc

RegDst

ALUcontrol

1

1

1

00

0

0

1

ALUOp

Instr[5-0]

Instr[15-0]

Instr[25-21]

Instr[20-16]

Instr[15 -11]

ControlUnit

Instr[31-26]

Branch

Shiftleft 2

0

1

Jump

32Instr[25-0]

26PC+4[31-28]

28

Page 25: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.27

An important point about the datapath

In this data path we see several shift left 2 functions and sign extend functions. They are crucial functions if the circuit is to work properly.

On the next chart is a circuit that will take the contents of a 4 bit register and shift it into a 4 bit register with its bits shifted 0, 1, 2, or 3 bits by using 4, 4 to 1 mulitplexers. This idea could be extended to a 32 bit multiplexer that would allow shifts of 0 to 31 bits (shamt is 5 bits)

The sign extend is relatively easy. All that needs to be done is feed the bits 0-15 into the least significant bits of a register and allow the 15th bit to fill the remaining bits 16-31.

Page 26: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.28

A left shifter circuit, 0 to 3 bits

x0, x1, x2, x3 are inputs from a 4 bit register

z0, z1, z2, z3 are outputs to a 4 bit register. s1 and s0 are the selector inputs for the number of bits to shift, 00, 01, 10, 11. The input 5 is 0.

Page 27: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.29

Problem

1. Discuss how the general shifter, (0 to 31 bits) could be implemented.

2. Since in our simple example we only need to shift left 2 bits, show how this can be done.

Page 28: COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections 5.1-5.4

COSC 3430 L08 Basic MIPS Architecture.30

Next Lecture and Reminders Next lecture

MIPS processor: single cycle control and multicycle- Reading assignment – PH, Chapter 5.4-5.5