orange coast college business division computer science department cs 116- computer architecture the...

45
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath & Control

Upload: clement-spencer

Post on 18-Jan-2018

218 views

Category:

Documents


0 download

DESCRIPTION

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 3 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Processor Design Step 3-a Instruction Fetch Unit – Common to all instruction types – Actions taken: Fetch the instruction from Memory: mem[PC] Update program counter: – Sequential Code: PC

TRANSCRIPT

Page 1: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

Orange Coast CollegeBusiness Division

Computer Science Department

CS 116- Computer Architecture

The Processor: Datapath & Control

Page 2: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 2OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Processor Design Step 3• Assemble Datapath Meeting Requirements

– Build the data path by adding up the components required to execute each instruction

– We need to consider:• Register transfer requirements • Instruction fetch• Read operands and execute operation

– We are going to consider one instruction format at a time and then combine what we have after each step

Page 3: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 3OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Processor Design Step 3-a• Instruction Fetch Unit

– Common to all instruction types

– Actions taken:• Fetch the instruction

from Memory: mem[PC]

• Update program counter:– Sequential Code:

PC <- PC + 4 – Branch and Jump:

PC <- branch address

PC

Instruction Memory

Read Address

4

Adder

Page 4: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 4OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Consider R-Type instructions• R-Format Instructions:

– Arithmetic instructions– Logic instructions

• Main actions:– Read 2 registers– Perform an ALU operation– Write result to destination

op rs rt rd shamt funct061116212631

6 bits 6 bits5 bits5 bits5 bits5 bits

Page 5: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 5OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

R-Type: What do we need?• To read data from a register we need

– 2-inputs to register file specifying register to be read

– 2-outputs from register file will carry the values read • Remember output is always available to whatever

register# given, therefore no control signal is needed

• To write data to a register we need– 1-input to register file with register# to write into– 1-data input will carry the data to be written – Write control signal that enables data to be written

Page 6: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 6OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Datapath for R-Format Instructions• Main components:

Register file

RegWrite

Writeregister

Readdata 1

Readdata 2

Readregister 1Readregister 2

Writedata

5

5

5ALU Operation

ALUresult

ALUZero

3

Page 7: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 7OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

R-Type Datapath• Datapath for Add & Subtract Instructions

R[rd] R[rs] ± R[rt] – Example:

add rd, rs, rt– The register selection lines come from register

fields– Control signals are from the control logic after

decoding the instruction • Opcode + funct

Page 8: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 8OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Now, consider the I-Type• Load & Store

R[rt] Mem[R[rs] + SignExt[imm16]] R[rt] Mem[R[rs] + SignExt[imm16]]

– Main actions:• Sign-extend offset• Add to contents of base register to calculate address• Load from or store into the calculated address

– We need a sign-extend unit for offset

11op rs rt/rd? offset

016212631

6 bits 16 bits5 bits5 bits

offset016 1531

16 bits16 bitssign-extended 16-bits

Page 9: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 9OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Datapath for I-Format instructions:• Immediate arithmetic operations

R[rt] R[rs] op SignExt[imm16]– Main actions:

• Sign extend immediate operand• Perform operation• Store result

– We need a “sign-extend” unit for immediate operand

11op rs rt/rd? offset

016212631

6 bits 16 bits5 bits5 bits

offset016 1531

16 bits16 bitssign-extended 16-bits

Page 10: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 10OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Datapath for I-Format instructions:• Immediate logical operations

R[rt] R[rs] op ZeroExt[imm16]– Main actions:

• Zero extend immediate operand• Perform operation• Store result

– We need a “zero-extend” unit for immediate operand

11op rs rt/rd? immediate

016212631

6 bits 16 bits5 bits5 bits

immediate016 1531

16 bits16 bits0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Page 11: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 11OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Load - The Details• Use offset in 16 immediate operand bits • Value read from memory must be written into

register fileR[rt] <- Mem[R[rs] + SignExt[imm16]]

• Example: lw rt, rs, imm16lw $t1, offset($t2) #$t2 = Base register

op rs rt immediate6 bits 5 bits 5 bits 16 bit

31 26 21 16 0

Page 12: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 12OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Store- The Details• Use offset in 16 immediate operand bits • Value to be stored read from register file

Mem[ R[rs] + SignExt[imm16] ] <- R[rt]• Example:

sw rt, rs, imm16sw $t1, offset($t2) #$t2 = Base register

