CSE 4293 Pipelining
CSE 4293 Pipelining
CSE 4293 Pipelining
Pipelining
Nafiz Imtiaz
Lecturer, EEE, AUST
Ref: https://www.geeksforgeeks.org/computer-organization-and-architecture-pipelining-set-1-execution-stages-and-throughput/
Execution, Stages
and Performance
Pay
Car/ 1 2 3 4 5 6 7 8 9
Time
Receive
Order
C1 O P R Store
C2 O P R
C3 O P R
Pay
Car/ 1 2 3 4 5 6 7 8 9
Time
Receive
Order
C1 O P R
Store
C2 O P R
C3 O P R
• Interface registers are used to hold the intermediate output between two
stages. These interface registers are also called latch or buffer.
• All the stages in the pipeline along with the interface registers are
controlled by a common clock.
S1 I1 I2 I3 I4
S2 I1 I2 I3 I4
stage
S3 I1 I2 I3 I4
S4 I1 I2 I3 I4
S5 I1 I2 I3 I4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Time
stage
S1 I1 I2 I3 I4
S2 I1 I2 I3 I4
S3 I1 I2 I3 I4
S4 I1 I2 I3 I4
S5 I1 I2 I3 I4
1 2 3 4 5 6 7 8 Time
𝐸𝑇𝑛𝑜𝑛 𝑝𝑖𝑝𝑒𝑙𝑖𝑛𝑖𝑛𝑔 = 𝐾 × 𝑁 𝑇𝑝
𝐸𝑇𝑝𝑖𝑝𝑒𝑙𝑖𝑛𝑖𝑛𝑔 = 𝐾 + 𝑁 − 1 𝑇𝑝
𝐺𝑖𝑣𝑒𝑛 𝑆𝑝𝑒𝑒𝑑 𝑈𝑝 𝑆 S
𝐸𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑐𝑦 = = =
𝑀𝑎𝑥 𝑠𝑝𝑒𝑒𝑑 𝑈𝑝 𝑆𝑚𝑎𝑥 K
𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝐼𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠 𝑁
𝑇ℎ𝑟𝑜𝑢𝑔ℎ𝑝𝑢𝑡 = =
𝑇𝑜𝑡𝑎𝑙 𝑡𝑖𝑚𝑒 𝑡𝑜 𝑐𝑜𝑚𝑝𝑙𝑒𝑡𝑒 𝑡ℎ𝑒 𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠 𝑘 + 𝑁 − 1 𝑇𝑝
Note: The cycles per instruction (CPI) value of an ideal pipelined processor is 1
𝐸𝑇𝑛𝑜𝑛 𝑝𝑖𝑝𝑒𝑙𝑖𝑛𝑖𝑛𝑔 = 𝐾 × 𝑁 𝑇𝑝
1
= 5 × 12 𝑇𝑝 here, Tp =
fclock
𝐸𝑇𝑝𝑖𝑝𝑒𝑙𝑖𝑛𝑖𝑛𝑔 = 𝐾 + 𝑁 − 1 𝑇𝑝
1
= 5 + 12 − 1 𝑇𝑝 here, Tp =
fclock
d) Efficiency:
𝐺𝑖𝑣𝑒𝑛 𝑆𝑝𝑒𝑒𝑑 𝑈𝑝 𝑆 S
𝐸𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑐𝑦 = = =
𝑀𝑎𝑥 𝑠𝑝𝑒𝑒𝑑 𝑈𝑝 𝑆𝑚𝑎𝑥 K
15
3
= 4 = = 75%
5 4
𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝐼𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠 𝑁
𝑇ℎ𝑟𝑜𝑢𝑔ℎ𝑝𝑢𝑡 = =
𝑇𝑜𝑡𝑎𝑙 𝑡𝑖𝑚𝑒 𝑡𝑜 𝑐𝑜𝑚𝑝𝑙𝑒𝑡𝑒 𝑡ℎ𝑒 𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠 𝑘 + 𝑁 − 1 𝑇𝑝
12 1
= (5+12−1) 𝑇𝑝 here, Tp = f
clock
1) Structural Dependency
2) Control Dependency
3) Data Dependency
This dependency arises due to the resource conflict in the pipeline. A resource conflict is
a situation when more than one instruction tries to access the same resource in the same
cycle. A resource can be a register, memory, or ALU.
In the above scenario, in cycle 4, instructions I1 and I4 are trying to access same resource
(Memory) which introduces a resource conflict. To avoid this problem, we have to keep the
instruction on wait until the required resource (memory in our case) becomes available.
stalls
Renaming :
According to renaming, we divide the memory into two independent modules used to store the
instruction and data separately called Code memory(CM) and Data memory(DM) respectively. CM
will contain all the instructions and DM will contain all the operands that are required for the
instructions.
This type of dependency occurs during the transfer of control instructions such as BRANCH,
CALL, JMP, etc. On many instruction architectures, the processor will not know the target
address of these instructions when it needs to insert the new instruction into the pipeline. Due to
this, unwanted instructions are fed to the pipeline.
Branch penalty : The number of stalls introduced during the branch operations in the pipelined
processor is known as branch penalty.
When the above instructions are executed in a pipelined processor, then data dependency
condition will occur, which means that I2 tries to read the data before I1 writes it, therefore,
I2 incorrectly gets the old value from I1.
Operand Forwarding :
In operand forwarding, we use the interface registers present between the stages to hold
intermediate output so that dependent instruction can access new value from the interface
register directly.
•WAR hazard occurs when instruction J tries to write data before instruction I reads it.
Example:
I: R2 <− R1 × R3
J: R3 <− R4 + R5 W(J)∩R(I) ≠ ∅
•WAW hazard occurs when instruction J tries to write output before instruction I writes it.
Example:
I: R2 <− R1 × R3
W(J)∩W(I) ≠ ∅
J: R2 <− R4 + R5
WAR and WAW hazards occur during the out-of-order execution of the instructions.