Docsity

Lesson 01 pipeline basic concepts, Lecture notes of Advanced Computer Architecture

Toggle sidebar
bg1
Course on: “Advanced Computer Architectures” Spring 2014
Prof. Cristina Silvano – Politecnico di Milano Pag. 1
Pipelining: Basic Concepts
Prof. Cristina Silvano
Politecnico di Milano
Course on: “Advanced Computer Architectures”
Cristina Silvano – Politecnico di Milano - 2 -
Outline
Reduced Instruction Set of MIPSProcessor
Implementation of MIPS Processor
Performance Optimization: Pipelining
Implementation of MIPS Processor Pipeline
The Problem of Pipeline Hazards
Performance Issues in Pipelining
March 2014
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27

Partial preview of the text

Download Lesson 01 pipeline basic concepts and more Lecture notes Advanced Computer Architecture in PDF only on Docsity!

Pipelining: Basic Concepts

Prof. Cristina Silvano

Politecnico di Milano

email: [email protected]

Course on: “Advanced Computer Architectures”

Cristina Silvano – Politecnico di Milano - 2 -

Outline

 Reduced Instruction Set of MIPS Processor

 Implementation of MIPS Processor

 Performance Optimization: Pipelining

 Implementation of MIPS Processor Pipeline

 The Problem of Pipeline Hazards

 Performance Issues in Pipelining

March 2014

Cristina Silvano – Politecnico di Milano - 3 -

Main Characteristics of MIPS Architecture

RISC (Reduced Instruction Set Computer) Architecture

Based on the concept of executing only simple instructions in a

reduced basic cycle to optimize the performance of CISC CPUs.

LOAD/STORE Architecture

ALU operands come from the CPU general purpose registers and they

cannot directly come from the memory.

Dedicated instructions are necessary to:

  • load data from memory to registers
  • store data from registers to memory

Pipeline Architecture:

Performance optimization technique based on the overlapping of the

execution of multiple instructions derived from a sequential

execution flow.

March 2014

Cristina Silvano – Politecnico di Milano - 4 -

Reduced Instruction Set of MIPS Processor

 ALU instructions:

add $s1, $s2, $s3 # $s1  $s2 + $s

addi $s1, $s1, 4 # $s1  $s1 + 4

 Load/store instructions:

lw $s1, offset ($s2) # $s1  M[$s2+offset]

sw $s1, offset ($s2) # M[$s2+offset]  $s

 Branch instructions to control the control flow of the program:

  • Conditional branches: the branch is taken only if the condition is satisfied.

Examples: beq ( branch on equal ) and bne ( branch on not equal )

beq $s1, $s2, L1 # go to L1 if ($s1 == $s2)

bne $s1, $s2, L1 # go to L1 if ($s1 != $s2)

  • Unconditional jumps: the branch is always taken.

Examples: j (jump) and jr (jump register)

j L1 # go to L

jr $s1 # go to add. contained in $s

March 2014

Cristina Silvano – Politecnico di Milano - 7 -

I-Format for Load/Store Instructions

op rs rt

6 bit 5 bit 5 bit 16 bit

offset

op (opcode): identifies the load/store instruction

type;

rs: base register;

rt: destination/source register for the data

loaded/stored from/to memory;

offset: The sum – called effective address – of the

contents of the base register and the sign-extended

offset is used as memory address.

March 2014

Cristina Silvano – Politecnico di Milano - 8 -

I-Format for Conditional Branches

op rs rt

6 bit 5 bit 5 bit 16 bit

address

op (opcode): identifies the conditional branch instruction type;

rs: first source register to compare;

rt: second source register to compare;

address (16-bit) indicates the word offset relative to the PC (PC-

relative word address)

 The offset corresponding to the L1 label (Branch Target Address) is

relative to the Program Counter (PC):

(L1- PC) /

beq $s1, $s2, L

March 2014

Cristina Silvano – Politecnico di Milano - 9 -

J-Format for Unconditional Jumps

6 bit 26 bit

op address

op (opcode): identifies the jump instruction type ;

address: contains 26-bit of 32-bit absolute word

address of jump destination:

4 bit 26 bit 2 bit

PC+

[31-28]

address [25-0] 00

March 2014

Cristina Silvano – Politecnico di Milano - 10 -

Formats of MIPS 32-bit Instructions

Type R (Register)

  • ALU Instructions

Type I (Immediate)

  • Immediate Instructions
  • Load/store instructions
  • Conditional branch instructions

Tipo J (jump)

  • Unconditional jumps instructions

J op address

I op rs rt offset/immediate

R op rs rt rd shamt funct

6-bit 5-bit 5-bit 5-bit 5-bit 6-bit

March 2014

Cristina Silvano – Politecnico di Milano - 13 -

Phases of execution of MIPS Instructions

Memory Access (ME)

  • Load instructions require a read access to the Data Memory using

the effective address

  • Store instructions require a write access to the Data Memory

using the effective address to write the data from the source

