Docsity

Advanced Pipelining - Computer Organization - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Advanced Pipelining - Computer Organization - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

CS 152: Computer Architecture

and Engineering

Lecture 13

Advanced Pipelining

Recap: Summary of Pipelining Basics

 Five Stages:

  • Fetch: Fetch instruction from memory
  • Decode: get register values and decode control information
  • Execute: Execute arithmetic operations/calculate addresses
  • Memory: Do memory ops (load or store)
  • Writeback: Write results back to registers (I.e. COMMIT)

 Pipelines pass control information down the pipe just as

data moves down pipe

 Forwarding/Stalls handled by local control

 Balancing length of instructions makes pipelining much

smoother

 Increasing length of pipe increases impact of hazards;

pipelining helps instruction bandwidth, not latency

Pipelining the Load Instruction

 The five independent functional units in the pipeline

datapath are:

  • Instruction Memory for the Ifetch stage
  • Register File’s Read ports (bus A and busB) for the Reg/Dec stage
  • ALU for the Exec stage
  • Data Memory for the Mem stage
  • Register File’s Write port (bus W) for the Wr stage

Clock

Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7

1st lw Ifetch Reg/Dec Exec Mem Wr

2nd lw Ifetch Reg/Dec Exec Mem Wr

3rd lw Ifetch Reg/Dec Exec Mem Wr

The Four Stages of R-type

 Ifetch: Instruction Fetch

  • Fetch the instruction from the Instruction Memory

 Reg/Dec: Registers Fetch and Instruction Decode

 Exec:

  • ALU operates on the two register operands
  • Update PC

 Wr: Write the ALU output back to the register file

Cycle 1 Cycle 2 Cycle 3 Cycle 4

R-type Ifetch Reg/Dec Exec Wr

Important Observation

 Each functional unit can only be used once per

instruction

 Each functional unit must be used at the same stage

for all instructions:

  • Load uses Register File’s Write Port during its 5th stage
  • R-type uses Register File’s Write Port during its 4th stage

Load Ifetch Reg/Dec Exec Mem Wr

R-type Ifetch Reg/Dec Exec Wr

 2 ways to solve this pipeline hazard.

Solution 1: Insert “Bubble” into the Pipeline

 Insert a “bubble” into the pipeline to prevent 2 writes

at the same cycle

  • The control logic can be complex.
  • Lose instruction fetch and issue opportunity.

 No instruction is started in Cycle 6!

Clock

Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9

R-type Ifetch Reg/Dec Exec Wr

Ifetch Reg/Dec Exec

Load Ifetch Reg/Dec Exec Mem Wr

R-type^ Ifetch^ Reg/Dec^ Exec^ Wr

R-type Ifetch^ Reg/Dec^ Pipeline Exec^ Wr Bubble

Ifetch Reg/Dec Exec Wr

Modified Control & Datapath

IR <- Mem[PC]; PC <– PC+4;

A <- R[rs]; B<– R[rt]

S <– A + B;

R[rd] <– M;

S <– A + SX;

M <– Mem[S]

R[rd] <– M;

S <– A or ZX;

R[rt] <– M;

S <– A + SX;

Mem[S] <- B

if Cond PC < PC+SX;

M <– S

Exec

Reg.File

Mem Acces

s

DataMem

A

B

S

RegFile

Equal

PC

Next PC

IR

Inst. Mem

D

M

M <– S

The Four Stages of Store

 Ifetch: Instruction Fetch

  • Fetch the instruction from the Instruction Memory

 Reg/Dec: Registers Fetch and Instruction Decode

 Exec: Calculate the memory address

 Mem: Write the data into the Data Memory

Cycle 1 Cycle 2 Cycle 3 Cycle 4

Store Ifetch Reg/Dec Exec Mem Wr

Control Diagram

IR <- Mem[PC]; PC < PC+4;

A <- R[rs]; B<– R[rt]

S <– A + B;

R[rd] <– S;

S <– A + SX;

M <– Mem[S]

R[rd] <– M;

S <– A or ZX;

R[rt] <– S;

S <– A + SX;

Mem[S] <- B

If Cond PC < PC+SX;

Exec

Reg.File

MemAcces

s

DataMem

A

B

S

RegFile

Equal

PC

Next PC

IR

Inst. Mem

D

M <– S (^) M <– S

M

Administrivia

 Get started on Lab 5: Pipelining is difficult to get

right! Be sure that we will test “gotcha” cases in our

mystery programs…

 Next Lecture: “state-of-the-art” pipelining

  • Out-of-order execution/register renaming
  • Reorder buffers

Recall: Single Cycle Control!

Data Out

Clk

Rw Ra Rb 32 32-bit Registers

Rd

ALU

Clk

Data In

Data Address Ideal Data Memory

Instruction

Instruction Address

Ideal Instruction Memory

Clk

PC

Rs 5

Rt

A

B

Next Address

Control

Datapath

Control Signals (^) Conditions

Data Stationary Control

 The Main Control generates the control signals during

Reg/Dec

  • Control signals for Exec (ExtOp, ALUSrc, ...) are used 1 cycle later
  • Control signals for Mem (MemWr Branch) are used 2 cycles later
  • Control signals for Wr (MemtoReg MemWr) are used 3 cycles later

IF/ID Register ID/Ex Register

Ex/Mem Register Mem/Wr Register

Reg/Dec Exec Mem

ExtOp

ALUOp RegDst

ALUSrc

Branch

MemW r

MemtoReg RegWr

Main Control

ExtOp

ALUOp RegDst

ALUSrc

MemtoReg RegWr

MemtoReg RegWr

MemtoReg RegWr

Branch

MemW r (^) Branch

MemW r

Wr

Let’s Try it Out

10 lw r1, r2(35)

14 addI r2, r2, 3

20 sub r3, r4, r

24 beq r6, r7, 100

30 ori r8, r9, 17

34 add r10, r11, r

100 and r13, r14, 15

these addresses are octal

Start: Fetch 10

Exec

Reg.File

MemAcces

s

DataMem

A

B

S

RegFile

IR

Inst. Mem

D

Decode^ Mem

Ctrl

WB

Ctrl

M

rs rt im

10 lw r1, r2(35) 14 addI r2, r2, 3 20 sub r3, r4, r 24 beq r6, r7, 100 30 ori r8, r9, 17 34 add r10, r11, r

100 and r13, r14, 15

IF

PC

Next PC

n n n n