Top Banner
Lecture 3 Processor: Datapath and Control 1
47

Lecture 3 Processor: Datapath and Control - IDA

Mar 24, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 3 Processor: Datapath and Control - IDA

Lecture 3Processor: Datapath and Control

1

Page 2: Lecture 3 Processor: Datapath and Control - IDA

ALUALU

Arithmetic Logic Unit is the hardware that performs addition, subtraction, AND, OR …p , , ,

2

Page 3: Lecture 3 Processor: Datapath and Control - IDA

§4.1 IntrRecap: Performance roductionRecap: Performance

Time Cycle ClockCPICount nInstructioTime CPU

CPU f f t CPU performance factors Instruction count

• Determined by Instruction Set Architecture and compiler• Determined by Instruction Set Architecture and compiler

CPI and Cycle time• Determined by implementation of the processory p p

Chapter 4 — The Processor —3

Page 4: Lecture 3 Processor: Datapath and Control - IDA

Components of a Computer

Page 5: Lecture 3 Processor: Datapath and Control - IDA

Processor

Datapath Control Components of the

processor that Component of the

processor that pperform arithmetic operations and holds

pcommands the datapath, memory, p

datap y

I/O devices according to the instructions of the memory

Page 6: Lecture 3 Processor: Datapath and Control - IDA

Building a Datapath§4.3 BuiBuilding a Datapath

D h

lding a Da

Datapath Elements that process data and addresses

atapath

in the CPU• Memories, registers, ALUs, …

We will build a MIPS datapath incrementally considering only a subset of instructions

To start, we will look at 3 elements

Chapter 4 — The Processor — 6

Page 7: Lecture 3 Processor: Datapath and Control - IDA

A memory unit to store instructions of a d l i i i ddprogram and supply instructions given an address

