第一章计算
王道计算机组成原理第一章——计算公式与单位换算
一、CPU性能计算
1. 主频与时钟周期
\[f=\frac{1}{T}
\]
\[T=\frac{1}{f}
\]
其中:
- \(f\):CPU主频
- \(T\):时钟周期
2. CPU时钟周期数
\[\text{CPU时钟周期数}
=
\text{指令条数}\times \mathrm{CPI}
\]
即:
\[C=IC\times \mathrm{CPI}
\]
其中:
- \(C\):总时钟周期数
- \(IC\):程序执行的指令总数
- \(\mathrm{CPI}\):平均每条指令所需的时钟周期数
3. CPI
\[\mathrm{CPI}
=
\frac{\text{执行程序所需的总时钟周期数}}
{\text{程序执行的指令总数}}
\]
如果程序中包含多类指令,则平均CPI为:
\[\mathrm{CPI}
=
\sum_{i=1}^{n}\mathrm{CPI}_i\times p_i
\]
其中:
\[p_i
=
\frac{\text{第 }i\text{ 类指令条数}}
{\text{指令总数}}
\]
也可以写成:
\[\mathrm{CPI}
=
\frac{\displaystyle\sum_{i=1}^{n}IC_i\times\mathrm{CPI}_i}
{\displaystyle\sum_{i=1}^{n}IC_i}
\]
4. CPU执行时间
\[T_{\mathrm{CPU}}
=
\text{CPU时钟周期数}\times\text{时钟周期}
\]
\[T_{\mathrm{CPU}}
=
IC\times\mathrm{CPI}\times T
\]
因为:
\[T=\frac{1}{f}
\]
所以:
\[\boxed{
T_{\mathrm{CPU}}
=
\frac{IC\times\mathrm{CPI}}{f}
}
\]
5. 指令条数
由CPU执行时间公式变形:
\[IC
=
\frac{T_{\mathrm{CPU}}\times f}
{\mathrm{CPI}}
\]
6. 总时钟周期数
\[C=T_{\mathrm{CPU}}\times f
\]
7. 主频
\[f
=
\frac{IC\times\mathrm{CPI}}
{T_{\mathrm{CPU}}}
\]
二、IPS与MIPS
1. IPS
IPS表示每秒执行的指令数:
\[\mathrm{IPS}
=
\frac{IC}{T_{\mathrm{CPU}}}
\]
结合CPU执行时间公式:
\[\boxed{
\mathrm{IPS}
=
\frac{f}{\mathrm{CPI}}
}
\]
2. MIPS
MIPS表示每秒执行多少百万条指令:
\[\mathrm{MIPS}
=
\frac{IC}
{T_{\mathrm{CPU}}\times10^6}
\]
也可以写成:
\[\boxed{
\mathrm{MIPS}
=
\frac{f}
{\mathrm{CPI}\times10^6}
}
\]
若主频的单位已经是MHz,则:
\[\boxed{
\mathrm{MIPS}
=
\frac{f(\mathrm{MHz})}
{\mathrm{CPI}}
}
\]
3. 根据MIPS计算执行时间
\[T_{\mathrm{CPU}}
=
\frac{IC}
{\mathrm{MIPS}\times10^6}
\]
三、FLOPS
FLOPS表示每秒执行的浮点运算次数:
\[\mathrm{FLOPS}
=
\frac{\text{浮点运算次数}}
{\text{执行时间}}
\]
由此可得:
\[\text{执行时间}
=
\frac{\text{浮点运算次数}}
{\mathrm{FLOPS}}
\]
四、性能与执行时间
计算机性能与程序执行时间成反比:
\[\boxed{
\text{性能}
=
\frac{1}{\text{执行时间}}
}
\]
对于计算机A和计算机B:
\[\frac{\text{性能}_A}{\text{性能}_B}
=
\frac{T_B}{T_A}
\]
如果A的执行时间比B短,则A的性能更高。
性能提高百分比
\[\text{性能提高率}
=
\frac{\text{新性能}-\text{原性能}}
{\text{原性能}}
\times100\%
\]
由于性能与时间成反比:
\[\text{性能提高率}
=
\left(
\frac{T_{\text{原}}}{T_{\text{新}}}-1
\right)
\times100\%
\]
注意:
\[\text{执行时间减少 }x\%
\neq
\text{性能提高 }x\%
\]
若执行时间减少\(x\%\),则:
\[T_{\text{新}}
=
(1-x\%)T_{\text{原}}
\]
性能提高率为:
\[\frac{1}{1-x\%}-1
\]
五、加速比
\[\boxed{
S
=
\frac{T_{\text{原}}}
{T_{\text{新}}}
}
\]
其中:
- \(S\):加速比
- \(T_{\text{原}}\):改进前执行时间
- \(T_{\text{新}}\):改进后执行时间
六、吞吐量
\[\text{吞吐量}
=
\frac{\text{完成的任务数量}}
{\text{总时间}}
\]
平均完成一个任务的时间为:
\[\text{平均任务时间}
=
\frac{\text{总时间}}
{\text{任务数量}}
\]
七、主存容量
1. 基本公式
\[\boxed{
\text{主存容量}
=
\text{存储单元数量}
\times
\text{每个存储单元的位数}
}
\]
若存储器有\(n\)根地址线,则存储单元数量为:
\[\boxed{
\text{存储单元数量}=2^n
}
\]
因此:
\[\boxed{
\text{主存容量}
=
2^n\times\text{存储字长}
}
\]
2. 按字节编址
若有\(n\)根地址线,并且按字节编址,则:
\[\text{主存容量}
=
2^n\mathrm{B}
\]
3. 按字编址
若有\(n\)根地址线,每个存储字包含\(m\)位,则:
\[\text{主存容量}
=
2^n\times m\mathrm{bit}
\]
换算成字节:
\[\text{主存容量}
=
\frac{2^n\times m}{8}\mathrm{B}
\]
4. 地址范围对应的存储单元数
\[\boxed{
\text{存储单元数}
=
\text{末地址}-\text{首地址}+1
}
\]
如果按字节编址:
\[\text{主存容量}
=
(\text{末地址}-\text{首地址}+1)\mathrm{B}
\]
5. 地址位数
若共有\(N\)个存储单元,则所需地址位数\(n\)满足:
\[2^n\geq N
\]
因此:
\[\boxed{
n=\left\lceil\log_2N\right\rceil
}
\]
若恰好有\(N=2^n\)个存储单元,则:
\[n=\log_2N
\]
八、常用单位换算
1. 位与字节
\[\boxed{
1\mathrm{B}=8\mathrm{bit}
}
\]
其中:
- \(\mathrm{bit}\)或小写\(\mathrm{b}\)表示“位”
- 大写\(\mathrm{B}\)表示“字节”
\[1\mathrm{Byte}=8\mathrm{bit}
\]
2. 存储容量单位——二进制换算
\[1\mathrm{KiB}=2^{10}\mathrm{B}=1024\mathrm{B}
\]
\[1\mathrm{MiB}=2^{10}\mathrm{KiB}=2^{20}\mathrm{B}
\]
\[1\mathrm{GiB}=2^{10}\mathrm{MiB}=2^{30}\mathrm{B}
\]
\[1\mathrm{TiB}=2^{10}\mathrm{GiB}=2^{40}\mathrm{B}
\]
常见简写习惯:
\[1\mathrm{KB}\approx2^{10}\mathrm{B}
\]
\[1\mathrm{MB}\approx2^{20}\mathrm{B}
\]
\[1\mathrm{GB}\approx2^{30}\mathrm{B}
\]
\[1\mathrm{TB}\approx2^{40}\mathrm{B}
\]
严格写法应使用:
| 单位 | 大小 |
|---|---|
| \(\mathrm{KiB}\) | \(2^{10}\mathrm{B}\) |
| \(\mathrm{MiB}\) | \(2^{20}\mathrm{B}\) |
| \(\mathrm{GiB}\) | \(2^{30}\mathrm{B}\) |
| \(\mathrm{TiB}\) | \(2^{40}\mathrm{B}\) |
3. 十进制数量单位
\[1\mathrm{K}=10^3
\]
\[1\mathrm{M}=10^6
\]
\[1\mathrm{G}=10^9
\]
\[1\mathrm{T}=10^{12}
\]
\[1\mathrm{P}=10^{15}
\]
\[1\mathrm{E}=10^{18}
\]
主频、网络速率、IPS和FLOPS通常采用十进制换算。
4. 频率单位
\[1\mathrm{kHz}=10^3\mathrm{Hz}
\]
\[1\mathrm{MHz}=10^6\mathrm{Hz}
\]
\[1\mathrm{GHz}=10^9\mathrm{Hz}
\]
\[1\mathrm{THz}=10^{12}\mathrm{Hz}
\]
5. 时间单位
\[1\mathrm{s}=10^3\mathrm{ms}
\]
\[1\mathrm{ms}=10^{-3}\mathrm{s}
\]
\[1\mathrm{\mu s}=10^{-6}\mathrm{s}
\]
\[1\mathrm{ns}=10^{-9}\mathrm{s}
\]
\[1\mathrm{ps}=10^{-12}\mathrm{s}
\]
换算关系:
\[1\mathrm{ms}=10^3\mathrm{\mu s}
\]
\[1\mathrm{\mu s}=10^3\mathrm{ns}
\]
\[1\mathrm{ns}=10^3\mathrm{ps}
\]
6. 主频与时钟周期快速对应
| 主频 | 时钟周期 |
|---|---|
| \(1\mathrm{kHz}\) | \(1\mathrm{ms}\) |
| \(1\mathrm{MHz}\) | \(1\mathrm{\mu s}\) |
| \(1\mathrm{GHz}\) | \(1\mathrm{ns}\) |
| \(2\mathrm{GHz}\) | \(0.5\mathrm{ns}\) |
| \(2.5\mathrm{GHz}\) | \(0.4\mathrm{ns}\) |
| \(4\mathrm{GHz}\) | \(0.25\mathrm{ns}\) |
快速计算:
\[\boxed{
T(\mathrm{ns})
=
\frac{1}{f(\mathrm{GHz})}
}
\]
\[\boxed{
T(\mathrm{\mu s})
=
\frac{1}{f(\mathrm{MHz})}
}
\]
7. FLOPS单位
\[1\mathrm{KFLOPS}=10^3\mathrm{FLOPS}
\]
\[1\mathrm{MFLOPS}=10^6\mathrm{FLOPS}
\]
\[1\mathrm{GFLOPS}=10^9\mathrm{FLOPS}
\]
\[1\mathrm{TFLOPS}=10^{12}\mathrm{FLOPS}
\]
\[1\mathrm{PFLOPS}=10^{15}\mathrm{FLOPS}
\]
\[1\mathrm{EFLOPS}=10^{18}\mathrm{FLOPS}
\]
九、十六进制与二进制换算
一个十六进制位对应4个二进制位:
\[\boxed{
1\text{位十六进制}=4\text{位二进制}
}
\]
因此:
\[2\text{位十六进制}=8\text{位二进制}
\]
\[4\text{位十六进制}=16\text{位二进制}
\]
\[8\text{位十六进制}=32\text{位二进制}
\]
常见数值:
\[10_{\mathrm{H}}=16_{\mathrm{D}}
\]
\[100_{\mathrm{H}}=2^8=256_{\mathrm{D}}
\]
\[1000_{\mathrm{H}}=2^{12}=4096_{\mathrm{D}}
\]
\[10000_{\mathrm{H}}=2^{16}=65536_{\mathrm{D}}
\]
十、第一章核心公式汇总
\[\boxed{T=\frac{1}{f}}
\]
\[\boxed{
\mathrm{CPI}
=
\frac{\text{总时钟周期数}}
{\text{总指令数}}
}
\]
\[\boxed{
\text{总时钟周期数}
=
IC\times\mathrm{CPI}
}
\]
\[\boxed{
T_{\mathrm{CPU}}
=
IC\times\mathrm{CPI}\times T
}
\]
\[\boxed{
T_{\mathrm{CPU}}
=
\frac{IC\times\mathrm{CPI}}{f}
}
\]
\[\boxed{
\mathrm{IPS}
=
\frac{f}{\mathrm{CPI}}
}
\]
\[\boxed{
\mathrm{MIPS}
=
\frac{f}
{\mathrm{CPI}\times10^6}
}
\]
\[\boxed{
\text{性能}
=
\frac{1}{\text{执行时间}}
}
\]
\[\boxed{
\text{加速比}
=
\frac{T_{\text{原}}}{T_{\text{新}}}
}
\]
\[\boxed{
\text{存储单元数量}=2^{\text{地址位数}}
}
\]
\[\boxed{
\text{主存容量}
=
\text{存储单元数量}
\times
\text{存储字长}
}
\]
\[\boxed{
\text{地址范围大小}
=
\text{末地址}-\text{首地址}+1
}
\]
\[\boxed{
1\mathrm{B}=8\mathrm{bit}
}
\]

浙公网安备 33010602011771号