Skip to content

Lecture 8.2 | The Processor-Part2

:material-circle-edit-outline: 约 427 个字 :fontawesome-solid-code: 8 行代码 :material-clock-time-two-outline: 预计阅读时间 2 分钟

承接上节课的预测

image-20240422183734609

image-20240422183758881

期中考试考到单周期,流水线不考

4.6 RISC-V Pipelined Datapath

单周期图划为五个区域,对应流水线的五个阶段

当然这不是最终的版本

image-20240422183900350

从右往左的线会造成hazard

左上角对应了控制冒险,这个mux决定下一条指令是pc+4还是跳转到imm对应的地址

右下角对应了数据冒险

Pipeline registers

image-20240422184339164

通过阶段之间的reg储存上一阶段的结果,方便下一阶段使用

IF for Load, Store, …

image-20240422184828944

ID for Load, Store, …

image-20240422184910265

EX for Load

image-20240422184927398

MEM for Load

image-20240422185016859

WB for Load

这张图有问题,地址是不对的

image-20240422185111230

Corrected Datapath for Load

image-20240422185207301

EX for Store

image-20240422185134475

Pipeline Operation

注意记一下两种diagram的名字

image-20240422184733104

Multi-Cycle Pipeline Diagram

image-20240422185251021

下图为简化画法,考试就用这种画就行

image-20240422185405589

Single-Cycle Pipeline Diagram

指令放最上面

注意是与muti-cycle相反,最上面这一行指令是从右往左顺序,即先运行ld x10, 40(x1)

image-20240422185439245

Pipelined Control

都要背下来

Pipelined Control (Simplified)

image-20240422190420970

image-20240422190438601

image-20240422190352252

没有考虑jal,不然太复杂了

4.7 Data Hazards

如何去解决data hazard,如何实现forwarding

Consider this sequence:

sub x2, x1,x3
and x12,x2,x5
or x13,x6,x2
add x14,x2,x2
sd x15,100(x2)

Dependencies & Forwarding

image-20240422190750643

Detecting the Need to Forward

  • Pass register numbers along pipeline
    • e.g., ID/EX.RegisterRs1 = register number for Rs1 sitting in ID/EX pipeline register
  • ALU operand register numbers in EX stage are given by
    • ID/EX.RegisterRs1, ID/EX.RegisterRs2

image-20240422191217873

  • But only if forwarding instruction will write to a register!
    • EX/MEM.RegWrite, MEM/WB.RegWrite
  • And only if Rd for that instruction is not x0
    • EX/MEM.RegisterRd ≠ 0, MEM/WB.RegisterRd ≠ 0

Forwarding Paths

image-20240422191643125

Forwarding Conditions

image-20240422191937632

Double Data Hazard

Consider the sequence

add x1,x1,x2
add x1,x1,x3
add x1,x1,x4

Revised Forwarding Condition

下面这个是描述hazard的语言,要学习,考试会考

不需要死记硬背

你会写黑的就会写蓝的

image-20240422192604011

Datapath with Forwarding

image-20240422192723199

Load-Use Hazard Detection

image-20240422192939007

How to Stall the Pipeline

image-20240422193018169

Load-Use Data Hazard

image-20240422193042499

Datapath with Hazard Detection

image-20240422193108840

Stalls and Performance

image-20240422194209281

4.8 Branch Hazards

image-20240422194231218

Reducing Branch Delay

image-20240422194306602

Example: Branch Taken

预测

$$image-20240422194333257

image-20240428163117011