[6]multicycle_datapath.pdf

22
Datapath with Control III Shift left 2 PC Instruction memory Read address Instruction [310] Data memory Read data Write data Registers Write register Write data Read data 1 Read data 2 Read register 1 Read register 2 Instruction [1511] Instruction [2016] Instruction [2521] Add ALU result Zero Instruction [50] MemtoReg ALUOp MemWrite RegWrite MemRead Branch Jump RegDst ALUSrc Instruction [3126] 4 M u x Instruction [250] Jump address [310] PC+4 [3128] Sign extend 16 32 Instruction [150] 1 M u x 1 0 M u x 0 1 M u x 0 1 ALU control Control Add ALU result M u x 0 1 0 ALU Shift left 2 26 28 Address 31-26 25-0 opcode address Jump MIPS datapath extended to jumps: control unit generates new Jump control bit New multiplexor with additional control bit Jump Composing jump target address

Upload: shivam-khandelwal

Post on 07-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Datapath with Control III

Shift

left 2

PC

Instruction

memory

Readaddress

Instruction[31– 0]

Datamemory

Readdata

Writedata

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Instruction [15– 11]

Instruction [20– 16]

Instruction [25– 21]

Add

ALUresult

Zero

Instruction [5– 0]

MemtoReg

ALUOp

MemWrite

RegWrite

MemRead

Branch

JumpRegDst

ALUSrc

Instruction [31– 26]

4

Mux

Instruction [25– 0] Jump address [31– 0]

PC+4 [31– 28]

Signextend

16 32Instruction [15– 0]

1

Mux

1

0

Mux

0

1

Mux

0

1

ALU

control

Control

AddALU

result

Mux

0

1 0

ALU

Shift

left 226 28

Address

31-26 25-0

opcode addressJump

MIPS datapath extended to jumps: control unit generates new Jump control bit

New multiplexor with additional control bit Jump

Composing jumptarget address

Break up the instructions into steps each step takes one clock cycle

balance the amount of work to be done in each step/cycle so that they are about equal

restrict each cycle to use at most once each major functional unit so that such units do not have to be replicated

functional units can be shared between different cycles within one instruction

Between steps/cycles At the end of one cycle store data to be used in later cycles of the

same instruction need to introduce additional internal (programmer-invisible)

registers for this purpose

Data to be used in later instructions are stored in programmer-visible state elements: the register file, PC, memory

Multicycle Approach

Note particularities of

multicyle vs. single-

diagrams single memory for data

and instructions

single ALU, no extra adders

extra registers to

hold data between

clock cycles

Multicycle Approach

PC

Instructionmemory

Readaddress

Instruction

16 32

Add ALUresult

Mux

Registers

Writeregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Shiftleft 2

4

Mux

ALU operation3

RegWrite

MemRead

MemWrite

PCSrc

ALUSrc

MemtoReg

ALUresult

ZeroALU

Datamemory

Address

Writedata

Readdata M

ux

Signextend

Add

PC

Memory

Address

Instructionor data

Data

Instructionregister

Registers

Register #

Data

Register #

Register #

ALU

Memorydata

register

A

B

ALUOut

Single-cycle datapath

Multicycle datapath (high-level view)

user
Typewritten Text
Temp Reg.

Multicycle Datapath

Shift

left 2

PC

Memory

MemData

Writedata

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Mux

0

1

Mux

0

1

4

Instruction[15– 0]

Sign

extend

3216

Instruction[25– 21]

Instruction[20– 16]

Instruction[15– 0]

Instruction

register1 M

ux

0

3

2

Mux

ALUresult

ALU

Zero

Memory

data

register

Instruction[15– 11]

A

B

ALUOut

0

1

Address

Basic multicycle MIPS datapath handles R-type instructions and load/stores:new internal register in red ovals, new multiplexors in blue ovals

user
Typewritten Text
Read from Memory and write to Memory Data Register can be done in 1 cycle since Register write is very fast.
user
Line
user
Typewritten Text
Instruction Fetch (PC) or ALU computed an address (ALUOUT) in case of for eg. LW/SW
user
Typewritten Text
rd
user
Typewritten Text
rt
user
Typewritten Text
rs
user
Line
user
Typewritten Text
select between rd and rt. Same as before, only difference is now we store Inst in Inst Register.
user
Line
user
Typewritten Text
To choose between ALU and Memory. ALU for R-Type and Memory for LW
user
Typewritten Text
same connection as before, from RD2 to WD of Mem (used in case of SW) only the placement is different

Our goal is to break up the instructions into steps so that

each step takes one clock cycle

