42
1 SEQ CPU Implementation

SEQ CPU Implementation

  • Upload
    fahim

  • View
    75

  • Download
    9

Embed Size (px)

DESCRIPTION

SEQ CPU Implementation. Outline. SEQ Implementation Suggested Reading 4.3.2, 4.3.4. What we will discuss today?. The implementation of a sequential CPU (SEQ) Every Instruction finished in one cycle. Instruction executes in sequential No two instruction execute in parallel or overlap. - PowerPoint PPT Presentation

Citation preview

Page 1: SEQ CPU Implementation

1

SEQ CPU Implementation

Page 2: SEQ CPU Implementation

2

Outline

• SEQ Implementation

• Suggested Reading 4.3.2, 4.3.4

Page 3: SEQ CPU Implementation

3

What we will discuss today?

• The implementation of a sequential CPU (SEQ)– Every Instruction finished in one cycle.– Instruction executes in sequential– No two instruction execute in parallel or overlap

Page 4: SEQ CPU Implementation

4

SEQ Hardware Structure

• Stages– Fetch: Read instruction from memory– Decode: Read program registers– Execute: Compute value or address– Memory: Read or write data– Write Back: Write program registers– PC: Update program counter

Page 5: SEQ CPU Implementation

5

InstructionInstruction memory PC increment

CCCC ALU

Data memory

Fetch

Decode

Execute

Memory

Write back

icode:ifun, rA:rB valC

RegisterM

valP

srcA, srcB

dstE,dstM

valA, valB

aluA,aluB

Cnd

valEaddrs,data

valM

PC

valE,valM

newPCPC

A B Register File

EM

PCPC

CC

Page 6: SEQ CPU Implementation

6

Difference between semantics and implementation

• ISA– Every stage may update some states, these

updates occur sequentially

• SEQ– All the state update operations occur

simultaneously at clock rising

Page 7: SEQ CPU Implementation

7

Page 8: SEQ CPU Implementation

8

SEQ Hardware

• Blue boxes: predesigned hardware blocks– e.g., memories, ALU

• Gray boxes: control logic– Describe in HCL

• White ovals: labels for signals

• Thick lines: 32-bit word values

• Thin lines: 4-8 bit values

• Dotted lines: 1-bit values

Page 9: SEQ CPU Implementation

9

Fetch Logic

Page 10: SEQ CPU Implementation

10

Fetch Logic

• Predefined Blocks– PC: Register containing PC– Instruction memory: Read 6 bytes (PC to PC+5)– Split: Divide instruction byte into icode and ifun– Align: Get fields for rA, rB, and valC

Page 11: SEQ CPU Implementation

11

Fetch Logic

• Control Blocks– Instr. Valid: Is this instruction valid?

– Need regids: Does this instruction have a register bytes?

– Need valC: Does this instruction have a constant word?

– icode|ifun: Set to “nop” if imem_error

Page 12: SEQ CPU Implementation

12

Some Macros

Name Value

Meaning

INOP 0 Code for nop instruction

IHALT 1 Code for halt instruction

IRRMOVL 2 Code for rrmovl instruction

IIRMOVL 3 Code for irmovl instruction

IRMMOVL 4 Code for rmmovl instruction

IMRMOVL 5 Code for mrmovl instruction

IOPL 6 Code for integer op instructions

IJXX 7 Code for jump instructions

………… …… ……………………………

IPOPL B Code for popl instruction

Page 13: SEQ CPU Implementation

13

Some Macros

Name Value

Meaning

RESP 6 Register ID for %esp

RNONE F Indicates no register file access

ALUADD 0 Function for addition operation

SAOK 1 Status code for normal operations

SADR 2 Status code for address exception

SINS 3 Status code for illegal instruction Exception

SHLT 4 Status code for halt

Page 14: SEQ CPU Implementation

14

pushl rA A 0 rA 8

jXX Dest 7 fn Dest

popl rA B 0 rA 8

call Dest 8 0 Dest

rrmovl rA, rB 2 0 rA rB

irmovlV, rB 3 0 8 rB V

rmmovl rA, D(rB) 4 0 rA rB D

mrmovl D(rB), rA 5 0 rA rB D

OPl rA, rB 6 fn rA rB

