计组教材的梦幻联动

Posted by HX on 2021-07-24 | 👓

这话得从 William Stallings 的《计算机组成与体系结构:性能设计》(Computer Organization and Architecture: Designing for Performance)说起。今天看这本书的时候,读到这段话,辨析计算机组成体系结构这两个术语:

For example, it is an architectural design issue whether a computer will have a multiply instruction. It is an organizational issue whether that instruction will be implemented by a special multiply unit or by a mechanism that makes repeated use of the add unit of the system.

简单来说,体系结构关心每一层里面要做什么,是个 what to do 的问题,计算机组成关心如何实现每一层的功能,是个 how to do 的问题。这里举了个乘法指令的例子来说明二者的不同。

等等,这个例子有点眼熟……?没错,就是你,唐朔飞版《计算机组成原理》!

这本书是我们本科的计组课教材,应该也是国内比较经典的一本教材。这两个例子的雷同,是一次巧合吗?答案恐怕是否定的,因为接下来,我们又读到了一个雷同的例子,不,不如说,是雷同的一段话:

Historically, and still today, the distinction between architecture and organization has been an important one. Many computer manufacturers offer a family of computer models, all with the same architecture but with differences in organization. Consequently, the different models in the family have different price and performance characteristics. Furthermore, a particular architecture may span many years and encompass a number of different computer models, its organization changing with changing technology. A prominent example of both these phenomena is the IBM System/370 architecture. This architecture was first introduced in 1970 and included a number of models. The customer with modest requirements could buy a cheaper, slower model and, if demand increased, later upgrade to a more expensive, faster model without having to abandon software that had already been developed.

不过,这也没什么好惊讶的,因为在书最后的“参考文献”一节,就把 William Stallings 的 COA 放在了第一的位置。所以,人家就是“参考”了,怎么地吧(doge

事实上,这也不是我第一次在唐书里读到和国外教材几乎一致的表述了。记得之前另一次是和 Andrew S. Tanenbaum 的《计算机组成:结构化方法》(Structured Computer Organization)雷同(可惜 Tanenbaum 的大作没能荣幸被列入唐书第一版的“参考文献”中,不知道第二版有没有,现在手头没第二版)。

你可能会说,这一个六层,一个五层,也没有一模一样嘛,但是其实不同之处也就只有上图最底下多了个数字逻辑层而已,这一层在下图里面是隐含的(感觉之所以下图不写出来,和计算机网络的物理层底下还有个物理介质一般不会写出来道理差不多……)。

其实真正让我觉得二者雷同的,并不是这个层次结构本身,而是那个“操作系统层”,毕竟除了这层,其他层都像是任何一本组成原理书里都可能列出的层次,换句话说,是一种“共识”,既然是共识,相同就没有什么奇怪的。

在我第一次学组成原理读唐书的时候,操作系统层让我十分费解:操作系统不是汇编语言(甚至高级语言)写的吗?怎么图里汇编语言层反而基于操作系统层?图里说“用机器语言解释操作系统”,当然,操作系统要翻译成机器语言才能运行,但哪个程序不是呢?为什么偏偏要给操作系统单独设立一层?唐书上的描述并没有解答我的这些疑惑。

后来读了 Tanenbaum 的书,才知道这个层次结构图是那里来的,书里也做了解释:

The next level is usually a hybrid level. Most of the instructions in its language are also in the ISA level. (There is no reason why an instruction appearing at one level cannot be present at other levels as well.) In addition, there is a set of new instructions, a different memory organization, the ability to run two or more programs concurrently, and various other features. More variation exists between level 3 designs than between those at either level 1 or level 2. The new facilities added at level 3 are carried out by an interpreter running at level 2, which, historically, has been called an operating system. Those level 3 instructions that are identical to level 2’s are carried out directly by the microprogram (or hardwired control), not by the operating system. In other words, some of the level 3 instructions are interpreted by the operating system and some are interpreted directly by the microprogram. This is what we mean by ‘‘hybrid’’ level.

总之就是操作系统层的指令包含指令集层(唐书的“机器语言机器”)所用的机器指令,再加上一些“广义指令”,也就是系统调用。系统调用是由操作系统来解释(也就是说,一条系统调用被操作系统翻译成(也许是)多条机器指令),机器指令则由微程序来解释。而概念上设立一个操作系统层则是因为在这一层加入了新的广义指令、内存组织发生了变化(引入虚拟内存)、加入了并发运行程序的能力(引入进程)等,作为汇编语言的(应用,而非系统)程序员,所使用的已经是操作系统引入这些特性后的新一层机器了。

有没有可能这种层次结构是唐书先提出,被 Tanenbaum 借鉴的呢?答案恐怕还是否定的,因为唐书第一版是 1998 年左右,而 Tanenbaum 那本书第一版是 1976 年,里面已经有这个层次结构图了(是的,为了求证这一点,我特地去下了这本第一版电子书)。至于 Tanenbaum 的书会不会也是借鉴别人的,那就不得而知了。

说了这么多,也并非要完全否定唐书。毕竟,本文提到的只是书里很小一部分,其他部分我还没对比过,但就我的学习经历来看,唐书写得还是比较简明扼要的,这似乎也是国内教材的通性:没那么多举例、比喻、题外话,让人比较容易把握重点。还是希望国内能写出更多更好的教材。