register read from the RF

  • Conditional branches can update the content of the PC with the

branch target address, if the conditional test yielded true.

Write-Back Cycle (WB)

  • Load instructions write the data read form memory in the

destination register of the RF

  • ALU instructions write the ALU results into the destination

register of the RF.

March 2014

Cristina Silvano – Politecnico di Milano - 14 -

Phases of execution of MIPS Instructions

ALU Instructions: op $x,$y,$z

Read of Source
Regs. $y and $z
Instr. Fetch
&. PC Increm.
ALU OP

($y op $z)

Write Back of
Destinat. Reg. $x

Conditional Branch: beq $x,$y,offset

Read of Source
Regs. $x and $y
Instr. Fetch
& PC Increm.
ALU Op. ($x-$y)

& (PC+4+offset)

Write
PC

Load Instructions: lw $x,offset($y)

Read of Base
Reg. $y
Instr. Fetch
& PC Increm.
ALU Op.

($y+offset)

Read Mem.

M($y+offset)

Write Back of
Destinat. Reg. $x

Store Instructions: sw $x,offset($y)

Read of Base Reg.
$y & Source $x
Instr. Fetch
& PC Increm.
ALU Op.

($y+offset)

Write Mem.

M($y+offset)

March 2014

Cristina Silvano – Politecnico di Milano - 15 -

Instruction Latency

Instruction

Type

Instruct.

Mem.

Register

Read

ALU

Op.

Data

Memory

Write

Back

Total

Latency

ALU Instr. 2 1 2 0 1 6 ns

Load 2 1 2 2 1 8 ns

Store 2 1 2 2 0 7 ns

Cond. Branch 2 1 2 0 0 5 ns

Jump 2 0 0 0 0 2 ns

March 2014

Cristina Silvano – Politecnico di Milano - 16 -

Basic Implementation of MIPS data path

Instruction Memory (read-only memory) separated from Data

Memory

 32 General-Purpose Registers organized in a Register File (RF) with

2 read ports and 1 write port.

Registers Register #

Data

Register #

Data memory

Address

Data

Register #

PC Instruction ALU

Instruction memory

Address

March 2014

Cristina Silvano – Politecnico di Milano - 19 -

Implementation of Load Instructions

Read Data

Write Data

Register Read 2

Register Read 1

Register Write

16 bit 32 bit

Instruction

Result

ALU
Register File

Sign Extension

Content Reg. 2

Content Reg. 1

Write Data

Write Address

Read Address

Data
Memory
[15-0]
[25-21]
[20-16]
WR
OP^ WR^ RD

March 2014

Cristina Silvano – Politecnico di Milano - 20 -

Implementation of Store Instructions

Read Data

Write Data

Register Read 2

Register Read 1

Write Register

16 bit 32 bit

Instruction

Result

ALU
Register File

Sign Extension

Content Reg. 2

Content Reg. 1

Write Data

Write Address

Read Address

Data
Memory
[15-0]
[25-21]
[20-16]
WR
OP WR^ RD

March 2014

Cristina Silvano – Politecnico di Milano - 21 -

Single-cycle Implementation of MIPS

 The length of the clock cycle is defined by the critical path given by

the load instruction: T = 8 ns (f = 125 MHz).

 We assume each instruction is executed in a single clock cycle

  • Each module must be used once in a clock
  • The modules used more than once in a cycle must be duplicated.

 We need an Instruction Memory separated from the Data Memory.

 Some modules must be duplicated, while other modules must be

shared from different instruction flows

 To share a module between two different instructions, we need a

multiplexer to enable multiple inputs to a module and select one of

different inputs based on the configuration of control lines.

March 2014

Cristina Silvano – Politecnico di Milano - 22 -

Implementation of ALU and Load/Store

Instructions

Main differences between ALU and load/store instructions:

 Different number of Write Register in the RF ( [15-11] bit for ALU

instructions or [20-16] bit for load/store instructions)

MUX at the input of Write Register of the RF

 The second input of ALU is a register for ALU instructions or the

least significant part of the instruction for load/store instructions

MUX at the second input of the ALU;

 Write data in the destination register can come from the ALU result

for ALU instructions or from the Data Memory for load instructions

MUX at the write data input of the RF.

March 2014

Cristina Silvano – Politecnico di Milano - 25 -

Implementation of MIPS data path

Content Reg. 2

Content Reg. 1

[15-0]

[25-21]

[20-16]

[15-11]

Read Data

Write Data

Register Read 2

Register Read 1

Write Register

Zero

16 bit 32 bit

M U X

M U Result X

ALU

Register File

Write Data

Write Address

Read Address

Data Memory

Sign Extension

Instruction Memory I i i

Instruction

Read Address

Adder

PC

2-bit Left Shifter

Adder MU X

M U X

WR

OP WR^ RD

March 2014

Cristina Silvano – Politecnico di Milano - 26 -

Implementation of MIPS data path

with Control Unit

Content Reg. 2

Content Reg. 1

[15-0]

[25-21]

[20-16]

[15-11]

Read Data

Write Data

Ragister Read 2

Register Read 1

Write Register

Zero

16 bit 32 bit

M U X

M U Result X

Register File^ ALU

Write Data

Write Address

Read Address

Data Memory

Sign Extension

Instruction Memory

Instruction

Read Address

Adder

PC

2-bit Left Shifter

Adder M U X

M U X

RegWR

MemWR MemRD

OP

[31-26] (^) Control Unit

Destination Register Branch

MemToReg

ALU_opB

A

B

ALU Control Unit

ALU_op [5-0]

March 2014

Cristina Silvano – Politecnico di Milano - 27 -

Multi-cycle Implementation

 The instruction execution is distributed on multiple

cycles (5 cycles for MIPS)

 The basic cycle is smaller

(2 ns  instruction latency = 10 ns)

 Implementation of multi-cycle CPU:

• Each phase of the instruction execution requires a clock cycle

• Each module can be used more than once per instruction in

different clock cycles: possible sharing of modules

• We need internal registers to store the values to be used in the

next clock cycles.

March 2014

PIPELINING

Cristina Silvano – Politecnico di Milano - 28 - March 2014

Cristina Silvano – Politecnico di Milano - 31 -

Sequential vs. Pipelining Execution

2 ns

Time

I
I
I1 IF ID EX MEM WB

2 ns

2 ns

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

2 ns IF ID EX MEM WB

I
I
I
I
IF ID EX MEM WB IF ID EX MEM WB

10 ns 10 ns

March 2014

Cristina Silvano – Politecnico di Milano - 32 -

Pipelining

 The time to advance the instruction of one stage in the

pipeline corresponds to a clock cycle.

 The pipeline stages must be synchronized: the duration

of a clock cycle is defined by the time requested by the

slower stage of the pipeline (i.e. 2 ns).

 The goal is to balance the length of each pipeline stage

 If the stages are perfectly balanced, the ideal speedup

due to pipelining is equal to the number of pipeline

stages.

March 2014

Cristina Silvano – Politecnico di Milano - 33 -

Performance Improvement

 Ideal case (asymptotically):If we consider the single-

cycle unpipelined CPU1 with clock cycle of 8 ns and the

pipelined CPU2 with 5 stages of 2 ns :

  • The latency (total execution time) of each instruction

is worsened: from 8 ns to 10 ns

  • The throughput (number of instructions completed in

the time unit) is improved of 4 times:

(1 instruction completed each 8 ns) vs.

(1 instruction completed each 2 ns)

March 2014

Cristina Silvano – Politecnico di Milano - 34 -

Performance Improvement

 Ideal case (asymptotically): If we consider the multi-

cycle unpipelined CPU3 composed of 5 cycles of 2 ns and

the pipelined CPU2 with 5 stages of 2 ns :

  • The latency (total execution time) of each instruction

is not varied (10 ns)

  • The throughput (number of instructions completed in

the time unit) is improved of 5 times:

(1 instruction completed every 10 ns) vs.

(1 instruction completed every 2 ns)

March 2014

Cristina Silvano – Politecnico di Milano - 37 -

Implementation of MIPS pipeline

 The division of the execution of each instruction in 5

stages implies that in each clock cycle 5 instructions are

in execution

 the implementation of pipelined CPU with 5 stages

must be composed of 5 modules corresponding to 5

execution stages

 we need pipeline registers to separate the different

stages

March 2014

Cristina Silvano – Politecnico di Milano - 38 -

Implementation of MIPS pipeline

Content register 2

Content register 1

[15-0]

[25-21]

[20-16]

[15-11]

Read Data

Write Data

Register Read 2

Register Read 1

Register Write

Zero

16 bit 32 bit

M U X

M U Result X

ALU
RF

Write Data

Write Address

Read Address

Data Memory

Sign extension

Instruction Memory

Instruction

Read Address

Adder

PC

2-bit Left Shifter

M U X

M U X

IF/ID ID/EX EX/MEM MEM/WB
IF — Instruction Fetch
ID — Instruction Decode EX — Execution WB —
Write Back
MEM — Memory Access

WR

OP WR^ RD

Adder

March 2014

Cristina Silvano – Politecnico di Milano - 39 -

Implementation of MIPS pipeline

 We need to pass throughout the pipeline registers

( ID/EX , EX/MEM and MEM/WB ), the address of the

register to write during the WB stage.

 The address of the write register pass throughout the

pipeline registers and then come from the MEM/WB

pipeline register with the write data

March 2014

Cristina Silvano – Politecnico di Milano - 40 -

Resources used during the pipeline execution

2 ns

Time

I
I
I

2 ns

2 ns

2 ns

I
I
IM REG^ DM REG

A L U

IM REG AL DM REG U

IM REG AL DM REG U

IM REG^ DM REG

A L U

IM REG^ DM REG

A L U

IM = Instruction Memory

REG = Register File

DM = Data Memory

March 2014