the amount of work to be done in each step/cycle is about equal

each cycle uses at most once each major functional unit so that such units do not have to be replicated

functional units can be shared between different cycles within one instruction

Data at end of one cycle to be used in next must be stored !!

Breaking instructions into steps

Breaking instructions into steps

We break instructions into the following potential execution steps – not all instructions require all the steps – each step takes one clock cycle

1. Instruction fetch and PC increment (IF)

2. Instruction decode and register fetch (ID)

3. Execution, memory address computation, or branch completion (EX)

4. Memory access or R-type instruction completion (MEM)

5. Memory read completion (WB)

Each MIPS instruction takes from 3 – 5 cycles (steps)

Use PC to get instruction and put it in the instruction register.

Increment the PC by 4 and put the result back in the PC.

Can be described succinctly using RTL (Register-Transfer Language):

IR = Memory[PC];

PC = PC + 4;

Step 1: Instruction Fetch & PC Increment (IF)

Read registers rs and rt in case we need them.

Compute the branch address in case the instruction is a branch.

RTL:A = Reg[IR[25-21]];

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

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

Step 2: Instruction Decode and Register Fetch (ID)

ALU performs one of four functions depending on instruction type memory reference:

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

R-type:ALUOut = A op B;

branch (instruction completes):if (A==B) PC = ALUOut;

jump (instruction completes):PC = PC[31-28] || (IR(25-0) << 2)

Step 3: Execution, Address Computation or Branch Completion (EX)

user
Typewritten Text
LW/SW

Again depending on instruction type:

Loads and stores access memory load

MDR = Memory[ALUOut];

store (instruction completes)

Memory[ALUOut] = B;

R-type (instructions completes)Reg[IR[15-11]] = ALUOut;

Step 4: Memory access or R-type Instruction Completion (MEM)

Again depending on instruction type: Load writes back (instruction completes)Reg[IR[20-16]]= MDR;

Important: There is no reason from a datapath (or control) point of view that Step 5 cannot be eliminated by performingReg[IR[20-16]]= Memory[ALUOut];

for loads in Step 4. This would eliminate the MDR as well.

The reason this is not done is that, to keep steps balanced in length, the design restriction is to allow each step to contain at most one ALU operation, or one register access, or onememory access.

Step 5: Memory Read Completion (WB)

Summary of Instruction Execution

Step name

Action for R-type

instructions

Action for memory-reference

instructions

Action for

branches

Action for

jumps

Instruction fetch IR = Memory[PC]

PC = PC + 4

Instruction A = Reg [IR[25-21]]

decode/register fetch B = Reg [IR[20-16]]

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

Execution, address ALUOut = A op B ALUOut = A + sign-extend if (A ==B) then PC = PC [31-28] II

computation, branch/ (IR[15-0]) PC = ALUOut (IR[25-0]<<2)

jump completion

Memory access or R-type Reg [IR[15-11]] = Load: MDR = Memory[ALUOut]

completion ALUOut or

Store: Memory [ALUOut] = B

Memory read completion Load: Reg[IR[20-16]] = MDR

1: IF

2: ID

3: EX

4: MEM

5: WB

Step

Multicycle Execution Step (1):Instruction Fetch

IR = Memory[PC];

PC = PC + 4;

4PC + 4

Multicycle Execution 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)

Branch

Target

Address

Reg[rs]

Reg[rt]

PC + 4

user
Typewritten Text
Sign Extend & Shift Left

Multicycle Execution Step (3):Memory Reference Instructions

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

Mem.

Address

Reg[rs]

Reg[rt]

PC + 4

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

ALUOut = A op B

R-Type

Result

Reg[rs]

Reg[rt]

PC + 4

Multicycle Execution Step (3):Branch Instructions

if (A == B) PC = ALUOut;

Branch

Target

Address

Reg[rs]

Reg[rt]

Branch

Target

Address

Multicycle Execution Step (3):Jump Instruction

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

Jump

Address

Reg[rs]

Reg[rt]

Branch

Target

Address

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

MDR = Memory[ALUOut];

Mem.

Data

PC + 4

Reg[rs]

Reg[rt]

Mem.

Address

Multicycle Execution Step (4):Memory Access - Write (sw)

Memory[ALUOut] = B;

PC + 4

Reg[rs]

Reg[rt]

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

Reg[IR[15:11]] = ALUOUT

R-Type

Result

Reg[rs]

Reg[rt]

PC + 4

Multicycle Execution Step (5):Memory Read Completion (lw)

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

PC + 4

Reg[rs]

Reg[rt]Mem.

Data

Mem.

Address