op rs rt immediate6 bits 5 bits 5 bits 16 bit

31 26 21 16 0

Page 13: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 13OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Load & Store- What do we need?• Actions:

– Register access– Memory address calculation– Read/Write from memory– Write into register (for load)

• What do we need?– Sign-extend unit– Data memory unit to read/ or write– Both write & read control signals

Page 14: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 14OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Implementation of Load & Store

RegWrite

RegisterFileWrteregister

Readdata 1

Readdata 2

Readregister 1Readregister 2

Wrtedata

5

5

5ALU Operation

ALUALUresut

Zero

3

16 32Signextend MemRead

MemWrite

Wr i t edata

Readdata

Address

Instruction

Data Memory

Page 15: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 15OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Combining Datapath components• A single datapath can be assembled

– From previous datapaths by adding multiplexors • One MUX at ALU input to read

– Either data bus – Or sign extended word

• One at the data input to the register file that – Takes the data from ALU – Or from data memory

Page 16: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 16OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Putting it all Together

Instruction

16 32

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1Readregister 2

DatamemoryWritedata

Readdata MuxMuxWritedata

Signextend

ALUresultZero

ALUAddress

RegWrite

ALU operation3

MemRead

MemWriteALUSrc MemtoReg

Page 17: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 17OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Combining Datapath components• Add in the instruction fetch

PC

Instructionmemory

Readaddress

Instruction

16 32

Registers

WriteregisterWritedata

Readdata 1Read

data 2

Readregister 1Readregister 2

Signextend

ALUresultZero

Datamemory

Address

Writedata

Readdata Mux

4Add

Mux

ALU

RegWrite

ALU operation3

MemRead

MemWrite

ALUSrcMemtoReg

Page 18: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 18OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Datapath for Branching (I-Format)• Datapath For Branch Instructions (I-Format)

beq $t1, $t2, offset• Steps:

– Compute branch target address– Compare register contents– Determine next instruction based on comparison

• In MIPS, branches are delayed– Instruction following the branch is always

executed• Independent of the branch condition– If branch condition is true, backtrack– Helps in speeding up (See pipelining)

Page 19: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 19OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Branching- The details• Step1: Compute branch target address

– Branch target address = PC + sign-extended offset field

– HW needed:• sign-extension unit• Adder

– Notes:• Offset could be positive or negative• Offset field is “Word offset”

– Shift offset left 2 bits (multiply by 4) to get byte offset• Branch offset based on instruction following branch

– i.e from PC +4

Page 20: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 20OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Branching- The details• Step2: Compare register contents

– Hardware needed:• Register file to get register contents• ALU to perform comparison

– By subtraction

Page 21: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 21OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Branching- The details• Step3: Determine next instruction

– Depends on the result of comparison– If condition is true:

• Branch is taken – If condition is false

• Branch is not taken

– Hardware needed:• ALU:

– Zero signal from ALU if the result is zero indicating the condition is true

Page 22: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 22OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Branching- The details• Step 4: Modify instruction fetch datapath

– If branch is taken • PC Branch target address

– If branch not taken• PC PC +4

– Hardware needed• Adder

Page 23: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 23OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

The Branching Datapath

RegWrite

Read Reg1

5

5

ALU Control

ALUZero

3

16 32

AddSum

Shiftleft 2 Branch

target

To branch control logicInstruction

PC +4 from instruction datapath

Read Reg2Write Reg

Write data

Register File

Read Data1

Read Data2

Sign exten

d

Page 24: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 24OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Finally, the J-typej target

• Unconditional jump – Requires no comparison

• Target is “Word target”– Target needs shifting 2 bits to the left – Original target 26 bits– Target after shifting 28 bits

• Target need to be loaded into PC– The lower 28 bits of PC are replaced with target

• Hardware needed:– Concatenating “00” unit

2 target 6 bits 26 bits

Page 25: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 25OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

The Combined Datapath• 1 clock cycle for each operation

– Load/store, ALU operations, Branches

PC

Instructionmemory

Readaddress

Instruction

32

Add ALUresult

Mux

Registers

WriteregisterWritedata

Readdata 1Readdata 2

Readregister 1Readregister 2

Shiftleft 2

4

Mux

ALU operation3

RegWrite

MemRead

MemWrite

PC Src

ALUSrc MemtoRegALUresultZero

ALU

Datamemory

Address

Writedata

Readdata Mux

Signextend

Add

16

Page 26: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 26OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Critical Path for Load• Total time needed =

PC’s change time+ Instruction Memory’s Access Time+ Register File’s Access Time+ ALU to Perform a 32-bit Add+ Data Memory Access Time+ Setup Time for Register File Write+ Clock Skew

Page 27: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 27OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Assemble Control Logic• Control Unit

– Analyze implementation of each instruction to determine setting of control points

Instruction<31:0>Inst

Memory

Address

Control

<21:25><16:20>

<11:15>

<0:15>

<21:25>

Imm16RdRsRtOp Fun

ALUctr

RegDst ALUSrcExtOp MemtoRegMemWr EqualnPC_sel RegWr

DATA PATH

Page 28: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 28OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

What control signals do we need?• Register selection:

– Rs, Rt, Rd and Imed16 hardwired into datapath• Operation selection:

– nPC_sel: 0 => PC <– PC + 4;1 => PC <– PC + 4 + SignExt(Im16) || 00

• Extension 16-bit control– ExtOp: “zero”, “sign”

• ALU data source – Register or immediate address– ALUsrc: 0 => regB; 1 => immed

Page 29: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 29OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

What control signals do we need?• ALU Operation selection (control)

– ALUctr: “add”, “sub”, “or”• Memory Write:

– MemWr• MemtoReg:

– 1 => Mem• RegDst:

– 0 => “rt”; 1 => “rd”• RegWr:

– write dest register

Page 30: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 30OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Control Signals for each instructioninst Register TransferADD R[rd] <– R[rs] + R[rt]; PC <– PC + 4

ALUsrc=RegB, ALUctrl=“add”, RegDst=rd, RegWr, nPC_sel=“+4”

SUB R[rd] <– R[rs] – R[rt]; PC <– PC + 4ALUsrc=RegB, ALUctr=“sub”, RegDst=rd, RegWr, nPC_sel=“+4”

ORi R[rt] <– R[rs] + zero_ext(Imm16); PC <– PC + 4ALUsrc=Im, Extop=“Z”, ALUctr=“or”,RegDst=rt, RegWr, nPC_sel=“+4”

Page 31: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 31OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Control Signals for each instructioninst Register TransferLOAD R[rt] <– MEM[ R[rs] + sign_ext(Imm16)]; PC <– PC + 4

ALUsrc = Im, Extop = “Sn”, ALUctr = “add”,MemtoReg, RegDst = rt, RegWr, nPC_sel = “+4”

STORE MEM[ R[rs] + sign_ext(Imm16)] <– R[rs]; PC <– PC + 4 ALUsrc=Im, Extop=“Sn”, ALUctr=“add”, MemWr, nPC_sel=“+4”

BEQ if (R[rs]== R[rt]) then PC<– PC+sign_ext(Imm16)] || 00 else PC <– PC + 4nPC_sel = EQUAL, ALUctr = “sub”

Page 32: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 32OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Assemble each signal

nPC_sel <= if (OP==BEQ) then EQUAL else 0

ALUsrc <= if (OP==“000000”) then “regB” else “immed”

ALUctr <= if (OP==“000000”) then functelseif (OP==ORi) then “OR”

elseif (OP==BEQ) then “SUB” else “ADD”

Page 33: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 33OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Assemble each signal

ExtOp <= if (OP == ORi) then “zero” else “sign”

MemWr <= (OP == Store)MemtoReg <= (OP == Load)

RegWr: <= if ((OP== Store) || (OP==BEQ)) then 0 else 1

RegDst: <= if ((OP==Load) || (OP==ORi))then 0 else 1

Page 34: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 34OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Datapath with Control Unit

MemReg

MemRead

MemWrite

ALUOp

ALUSrc

RegDst

PC

Instruction memory

Read addressInstruction

(31-0)Instruction [20–16]

Instruction [25–21]

Add

Instruction [5–0]

RegWrite4

16 32Instruction [15–0]0

Register file

Writedata

Read reg1

Sign exten

d

ALUresultZero

Datamemory

Address Readdata Mux

1

0

Mux

1

0

Mux

1

0

Mux

1

Instruction [15–11]

ALU Contr

ol

Shiftleft 2

PCSrc

ALU

Add ALUresult

Read reg2WriteregWrite data

Read data1Read data2

Page 35: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 35OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Summary• 5 steps to design a processor

1. Analyze instruction set => datapath requirements2. Select set of datapath components & establish