ret 9 0

nop 0 0

halt 1 0

pushl rA A 0 rA 8pushl rA A 0A 0 rA 8rA 8

jXX Dest 7 fn DestjXX Dest 7 fn7 fn Dest

popl rA B 0 rA 8popl rA B 0B 0 rA 8rA 8

call Dest 8 0 Destcall Dest 8 08 0 Dest

rrmovl rA, rB 2 0 rA rBrrmovl rA, rB 2 02 0 rA rBrA rB

irmovlV, rB 3 0 8 rB VirmovlV, rB 3 03 0 8 rB8 rB V

rmmovl rA, D(rB) 4 0 rA rB Drmmovl rA, D(rB) 4 04 0 rA rBrA rB D

mrmovl D(rB), rA 5 0 rA rB Dmrmovl D(rB), rA 5 05 0 rA rBrA rB D

OPl rA, rB 6 fn rA rBOPl rA, rB 6 fn6 fn rA rBrA rB

ret 9 0ret 9 09 0

nop 0 0nop 0 00 0

halt 1 0halt 1 01 0

need_regids

Page 15: SEQ CPU Implementation

15

Fetch Control Logic

bool need_regids = icode in { IRRMOVL, IIRMOVL, IRMMOVL, IMRMOVL, IOPL, IPUSHL, IPOPL };

bool instr_valid = icode in { INOP, IHALT, IRRMOVL, IIRMOVL, IRMMOVL, IMRMOVL, IOPL, IJXX, ICALL, IRET, IPUSHL, IPOPL };

Page 16: SEQ CPU Implementation

16

Decode & Write-Back Logic

Page 17: SEQ CPU Implementation

17

• Predefined Blocks– Registers File

• Read ports A, B & Write ports E, M• Addresses are register IDs or F (no access)

Decode & Write Back Logic

Page 18: SEQ CPU Implementation

18

• Control Logic– srcA: read port address for valA {rA, %esp}– srcB: read port address for valB {rB, %esp}– dstE: write port address for valE {rB, %esp}– dstM: write port address for valM {rA}– Cnd: used to decide whether set valE (cmovXX)

Decode & Write Back Logic

Page 19: SEQ CPU Implementation

19

A Source

opl rA, rB

valA R[rA]Decode Read operand A

rmmovl rA, D(rB)

valA R[rA]Decode Read operand A

popl rA

valA R[%esp]Decode Read stack pointer

jXX Dest

Decode No operand

call Dest

valA R[%esp]Decode Read stack pointer

ret

Decode No operand

Page 20: SEQ CPU Implementation

20

A Source

int srcA = [icode in { IRRMOVL, IRMMOVL, IOPL, IPUSHL } : rA;icode in { IPOPL, IRET } : RESP;1 : RNONE; # Don't need register

];

Page 21: SEQ CPU Implementation

21

E Destination

None

R[%esp] valE Update stack pointer

None

R[rB] valEopl rA, rB

Write-backrmmovl rA, D(rB)

popl rA

jXX Dest

call Dest

ret

Write-back

Write-back

Write-back

Write-back

Write-back

Write back result

R[%esp] valE Update stack pointer

R[%esp] valE Update stack pointer

Page 22: SEQ CPU Implementation

22

E Destination

int dstE = [icode in { IRRMOVL, IIRMOVL, IOPL} : rB;icode in { IPUSHL, IPOPL, ICALL, IRET }: RESP;1 : RNONE; # Don't need register

];// not conside cmovXX

Page 23: SEQ CPU Implementation

23

Execute Logic

Page 24: SEQ CPU Implementation

24

• Predefined Blocks– ALU: implements 4 required functions and

generate condition code values– CC: register with 3 condition code bits– cond: computes condition flag

Execute Logic

Page 25: SEQ CPU Implementation

25

• Control Logical– Set CC: Should condition code register be loaded?– ALU A: Input A to ALU {valA, valC, +4, -4}– ALU B: Input B to ALU {valB, 0}– ALU fun: What function should ALU compute?

Execute Logic

Page 26: SEQ CPU Implementation

26

ALU A Input

valE valB + –4 Decrement stack pointer

No operation

valE valB + 4 Increment stack pointer

