说明
本文是个人学习用的非官方中英对照译文,原文:https://diveintosystems.org/book/C5-Arch/index.html。
原书采用 CC BY-NC-ND 4.0 许可(禁止演绎),请勿公开传播本译文。
标为「译注」「现代更新」的内容是译者补充,不代表原书作者观点;代码与原文逐字一致,未作改动。
5. What von Neumann Knew: Computer Architecture
计算机体系结构(computer architecture)这个术语可以指计算机的整个硬件层面。不过它更常用来指计算机硬件中数字处理器部分的设计与实现,本章关注的就是计算机处理器的体系结构。
The term computer architecture may refer to the entire hardware level of the computer. However, it is often used to refer to the design and implementation of the digital processor part of the computer hardware, and we focus on the computer processor architecture in this chapter.
中央处理器(central processing unit,CPU,或称处理器)是计算机中在程序数据上执行程序指令的部件。程序指令和数据存放在计算机的随机存取存储器(RAM)中。一个具体的数字处理器实现了某种特定的指令集架构(instruction set architecture,ISA),ISA 定义了指令集合及其二进制编码、CPU 寄存器的集合,以及执行指令对处理器状态的影响。ISA 有很多种,包括 SPARC、IA32、MIPS、ARM、ARC、PowerPC 和 x86(后者包括 IA32 和 x86-64)。微体系结构(microarchitecture)定义了某种特定 ISA 的一种实现的电路。同一种 ISA 的不同微体系结构实现可以各不相同,只要它们都实现了 ISA 的定义即可。例如,Intel 和 AMD 生产了 IA32 ISA 的不同微处理器实现。
The central processing unit (CPU, or processor) is the part of the computer that executes program instructions on program data. Program instructions and data are stored in the computer’s random access memory (RAM). A particular digital processor implements a specific instruction set architecture (ISA), which defines the set of instructions and their binary encoding, the set of CPU registers, and the effects of executing instructions on the state of the processor. There are many different ISAs, including SPARC, IA32, MIPS, ARM, ARC, PowerPC, and x86 (the latter including IA32 and x86-64). A microarchitecture defines the circuitry of an implementation of a specific ISA. Microarchitecture implementations of the same ISA can differ as long as they implement the ISA definition. For example, Intel and AMD produce different microprocessor implementations of IA32 ISA.
有些 ISA 定义的是精简指令集计算机(reduced instruction set computer,RISC),另一些定义的是复杂指令集计算机(complex instruction set computer,CISC)。RISC ISA 只有一小组基本指令,每条指令都执行得很快;每条指令大约在一个处理器时钟周期内完成,编译器把若干条基本 RISC 指令组合成序列来实现更高层的功能。相比之下,CISC ISA 的指令提供比 RISC 指令更高层的功能。CISC 体系结构还定义了比 RISC 更大的指令集合,支持更复杂的寻址模式(表示程序数据内存位置的方式),并支持变长指令。一条 CISC 指令可能执行一连串底层操作,可能需要好几个处理器时钟周期才能执行完。同样的功能在 RISC 体系结构上则需要多条指令。
Some ISAs define a reduced instruction set computer (RISC), and others define a complex instruction set computer (CISC). RISC ISAs have a small set of basic instructions that each execute quickly; each instruction executes in about a single processor clock cycle, and compilers combine sequences of several basic RISC instructions to implement higher-level functionality. In contrast, a CISC ISA’s instructions provide higher-level functionality than RISC instructions. CISC architectures also define a larger set of instructions than RISC, support more complicated addressing modes (ways to express the memory locations of program data), and support variable-length instructions. A single CISC instruction may perform a sequence of low-level functionality and may take several processor clock cycles to execute. This same functionality would require multiple instructions on a RISC architecture.
原书旁注 · RISC 与 CISC 的历史(The History of RISC versus CISC)
1980 年代初,伯克利大学和斯坦福大学的研究人员通过伯克利 RISC 项目和斯坦福 MIPS 项目开发了 RISC。伯克利的 David Patterson 和斯坦福的 John Hennessy 因开发 RISC 体系结构的工作,获得了 2017 年度的图灵奖1(计算机领域的最高奖项)。
在 RISC 诞生的年代,它与当时普遍认为 ISA 必须越来越复杂才能获得高性能的观点截然不同。「RISC 方法与当时盛行的复杂指令集计算机(CISC)不同,它只需要一小组简单而通用的指令(计算机必须执行的功能),所需的晶体管比复杂指令集更少,也减少了计算机必须完成的工作量。」2
CISC ISA 用比 RISC 更少的指令来表达程序,因而可执行文件往往更小。在主存较小的系统上,可执行文件的大小是影响程序性能的重要因素,因为可执行文件越大,留给运行中程序内存空间其他部分的 RAM 就越少。基于 CISC 的微体系结构通常也经过专门设计,以高效执行 CISC 的变长、高功能指令。用于执行更复杂指令的专用电路,可以更高效地执行特定的高层功能,但代价是所有指令的执行都需要更复杂的电路。
比较 RISC 和 CISC:RISC 程序要执行的指令总数更多,但每条指令的执行效率远高于大多数 CISC 指令,而且 RISC 允许比 CISC 更简单的微体系结构设计。CISC 程序的指令更少,CISC 微体系结构被设计成能高效执行更复杂的指令,但它们需要更复杂的微体系结构设计和更高的时钟频率。总的来说,RISC 处理器带来更高效的设计和更好的性能。随着计算机内存容量的不断增长,可执行文件的大小对程序性能的影响已经不那么重要了。然而,CISC 一直是占主导地位的 ISA,这在很大程度上是因为它得到了产业界的实现和支持。
今天,CISC 仍然是台式机和许多服务器级计算机的主流 ISA。例如,Intel 的 x86 ISA 就是基于 CISC 的。RISC ISA 更常见于高端服务器(例如 SPARC)和移动设备(例如 ARM),因为它们功耗低。某种 RISC 或 CISC ISA 的具体微体系结构实现,在内部可能同时融合了 RISC 和 CISC 的设计。例如,大多数 CISC 处理器使用微码(microcode),把一些 CISC 指令编码为一种更像 RISC 的指令集,交由底层处理器执行;而一些现代 RISC 指令集也包含了比最初的 MIPS 和伯克利 RISC 指令集多一些的复杂指令或寻址模式。
In the early 1980s, researchers at Berkeley and Stanford universities developed RISC through the Berkeley RISC project and the Stanford MIPS project. David Patterson of Berkeley and John Hennessy of Stanford won the 2017 Turing Award1 (the highest award in computing) for their work developing RISC architectures.
At the time of its development, the RISC architecture was a radical departure from the commonly held view that ISAs needed to be increasingly complex to achieve high performance. “The RISC approach differed from the prevailing complex instruction set computer (CISC) computers of the time in that it required a small set of simple and general instructions (functions a computer must perform), requiring fewer transistors than complex instruction sets and reducing the amount of work a computer must perform.”2
CISC ISAs express programs in fewer instructions than RISC, often resulting in smaller program executables. On systems with small main memory, the size of the program executable is an important factor in the program’s performance, since a large executable leaves less RAM space available for other parts of a running program’s memory space. Microarchitectures based on CISC are also typically specialized to efficiently execute the CISC variable-length and higher-functionality instructions. Specialized circuitry for executing more complex instructions may result in more efficient execution of specific higher-level functionality, but at the cost of requiring more complexity for all instruction execution.
In comparing RISC to CISC, RISC programs contain more total instructions to execute, but each instruction executes much more efficiently than most CISC instructions, and RISCs allow for simpler microarchitecture designs than CISC. CISC programs contain fewer instructions, and CISC microarchitectures are designed to execute more complicated instructions efficiently, but they require more complex microarchitecture designs and faster clock rates. In general, RISC processors result in more efficient design and better performance. As computer memory sizes have increased over time, the size of the program executable is less important to a program’s performance. CISC, however, has been the dominant ISA due in large part to it being implemented by and supported by industry.
Today, CISC remains the dominant ISA for desktop and many server-class computers. For example, Intel’s x86 ISAs are CISC-based. RISC ISAs are more commonly seen in high-end servers (e.g. SPARC) and in mobile devices (e.g. ARM) due to their low power requirements. A particular microarchitecture implementation of a RISC or CISC ISA may incorporate both RISC and CISC design under the covers. For example, most CISC processors use microcode to encode some CISC instructions in a more RISC-like instruction set that the underlying processor executes, and some modern RISC instruction sets contain a few more complex instructions or addressing modes than the initial MIPS and Berkeley RISC instruction sets.
现代更新(截至 2026-11)· RISC 进入个人电脑
原书说「CISC 仍是台式机的主流 ISA」,这一格局已经松动。2020 年 11 月,Apple 发布了第一款为 Mac 设计的自研芯片 M1(ARM 架构),并宣布用大约两年时间把整个 Mac 产品线从 Intel x86 处理器迁移到 Apple Silicon,如今在售的 Mac 全部采用 ARM 芯片。Apple Newsroom:Apple unleashes M1
所有现代处理器,无论采用什么 ISA,都遵循冯·诺依曼体系结构模型。冯·诺依曼体系结构的通用设计使它能执行任何类型的程序。它采用存储程序模型,也就是说,程序指令与程序数据一起存放在计算机内存中,两者都是处理器的输入。
All modern processors, regardless of their ISA, adhere to the von Neumann architecture model. The general-purpose design of the von Neumann architecture allows it to execute any type of program. It uses a stored-program model, meaning that the program instructions reside in computer memory along with program data, and both are inputs to the processor.
本章介绍冯·诺依曼体系结构,以及支撑现代计算机体系结构的历史渊源和组成部分。我们会基于冯·诺依曼体系结构模型构建一个示例数字处理器(CPU):用以逻辑门为构件搭建的数字电路设计一个 CPU,并演示 CPU 如何执行程序指令。
This chapter introduces the von Neumann architecture and the ancestry and components that underpin modern computer architecture. We build an example digital processor (CPU) based on the von Neumann architecture model, design a CPU from digital circuits that are constructed from logic gate building blocks, and demonstrate how the CPU executes program instructions.
参考文献
References
ACM A. M. Turing Award Winners. https://amturing.acm.org/
“Pioneers of Modern Computer Architecture Receive ACM A.M. Turing Award”, ACM Media Center Notice, March 2018. https://www.acm.org/media-center/2018/march/turing-award-2017