clock methodology3. Assemble datapath meeting the requirements4. Analyze implementation of each instruction to

determine setting of control points that effects the register transfer.

5. Assemble the control logic

Page 36: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 36OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Summary•MIPS makes it easier

–Instructions are all the same size–Source registers are always in same place in the

instruction–Immediate operands are the same size & in the

same location–Operations are always on either register contents or

immediate operands•Single cycle datapath

=> CPI=1

Page 37: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 37OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

The Control Unit• Functions:

– Select operations to be performed (ALU, read/write, etc.)

– Control data flow (multiplexor inputs) • Major components:

– ALU control• Operation based on instruction type and function code

– Other controls• Input:

– Information comes from the 32 bits of the instruction • Output:

– Control signals

Control Unit

Instruction code

Control Signals

Page 38: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 38OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

Quick review: MIPS Instruction Formats

op target address0 2631

6 bits 26 bits

op rs rt rd shamt funct0 6 11 16 21 2631

6 bits 6 bits5 bits5 bits5 bits5 bits

rsop rt immediate0 16 21 2631

6 bits 16 bits5 bits5 bits

R-type

I-type

J-type

Page 39: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 39OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

ALU Control• ALU has 3 control inputs

– Allows 8-combinations• Only 5 combinations are used.

– The rest could be used as don’t-care in minimization000 AND001 OR010 add110 subtract111 set-on-less-than

Page 40: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 40OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

ALU Control• Remember:

– ALU is needed for all instruction categories• lw/sw(I-Format): Compute memory address• Arithmetic/logic(R-Format): Arithmetic / logic

operation• Branch(beq)(I-Format): Subtract registers

– We need to find ALU control signals from the information in the instruction

1111010100x2a0SLL1101000100x220SUB0101000000x200ADD0011001010x250OR0001001000x240AND

ALUControl

Funct-Binary

Funct-field0x

Op-fieldInstruction

Page 41: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 41OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

ALU Control• ALU performs one of 5 instructions based on

instruction class• ALUOp:

– A 2-bit input control used with the “funct” field • Determines 3-bit combination to control the ALU

ALUOp Control

6-bit “funct feld”

2-bit “ALUOp” input00 Add(for load & store)01 Subtract (for beq)10 Depends on code in funct field

3-bit “ALU operation”000 and001 or010 add110 sub111 slt

Page 42: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 42OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

How ALU control bits are set• (ALUOp = 00 or 01 )

– Depend on “op” field & not on “funct” field• (ALUOp code = 10 )

– Depend on “funct” field to set the ALU control input

InstructionOpcode ALUOp

Instructionoperation Funct field

Desired ALUaction

ALU controlinput

lw 00 load word XXXXXX add 010sw 00 store word XXXXXX add 010Branch equal 01 branch equal XXXXXX subtract 110R-type 10 add 100000 add 010R-type 10 subtract 100010 subtract 110R-type 10 AND 100100 and 000R-type 10 OR 100101 or 001R-type 10 set on less than 101010 set on less than 111

1

2

1

2

Page 43: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 43OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

ALU Control• Multiple level of decoding is used

1. The main control unit generates the ALUOp bits2. ALUOp bits are used as input to ALU control3. ALU control generates the actual signal to ALU unit

• Why use multiple levels?– Reduce size of main control unit– Increase speed of control unit

Page 44: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 44OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

ALU Control: Truth Table

• 8-input lines, 3 output lines– Actual table size should be 28 = (256)– Only relevant combinations are listed

• Details in (Appendix C2, p. C4)• F5 & F4 are always don’t cares

– F3-F0 only are considered

ALUOp Funct field Operation InstructionALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0

0 0 X X X X X X 010 lw/swX 1 X X X X X X 110 beq1 X X X 0 0 0 0 010 add1 X X X 0 0 1 0 110 sub1 X X X 0 1 0 0 000 and1 X X X 0 1 0 1 001 or1 X X X 1 0 1 0 111 sll

Page 45: Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Processor: Datapath  Control

OCC - CS/CIS CS116-Ch00-Orientation 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 45OCC-CS 116 Fall 2003 1998 Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers)

ALU Control: Logic Circuit• Details in Appendix C2, p. C4• Based on “funct” code & ALUOp

Operation2ALU operation(Control signals)

F3F2F1F0

F (5– 0)

ALUOp0

ALUOpALU Control Circuit Diagram

3

2

5

ALUOp1

Operation1

Operation0