34
1 Performance of Single-Cycle Machine CPI = 1.0, but what about cycle time? Unit reuse (I.e. adder for PC vs. ALU) Arithmetic & Logic Load Store Branch Jump Instr. Memory PC mux Reg Read ALU mux Reg Setup Data Memory Instr. Memory PC Reg Read ALU mux Data Memory Adder PC setup Instr. Memory PC Reg Read ALU mux mux Instr. Memory PC Reg Read ALU mux mux Reg Setup Instr. Memory PC PC setup mux

Performance of Single-Cycle Machine

  • Upload
    drago

  • View
    44

  • Download
    0

Embed Size (px)

DESCRIPTION

PC. Instr. Memory. Reg Read. mux. ALU. Adder. mux. PC setup. PC. Instr. Memory. Reg Read. mux. ALU. Data Memory. PC. Instr. Memory. Reg Read. mux. ALU. mux. Reg Setup. PC. Instr. Memory. mux. PC setup. PC. Instr. Memory. Reg Read. mux. ALU. Data Memory. mux. - PowerPoint PPT Presentation

Citation preview

Page 1: Performance of Single-Cycle Machine

1

Performance of Single-Cycle Machine

CPI = 1.0, but what about cycle time? Unit reuse (I.e. adder for PC vs. ALU)

Arithmetic & Logic

Load

Store

Branch

Jump

Instr. MemoryPC muxReg Read ALUmux Reg SetupData Memory

Instr. MemoryPC Reg Read ALUmux Data Memory

Adder PCsetupInstr. MemoryPC Reg Read ALUmux mux

Instr. MemoryPC Reg Read ALUmux mux Reg Setup

Instr. MemoryPC PCsetupmux

Page 2: Performance of Single-Cycle Machine

2

Reducing Cycle Time

Cut combinational dependency graph and insert register / latch

Do same work in two fast cycles, rather than one slow one

storage element

Acyclic CombinationalLogic (A)

storage element

storage element

Acyclic CombinationalLogic (B)

storage element

Acyclic CombinationalLogic

storage element

Page 3: Performance of Single-Cycle Machine

3

Divide datapath into multiple cycles

Multicycle Processor Overview

PC

DataMemory

Instr.Memory

RegisterFile

RegisterFile

IFInstruction

Fetch

RFRegister

Fetch

EXExecute

MEMData

Memory

WBWriteback

Page 4: Performance of Single-Cycle Machine

4

Multicycle Processor Changes

Only one memory

Shared between instructions and data

Only one ALU/adder

Use ALU for instructions & PC computations

Add registers to datapath

IR: instruction register

MDR: Memory Data Register

A & B: Values read from register file

ALUout: Output of ALU

Page 5: Performance of Single-Cycle Machine

5

Cycle 1: Instruction Fetch

Put the instruction to execute into the Instruction Register (IR)

RTL:

Set the PC to the next instruction (ignore branches)

RTL:

Page 6: Performance of Single-Cycle Machine

6

Cycle 1 Datapath

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db

Page 7: Performance of Single-Cycle Machine

7

Cycle 2: Instruction Decode, Register Fetch

Store the two GPR operands into registers A and B

RTL:

Compute Branch Target (in case it’s a branch operation, won’t have time later)

RTL:

Page 8: Performance of Single-Cycle Machine

8

Cycle 1+2 Datapath

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

Page 9: Performance of Single-Cycle Machine

9

Cycle 3 (Branch)

Branch (Beq) – Branch address in ALUout. Set PC to branch address if A==B

RTL:

Page 10: Performance of Single-Cycle Machine

10

Branch Datapath

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

Page 11: Performance of Single-Cycle Machine

11

Cycle 3-4 (Add, Subtract)

Cycle 3: compute function in ALU, operands in A & B. Store in ALUout

RTL:

Cycle 4: Write value from ALUout to destination register

RTL:

Page 12: Performance of Single-Cycle Machine

12

Branch, R-Type Datapath

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

Page 13: Performance of Single-Cycle Machine

13

Cycle 3-4 (Store)

Cycle 3: compute address from operand A and IR[15-0], put into ALUout

RTL:

Cycle 4: Store value from operand B to address specified in ALUout

RTL:

Page 14: Performance of Single-Cycle Machine

14

Branch, R-Type, Store Datapath

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

Page 15: Performance of Single-Cycle Machine

15

Cycle 3-5 (Load)

Cycle 3: compute address from operand A and IR[15-0], put into ALUout

RTL:

Cycle 4: Load value from address specified in ALUout to MDR

RTL:

Cycle 5: Write value from MDR to destination register

RTL:

Page 16: Performance of Single-Cycle Machine

16

Multicycle Processor Datapath

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

Page 17: Performance of Single-Cycle Machine

17

Multicycle Processor Control

Need to control data path to perform required operations

Multiple cycles w/different control values each cycle, so control is an FSM.Cycle 1: IR = Mem[PC]; PC = PC + 4

