































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
































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:
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:
Load/store instructions:
Branch instructions to control the control flow of the program:
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:
March 2014
Cristina Silvano – Politecnico di Milano - 10 -
Formats of MIPS 32-bit Instructions
Type R (Register)
Type I (Immediate)
Tipo J (jump)
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)
the effective address
using the effective address to write the data from the source
register read from the RF
branch target address, if the conditional test yielded true.
Write-Back Cycle (WB)
destination register of the RF
register of the RF.
March 2014
Cristina Silvano – Politecnico di Milano - 14 -
Phases of execution of MIPS Instructions
($y op $z)
& (PC+4+offset)
($y+offset)
M($y+offset)
($y+offset)
M($y+offset)
March 2014
Cristina Silvano – Politecnico di Milano - 15 -
Instruction Latency
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
Sign Extension
Content Reg. 2
Content Reg. 1
Write Data
Write Address
Read Address
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
Sign Extension
Content Reg. 2
Content Reg. 1
Write Data
Write Address
Read Address
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
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 -
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
Register File
Write Data
Write Address
Read Address
Data Memory
Sign Extension
Instruction Memory I i i
Instruction
Read Address
Adder
2-bit Left Shifter
Adder MU X
M U X
WR
OP WR^ RD
March 2014
Cristina Silvano – Politecnico di Milano - 26 -
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 -
March 2014
Cristina Silvano – Politecnico di Milano - 28 - March 2014
Cristina Silvano – Politecnico di Milano - 31 -
Sequential vs. Pipelining Execution
2 ns
Time
2 ns
2 ns
2 ns 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 :
is worsened: from 8 ns to 10 ns
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 :
is not varied (10 ns)
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
Write Data
Write Address
Read Address
Data Memory
Sign extension
Instruction Memory
Instruction
Read Address
Adder
2-bit Left Shifter
M U X
M U X
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
2 ns
2 ns
2 ns
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