[7]muticycle_control.pdf

46
Multicycle Datapath with Control I Shift left 2 MemtoReg IorD MemRead MemWrite PC Memory MemData Write data M u x 0 1 Registers Write register Write data Read data 1 Read data 2 Read register 1 Read register 2 Instruction [1511] M u x 0 1 M u x 0 1 4 ALUOp ALUSrcB RegDst RegWrite Instruction [150] Instruction [50] Sign extend 32 16 Instruction [2521] Instruction [2016] Instruction [150] Instruction register 1 M u x 0 3 2 ALU control M u x 0 1 ALU result ALU ALUSrcA Zero A B ALUOut IRWrite Address Memory data register … with control lines and the ALU control block added – not all control lines are shown

Upload: shivam-khandelwal

Post on 07-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Multicycle Datapath with Control I

Shift

left 2

MemtoReg

IorD MemRead MemWrite

PC

Memory

MemData

Writedata

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Instruction[15– 11]

Mux

0

1

Mux

0

1

4

ALUOpALUSrcB

RegDst RegWrite

Instruction[15– 0]

Instruction [5– 0]

Sign

extend

3216

Instruction[25– 21]

Instruction[20– 16]

Instruction[15– 0]

Instruction

register1 M

ux

0

3

2

ALU

control

Mux

0

1ALU

result

ALU

ALUSrcA

ZeroA

B

ALUOut

IRWrite

Address

Memory

data

register

… with control lines and the ALU control block added – not all control lines are shown

Multicycle Datapath with Control II

Complete multicycle MIPS datapath (with branch and jump capability)and showing the main control block and all control lines

Shiftleft 2

PC

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Instruction[15– 11]

Mux

0

1

Mux

0

1

4

Instruction[15– 0]

Signextend

3216

Instruction[25– 21]

Instruction[20– 16]

Instruction[15– 0]

Instructionregister

ALUcontrol

ALUresult

ALU

Zero

Memorydata

register

A

B

IorD

MemRead

MemWrite

MemtoReg

PCWriteCond

PCWrite

IRWrite

ALUOp

ALUSrcB

ALUSrcA

RegDst

PCSource

RegWrite

Control

Outputs

Op[5–0]

Instruction[31-26]

Instruction [5– 0]

Mux

0

2

Jumpaddress [31-0]Instruction [25– 0] 26 28

Shiftleft 2

PC [31-28]

1

1 Mux

0

3

2

Mux

0

1ALUOut

Memory

MemData

Writedata

Address

New multiplexorNew gates

For the jump address

Multicycle Control Step (1): Fetch

IR = Memory[PC];

PC = PC + 4;

1

0

1

0

1

0X

0

X

0010

1

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDRMemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

M

U

X

0

1

2

3

M

U

X

1

0

M

U

X

0

1A

B

ALUOUT

0

1

2M

U

X

<<2 CONCAT

28 32

M

U

X

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

Multicycle Control Step (2):Instruction Decode & Register Fetch

A = Reg[IR[25-21]]; (A = Reg[rs])

B = Reg[IR[20-15]]; (B = Reg[rt])

ALUOut = (PC + sign-extend(IR[15-0]) << 2);

0

0

X0

0

X

3

0X

X

010

0

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDRMemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

M

U

X

0

1

2

3

M

U

X

1

0

M

U

X

0

1A

B

ALUOUT

0

1

2M

U

X

<<2 CONCAT

28 32

M

U

X

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

Multicycle Datapath with Control II

Complete multicycle MIPS datapath (with branch and jump capability)and showing the main control block and all control lines

Shiftleft 2

PC

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Instruction[15– 11]

Mux

0

1

Mux

0

1

4

Instruction[15– 0]

Signextend

3216

Instruction[25– 21]

Instruction[20– 16]

Instruction[15– 0]

Instructionregister

ALUcontrol

ALUresult

ALU

Zero

Memorydata

register

A

B

IorD

MemRead

MemWrite

MemtoReg

PCWriteCond

PCWrite

IRWrite

ALUOp

ALUSrcB

ALUSrcA

RegDst

PCSource

RegWrite

Control

Outputs

Op[5–0]

Instruction[31-26]

Instruction [5– 0]

Mux

0

2

Jumpaddress [31-0]Instruction [25– 0] 26 28

Shiftleft 2

PC [31-28]

1

1 Mux

0

3

2

Mux

0

1ALUOut

Memory

MemData

Writedata

Address

New multiplexorNew gates

For the jump address

0

X

Multicycle Control Step (3):Memory Reference Instructions

ALUOut = A + sign-extend(IR[15-0]);

X

2

0

0

X0 1

X

010

0

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDRMemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

M

U

X

0

1

2

3

