Professional Documents
Culture Documents
CS225 Lect24 Basics of Pipelining
CS225 Lect24 Basics of Pipelining
CS-225: Lecture-24
Majority of the content is modified from CMU’s “Introduction to Computer Systems” Course by Randal E.
Bryant and David R. O’Hallaron who are also the authors of the course textbook.
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
2
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Control logic RF
%rbx = 0x100
All the gray boxes
PC Increment
Memory reads PC
0x014
Instruction memory
Register file
Data memory
4
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
SEQ Processor:
Cycle 1 Cycle 2 Cycle 3 Cycle 4
Clock
irmovq irmovq addq je
Operation#2 Cycle 1:
Cycle 2:
0x000:
0x00a:
irmovq $0x100,%rbx
irmovq $0x200,%rdx
# %rbx <-- 0x100
Read Write
Combinational
logic Data state set according to
memory
CC
second irmovq instr.
100
Read Write combinational logic
ports ports
PC
0x014
5
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
SEQ Processor:
Cycle 1 Cycle 2 Cycle 3 Cycle 4
Clock
irmovq irmovq addq je
Operation#3 Cycle 1:
Cycle 2:
0x000:
0x00a:
irmovq $0x100,%rbx
irmovq $0x200,%rdx
# %rbx <-- 0x100
Read Write
Combinational
logic Data state set according to
memory
CC
second irmovq instr.
100
000
Read Write combinational logic
ports ports
0x016
PC
0x014
6
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
SEQ Processor:
Cycle 1 Cycle 2 Cycle 3 Cycle 4
Clock
irmovq irmovq addq je
Operation#4 Cycle 1:
Cycle 2:
0x000:
0x00a:
irmovq $0x100,%rbx
irmovq $0x200,%rdx
# %rbx <-- 0x100
Read Write
Combinational
logic Data state set according to
memory
addq instruction
CC
000
Read Write combinational logic
ports ports
RF
starting to react to state
%rbx = 0x300
changes
PC
0x016
7
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
SEQ Processor:
Cycle 1 Cycle 2 Cycle 3 Cycle 4
Clock
irmovq irmovq addq je
Operation#5 Cycle 1:
Cycle 2:
0x000:
0x00a:
irmovq $0x100,%rbx
irmovq $0x200,%rdx
# %rbx <-- 0x100
Read Write
Combinational
logic Data state set according to
memory
addq instruction
CC
000
Read Write combinational logic
ports ports
generates results for je
RF
%rbx = 0x300
instruction
0x01f
PC
0x016
8
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Why Pipelining?
9
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
10
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Parallelism
Pipelining
11
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
12
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
13
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
T1 T2 T3 T4 T5 T6
14
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
IF ID EX MEM WB PU
I1
I2 I1
I3 I2 I1
I4 I3 I2 I1
I5 I4 I3 I2 I1
I6 I5 I4 I3 I2 I1
I6 I5 I4 I3 I2 I1
I6 I5 I4 I3 I2
I6 I5 I4 I3
I6 I5 I4
Time
I6 I5
I6
15
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Pipelined
Idea
Divide process into independent stages
Move objects through stages in sequence
At any given time, multiple objects being
processed
16
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
17
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Computational Example
300 ns 20 ns
R
Combinational Delay = 320 ns
e
logic Throughput = 3.125 MIPS
g
Clock
Unpipelined System
Computation requires total of 300 nano seconds (ns)
Additional 20 ns to save result in register
Must have clock cycle of at least 320 ns
18
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Clock
Pipelined System
Divide combinational logic into 3 blocks of 100 ns each
Can begin new operation as soon as previous one passes
through stage A.
Begin new operation every 120 ns
Overall latency increases
360 ns from start to finish
19
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Pipeline Diagrams
Unpipelined
320 ns
I1 640 ns
I2 960 ns
I3
Time
20
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Operating a Pipeline # 1
239
Clock
I1 A B C
I2 A B C
I3 A B C
Clock
21
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Operating a Pipeline # 2
241
Clock
I1 A B C
I2 A B C
I3 A B C
Clock
22
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Operating a Pipeline # 3
300
Clock
I1 A B C
I2 A B C
I3 A B C
Clock
23
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Operating a Pipeline # 4
359
Clock
I1 A B C
I2 A B C
I3 A B C
Clock
24
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Clock
I1 A B C
I2 A B C
I3 A B C
Time
25
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Combinational R
logic e
g
Clock
320 ns
I1 640 ns
I2 960 ns
I3
Time
System
Each operation depends on result from preceding one
27
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
28
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Clock
irmovq $50, %rax I1 A B C
addq %rax, %rbx I2 A B C
mrmovq 100(%rbx), %rdx I3 A B C
I4 A B C
Time
0 120 240 360 480 600 720
29
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
I1 loop:
I2 subq %rdx,%rbx
I3 jne target
I4 irmovq $10,%rdx
I5 jmp loop
I6 target:
I7 halt
30
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Clock
jne target I1 A B C
irmovq $10,%rdx I2 A B C
jmp loop I3 A B C
I4 A B C
Time
0 120 240 360 480 600 720
31
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
32
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
33
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
OPq rA, rB 6 fn rA rB
irmovq V, rB 3 0 F rB V
popq rA B 0 rA F
34
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
35
CS-225: Comp. Sys. Fund. 11/22/2023
Slides modified from: Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Adeel Pasha, LUMS, Fall’23
Topics covered:
36
CS-225: Comp. Sys. Fund. 11/22/2023