valE valB + valC Compute effective address

valE valB OP valA Perform ALU operationOPl rA, rB

Executermmovl rA, D(rB)

popl rA

jXX Dest

call Dest

ret

Execute

Execute

Execute

Execute

Execute valE valB + 4 Increment stack pointer

Page 27: SEQ CPU Implementation

27

ALU A Input

int aluA = [icode in { IRRMOVL, IOPL } : valA;icode in { IIRMOVL, IRMMOVL,IMRMOVL}

: valC;icode in { ICALL, IPUSHL } : -4;icode in { IRET, IPOPL } : 4;# Other instructions don't need ALU

];

Page 28: SEQ CPU Implementation

28

ALU Operation

valE valB + –4 Decrement stack pointer

No operation

valE valB + 4 Increment stack pointer

valE valB + valC Compute effective address

valE valB OP valA Perform ALU operationopl rA, rB

Execute

rmmovl rA, D(rB)

popl rA

jXX Dest

call Dest

ret

Execute

Execute

Execute

Execute

Execute valE valB + 4 Increment stack pointer

Page 29: SEQ CPU Implementation

29

ALU Operation / Condition Set

int alufun = [icode == IOPL : ifun;1 : ALUADD;

];

Bool set_cc = icode in { IOPL };

Page 30: SEQ CPU Implementation

30

Memory Logic

Page 31: SEQ CPU Implementation

31

• Predefined Blocks– Memory: Reads or writes memory word

Memory Logic

Page 32: SEQ CPU Implementation

32

• Control Logical– Mem. read: should word be read?– Mem. write: should word be written?– Mem. addr.: Select address {valA, valE}– Mem. data.: Select data {valA, valP}

Memory Logic

Page 33: SEQ CPU Implementation

33

Memory Address

opl rA, rB

Memory

rmmovl rA, D(rB)

popl rA

jXX Dest

call Dest

ret

No operation

M4[valE] valAMemory Write value to memory

valM M4[valA]Memory Read from stack

M4[valE] valP Memory Write return value on stack

valM M4[valA] Memory Read return address

Memory No operation

Page 34: SEQ CPU Implementation

34

Memory Address

int mem_addr = [icode in { IRMMOVL, IPUSHL,

ICALL, IMRMOVL } : valE;icode in { IPOPL, IRET } : valA;# Other instructions don't need address

];

Page 35: SEQ CPU Implementation

35

Memory Read

opl rA, rB

Memory

rmmovl rA, D(rB)

popl rA

jXX Dest

call Dest

ret

No operation

M4[valE] valAMemory Write value to memory

valM M4[valA]Memory Read from stack

M4[valE] valP Memory Write return value on stack

valM M4[valA] Memory Read return address

Memory No operation

Page 36: SEQ CPU Implementation

36

Memory Read/Write

bool mem_read = icode in { IMRMOVL, IPOPL, IRET };

bool mem_write = icode in { IRMMOVL, IPUSHL, ICALL };

Page 37: SEQ CPU Implementation

37

PC Update Logic

• New PC– Select next value of PC

Page 38: SEQ CPU Implementation

38

PC Update

OPl rA, rB

rmmovl rA, D(rB)

popl rA

jXX Dest

call Dest

ret

PC valPPC update Update PC

PC valPPC update Update PC

PC valPPC update Update PC

PC Bch ? valC : valPPC update Update PC

PC valCPC update Set PC to destination

PC valMPC update Set PC to return address

Page 39: SEQ CPU Implementation

39

PC Update

int new_pc = [

icode == ICALL : valC;

icode == IJXX && Cnd : valC;

icode == IRET : valM;

1 : valP;

];

Page 40: SEQ CPU Implementation

40

Page 41: SEQ CPU Implementation

41

SEQ Summary

• Implementation– Express every instruction as series of simple

steps– Follow same general flow for each instruction

type– Assemble registers, memories, predesigned

combinational blocks– Connect with control logic

Page 42: SEQ CPU Implementation

42

SEQ Summary

• Limitations– Too slow to be practical– In one cycle, must propagate through

instruction memory, register file, ALU, and data memory

– Would need to run clock very slowly– Hardware units only active for fraction of clock

cycle