M

U

X

1

0

M

U

X

0

1A

B

ALUOUT

0

1

2M

U

X

<<2 CONCAT

28 32

M

U

X

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

Multicycle Control Step (3):ALU Instruction (R-Type)

ALUOut = A op B;

0

X

X

0

0

0

X0 1

X

???

0

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDRMemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

M

U

X

0

1

2

3

M

U

X

1

0

M

U

X

0

1A

B

ALUOUT

0

1

2M

U

X

<<2 CONCAT

28 32

M

U

X

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

1 if

Zero=1

Multicycle Control Step (3):Branch Instructions

if (A == B) PC = ALUOut;

0

X

X

0

0

X0 1

1

011

0

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDRMemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

M

U

X

0

1

2

3

M

U

X

1

0

M

U

X

0

1A

B

ALUOUT

0

1

2M

U

X

<<2 CONCAT

28 32

M

U

X

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

Multicycle Execution Step (3):Jump Instruction

PC = PC[21-28] concat (IR[25-0] << 2);

0

X

X

X

0

1

X0 X

2

XXX

0

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDRMemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

M

U

X

0

1

2

3

M

U

X

1

0

M

U

X

0

1A

B

ALUOUT

0

1

2M

U

X

<<2 CONCAT

28 32

M

U

X

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

Multicycle Control Step (4):Memory Access - Read (lw)

MDR = Memory[ALUOut];

0

X

X

X

1

0

10 X

X

XXX

0

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDRMemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

M

U

X

0

1

2

3

M

U

X

1

0

M

U

X

0

1A

B

ALUOUT

0

1

2M

U

X

<<2 CONCAT

28 32

M

U

X

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

Multicycle Execution Steps (4)Memory Access - Write (sw)

Memory[ALUOut] = B;

0

X

X

X

0

0

11 X

X

XXX

0

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDRMemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

M

U

X

0

1

2

3

M

U

X

1

0

M

U

X

0

1A

B

ALUOUT

0

1

2M

U

X

<<2 CONCAT

28 32

M

U

X

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

10

0

X0

X

0

XXX

X

X

1

15 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDR

MemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

MUX

0

1

2

3

MUX

0

1

MUX

0

1A

B

ALUOUT

0

1

2MUX

<<2 CONCAT

28 32

MUX

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

Multicycle Control Step (4):ALU Instruction (R-Type)

(Reg[Rd] = ALUOut)

Multicycle Execution Steps (5)Memory Read Completion (lw)

Reg[IR[20-16]] = MDR;

1

0

0

X

0

0

X0 X

X

XXX

0

5 5

RD1

RD2

RN1 RN2 WN

WD

RegWrite

Registers

Operation

ALU

3

EXTND

16 32

Zero

RD

WD

MemRead

Memory

ADDR

MemWrite

5

Instruction I

32

ALUSrcB

<<2

PC

4

RegDst

5

IR

MDR

MUX

0

1

2

3

MUX

0

1

MUX

0

1A

B

ALUOUT

0

1

2MUX

<<2 CONCAT

28 32

MUX

0

1

ALUSrcA

jmpaddr

I[25:0]rd

MUX0 1

rtrs

immediate

PCSource

MemtoReg

IorD

PCWr*

IRWrite

Value of control signals is dependent upon:

what instruction is being executed

which step is being performed

Use the information we have accumulated to specify a finite state machine

specify the finite state machine graphically, or

use microprogramming

Implementation is then derived from the specification

Implementing Control

user
Typewritten Text
IorD decides whether to load PC for going to the next instruction or Use the memory for LW/SW type instructions to read/write to memory.

Finite state machines (FSMs): a set of states and

next state function, determined by current state and the input

output function, determined by current state and possibly input

We’ll use a Moore machine – output based only on current state

Review: Finite State Machines

Next-state

functionCurrent state

Clock

Output

function

Next

state

Outputs

Inputs

FSM Control: High-level View

Memory access

instructions

(Figure 5.38)

R-type instructions

(Figure 5.39)

Branch instruction

(Figure 5.40)

Jump instruction

(Figure 5.41)

Instruction fetch/decode and register fetch

(Figure 5.37)

Start

ALUSrcA = 0ALUSrcB = 11ALUOp = 00

MemReadALUSrcA = 0

IorD = 0IRWrite

ALUSrcB = 01ALUOp = 00

PCWritePCSource = 00

Instruction fetchInstruction decode/

Register fetch

(Op

='J

MP

')

01

Start

Memory reference FSM(Figure 5.38)

R-type FSM(Figure 5.39)

Branch FSM(Figure 5.40)

Jump FSM(Figure 5.41)

High-level view of FSM control

Instruction fetch and decode steps of every instruction is identical

Asserted signalsshown insidestate circles

user
Typewritten Text
IF
user
Typewritten Text
ID
user
Typewritten Text
LW/SW

FSM Control: Memory Reference

MemWrite

IorD = 1

MemRead

IorD = 1

ALUSrcA = 1

ALUSrcB = 10

ALUOp = 00

RegWrite

MemtoReg = 1

RegDst = 0

Memory address computation

(Op = 'LW') or (Op = 'SW')

Memory

access

Write-back step

( Op

='L

W')

4

2

53

From state 1

To state 0

(Figure 5.37)

Memory

access

FSM control for memory-reference has 4 states

user
Typewritten Text
EX
user
Typewritten Text
Common to both LW and SW
user
Typewritten Text
MEM (LW)
user
Typewritten Text
MEM(SW) Complete
user
Typewritten Text
WB(LW) Complete

FSM Control: R-type Instruction

ALUSrcA = 1

ALUSrcB = 00

ALUOp = 10

RegDst = 1

RegWrite

MemtoReg = 0

Execution

R-type completion

6

7

(Op = R-type)

From state 1

To state 0

(Figure 5.37)

FSM control to implement R-type instructions has 2 states

user
Typewritten Text
EX
user
Typewritten Text
MEM

FSM Control: Branch Instruction

Branch completion

8

(Op = 'BEQ')

From state 1

To state 0

(Figure 5.37)

ALUSrcA = 1

ALUSrcB = 00

ALUOp = 01

PCWriteCond

PCSource = 01

FSM control to implement branches has 1 state

user
Typewritten Text
EX

FSM Control: Jump Instruction

Jump completion

9

(Op = 'J')

From state 1

To state 0

(Figure 5.37)

PCWrite

PCSource = 10

FSM control to implement jumps has 1 state

user
Typewritten Text
EX

FSM Control: Complete View

PCWritePCSource = 10

ALUSrcA = 1ALUSrcB = 00ALUOp = 01PCWriteCond

PCSource = 01

ALUSrcA =1ALUSrcB = 00ALUOp= 10

RegDst = 1RegWrite

MemtoReg = 0

MemWriteIorD = 1

MemReadIorD = 1

ALUSrcA = 1ALUSrcB = 10ALUOp = 00

RegDst=0RegWrite

MemtoReg=1

ALUSrcA = 0ALUSrcB = 11ALUOp = 00

MemReadALUSrcA = 0

IorD = 0IRWrite

ALUSrcB = 01ALUOp = 00

PCWritePCSource = 00

Instruction fetchInstruction decode/

register fetch

Jumpcompletion

BranchcompletionExecution

Memory addresscomputation

Memoryaccess

Memoryaccess R-type completion

Write-back step

(Op

='J

')

(Op

='L

W')

4

01

9862

753

Start

The complete FSM control for the multicycle MIPS datapath:refer Multicycle Datapath with Control II

Labels on arcs are conditionsthat determine next state

IF ID

EX

MEM

WB

FSM Control: Implement-ation

High-level view of FSM implementation: inputs to the combinational logic block are the current state number and instruction opcode bits; outputs are the next state number and control signals to be asserted for the current state

PCW rite

PCWriteCond

IorD

MemtoReg

PCSource

ALUOp

ALUSrcB

ALUSrcA

RegWrite

RegDst

NS3

NS2

NS1

NS0

Op

5

Op

4

Op

3

Op

2

Op

1

Op

0

S3

S2

S1

S0

State register

IRWrite

MemRead

MemWrite

Instruction register

opcode field

Outputs

Control logic

Inputs

Four state bits are required for 10 states

Logic Equation for Control Unit

Example of Combinational Circuit NS0 = NextState1 + NextState3 + NextState5 + NextState7 + NextState9

Truth Table for Next-State

Truth Table for 16 Control Signals

FSMControl:PLA Implem-entation

O p5

O p4

O p3

O p2

O p1

O p0

S3

S2

S1

S0

IorD

IRW rite

MemRead

MemWrite

PCWrite

PCWriteCond

MemtoReg

PCSource1

ALUOp1

ALUSrcB0

ALUSrcA

RegWrite

RegDst

NS3

NS2

NS1

NS0

ALUSrcB1

ALUOp0

PCSource0

Upper half is the AND plane that computes all the products. The products are carriedto the lower OR plane by the vertical lines. The sum terms for each output is given bythe corresponding horizontal lineE.g., IorD = S0.S1.S2.S3 + S0.S1.S2.S3

ROM (Read Only Memory) values of memory locations are fixed ahead of time

A ROM can be used to implement a truth table if the address is m-bits, we can address 2m entries in the ROM

outputs are the bits of the entry the address points to

FSM Control: ROM Implementation

m n

0 0 0 0 0 1 1

0 0 1 1 1 0 0

0 1 0 1 1 0 0

0 1 1 1 0 0 0

1 0 0 0 0 0 0

1 0 1 0 0 0 1

1 1 0 0 1 1 0

1 1 1 0 1 1 1

ROM m = 3

n = 4

The size of an m-input n-output ROM is 2m x n bits – such a ROM canbe thought of as an array of size 2m with each entry in the array beingn bits

outputaddress

First improve the ROM: break the table into two parts

4 state bits give the 16 output signals – 24 x 16 bits of ROM

all 10 input bits give the 4 next state bits – 210 x 4 bits of ROM

Total – 4.3K bits of ROM

PLA is much smaller

can share product terms

only need entries that produce an active output

can take into account don't cares

PLA size = (#inputs #product-terms) + (#outputs

#product-terms)

FSM control PLA = (10x17)+(20x17) = 460 PLA cells

PLA cells usually about the size of a ROM cell (slightly bigger)

FSM Control: ROM vs. PLA

Microprogramming is a method of specifying FSM control that resembles a programming language – textual rather graphic this is appropriate when the FSM becomes very large, e.g., if the

instruction set is large and/or the number of cycles per instruction is large

in such situations graphical representation becomes difficult as there may be thousands of states and even more arcs joining them

a microprogram is specification : implementation is by ROM or PLA

A microprogram is a sequence of microinstructions each microinstruction has eight fields (label + 7 functional)

Label: used to control microcode sequencing

ALU control: specify operation to be done by ALU

SRC1: specify source for first ALU operand

SRC2: specify source for second ALU operand

Register control: specify read/write for register file

Memory: specify read/write for memory

PCWrite control: specify the writing of the PC

Sequencing: specify choice of next microinstruction

Microprogramming

Microprogramming

The Sequencing field value determines the execution order of the microprogram

value Seq : control passes to the sequentially next microinstruction

value Fetch : branch to the first microinstruction to begin the next MIPS instruction, i.e., the first microinstruction in the microprogram

value Dispatch i : branch to a microinstruction based on control input and a dispatch table entry (called dispatching):

Dispatching is implemented by means of creating a table, called dispatch table, whose entries are microinstruction labels and which is indexed by the control input. There may be multiple dispatch tables – the value Dispatch i in the sequencing field indicates that the i th dispatch table is to be used

Control Microprogram The microprogram corresponding to the FSM control shown

graphically earlier:

Label

ALU

control SRC1 SRC2

Register

control Memory

PCWrite

control Sequencing

Fetch Add PC 4 Read PC ALU Seq

Add PC Extshft Read Dispatch 1

Mem1 Add A Extend Dispatch 2

LW2 Read ALU Seq

Write MDR Fetch

SW2 Write ALU Fetch

Rformat1 Func code A B Seq

Write ALU Fetch

BEQ1 Subt A B ALUOut-cond Fetch

JUMP1 Jump address Fetch

Dispatch ROM 1

Op Opcode name Value

000000 R-format Rformat1

000010 jmp JUMP1

000100 beq BEQ1

100011 lw Mem1

101011 sw Mem1

Dispatch ROM 2

Op Opcode name Value

100011 lw LW2

101011 sw SW2

Microprogram containing 10 microinstructions

Dispatch Table 2

Dispatch Table 1

user
Typewritten Text
Branch
user
Typewritten Text
Next Inst
user
Typewritten Text
R-type
user
Typewritten Text
LW/SW
user
Sticky Note
If Zero output is active and PCSource is 1, then Branch Target is written into PC

Fetch & Decode

Memory Reference

R-Type

Beq & Jump

Implementing the Microprogram

Implementing the Address Select Logic

Microcode: Trade-offsSpecification advantages

easy to design and write

typically manufacturer designs architecture and microcode in parallel

Implementation advantages

easy to change since values are in memory (e.g., off-chip ROM)

Implementation disadvantages

control is implemented nowadays on same chip as processor so the

advantage of an off-chip ROM does not exist

ROM is not fast

there is little need to change the microcode as general-purpose

computers are used far more nowadays than computers designed for

specific applications

Exception Handling

Summary

Multicycle datapaths offer two great advantages over single-cycle functional units can be reused within a single instruction if they are

accessed in different cycles – reducing the need to replicate expensive logic

instructions with shorter execution paths can complete quicker by consuming fewer cycles

Modern computers, in fact, take the multicycle paradigm to a higher level to achieve greater instruction throughput: pipelining (next topic) where multiple instructions execute

simultaneously by having cycles of different instructions overlap in the datapath

the MIPS architecture was designed to be pipelined