Computer Science 37 Lecture 20

17
1 Lecture20 ControllingaPipelinedDatapath

Transcript of Computer Science 37 Lecture 20

Page 1: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 1/17

1

Lecture20

ControllingaPipelinedDatapath

Page 2: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 2/17

2

Instructionmemory

 Address

4

32

0

Add Add

result

Shiftleft 2

Instruction

Mux

0

1

Add

PC

0Writedata

Mux

1

Registers

Readdata 1

Readdata 2

Readregister 1

Readregister 2

16Sign

extend

Writeregister

Writedata

Readdata

 Address

Data

memory1

 ALUresult

Mux

ALU

Zero

IF: Instruction fetch ID: Instruction decode/

register file read

EX: Execute/

address calculation

MEM: Memory access WB: Write back

Page 3: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 3/17

3

Pipelineregisters: Intermediatestorage

Question: howdowedeterminethewidthoftheregisters?

Page 4: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 4/17

4

Step-by-stepExecutionoflw

InstructionFetch

Page 5: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 5/17

5

Step-by-stepExecutionoflw

InstructionDecode

InstructionDecode

Page 6: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 6/17

6

Step-by-stepExecutionoflw

InstructionExecution

Instruction

memory

 Address

4

32

0

AddAdd

result

Shift

left 2

       I     n     s       t     r     u     c       t       i     o     n

IF/ID EX/MEM

Mux

0

1

Add

PC

0Writedata

Mux

1

Registers

Readdata 1

Readdata 2

Readregister 1

Readregister 2

16Sign

extend

Writeregister

Writedata

Readdata

1

 ALUresult

Mux

ALU

Zero

ID/EX MEM/WB

Execution

lw

 Address

Data

memory

Page 7: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 7/17

7

Step-by-stepExecutionoflw

MemoryAccess

Page 8: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 8/17

8

Step-by-stepExecutionoflw

WriteBacktoRegister

Page 9: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 9/17

9

AlternativeGraphicalRepresentationofPipelines

IM Reg DM Reg

IM Reg DM Reg

CC 1 CC 2 CC 3 CC 4 CC 5 CC 6

Time (in clock cycles)

lw $10, 20($1)

Programexecutionorder(in instructions)

sub $11, $2, $3

 ALU

 ALU

lw $10,$20($1)

sub $11,$2,$3

Question: Arethereanyhazardsinthecodeabove?

Page 10: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 10/17

10

ControllingaPipelinedDatapath

PC

Instructionmemory

 Address

       I     n     s      t     r     u     c      t       i     o     n

Instruction

[20–16]

MemtoReg

 ALUOp

Branch

RegDst

 ALUSrc

4

16 32

Instruction[15–0]

0

0Registers

Writeregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux

1Write

data

Read

data Mux

1

ALU

control

RegWrite

MemRead

Instruction[15–11]

6

IF/ID ID/EX EX/MEM MEM/WB

MemWrite

 Address

Datamemory

PCSrc

Zero

AddAdd

result

Shift

left 2

 ALUresult

ALU

Zero

Add

0

1

Mux

0

1

Mux

Page 11: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 11/17

11

KeyAspectstoNoticeinThisDesign:

1) There’snoneedtohavewritecontrolstothePCortothepipeline

registers.

2) Fetch:nothingtocontrol.Samethingdoneeveryclockcycle.

3) Decode:nothingtocontrol.Samethingdoneeveryclockcycle.

4) Execution:decidehowtousetheALU(operands,operation,result)–

RegDst,ALUOp,ALUSrc.

5) Memoryaccess:branch,loadandstoreinstructionshavedifferent

requirements,soonemustspecifyBranch,MemRead,MemWrite

6) Writeback:choosewhatgetswrittenbacktotheregisterfile(theALUresultoramemoryvalue);thecontrolsareMemToReg andRegWrite.

Weusethesamecontrollinesasbefore,butgroupthembypipelinestage.

Page 12: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 12/17

12

So,whathasreallychanged?

Remember: Eachinstructiondefineswhatcontrolvaluesareapplied.

Question: WhathappensnowthatIcanhaveupto5instructionsexecuting

atthesametimeinthedatapath?

Control

EX

M

WB

M

WB

WB

IF/ID ID/EX EX/MEM MEM/WB

Instruction

Allcontroldecisionsaremadeduringtheinstructiondecodingandarecarried

forwardacrossstagesinthepipeline.

Page 13: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 13/17

13

PC

Instructionmemory

    I   n   s    t   r   u   c    t    i   o   n

Add

Instruction ¡ ¢ £ ¥ ¤ ¦ §

    M   e   m    t   o    R   e   g

 ALUOp

Branch

RegDst

 ALUSrc

4

16 32Instruction

¤ ¨ £ ¢ §

0

0

Mux

0

1

AddAdd

result

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

 ALUresult

Zero

Writedata

Readdata

Mux

1

ALUcontrol

Shiftleft 2

    R   e   g    W   r    i    t   e

MemRead

Control

ALU

Instruction ¤ ¨ £ ¥ ¤ ¤ §

6

EX

M

WB

M

WB

WBIF/ID

PCSrc

ID/EX

EX/MEM

MEM/WB

Mux

0

1

    M   e   m    W   r    i    t   e

 Address

Datamemory

 Address

Page 14: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 14/17

14

Workthroughtheexampleoftheexecutionof

fiveinstructionsstartinginpage471!

Page 15: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 15/17

15

DataHazardsandForwarding

Question: Whatisadata hazard?

sub $2, $1, $3

and $12, $2, $5

or $13, $6, $2

add $14, $2, $2

sw $15, 100($2)

Page 16: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 16/17

16

IM Reg

IM Reg

CC 1 CC 2 CC 3 CC 4 CC 5 CC 6

Time (in clock cycles)

sub $2, $1, $3

Program

executionorder(in instructions)

and $12, $2, $5

IM Reg DM Reg

IM DM Reg

IM DM Reg

CC 7 CC 8 CC 9

10 10 10 10  ¡ £ ¥ ¦ ¡ ¥ ¦ ¡ ¥ ¦ ¡ ¥ ¦ ¡ ¥ ¦ ¡

or $13, $6, $2

add $14, $2, $2

sw $15, 100($2)

 Value of register $2:

DM Reg

Reg

Reg

Reg

DM

Page 17: Computer Science 37 Lecture 20

8/4/2019 Computer Science 37 Lecture 20

http://slidepdf.com/reader/full/computer-science-37-lecture-20 17/17

17

sub $2, $1, $3

nop

nop

and $12, $2, $5

or $13, $6, $2

add $14, $2, $2sw $15, 100($2)

Possiblesolution: Letthecompilerresolvethehazard

bubble

bubble

Hardwaredesign:

Registerwritesalways

happenatthefirsthalf 

oftheclockcycle.

Registerreadsalways

happenatthesecondhalf 

theclockcycle.

Nohazardfordatathat

iswrittenandreadinthe

sameclockcycle.

Question: Whatisthedrawbackofthissolution?