94
Outline Combinational & sequential logic Single-cycle CPU Multi-cycle CPU

Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

  • Upload
    others

  • View
    23

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

1

Outline

• Combinational & sequential logic• Single-cycle CPU• Multi-cycle CPU

Page 2: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

2

Combinational Element

combinationallogicinput n outputn•Output determined entirely by input•Contains no storage element

Page 3: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

3

Examples of Combinational Elements MUXn2n 1•Multiplexor selects one out of 2n inputs•ALU performs arithmetic & logic operations–AND: 000–OR: 001–add: 010–subtract: 110–set on less than: 111–other 3 combinations unused ALU6464 643 resultzero

Page 4: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

4

State (Sequential) Element

storageState Elementinput outputwriteclock

•State element has storage (i.e., memory)•State defined by storage content•Output depends on input and the state•Write lead controls storage update•Clock lead determines time of update•Examples: main memory, registers, PC

Page 5: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

5

Clocking Methodology•Needed to prevent simultaneous read/write to state elements•Edge-triggered methodology:state elements updated at rising clock edgeState element 1 State element 2Combinationallogicclock input

Page 6: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

6

Input/Output of Elements

•Combinational elements take input from one state element at clock edge and output to another state element at the next clock edge,•Within a clock cycle, state elements are not updated and their stable state is available as input to combinational elements,•Output can be derived from a state element at the edge of one cycle and input into the same state at the next.

State element 1 Combinationallogic

Page 7: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

7

Register File

Read reg 1Read reg 2Write regWrite dataRegisters555 Readdata 1Readdata 2 6464Register numbersData 64•Register file is the structure that contains the processor’s 32 registers•Any register can be accessed for read or written by specifying the register number•Register File’s I/O structure–3 inputs derived from current instruction to specify register operands (2 for read and 1 for write)–1 input to write data into a register–2 outputs carrying contents of the specified registers •Register file’s outputs are always available on the output lines•Register write is controlled byRegWrite lead RegWrite

Page 8: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

8

MIPS64 Instruction Formats

opcode Offset added to PC6 26 Note the regularity of instruction encoding. This is important for implementing an efficient pipelined CPU.opcode rs rd immediate6 5 5 16I-TypeR-TypeJ-Type opcode rs rt6 5 5 rd5 shamt5 func6

Page 9: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

9

Common Steps in Instruction Execution

• Execution of all instructions require the following steps– send PC to memory and fetch instruction stored at l ocation

specified by PC– read 0-2 registers, using fields specifying the reg isters in the

instruction

• All instructions use ALU functionality– data transfer instructions: compute address– ALU instructions: execute ALU operations– branch instructions: comparison & address compuatio n

Page 10: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

10

Differences in Instruction Execution

• Data transfer (strictly load/store ISA)– load: access memory for read data {ld R1, 0(R2)}– store: access memory for write data {ld 0(R2), R1}

• ALU instruction – no memory access for operands– access a register for write of result {add R1,R2, R 3}

• Branch instruction – change PC content based on comparison {bnez R1, Lo op}

Page 11: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

11

Summary

Fetch Decode ReadRegisters Compute AccessMemory WriteRegistersadd/sub X X X X Xload X X X X X Xstore X X X X Xconditionalbranch X X X Xunconditionalbranch X X X

Page 12: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

12

Data Path & Control path

• Datapath is the signal path through which data in th e CPU flows including the functional elements

• Elements of Datapath– combinational elements– state (sequential) elements

• Control path– the signal path from the controller to the Datapath

elements– exercises timing & control over Datapath elements

Page 13: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

13

What Should be in the Datapath

• At a minimum we need combinational and sequential logic elements in the datapath to support the following functions– fetch instructions and data from memory– Read registers– decode instructions and dispatch them to the execut ion

unit– execute arithmetic & logic operations– update state elements (registers and memory)

Page 14: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

14

Datapath Schematic

PC AddressInstructionInstructionMemory DataRegister # Register # Register # Registers AddressData DataMemoryALUALUWhat is this for?

Page 15: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

15Readaddress InstructionInstructionMemoryPC ALUAdder4 32

How wide is this in MIPS64?Datapath Building Blocks: Instruction Access

• Program Counter (PC)– a register that points to the next

instruction to be fetched– it is incremented each clock cycle

• Content of PC is input to Instruction Memory

• The instruction is fetched and supplied to upstream datapathelements

• Adder is used to increment PC by 4 in preparation for the next instruction (why 4?)