Needs to provide only read access (once the p y (program is loaded). No control signal is need. No control signal is need.

7

Page 8: Lecture 3 Processor: Datapath and Control - IDA

PC (Program Counter or Instruction address register) is a register that holds the address of the current ginstruction

A new value is written to it every clock cycle. No l i l i i d bl icontrol signal is required to enable write

8

Page 9: Lecture 3 Processor: Datapath and Control - IDA

Adder to increment the PC to the address of the next instruction

An ALU permanently wired to do only addition. p y yNo extra control signal required

9

Page 10: Lecture 3 Processor: Datapath and Control - IDA

Datapath portion for Instruction FetchDatapath portion for Instruction Fetch

Increment by 4 f t

32‐bit register

4 for next instruction

Chapter 4 — The Processor —10

Page 11: Lecture 3 Processor: Datapath and Control - IDA

Types of Elements in the DatapathTypes of Elements in the Datapath

State element: A memory element, i.e., it contains a statey , , E.g., program counter, instruction memory

Combinational element: Elements that operate on values E g adder ALUE.g. adder, ALU

11

Page 12: Lecture 3 Processor: Datapath and Control - IDA

Now, we will look at datapath elements required by the different classes of q yinstructions Arithmetic and logical instructions Arithmetic and logical instructions Data transfer instructions Branch instructions

12

Page 13: Lecture 3 Processor: Datapath and Control - IDA

R-Format ALU InstructionsR Format ALU Instructions E.g., add $t1, $t2, $t3 Perform arithmetic/logical operation Read two register operands and write register Read two register operands and write register

result

Chapter 4 — The Processor —13

Page 14: Lecture 3 Processor: Datapath and Control - IDA

R-Format ALU Instructions

Register file: A collection of the registers Register file: A collection of the registers Any register can be read or written by specifying

h b f h ithe number of the register Contains the register state of the computer

Chapter 4 — The Processor —14

Page 15: Lecture 3 Processor: Datapath and Control - IDA

Read from register file2 i t t th i t fil if i th b 2 inputs to the register file specifying the numbers

• 5 bit wide inputs for the 32 registers 2 outputs from the register file with the read values2 outputs from the register file with the read values

• 32 bit wide For all instructions. No control required.

Chapter 4 — The Processor —15

q

Page 16: Lecture 3 Processor: Datapath and Control - IDA

Write to register file 1 input to the register file specifying the number

• 5 bit wide inputs for the 32 registers

1 i h i fil i h h l b i 1 input to the register file with the value to be written• 32 bit wide

O l f i t ti R W it t l i lChapter 4 — The Processor —16

Only for some instructions. RegWrite control signal.

Page 17: Lecture 3 Processor: Datapath and Control - IDA

ALU Takes two 32 bit input and produces a 32 bit output Also, sets one-bit signal if the results is 0 The operation done by ALU is controlled by a 4 bit

control signal input. This is set according to the instruction

Chapter 4 — The Processor —17

instruction

Page 18: Lecture 3 Processor: Datapath and Control - IDA

Data transfer instructionsData transfer instructions

lw $t1, offset_value($t2) Load: Read memory and update registerLoad: Read memory and update register

sw $t1, offset_value($t2) Store: Write register value to memoryg y

18

Page 19: Lecture 3 Processor: Datapath and Control - IDA

Data transfer instructionsData transfer instructions

Compute the memory address by adding the value in base register and the 16 bit offsetg need the ALU Calculate address using 16-bit offsetCalculate address using 16 bit offset

• Use ALU, but sign-extend offset

Write to or read from register need the register file

19

Page 20: Lecture 3 Processor: Datapath and Control - IDA

Two additional units – data memory and sign unit extensionunit extension Data memory State element with

• input for address and data to be written• output for read result

Page 21: Lecture 3 Processor: Datapath and Control - IDA

Data memory Separate control for read and write Separate control for read and write Control for read is required because reading from

i lid dd l d t blinvalid address can lead to problems

Sign-extension unit takes a 16 bit input and extend it to a 32 bit output

Page 22: Lecture 3 Processor: Datapath and Control - IDA

22

Page 23: Lecture 3 Processor: Datapath and Control - IDA

Composing the Elements for R-type and data transfer instructions

A simple data path that does an instruction in one clock cycley Each datapath element can only do one function at

a timea time Hence, we need separate instruction and data

memoriesmemories

Use multiplexers where alternate data sources are used for different instructions

Chapter 4 — The Processor —23

Page 24: Lecture 3 Processor: Datapath and Control - IDA

MultiplexorsMultiplexors

An ALU might need input from Two registersTwo registers Or one registers and one immediate field

( ff )(or offset)

To choose correctly from multiple sources, a h d l t ll d lti l i d hardware element called multiplexor is used with appropriate control signals

24

Page 25: Lecture 3 Processor: Datapath and Control - IDA

MultiplexorsMultiplexors

The data written to registers may come from Data memoryData memory Or ALU

To choose correctly from multiple sources a To choose correctly from multiple sources, a hardware element called multiplexor is used

ith i t t l i lwith appropriate control signals

25

Page 26: Lecture 3 Processor: Datapath and Control - IDA

R Type/Load/Store DatapathR-Type/Load/Store Datapath

Chapter 4 — The Processor —26

Page 27: Lecture 3 Processor: Datapath and Control - IDA

Branch InstructionsBranch Instructions

beq $t1, $t2, offset

Read two registers and compare them

Take the 16 bit offset and add it to the address Take the 16 bit offset and add it to the address of next instruction following the branch i t ti t bt i th b h t t instruction to obtain the branch target address

Chapter 4 — The Processor —27

Page 28: Lecture 3 Processor: Datapath and Control - IDA

Branch InstructionsBranch Instructions

Read register operands Compare operandsCompare operands Use ALU, subtract and check Zero output

Calculate target address Sign-extend the offsetg Shift left 2 places (word displacement) Add to PC + 4 Add to PC + 4

• Already calculated by instruction fetch

Chapter 4 — The Processor —28

Page 29: Lecture 3 Processor: Datapath and Control - IDA

Branch InstructionsBranch Instructions

JustJustre‐routes wires

Sign‐bit wire 

Chapter 4 — The Processor —29

replicated

Page 30: Lecture 3 Processor: Datapath and Control - IDA

Composing all elements togetherComposing all elements together

Instruction fetch datapath Datapath for R-type and memory instructionsDatapath for R type and memory instructions Datapath for branches

Need an additional multiplexor to select the Need an additional multiplexor to select the sequential address after branch or the branch t t dd t b itt t th PCtarget address to be written to the PC

30

Page 31: Lecture 3 Processor: Datapath and Control - IDA

Datapath portion for Instruction FetchDatapath portion for Instruction Fetch

Increment by 4 f t

32‐bit register

4 for next instruction

Chapter 4 — The Processor —31

Page 32: Lecture 3 Processor: Datapath and Control - IDA

Full DatapathFull Datapath

Chapter 4 — The Processor —32

Page 33: Lecture 3 Processor: Datapath and Control - IDA

Datapath With ControlDatapath With Control AND gate forbranch

Chapter 4 — The Processor —33

Page 34: Lecture 3 Processor: Datapath and Control - IDA

A Recap: Combinational ElementsA Recap: Combinational Elements

AND gate A Adder AND-gate Y = A & B

A

BY+

Adder Y = A + B

AB

Y

/ Multiplexer

Arithmetic/Logic Unit Y = F(A, B)

I0Y

M

Y = S ? I1 : I0A

YALU

( , )

I1Yu

x

S

B

YALU

F

Chapter 4 — The Processor —34

S F

Page 35: Lecture 3 Processor: Datapath and Control - IDA

A Recap: State Elements A Recap: State Elements

Registers Data MemoryData Memory Instruction Memory

Clocks are needed to decide when an element that contains state should be updated

35

Page 36: Lecture 3 Processor: Datapath and Control - IDA

Recap from Lecture 1:CPU ClockingCPU Clocking

Operation of digital hardware governed by a Operation of digital hardware governed by a constant-rate clock

Clock period: duration of a clock cycle Clock frequency (rate): cycles per second

36

Page 37: Lecture 3 Processor: Datapath and Control - IDA

ClocksClocks

A clock is a signal with a fixed cycle time (period)A clock is a signal with a fixed cycle time (period)

The clock frequency is the inverse of the cycle time

37

Page 38: Lecture 3 Processor: Datapath and Control - IDA

ClocksClocks

The clock cycle time or clock period is divided into two portions: p when the clock is high

h th l k i l when the clock is low

38

Page 39: Lecture 3 Processor: Datapath and Control - IDA

Clocking Methodology Clocking Methodology

We studyEd i d h d l Edge triggered methodology

• Because it is simple

Edge triggered methodology: All state changes occur on a clock edgeAll state changes occur on a clock edge

Chapter 4 — The Processor —39

Page 40: Lecture 3 Processor: Datapath and Control - IDA

Clocking Methodology :S ElState Elements

Register: stores data in a circuitRegister: stores data in a circuit Uses a clock signal to determine when to update

the stored valuethe stored value Edge-triggered: update when Clk changes from 0

t 1to 1

ClkD Q

Clk

D

ClkQ

Chapter 4 — The Processor —40

Page 41: Lecture 3 Processor: Datapath and Control - IDA

Clocking Methodology :St t El t

Register with write controlState Elements

Only updates on clock edge when write control input is 1p

Used when stored value is required later

Clk

D QWrite

Write

DClk

D

Q

Chapter 4 — The Processor —41

Page 42: Lecture 3 Processor: Datapath and Control - IDA

Clocking MethodologyClocking Methodology Combinational logic transforms data during

clock cyclesclock cycles Between clock edges Input from state elements output to state element Input from state elements, output to state element

• The state elements, whose outputs change only after the clock edge, provide valid inputs to the g p pcombinational logic block.

Chapter 4 — The Processor —42

Page 43: Lecture 3 Processor: Datapath and Control - IDA

Clocking MethodologyClocking Methodology To ensure that the values written into the state elements on the active

clock edge are valid, the clock must have a long enough period so that all the signals in the combinational logic block stabilize, then the clock edge samples those values for storage in the state elements.

This constraint sets a lower bound on the length of the clock period, which must be long enough for all state element inputs to be valid.

Longest delay determines clock period

Chapter 4 — The Processor —43

Page 44: Lecture 3 Processor: Datapath and Control - IDA

It is possible to have a state element that is used as both an input and output to the same combinationallogic block

Ensure that the clock period is long enough

44

Page 45: Lecture 3 Processor: Datapath and Control - IDA

Single Clock CycleSingle Clock Cycle

We studied a simple implementation where a single clock cycle is required for every g y q yinstruction. Every instruction begins on one clock edge and completes execution on the clock edge and completes execution on the next

45

Page 46: Lecture 3 Processor: Datapath and Control - IDA

Performance IssuesPerformance Issues

L d l d l k d Longest delay determines clock period Critical path: load instruction Instruction memory register file ALU

data memory register file Not feasible to vary period for different

instructionsst uct o s The clock cycle must be extended to

accommodate the longest instructionaccommodate the longest instruction Improve performance by pipelining

Chapter 4 — The Processor —46

Page 47: Lecture 3 Processor: Datapath and Control - IDA

ConclusionConclusion

ISA influences the design of datapath and control for a processor p

W d d l b d l We studied an implementation based on single cycle

47