当前位置:文档之家› 计算机体系结构之流水线工作原理与分类

计算机体系结构之流水线工作原理与分类


IFetch Dcd Exec Mem WB
IFetch Dcd Exec Mem WB
程序流
IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB
为什么采用流水线呢? 因为有资源空闲!
时间 (时钟周期)
ALU ALU ALU ALU ALU

令 Inst

序 Inst
• 从指令存储器中获取指令
°Reg /Dec: 获取寄存器,指令译码 °Exec: 计算内存地址 °Mem : 从数据存储器中读数据 °Wr : 向寄存器文件写回数据
Pipelining
通过增加指令的执行阶段增强性能
程序 执行
° 顺序
T im e
2
4
6
8
10
12
14
16
18
lw $ 1, 10 0($0)
In s tru ctio n R eg
fe tch
ALU
lw $ 2, 20 0($0)
8 ns

lw $ 3, 30 0($0)
D a ta access
R eg
In s tru c tio n R eg
fe tch
ALU
8 ns
D ata ac c e ss
R eg
In s tru ctio n fe tch
32
Sign
e xtend
Sh if t left 2
Add Add res ult
• 10ns /cycle x (1 CPI x 100inst + 4 cycle drain) = 1040ns
Load指令的五个阶段
Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5
Load Ifetch Reg /Dec Exec Mem Wr
°Ifetch : 获取指令
°还要花费 30 分钟的时间
将衣物放在衣柜里
ABCD
顺序操作
6 下午 7
8
9
10
11
12
1 2 上午
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30

时间
务A
顺 序B
C
D
°
洗4 个人的衣物,顺序操作需要 8 个小时
°
如果使用流水线作业, 将需要多少时间呢?
...
8 ns
P rogram exec ution ord er
T im e
2
4
6
8
10
12
14
(in in struc tio ns) lw $1, 1 00 ($ 0)
In s tru c tion fe tch
Reg
ALU
D a ta access
R eg
lw $2, 2 00 ($ 0)
2 ns
°多个任务同时操作需要不同 的资源
°可能的加速比 = 流水线的段数
°流水线的速率受速度最慢 的流水段的限制
°流水线各段长度不均会降低 加速比
°充满流水线所需的时间和 排空流水线所需的时间影响 加速比
°会由于依赖而造成阻塞
传统的流水线执行表示
时间轴
IFetch Dcd Exec Mem WB
IFetch Dcd Exec Mem WB
Add 4
PC
A dd re ss
In stru ctio n
In struction m em ory
R ead
re gis ter 1
Re ad
R ead
data 1
re gis ter 2
R eg iste rs Re ad
W rite
data 2
re gis ter
W rite d ata
16
为什么使用流水线?
°设想我们要执行 100 条指令 °单周期的机器
• 45ns /cycle x 1 CPI x 100inst = 4500ns
°多周期的机器
• 10ns/cycle x 4.2 CPI (due to inst mix) x 100inst = 4200 ns
°理想的流水线机器
0 Im 1
Reg
Dm Reg
Im Reg
Dm Reg
Inst 2 Inst 3
Inst 4
Im Reg
Dm Reg
Im Reg
Dm Reg
Im Reg
Dm Reg
单时钟周期, 多时钟周期,同流水线比较.
Cycle 1 Clk
单时钟周期的实现:
Load
Cycle 2
Store
Waste
Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9 Cycle 10 Clk
多时钟周期的实现: Load Ifetch Reg Exec
Mem
Store Wr Ifetch Reg
Exec
Mem
R-type Ifetch
流水线的实现: Load Ifetch Reg Exec Mem Wr
Store Ifetch Reg Exec Mem Wr R-type Ifetch Reg Exec Mem Wr
基本思想
IF : In s tru c tio n fe tc h
0 M u x 1
ID : In s tru c tio n d e co d e / r e g is te r file re a d
E X : E xe cute/ a d d re ss c a lc u la tio n
M E M : M e m ory a cc e ss W B : W rite ba ck
计算机体系结构之流水线工作原理与分类
路漫漫其悠远
少壮不努力,老大徒悲伤
流水线技术
流水线技术 相关性分析技术 超标量处理机 超流水线处理机 超标量超流水线处理机
流水线是很自然的!
°洗衣店的例子 °A, B, C, D
均有一些衣务要清洗,甩干,折叠
°清洗要花 30 分钟
°甩干要用 30 分钟
°叠衣物也需要 30 分钟
流水线作业
6 下午 7
8
9
10
11
12

30 30 30 30 30 30 30
务A 顺 序B
C
D
时间
1 2 上午
°流水线作业洗4个人的衣物只需要 3.5 个小时!
流水线
6 下午 7
8
9

时间

30 30 30 30 30 30 30
顺A 序
B
C
D
°流水线无法帮助解决单个任务 的延迟, 有利于减少整个工作 全部时间
In s tru c tio n fe tc h
Reg
ALU
D a ta access
Reg
lw $3, 3 00 ($ 0)
2 ns
In s tru c tio n fe tc h
Reg
ALU
D a ta a cc es s
R eg
2 ns
2 ns
2 ns
2 ns
2 ns
理想的加速比是流水线的段数. 我们能够获得这个加速比吗?
相关主题