• Adder: an ALU with control input hardwired to perform add instruction only

• For reasons that will become clear later, we assume separate memory units for instructions & data

Page 16: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

16

Datapath Building Blocks: R-Type InstructionRead reg 1Read reg 2Write regWrite dataRegisterFile Readdata 1Readdata 2 ALUALUInstructionRegWrite

ALUop555 zeroopcode rs rt6 5 5 rd5 shamt5 func6R-Type Format• Used for arithmetic & logic

operations• Read two register, rs and rt• ALU operates on registers’

content

• Write result to register rd

• Example: add R1, R2, R3

– rs=R2, rt=R3, rd=R1

• Controls– RegWrite is asserted to enable

write at clock edge– ALUop to control operation

Page 17: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

17

I-Type Instruction: load/store

opcode rs rt immediate6 5 5 16I-Type LW R2, 232(R1)SW R5, -88(R4)• rs contains the base field for

the displacement address mode

• rt specifies register– to load from memory for

load

– to write to memory for store

• Immediate contains address offset

• To compute memory address, we must– sign-extend the 16-bit

immediate to 64 bits– add it to the base in rs

Page 18: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

18

• Register file

– load : registers to read for base address & to write for data

– store : registers to read for base address & for data

• Sign extender

– to sign-extend and condition immediate field for 2’ s complement additionof address offset using 64-bit ALU

• ALU

– to add base address and sign-extended immediate fie ld

• Data memory to load/store data:

– memory address; data input for store; data output f or load

– control inputs: MemRead, MemWrite, clock

Required Datapath Elements for load/store

signextend 6416

Page 19: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

19

Datapath Building Blocks: load/store

Read reg 1

Read reg 2

Write reg

Write data

Registers

Readdata 1

Readdata 2

ALUALU

Instruction

RegWrite

ALUop

5

5zero

sign

extend

5

16

Address

Writedata

DataMemory

Readdata

64

MemWrite

MemRead

opcode rs rt immediate

6 5 5 16

I-Type

Page 20: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

20

I-Type Instruction: bne

opcode rs rt immediate6 5 5 16I-Type bne R1, R2, Imm• Branch datapath must compute

branch condition & branch address

• rs and rt refer to registers to be compared for branch condition

