computer organization cs224

22
Computer Organization CS224 Fall 2012 Lesson 23

Upload: jewell

Post on 23-Jan-2016

199 views

Category:

Documents


12 download

DESCRIPTION

Computer Organization CS224. Fall 2012 Lesson 23. Building a Datapath. Datapath Elements that process data and addresses in the CPU Registers, ALUs, MUX’s, memories, … We will build a MIPS datapath incrementally Refining the overview design. §4.3 Building a Datapath. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computer Organization CS224

Computer OrganizationCS224

Fall 2012

Lesson 23

Page 2: Computer Organization CS224

Building a Datapath

Datapath Elements that process data and addresses

in the CPU

- Registers, ALUs, MUX’s, memories, …

We will build a MIPS datapath incrementally Refining the overview design

§4.3 Building a D

atapath

Page 3: Computer Organization CS224

Instruction Fetch (IF) RTL

Common RTL operations Fetch instruction

Mem[PC]; Fetch instruction from memory

Update program counter- Sequential

PC <- PC + 4; Calculate next address

Page 4: Computer Organization CS224

Datapath: Instruction Fetch Unit

32

Instruction WordAddress

InstructionMemory

PCClk

Ad

der

4

Page 5: Computer Organization CS224

Add RTL

Add instructionadd rd, rs, rt

Mem[PC]; Fetch instruction from memory

R[rd] <- R[rs] + R[rt]; Add operation

PC <- PC + 4; Calculate next address

OP=0 rs rt rd sa funct

Bits 6 5 5 5 5 6

firstsource

register

secondsource

register

resultregister

shiftamount

functioncode(=32)

Page 6: Computer Organization CS224

Sub RTL

Sub instructionsub rd, rs, rt

Mem[PC]; Fetch instruction from memory

R[rd] <- R[rs] - R[rt]; Sub operation

PC <- PC + 4; Calculate next address

OP=0 rs rt rd sa funct

Bits 6 5 5 5 5 6

firstsource

register

secondsource

register

resultregister

shiftamount

functioncode(=34)

Page 7: Computer Organization CS224

Datapath: Reg-Reg Operations

R[rd] <- R[rs] op R[rt]; ALU control and RegWr coming from Control Unit, based on

decoded instruction Ra, Rb, and Rw from rs, rt, rd fields

32

Result

ALU control

Clk

busW

RegWr

3232

busA

32busB

5 5 5

Rw Ra Rb32 32-bitRegisters

Rs RtRd

AL

U

Instruction

Page 8: Computer Organization CS224

OR Immediate RTL

OR Immediate instructionori rt, rs, imm

Mem[PC]; Fetch instruction from memory

R[rt] <- R[rs] OR ZeroExt(imm);

OR operation with Zero-Extend

PC <- PC + 4; Calculate next address

OP rs rt imm

Bits 6 5 5 16

firstsource

register

secondregister(dest)

immediate

Page 9: Computer Organization CS224

Datapath: Immediate Ops

Rw set by MUX and ALU B set as busB or ZeroExt(imm)

ALUsrc and RegDst set based on instruction

Rd Rt

32

Result

ALU control

Clk

busW

RegWr

3232

busA

32busB

5 5 5

Rw Ra Rb32 32-bitRegisters

Rs Rt (Don’t Care)

RegDst

Zero

Ext

Mux

3216imm16

ALUSrc

AL

U

MU

X

Page 10: Computer Organization CS224

Load RTL

Load instructionlw rt, rs, imm

Mem[PC]; Fetch instruction from memory

Addr <- R[rs]+ SignExt(imm); Compute memory address

R[rt] <- Mem[Addr]; Load data into register

PC <- PC + 4; Calculate next address

OP rs rt imm

Bits 6 5 5 16

firstsource

register

secondregister(dest)

immediate

Page 11: Computer Organization CS224

Datapath: Load

Extender handles sign vs. zero extension of immediate

MUX selects between ALU result and Memory output

RtRd

32

ALUctr

Clk

busW

RegWr

3232

busA

32busB

5 5 5

Rw Ra Rb32 32-bitRegisters

Rs Rt (Don’t Care)

RegDst

Exten

der

3216

imm16

ALUSrc

ExtOp

MemtoReg

Clk

Data InWrEn

32

Adr

DataMemory

32MemWr

Mux

MU

XMU

X

AL

U

Page 12: Computer Organization CS224

Store RTL

Store instructionsw rt, rs, imm

Mem[PC]; Fetch instruction from memory

Addr <- R[rs]+ SignExt(imm); Compute memory addr

Mem[Addr] <- R[rt]; Load data into register

PC <- PC + 4; Calculate next address

OP rs rt imm

Bits 6 5 5 16

firstsource

register

secondsource

register

immediate

Page 13: Computer Organization CS224

Datapath: Store

Register rt is passed on busB into memory

Memory address calculated just as in lw case

32

ALUctr

Clk

busW

RegWr

3232

busA

32busB

55 5

Rw Ra Rb32 32-bitRegisters

Rs RtRegDst

Exten

der

3216imm16

ALUSrc

MemtoReg

Clk

Data In WrEn32

Adr

DataMemory

MemWr

RtRd

Mux

AL

U

MU

X

32

MU

X

ExtOp

Page 14: Computer Organization CS224

Branch RTL

Branch instructionbeq rs, rt, imm

Mem[PC]; Fetch instruction from memory

Diff <- R[rs] – R[rt]; Calculate branch condition

if (Diff eq 0) Test if equal

PC <- PC + 4 +

SignExt(imm)*4;Calculate PC Relative address

else

PC <- PC + 4; Calculate next address

OP rs rt imm

Bits 6 5 5 16

firstsource

secondsource

immediate

Page 15: Computer Organization CS224

Datapath: Branch

ExtOp

ALUctr

Clk

busW

RegWr

3232

busA

32busB

5 5 5

Rw Ra Rb32 32-bitRegisters

Rs Rt

RegDst

Exten

der

3216

imm16

ALUSrc

PCClk

Next AddressLogic16

imm16

Branch

To InstructionMemory

Zero

More Detail to Come

AL

U

MU

X

RtRd

Mux

Page 16: Computer Organization CS224

The Next Address

PC is byte-addressed in instruction memory Sequential

PC[31:0] = PC[31:0] + 4

Branch operationPC[31:0] = PC[31:0] + 4 + SignExt(imm) × 4

Instruction Addresses PC is byte addressed, but instructions are 4 bytes long Therefore 2 LSBs of the 32 bit PC are always 0 No reason to have hardware keep the 2 LSBs Simplify hardware by using 30 bit PC

- SequentialPC[31:2] = PC[31:2] + 1

- Branch operationPC[31:2] = PC[31:2] + 1 + SignExt(imm)

Page 17: Computer Organization CS224

Datapath: Fast, Expensive Next-IF Logic

PC incremented to next instruction normally

On beq instruction then can add immediate × 4 to PC + 4

3030

Sig

nE

xt

30

16imm16

“1”

PC

Clk

30

30

BranchZero

Addr[31:2]

InstructionMemory

Addr[1:0]“00”

32

Instruction[31:0]Instruction[15:0]

30Ad

der A

dd

er

MU

X

Page 18: Computer Organization CS224

Datapath: Slow, Smaller Next-IF Logic

Slow because cannot start address add until ALU zero

But probably not the critical path (LOAD is usually)

30

30

Sig

nE

xt

3016imm16

“0”

PC

Clk

30

Branch Zero

Addr[31:2]

InstructionMemory

Addr[1:0]“00”

32

Instruction[31:0]

30

“1”

Carry In

Instruction[15:0]

MU

X

Ad

der

Page 19: Computer Organization CS224

Jump RTL

Jump instructionj target

Mem[PC]; Fetch instruction from memory

PC[31:2] <- PC[31:28] ||

target[25:0]; Calculate next address

OP target

Bits 6 26

jump target address

Page 20: Computer Organization CS224

Datapath: IFU with Jump

MUX controls if PC is pseudodirect jump

3030

Sig

nE

xt

30

16imm16

“1”

PC

Clk

30

30

Branch Zero

“00”

Addr[31:2]

InstructionMemory

Addr[1:0]

32

26

4PC[31:28]

Target 30

Jump

Instruction[15:0]

Instruction[31:0]

30

Instruction[25:0]M

UX

Ad

der

MU

X

Ad

der

Page 21: Computer Organization CS224

Putting it All Together

32

ALUctr

Clk

busW

RegWr

3232

busA

32busB

55 5

Rw Ra Rb32 32-bitRegisters

Rs Rt

RegDst

Exten

der

3216imm16

ALUSrc

ExtOp

MemtoReg

Clk

Data In WrEn32

Adr

DataMemory

32

MemWr

InstructionFetch Unit

Clk

Zero

Instruction[31:0]

JumpBranch [21:25]

[16:20]

[11:15]

[0:15]

Imm16RdRsRt

MU

X

MU

X

AL

U

RtRd

Mux

Page 22: Computer Organization CS224

A Real MIPS Datapath