Datapath and control
引入
6:22
计算机体系结构
本课程探讨程序底层的机器,以及它如何实现高速运行。前两个单元介绍约定,也就是指令集,以及遵守这一约定的机器,也就是数据通路。接下来的两个单元介绍如何用流水线和存储层次结构提高速度。最后两个单元介绍它如何连接输入输出设备和其他处理器。所有关于时间的结论都根据给定参数计算得出。
英文讲解 · 可切换中英文字幕
本课内容
| English | 释义 | 拼音 |
|---|---|---|
| datapath/ˈdeɪtəpæθ/ | 数据通路 | shù jù tōng lù |
| ALU/ˌeɪ el ˈjuː/ | 算术逻辑单元 | suàn shù luó jí dān yuán |
| Control/kənˈtrəʊl/ | 控制 | kòng zhì |
| don't-care/dəʊnt keə/ | 无关项 | wú guān xiàng |
| CPI/ˌsiː piː ˈaɪ/ | 每指令周期数 | měi zhǐ lìng zhōu qī shù |
一时钟一条指令
- 数据通路 datapath 就是管道:PC 喂指令存储器,寄存器堆读两个源,ALU 算术逻辑单元计算,数据存储器读写,结果写回,PC 取 PC+4 或分支目标。
- 控制 control 是每条指令的开关设置:RegWrite、MemRead、MemWrite、MemToReg、ALUSrc、Branch——对 opcode 与 funct 的纯组合逻辑。

The single-cycle clock must wait for —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
All work fits in one clock, so lw (IM+RF+ALU+DM+wiring = 900 ps) sets the cycle.
周期取决于最慢者
- 所有工作挤进一个时钟,时钟就得等最长的指令:
lw的路径。按课程参数(IM 200、RF 100、ALU 200、DM 250、连线 150 ps):$200 + 100 + 200 + 250 + 150 = 900$ ps 每周期。 - 100 条指令 $90\,000$ ps。加速
add无济于事——机器按最慢指令的步调走。
With IM 200, RF 100, ALU 200, DM 250, wiring 150 ps, the lw cycle is —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
200+100+200+250+150 = 900 ps: the slowest instruction sets the clock.
In the single-cycle machine, making add faster would shorten the clock period.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The clock must fit the slowest instruction, lw at $900$ ps. A faster add finishes earlier inside the same cycle and then waits.
每条指令六个比特
lw R4, 8(R1):RegWrite 1、MemRead 1、MemToReg 1、ALUSrc 1(立即数进 ALU)、Branch 0、MemWrite 0。sw R5, 12(R1):RegWrite 0、MemWrite 1、MemRead 0、MemToReg = x——无关项:没有写回,这一位怎么设都不影响可见行为。无关项是设计者的自由。
For lw, the ALUSrc control bit selects —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The ALU must add base + immediate, so ALUSrc = 1 routes the immediate.
这是一张新卡片,翻译完成前会显示英文。
The multi-cycle alternative
- Split each instruction into steps and clock at the slowest unit, $250$ ps. Now
lwtakes $5$ cycles, R-type andswtake $4$, andbeqtakes $3$. For a mix of $25\%$ loads, $10\%$ stores, $50\%$ R-type and $15\%$ branches: CPI 每指令周期数 $= 1.25 + 0.4 + 2.0 + 0.45 = 4.1$. - The time per instruction is $4.1 \times 250 = 1025$ ps, slower than the single cycle's $900$ ps. Whether multi-cycle is faster depends on the instruction mix, cycle counts and clock periods.
- The real gain comes from overlapping the steps of different instructions: pipelining. Note that
beqsets ALUSrc to $0$, because it compares two registers.
A multi-cycle machine runs 40% loads (5 cycles) and 60% R-type (4 cycles). What is the CPI?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
0.4 x 5 + 0.6 x 4 = 2.0 + 2.4 = 4.4.
支持 beq R1, R2, loop, the ALUSrc control bit is —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The branch subtracts R2 from R1 to test equality, so the second ALU input is a register.
这是一张新卡片,翻译完成前会显示英文。
The iron law of performance
- Time = instructions × CPI 每指令周期数 × cycle time. Everything an architect does changes one of the three, and usually makes another worse.
- For 100 instructions: single-cycle $100 \times 1 \times 900 = 90\,000$ ps; multi-cycle $100 \times 4.1 \times 250 = 102\,500$ ps; a 5-stage pipeline at CPI 1.129 and 250 ps gives $\mathbf{28\,225}$ ps. Pipelining wins because it keeps CPI near 1 with the short clock.
100 instructions at CPI 1.129 with a 250 ps clock: total time (ps)?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
$100 \times 1.129 \times 250 = 28\,225$.
A lower CPI always means a faster program.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Time also depends on the cycle time: the single-cycle design has CPI 1 at 900 ps and takes 90,000 ps, while the pipeline has CPI 1.129 at 250 ps and takes 28,225.
这是一张新卡片,翻译完成前会显示英文。
Worked example: control bits for beq and addi
beq R1, R2, L: RegWrite 0, MemRead 0, MemWrite 0, ALUSrc 0 (two registers), Branch 1, MemToReg x. The ALU 算术逻辑单元 subtracts; its Zero output AND Branch chooses the target.addi R4, R1, 127: RegWrite 1, ALUSrc 1 (the immediate), MemToReg 0 (the ALU result is written back), Branch 0, and no memory access. Seven instructions give seven rows of one truth table.
支持 addi, which control setting is right?
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The immediate feeds the ALU and the ALU result is written back.
这是一张新卡片,翻译完成前会显示英文。
Marks that slip away
- Speeding up the common instruction. The single-cycle clock is set by
lw, so a fasteraddchanges nothing. - Fixing don't-cares out of habit. A don't-care 无关项 is free only when nothing can observe it, as with MemToReg on
sw; fixing it costs logic and gains nothing. - Assuming multi-cycle is faster. For the course mix it averages $1025$ ps against $900$ ps. The result depends on the instruction mix, cycle counts and clock periods.
这是一张新卡片,翻译完成前会显示英文。
Recap
- Datapath: PC, instruction memory, register file, ALU, data memory, write-back.
- Single-cycle clock = slowest instruction: $900$ ps for
lwhere. For 100 instructions of the course mix:
| Design | Clock (ps) | CPI | Time (ns) |
|---|---|---|---|
| Single-cycle | 900 | 1 | 90.0 |
| Multi-cycle | 250 | 4.1 | 102.5 |
| Pipeline | 250 | 1.129 | 28.2 |
-
CPI is cycles per instruction; the pipeline has 5 stages.
-
Control is combinational: six bits per instruction, with don't-cares 无关项 where nothing can be observed.
出了什么问题?只有网站团队能看到这些信息。