• if Reg[rs] != Reg[rd], – PC = PC + Imm<< 2 (note that at

this point PC is already incremented. In effect PCcurrent =(PCprevious +4) + Imm<< 2

• else if Reg[rs] == Reg[rt]– PC remains unchanged:

PCcurrent =(PCprevious +4) – the next sequential instruction

is taken

• Required functional elements– RegFile, sign extender, adder,

shifter

64 shiftleft 2 64

Page 21: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

21

Sign Extend & Shift Operations

• Sign extension is required because– 16-bit offset must be

expanded to 64 bits in order to be used in the 64-bit adder

– we are using 2’s complement arithmetic

• Shift by 2 is required because– instructions are 32-bits wide

and are aligned on a word (4 bytes) boundary

– in effect we are using an 18-bit offset instead of 16

64 shiftleft 2 6416 signextend ALUAdderPC+40xb123 0xffffb123 0xfffec48c-20189 -20189 -80756

Page 22: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

22

Datapath Building Blocks: bne

Read reg 1Read reg 2Write regWrite dataRegistersReaddata 1Readdata 2 ALUALUInstruction RegWriteALUop = subtract5 zero

signextend16 645 To branchcontrol logic

ALUAdderPC+4 fromInstruction Datapath shiftleft 2 Branch targetopcode rs rt immediate6 5 5 16I-Type

Page 23: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

23

Computing Address & Branch Condition

• The register operands of bne are compared in the sam e ALU we use for load/store/arithmetic/logic instructions– the ALU provides a ZERO output signal to indicate c ondition– the ZERO signal controls what instruction will be f etched next

depending on whether the branch is taken or not

• We also need to compute the address– we may not be able to use the ALU if it is being us ed to

compute the branch condition (more on this later)– need an additional ADDER (an ALU hardwired to add o nly) to

compute branch address

Page 24: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

24

Putting it All Together

• Combine datapath building blocks to build the full d atapath– now we must decide some specifics of implementation

• Single-cycle CPU– each instruction executes in one clock cycle– CPI=1 for all instructions

• Multi-cycle CPU– instructions execute in multiples of a shorter cloc k cycle– different instructions have different CPI

Page 25: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

25

Single-Cycle CPU

• One clock cycle for all instructions• No datapath resource can be used more than once per

clock cycle– results in resource duplication for elements that m ust

be used more than once– examples: separate memory units for instruction and

data; two ALUs for conditional branches• Some datapath elements may be shared through

multiplexing as long as they are used once

Page 26: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

26

• We're ready to look at an implementation of the MIP S• Simplified to contain only:

– memory-reference instructions: lw, sw

– arithmetic-logical instructions: add, sub, and, or, slt

– control flow instructions: beq, j

• Generic Implementation:

– use the program counter (PC) to supply instruction address– get the instruction from memory– read registers– use the instruction to decide exactly what to do

• All instructions use the ALU after reading the regi stersWhy? memory-reference? arithmetic? control flow?

The Processor: Datapath & Control

Page 27: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

27Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

MIPS Fetch-Execute Processor Architecture

Page 28: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

28Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Initialize Program Counter (PC) ⇒ first instruction

Page 29: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

29

Activate Control Logic

Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Page 30: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

30

Route Address to Program Memory

Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Page 31: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

31Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Route Instruction to Instruction Register (IR)

Page 32: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

32Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Select Appropriate Data From Register File

Page 33: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

33Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Route Data to Arithmetic Logic Unit (ALU)

Page 34: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

34Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Do the Computation

Page 35: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

35Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Store the Result

Page 36: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

36Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Increment PC ⇒ Point to Next Instruction

Page 37: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

37Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Increment PC ⇒ Point to Next Instruction

Page 38: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

38Data In

Address

Program Memory

Control Logic

Rdest

Rs

Rt

Instruction Register

Data Memory

(Register File)

Program Counter (PC)

ALU

4

Execute Next Instruction

Page 39: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

39

• Unclocked vs. Clocked• Clocks used in synchronous logic

– when should an element that contains state be updat ed?

State Elements

Clock period Rising edge

Falling edge

cycle time

Page 40: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

40

• The set-reset latch– output depends on present inputs and also on past i nputs

An unclocked state element

R

S

Q

Q

Page 41: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

41

• Output is equal to the stored value inside the element (don't need to ask for permission to look a t the value)

• Change of state (value) is based on the clock– Latches: output changes whenever the inputs change ,

and the clock is asserted (level-triggered methodol ogy)– Flip-flops: state changes only on a clock edge

(edge-triggered methodology)

• A clocking methodology defines when signals can be read and written— wouldn't want to read a signal at the same time it was being written

Latches and Flip-flops

Page 42: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

42

• Two inputs:– the data value to be stored (D)– the clock signal (C) indicating when to read & stor e D

• Two outputs:– the value of the internal state (Q) and it's comple ment

D-latch

Q

C

D

_Q

D

C

Q

Page 43: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

43

D flip-flop

• Output changes only on the clock edge

D

C

Q

D

C

Dlatch

D

C

QD

latch

D

C

Q Q

Q Q

Page 44: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

44

Our Implementation

• An edge triggered methodology• Typical execution:

– read contents of some state elements – send values through some combinational logic– write results to one or more state elements

Stateelement

1

Stateelement

2Combinational logic

Clock cycle

Page 45: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

45

• Built using D flip-flops

Register File

Read registernumber 1 Read

data 1Read registernumber 2

Readdata 2

Writeregister

WriteWritedata

Register file

Read registernumber 1

Register 0

Register 1

. . .

Register n – 2

Register n – 1

M

u

x

Read registernumber 2

M

u

x

Read data 1

Read data 2

Do you understand? What is the “Mux” above?

Page 46: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

46

Abstraction

• Make sure you understand the abstractions!• Sometimes it is easy to think you do, when you

don’t

Mux

C

Select

32

32

32

B

A

Mux

Select

B31

A31

C31

Mux

B30

A30

C30

Mux

B0

A0

C0

...

...

Page 47: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

47

Register File

• Note: we still use the real clock to determine whe n to write

Write

01

n-to-2ndecoder

n – 1

n

Register 0

C

D

Register 1

C

D

Register n – 2

C

D

Register n – 1

C

D

...

Register number...

Register data

Page 48: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

48

Simple Implementation

• Include the functional units we need for each instr uction

PC

Instructionaddress

Instruction

Instructionmemory

Add Sum

a. Instruction memory b. Program counter c. Adder

Readregister 1

Readregister 2

Writeregister

WriteData

Registers ALUData

Data

Zero

ALUresult

RegWrite

a. Registers b. ALU

5

5

5

Registernumbers

Readdata 1

Readdata 2

ALU operation4

AddressReaddata

Datamemory

a. Data memory unit

Writedata

MemRead

MemWrite

b. Sign-extension unit

Signextend

16 32

Page 49: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

49

Building the Datapath

• Use multiplexors to stitch them together

Readregister 1

Readregister 2

Writeregister

Writedata

Writedata

Registers ALU

Add

Zero

RegWrite

MemRead

MemWrite

PCSrc

MemtoReg

Readdata 1

Readdata 2

ALU operation4

Signextend

16 32

InstructionALU

result

Add

ALUresult

Mux

Mux

Mux

ALUSrc

Address

Datamemory

Readdata

Shiftleft 2

4

Readaddress

Instructionmemory

PC

Page 50: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

50

Control

• Selecting the operations to perform (ALU, read/writ e, etc.)

• Controlling the flow of data (multiplexor inputs)

• Information comes from the 32 bits of the instructi on

• Example:

add $8, $17, $18 Instruction Format:000000 10001 10010 01000 00000 100000

op rs rt rd shamt funct

• ALU's operation based on instruction type and funct ion code

Page 51: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

51

• e.g., what should the ALU do with this instruction• Example: lw $1, 100($2)

35 2 1 100

op rs rt 16 bit offset

• ALU control input

0000 AND0001 OR0010 add0110 subtract0111 set-on-less-than1100 NOR

• Why is the code for subtract 0110 and not 0011?

Control

Page 52: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

52

• Must describe hardware to compute 4-bit ALU control input– given instruction type

00 = lw, sw01 = beq, 10 = arithmetic

– function code for arithmetic

• Describe it using a truth table (can turn into gate s):

ALUOp computed from instruction type

Control

Page 53: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

Instruction RegDst ALUSrcMemto-

RegReg

WriteMem Read

Mem Write Branch ALUOp1 ALUp0

R-format 1 0 0 1 0 0 0 1 0lw 0 1 1 1 1 0 0 0 0sw X 1 X 0 0 1 0 0 0beq X 0 X 0 0 0 1 0 1

Readregister 1

Readregister 2

Writeregister

Writedata

Writedata

Registers

ALU

Add

Zero

Readdata 1

Readdata 2

Signextend

16 32

Instruction[31–0] ALU

result

Add

ALUresult

Mux

Mux

Mux

Address

Datamemory

Readdata

Shiftleft 2

4

Readaddress

Instructionmemory

PC

1

0

0

1

0

1

Mux

0

1

ALUcontrol

Instruction [5–0]

Instruction [25–21]

Instruction [31–26]

Instruction [15–11]

Instruction [20–16]

Instruction [15–0]

RegDstBranchMemReadMemtoRegALUOpMemWriteALUSrcRegWrite

Control

Page 54: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

54

R-type Instruction

Page 55: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

55

Load Instruction

Page 56: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

56

Branch on Equal

Page 57: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

57

Control

• Simple combinational logic (truth tables)

Operation2

Operation1

Operation0

Operation

ALUOp1

F3

F2

F1

F0

F (5– 0)

ALUOp0

ALUOp

ALU control block

R-format Iw sw beq

Op0

Op1

Op2

Op3

Op4

Op5

Inputs

Outputs

RegDst

ALUSrc

MemtoReg

RegWrite

MemRead

MemWrite

Branch

ALUOp1

ALUOpO

Page 58: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

58

• All of the logic is combinational

• We wait for everything to settle down, and the righ t thing to be done– ALU might not produce “right answer” right away

– we use write signals along with clock to determine when to write

• Cycle time determined by length of the longest path

Our Simple Control Structure

We are ignoring some details like setup and hold times

Stateelement

1

Stateelement

2Combinational logic

Clock cycle

Page 59: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

59

Single Cycle Implementation

• Calculate cycle time assuming negligible delays exc ept:– memory (200ps),

ALU and adders (100ps), register file access (50ps)

Readregister 1

Readregister 2

Writeregister

Writedata

Writedata

Registers ALU

Add

Zero

RegWrite

MemRead

MemWrite

PCSrc

MemtoReg

Readdata 1

Readdata 2

ALU operation4

Signextend

16 32

InstructionALU

result

Add

ALUresult

Mux

Mux

Mux

ALUSrc

Address

Datamemory

Readdata

Shiftleft 2

4

Readaddress

Instructionmemory

PC

Page 60: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

60

Where we are headed

• Single Cycle Problems:– what if we had a more complicated instruction like floating point?– wasteful of area

• One Solution:– use a “smaller” cycle time– have different instructions take different numbers of cycles– a “multicycle” datapath:

Data

Register #

Register #

Register #

PC Address

Instructionor dataMemory Registers ALU

Instructionregister

Memorydata

register

ALUOut

A

BData

Page 61: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

61

• Reuse functional units– ALU used to compute address and to increment PC– Memory used for instruction and data

• Control signals will not be determined directly by instruction– e.g., what should the ALU do for a “subtract” instr uction?– There must be some sequencing involved leading to ….

• Use a finite state machine for control

Multicycle Approach

Page 62: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

62

• Break up the instructions into steps, each step tak es a cycle– balance the amount of work to be done– restrict each cycle to use only one major functiona l unit

• At the end of a cycle– store values for use in later cycles (easiest thing to do)– this introduces additional “internal” registers

Multicycle Approach

Readregister 1

Readregister 2

Writeregister

Writedata

Registers ALU

Zero

Readdata 1

Readdata 2

Signextend

16 32

Instruction[25–21]

Instruction[20–16]

Instruction[15–0]

ALUresult

Mux

Mux

Shiftleft 2

Instructionregister

PC 0

1

Mux

0

1

Mux

0

1

Mux

0

1A

B 0

1

2

3

ALUOut

Instruction[15–0]

Memorydata

register

Address

Writedata

Memory

MemData

4

Instruction[15–11]

Page 63: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

63

Instructions from ISA perspective

• Consider each instruction from the perspective of I SA• Example:

– The add instruction changes a register – Instruction specified by the PC– Destination register specified by bits 15:11 of ins truction– New value is the sum (“op”) of two registers– Source registers specified by bits 25:21 and 20:16 of the instruction

Reg[Memory[PC][15:11]] <= Reg[Memory[PC][25:21]] op Reg[Memory[PC][20:16]]

– In order to accomplish this, we must break up the i nstruction (kind of like introducing variables when programming)

Page 64: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

64

Breaking down an instruction

• ISA definition of arithmetic:

Reg[Memory[PC][15:11]] <= Reg[Memory[PC][25:21]]

op Reg[Memory[PC][20:16]]

• Could break down to:– IR <= Memory[PC]

– A <= Reg[IR[25:21]]

– B <= Reg[IR[20:16]]

– ALUOut <= A op B

– Reg[IR[20:16]] <= ALUOut

• Don’t forget an important part of the operation:– PC <= PC + 4

Page 65: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

65

Idea behind multicycle approach

• We define each instruction from the ISA perspective• Break it down into steps following the rule that da ta flows

through, at most, one major functional unit (e.g., balance work across steps)

• Introduce new registers as needed (A, B, ALUOut, M DR, etc.)• Finally, try and pack as much work into each step ( avoid

unnecessary cycles) while also trying to share step s where possible (minimizes control and likely hardware, he lps to simplify solution)

Result: The textbook’s multicycle Implementation.

Page 66: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

66

• Instruction Fetch

• Instruction Decode and Register Fetch

• Execution, Memory Address Computation, or Branch Completion

• Memory Access or R-type instruction completion

• Write-back step

INSTRUCTIONS TAKE FROM 3 - 5 CYCLES

Five Execution Steps

Page 67: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

67

• Use PC to get instruction and put it in the Instruc tion Register• Increment the PC by 4 and put the result back in th e PC• Can be described succinctly using RTL "Register-Tra nsfer

Language"

IR <= Memory[PC];PC <= PC + 4;

What is the advantage of updating the PC now?

Step 1: Instruction Fetch

Page 68: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

68

• 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);

• We aren't setting any control lines based on the instruction type

Step 2: Instruction Decode and Register Fetch

Page 69: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

69

• ALU is performing one of three functions, based on instruction type

– Memory Reference:

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

– R-type:

ALUOut <= A op B;

– Branch:

if (A==B) PC <= ALUOut;

Step 3: (Instruction dependent)

Page 70: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

70

• Loads and stores access memory

MDR <= Memory[ALUOut];or

Memory[ALUOut] <= B;

• R-type instructions finish

Reg[IR[15:11]] <= ALUOut;

The write actually takes place at the end of the cy cle on the edge

Step 4: (R-type or memory-access)

Page 71: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

71

• Reg[IR[20:16]] <= MDR;

Which instruction needs this?

Step 5: Write-back step

Page 72: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

72

Summary:

Page 73: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

73

• How many cycles will it take to execute this code?

lw $t2, 0($t3)lw $t3, 4($t3)beq $t2, $t3, Labelnop

add $t5, $t2, $t3sw $t5, 8($t3)

Label: ...

• What is going on during the 8th cycle of execution?• In what cycle does the actual addition of $t2 and $t3 take

place?

Simple Questions

Page 74: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

Readregister 1

Readregister 2

Writeregister

Writedata

Registers ALU

Zero

Readdata 1

Readdata 2

Signextend

16 32

Instruction[31–26]

Instruction[25–21]

Instruction[20–16]

Instruction[15–0]

ALUresult

Mux

Mux

Shiftleft 2

Shiftleft 2

Instructionregister

PC 0

1

Mux

0

1

Mux

0

1

Mux

0

1A

B 0

1

2

3

Mux

0

1

2

ALUOut

Instruction[15–0]

Memorydata

register

Address

Writedata

Memory

MemData

4

Instruction[15–11]

PCWriteCond

PCWrite

IorD

MemRead

MemWrite

MemtoReg

IRWrite

PCSource

ALUOp

ALUSrcB

ALUSrcA

RegWrite

RegDst

26 28

Outputs

Control

Op[5–0]

ALUcontrol

PC [31–28]

Instruction [25-0]

Instruction [5–0]

Jumpaddress[31–0]

Page 75: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

75

• Finite state machines:– a set of states and – next state function (determined by current state an d the input)– output function (determined by current state and po ssibly input)

– We’ll use a Moore machine (output based only on cur rent state)

Review: finite state machines

Inputs

Current state

Outputs

Clock

Next-statefunction

Outputfunction

Nextstate

Page 76: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

76

Review: finite state machines

• Example:

B. 37 A friend would like you to build an “electronic eye” for use as a fake security device. The device consists of three lights lined up in a row, controlled by the outputs Left, Middle, and Right, which, if asserted, indicate that a light should be on. Only one light is on at a time, and the light “moves” from left to right and then from right to left, thus scaring away thieves who believe that the device is monitoring their activity. Draw the graphical representation for the finite state machine used to specify the electronic eye. Note that the rate of the eye’s movement will be controlled by the clock speed (which should not be too great) and that there are essentially no inputs.

Page 77: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

77

• Value of control signals is dependent upon:– what instruction is being executed– which step is being performed

• Use the information we’ve accumulated to specify a finite state machine– specify the finite state machine graphically, or– use microprogramming

• Implementation can be derived from specification

Implementing the Control

Page 78: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

78

• Note:– don’t care if not mentioned– asserted if name only– otherwise exact value

• How many state bits will we need?

Graphical Specification of FSMMemRead

ALUSrcA = 0IorD = 0IRWrite

ALUSrcB = 01ALUOp = 00

PCWritePCSource = 00

ALUSrcA = 0ALUSrcB = 11ALUOp = 00

ALUSrcA = 1ALUSrcB = 00ALUOp = 10

ALUSrcA = 1ALUSrcB = 10ALUOp = 00

MemReadIorD = 1

MemWriteIorD = 1

RegDst = 1RegWrite

MemtoReg = 0

RegDst = 1RegWrite

MemtoReg = 0

PCWritePCSource = 10

ALUSrcA = 1ALUSrcB = 00ALUOp = 01

PCWriteCondPCSource = 01

Instruction decode/register fetch

Instruction fetch

0 1

Start

Jumpcompletion

9862

3

4

5 7

Memory readcompleton step

R-type completionMemoryaccess

Memoryaccess

ExecutionBranch

completionMemory address

computation

Page 79: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

79

• Implementation:

Finite State Machine for Control

PCWrite

PCWriteCondIorD

MemtoReg

PCSource

ALUOp

ALUSrcB

ALUSrcA

RegWrite

RegDst

NS3NS2NS1NS0

Op5

Op4

Op3

Op2

Op1

Op0

S3

S2

S1

S0

State register

IRWrite

MemRead

MemWrite

Instruction register opcode field

Outputs

Control logic

Inputs

Page 80: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

80

PLA Implementation

• If I picked a horizontal or vertical line could you explain it?

Op5

Op4

Op3

Op2

Op1

Op0

S3

S2

S1

S0

IorD

IRWrite

MemReadMemWrite

PCWritePCWriteCond

MemtoRegPCSource1

ALUOp1

ALUSrcB0ALUSrcARegWriteRegDstNS3NS2NS1NS0

ALUSrcB1ALUOp0

PCSource0

Page 81: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

81

• 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 2 m entries in the ROM.– our outputs are the bits of data that the address p oints to.

m is the "height", and n is the "width"

ROM Implementation

m n

0 0 0 0 0 1 10 0 1 1 1 0 00 1 0 1 1 0 00 1 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 11 1 0 0 1 1 01 1 1 0 1 1 1

Page 82: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

82

• How many inputs are there?6 bits for opcode, 4 bits for state = 10 address li nes(i.e., 210 = 1024 different addresses)

• How many outputs are there?16 datapath-control outputs, 4 state bits = 20 outp uts

• ROM is 2 10 x 20 = 20K bits (and a rather unusual size)

• Rather wasteful, since for lots of the entries, the outputs are the same

— i.e., opcode is often ignored

ROM Implementation

Page 83: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

83

• Break up the table into two parts— 4 state bits tell you the 16 outputs, 2 4x16 bits of ROM— 10 bits tell you the 4 next state bits, 2 10x4 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

• Size is (#inputs ×××× #product-terms) + (#outputs ×××× #product-terms)

For this example = (10x17)+(20x17) = 510 PLA cell s

• PLA cells usually about the size of a ROM cell (sli ghtly bigger)

ROM vs PLA

Page 84: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

84

• Complex instructions: the "next state" is often current state + 1

Another Implementation Style

AddrCtl

Outputs

PLA or ROM

State

Address select logic

Op

[5–

0]

Adder

Instruction register opcode field

1

Control unit

Input

PCWritePCWriteCondIorD

MemtoRegPCSourceALUOpALUSrcBALUSrcARegWriteRegDst

IRWrite

MemReadMemWrite

BWrite

Page 85: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

85

Details

Dispatch ROM 1 Dispatch ROM 2Op Opcode name Value Op Opcode name Value

000000 R-format 0110 100011 lw 0011000010 jmp 1001 101011 sw 0101000100 beq 1000100011 lw 0010101011 sw 0010

State number Address-control action Value of AddrCtl0 Use incremented state 31 Use dispatch ROM 1 12 Use dispatch ROM 2 23 Use incremented state 34 Replace state number by 0 05 Replace state number by 0 06 Use incremented state 37 Replace state number by 0 08 Replace state number by 0 09 Replace state number by 0 0

State

Adder

1

PLA or ROM

Mux3 2 1 0

Dispatch ROM 1Dispatch ROM 2

0

AddrCtl

Address select logic

Instruction registeropcode field

Page 86: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

86

Microprogramming

• What are the “microinstructions” ?

PCWritePCWriteCondIorD

MemtoRegPCSourceALUOpALUSrcBALUSrcARegWrite

AddrCtl

Outputs

Microcode memory

IRWrite

MemReadMemWrite

RegDst

Control unit

Input

Microprogram counter

Address select logic

Adder

1

Instruction registeropcode field

BWrite

Datapath

Page 87: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

87

• A specification methodology– appropriate if hundreds of opcodes, modes, cycles, etc.– signals specified symbolically using microinstructi ons

• Will two implementations of the same architecture have the same microcode?

• What would a microassembler do?

Microprogramming

LabelALU

control SRC1 SRC2Register control Memory

PCWrite control Sequencing

Fetch Add PC 4 Read PC ALU SeqAdd PC Extshft Read Dispatch 1

Mem1 Add A Extend Dispatch 2LW2 Read ALU Seq

Write MDR FetchSW2 Write ALU FetchRformat1 Func code A B Seq

Write ALU FetchBEQ1 Subt A B ALUOut-cond FetchJUMP1 Jump address Fetch

Page 88: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

88

Microinstruction formatField name Value Signals active Comment

Add ALUOp = 00 Cause the ALU to add.ALU control Subt ALUOp = 01 Cause the ALU to subtract; this implements the compare for

branches.Func code ALUOp = 10 Use the instruction's function code to determine ALU control.

SRC1 PC ALUSrcA = 0 Use the PC as the first ALU input.A ALUSrcA = 1 Register A is the first ALU input.B ALUSrcB = 00 Register B is the second ALU input.

SRC2 4 ALUSrcB = 01 Use 4 as the second ALU input.Extend ALUSrcB = 10 Use output of the sign extension unit as the second ALU input.Extshft ALUSrcB = 11 Use the output of the shift-by-two unit as the second ALU input.Read Read two registers using the rs and rt fields of the IR as the register

numbers and putting the data into registers A and B.Write ALU RegWrite, Write a register using the rd field of the IR as the register number and

Register RegDst = 1, the contents of the ALUOut as the data.control MemtoReg = 0

Write MDR RegWrite, Write a register using the rt field of the IR as the register number andRegDst = 0, the contents of the MDR as the data.MemtoReg = 1

Read PC MemRead, Read memory using the PC as address; write result into IR (and lorD = 0 the MDR).

Memory Read ALU MemRead, Read memory using the ALUOut as address; write result into MDR.lorD = 1

Write ALU MemWrite, Write memory using the ALUOut as address, contents of B as thelorD = 1 data.

ALU PCSource = 00 Write the output of the ALU into the PC.PCWrite

PC write control ALUOut-cond PCSource = 01, If the Zero output of the ALU is active, write the PC with the contentsPCWriteCond of the register ALUOut.

jump address PCSource = 10, Write the PC with the jump address from the instruction.PCWrite

Seq AddrCtl = 11 Choose the next microinstruction sequentially.Sequencing Fetch AddrCtl = 00 Go to the first microinstruction to begin a new instruction.

Dispatch 1 AddrCtl = 01 Dispatch using the ROM 1.Dispatch 2 AddrCtl = 10 Dispatch using the ROM 2.

Page 89: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

89

• No encoding:– 1 bit for each datapath operation

– faster, requires more memory (logic)

– used for Vax 780 — an astonishing 400K of memory!

• Lots of encoding:– send the microinstructions through logic to get con trol signals

– uses less memory, slower

• Historical context of CISC:– Too much logic to put on a single chip with everyth ing else

– Use a ROM (or even RAM) to hold the microcode

– It’s easy to add new instructions

Maximally vs. Minimally Encoded

Page 90: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

90

Microcode: Trade-offs

• Distinction between specification and implementation is sometimes blurred

• Specification Advantages:– Easy to design and write

– Design architecture and microcode in parallel

• Implementation (off-chip ROM) Advantages

– Easy to change since values are in memory

– Can emulate other architectures

– Can make use of internal registers

• Implementation Disadvantages, SLOWER now that:

– Control is implemented on same chip as processor

– ROM is no longer faster than RAM

– No need to go back and make changes

Page 91: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

91

Historical Perspective

• In the ‘60s and ‘70s microprogramming was very impo rtant for implementing machines

• This led to more sophisticated ISAs and the VAX• In the ‘80s RISC processors based on pipelining bec ame

popular• Pipelining the microinstructions is also possible!• Implementations of IA-32 architecture processors si nce 486

use:– “hardwired control” for simpler instructions

(few cycles, FSM control implemented using PLA or r andom logic)

– “microcoded control” for more complex instructions(large numbers of cycles, central control store)

• The IA-64 architecture uses a RISC-style ISA and ca n be implemented without a large central control store

Page 92: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

92

Pentium 4

• Pipelining is important (last IA-32 without it was 80386 in 1985)

• Pipelining is used for the simple instructions favo red by compilers

“Simply put, a high performance implementation need s to ensure that the simple instructions execute quickly, and t hat the burden of the complexities of the instruction set penalize the complex,less frequently used, instructions”

Control

Control

Control

Enhancedfloating pointand multimedia

Control

I/Ointerface

Instruction cache

Integerdatapath

Datacache

Secondarycacheandmemoryinterface

Advanced pipelininghyperthreading support

Chapter 6

Chapter 7

Page 93: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

93

Pentium 4

• Somewhere in all that “control” we must handle comp lex instructions

• Processor executes simple microinstructions, 70 bit s wide (hardwired)

• 120 control lines for integer datapath (400 for flo ating point)• If an instruction requires more than 4 microinstruc tions to implement,

control from microcode ROM (8000 microinstructions)• Its complicated!

Control

Control

Control

Enhancedfloating pointand multimedia

Control

I/Ointerface

Instruction cache

Integerdatapath

Datacache

Secondarycacheandmemoryinterface

Advanced pipelininghyperthreading support

Page 94: Combinational & sequential logic Single-cycle CPU Multi ...comarc/slides/lect4-1.pdf · Differences in Instruction Execution • Data transfer (strictly load/store ISA) – load:

94

Chapter 5 Summary

• If we understand the instructions …

We can build a simple processor!

• If instructions take different amounts of time, mul ti-cycle is

better

• Datapath implemented using:

– Combinational logic for arithmetic

– State holding elements to remember bits

• Control implemented using:

– Combinational logic for single-cycle implementation

– Finite state machine for multi-cycle implementation