Cycle 2: A = Reg[RS]; B = Reg[Rt];

ALUOut = PC + (Sign-extend(Imm16)<<2)

Cycle 3 Branch: Zero = (A-B); If (zero) PC = ALUout

Cycle 3 R-Type: ALUout = A op B

Cycle 4 R-Type: Reg[Rd] = ALUout

Cycle 3 Store: ALUout = A + sign-extend(Imm16)

Cycle 4 Store: Mem[ALUout] = B

Cycle 3 Load: ALUout = A + sign-extend(Imm16)

Cycle 4 Load: MDR = Mem[ALUout]

Cycle 5 Load: Reg[Rt] = MDR

Page 18: Performance of Single-Cycle Machine

18

Control FSM

Opcodes: LW 35, SW 43, BEQ 4, add/sub 0

Page 19: Performance of Single-Cycle Machine

19

Datapath Control Signals

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

Page 20: Performance of Single-Cycle Machine

20

Multicycle Datapath Control

WE ALU

State PC Mem Reg IR SrcA SrcB Op Dest MemIn RegIn PCSrc

1

2

3Br

3Rt

4Rt

3St

4St

3Lo

4Lo

5Lo

A <<2 Rt[20:16] PC MDR ALU

PC SE Rd[15:11] ALUout ALUout ALUout

B

4

1:IR = Mem[PC]PC = PC + 4

2:A = Reg[Rs]B = Reg[Rt]ALUOut = PC + (SE(imm16)<<2)

3Br:Zero = (A-B)If (zero) PC = ALUout

3Rt:ALUout = A op B

4Rt:Reg[Rd] = ALUout

3St:ALUout = A + SE(Imm16)

4St:Mem[ALUout] = B

3Lo:ALUout = A + SE(Imm16)

4Lo:MDR = Mem[ALUout]

5Lo:Reg[Rt] = MDR

Page 21: Performance of Single-Cycle Machine

21

IR = Mem[PC]; PC = PC + 4

Cycle 1 Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 22: Performance of Single-Cycle Machine

22

A=Reg[Rs]; B=Reg[Rt]; ALUOut = PC+(Sign-extend(Imm16)<<2)

Cycle 2 Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 23: Performance of Single-Cycle Machine

23

Zero = (A-B); If (zero) PC = ALUout

Cycle 3 (Branch) Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 24: Performance of Single-Cycle Machine

24

ALUout = A op B

Cycle 3 (R-Type) Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 25: Performance of Single-Cycle Machine

25

Reg[Rd] = ALUout

Cycle 4 (R-Type) Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 26: Performance of Single-Cycle Machine

26

ALUout = A + sign-extend(Imm16)

Cycle 3 (Store) Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 27: Performance of Single-Cycle Machine

27

Mem[ALUout] = B

Cycle 4 (Store) Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 28: Performance of Single-Cycle Machine

28

ALUout = A + sign-extend(Imm16)

Cycle 3 (Load) Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 29: Performance of Single-Cycle Machine

29

MDR = Mem[ALUout]

Cycle 4 (Load) Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 30: Performance of Single-Cycle Machine

30

Reg[Rt] = MDR

Cycle 5 (Load) Control

Sign

Extn

d

PC

<<2

MDR

ALUOutB

A

WrEnAddr DoutMemory

Din

IR

Rs

Rt

Rd

Imm

16

Aw Ab Aa DaRegisters

Dw WrEn Db4

MemIn

Mem_WE IR_WEPC_WE

RegIn

Dst

Reg_WE

ALUSrcA

ALUSrcB

ALUOp

PCSrc

Page 31: Performance of Single-Cycle Machine

31

Advanced: Exceptions

Exception = unusual event in processorArithmetic overflow, divide by zero, …Call an undefined instructionHardware failureI/O device request (called an “interrupt”)

ApproachesMake software test for exceptional events when they may occur (“polling”)Have hardware detect these events & react:

Save state (Exception Program Counter, protect the GPRs, note cause)Call Operating System

If (undef_instr) PC = C0000000If (overflow) PC = C0000020If (I/O) PC = C0000040…

user program

Exception:

SystemExceptionHandler

return fromexception

Page 32: Performance of Single-Cycle Machine

32

Advanced: Exceptions (cont.)

IFetch

Decode

Branch R-type1

R-type2

Store 1 Load 1

Load 2

Load 3

Store 2

Op = = 4Op = = 0 Op = = 43

Op = = 35

Exception:EPC = PC

PC = ExcepHandlerSet Cause

Page 33: Performance of Single-Cycle Machine

33

Multicycle CPI

Compute the CPI of the machine, given the frequencies specified

types

typetype FrequencyCyclesCPI *

Instruction Type Type Cycles Type Frequency Cycles * Freq

ALU 50%

Load 20%

Store 10%

Branch 20%

CPI:

Page 34: Performance of Single-Cycle Machine

34

Multicycle Summary

By splitting the single-cycle datapath up we achieve: