I will upload my new book "self-writing processor" (not published yet). Today is the second article. I try to write it every Thursday.
Chapter 2 processors and MIPS
It's time!
-- Hu Feng 1949
Let's start reading this book with a poetic sentence.
Starting from January 1, November 15, 1971, Intel released the world's first single-chip microprocessor, 4004.
1.1 simple computer model
The computer is very complicated. It is terrible and complicated to listen to songs, watch movies, surf the internet, and play games.
The computer is very simple. It is too simple to do operations such as addition, subtraction, multiplication, division, logic, shift, transfer, storage, and loading.
Complicated? Simple? In fact, it depends on the degree of understanding of things. The more you know, the deeper you know, the closer you get to the essence. The essence is always simple, such as the well-known energy equation, A simple expression explains the relationship between quality and energy.
A computer is a computing device and a basic computing device. It can only compute the four Arithmetic Operations taught in the elementary school mathematics class, plus some non-complex logical operations such as sum, or, non, and so on, the rest, such as square, differential, points, and so on, cannot be done. Some readers may have doubts. You are too simple to say. Don't worry, and listen to me.
1.1.1 simple computer composition model
The computer consists of three parts: CPU (Central Processing Unit), input/output (I/O: input/output), and memory (memory ). The processor obtains the command from the memory and then executes certain operations according to the command. The input and output are used to provide the operation data and display the operation result. 1-1.
Commands are stored in the memory, and commands are an Operational Command. For example, you can add a and B and store the result to C. The processor can execute the command. The current computer is a binary world, and all information is expressed in a combination of 0 and 1. Therefore, an instruction is a string of 0 and 1 encoding, as shown in Figure 1-1. The processor has an internal decoding function, which is used to explain the operation type of the received 0 and 1 encoding, and perform the operation accordingly.
1.1.2 simple computer use model
We use computers to access the Internet and work through certain applications, and these applications are actually a collection of commands. Of course, the "batch" here refers to the large number of commands. In fact, there are very few types, only a few hundred, and dozens of commonly used commands. Through the organization and cooperation of these commands, we have implemented a variety of applications.
Theoretically, 0 and 1 encoding can be used directly for program design, but it is obviously too inconvenient and error-prone. Therefore, people use some mnemonic symbols to express various commands, which are Assembly commands, the assembler program translates Assembly commands into 0 and 1 codes that can be recognized by computers. Later, the advanced language was invented. Its syntax and usage are more convenient and easier to understand than assembly. Generally, the compilation program is used to translate programs written in advanced languages into assembly instructions, and then the assembler program is used to translate the programs into 0 and 1 encoding. It is essentially the same. 1-2.
This is the simple usage model of the computer, whether it is video software, browsers, or any other software; whether it is developed using C # development, Java Development, or any other language; whether running in windows, Android, or any other platform, whether running on arm processing or Intel processor, or on any other processor, whether running on a mainframe like galaxy 2, a PC for personal use, or on any other machine, all follow this set of use models.
To sum up, the computer only recognizes 0 and 1 encoding strings. Any program must eventually convert to 0 and 1 encoding strings, and the types of 0 and 1 encoding are limited, the computer operates according to the 0 and 1 encoding commands. In this case, the reader should think that the computer is very simple.
The core of a computer is a processor, also known as a CPU. It recognizes 0 and 1 encoding and performs various operations and data processing accordingly. The goal of this book is to achieve a CPU.
1.2 architecture and Instruction Set
Similar to people in different countries using different texts, different processors also use different commands. In this way, a program written for processor A cannot be used directly on processor B and needs to be rewritten, it can be used only after compilation and assembly, reducing the portability of the software. Obviously, it is extremely inconvenient.
IBM has introduced the instruction set architecture (ISA: instruction set architecture) to its system/360 computers to free them from the hassle of repeatedly writing software) the hardware information required for programming is abstracted from the hardware system. In this way, software engineers can program Isa, the developed software can be applied to all computers that match the ISA without modification. ISA is used to describe the abstract machine used in programming, rather than the specific implementation of this machine. From the perspective of software personnel, ISA includes a set of instruction sets and some registers, you can write programs by knowing them.
A concept corresponding to ISA is microarchitecture, which is an implementation of the former. For example, many Intel processors follow the ISA of X86, however, each processor has its own microarchitecture. ISA is like a design specification, while micro-architecture is a specific implementation. The same Isa, different micro-architectures will bring different performance.
1.2.1 CISC and RISC
According to ISA, there are two types of computers: The Complex Instruction Set Computer (CISC: Complex Instruction Set Computer) and the short Instruction Set Computer (Proteus: CED Instruction Set Computer ). The main difference is that each instruction in CISC corresponds to different lengths of 0 and 1 encoded strings, while the length of each instruction in Proteus is fixed.
In the early days of computer development, people used assembly language programming to prefer powerful and easy-to-use instruction sets. processor designers designed instruction sets more powerful and flexible, in addition, the memory in that period was expensive and slow, so the instruction used variable-length encoding to save storage space. Since one instruction can complete many functions, this reduces the number of accesses to the memory and reduces the impact of slow memory access on program performance. The typical CISC instruction set architecture is Intel's X86 Isa. In the middle of the 1970s s, it was found that the frequency of using various commands in the CISC instruction set was very different. About 20% of the commands were used repeatedly, accounting for 80% of the whole program code. The remaining 80% of commands are not frequently used, and only account for 20% of the entire program code. Obviously, this structure is not reasonable. As a result, people proposed to re-design the instruction set and processor to reduce the number of commonly used commands and retain only common simple commands, in this way, the processor does not need to waste too much transistor to do those very complex and rarely used functions, so it produces a hierarchical. In 1979, David pattern of the University of California, Berkeley, first proposed the concept of the "RISC", which is not just a simple command reduction, the main purpose is to study how to make the computer structure simpler and more reasonable to increase the computing speed. It features fixed instruction length, fewer instruction formats, fewer addressing methods, and a large number of registers. Since most of the commands used in the Proteus are simple commands that can be completed within a clock cycle, the frequency of the processor is greatly increased and the pipeline is easy to design. It was a milestone in computer history, so someone joked about defining it as all the processors released after 1985.
Intel also tried to use the RISC processor, but it was unsuccessful due to compatibility issues. Later in 1995, Intel's David B. papworth and his colleagues designed the Pentium Pro processor. In this processor, x86 commands are first decoded as Microoperation (uops ), later, the execution process adopted the RISC kernel, which continued until now.
1.2.2 main ISA types
At present, there is no unified ISA accepted by various processor manufacturers, but there are multiple Isa, just like there are multiple languages in the world, but there are only several major languages: chinese, English, French, and Russian. There are only a few major ISA types: x86, arm, iSCSI, power, MIPS. Except for x86, Which is cisc isa, the rest of the ISA types are.
1. x86
The X86 architecture was first introduced in 1978 as an Intel 8086 processor. Three years later, Intel 8086 was chosen for ibm pc, and x86 became a standard platform for personal computers, it became the most successful instruction set architecture in history. Currently, most PCs use processors compatible with the x86 instruction set architecture.
2. Arm
In 1985, the British company acorn designed its first generation 32-bit, 6 MHz processor named acorn RISC machine (arm1. In 1990, Apple and the integrated storage technology company jointly funded the restructuring of acorn as an arm computer company. At the same time, they no longer involved in specific chip production and only sold IP cores. Arm designs low-power, high-performance CPU cores and then authorizes other companies to design and produce specific processor chips. Arm focuses on low power consumption and low cost, mainly for embedded applications. With the popularization of mobile devices such as smartphones and tablets, arm has developed very rapidly.
ARM architecture from V4, v4t, V5, v5e, V6, developed to V7, V7 is divided into v7-A, v7-R, v7-M, etc., Apple's A9 processor is arm v7-A architecture.
3.
The scalable processor architecture, a scalable processor architecture, was first proposed by sun in 1980s, a study by Berkeley in the 1985 s. In 1989, sun became a commercial architecture and produced a platinum series processor. Sun used it on high-performance workstations and servers. The current versions of the iSCSI architecture include V8 and V9.
The open source code processor, such as Sun's ultrasparc T1 and Leon, is built on the open source architecture. Among them, Leon is a processor of the HPC V8 architecture and has been released to leon4. Initially, leon1 and leon2 were released by the European Space Agency, and leon3 was designed and released by gaisler research. In 2008, aeroflex acquired gaisler research and released leon4 in January 2010, however, the source code of leon4 has not yet been published. The Leon series uses VHDL to write code, which was originally intended to be used on spacecraft.
4. Power
Performance Optimization with enhanced RISC is an instruction set architecture designed and developed by IBM. Many of IBM's servers, mainframes, minicomputers, and workstations use power-based microprocessors as their main CPUs.
In 1991, the aim Alliance was established (the first letter of apple, IBM, and Motorola) to modify the Power Architecture and form a PowerPC architecture. In 2004, IBM launched the power.org alliance and released a unified instruction set architecture, which unified power and PowerPC into the new power architecture.
5. MIPS
MIPs stands for the microprocessor without interlocked piped stages, which was an important representative of the back-to-back world of the 1980s S. Its designer John Hennessy was then a professor at Stanford University. The original design was based on the following philosophy: using relatively simple commands, combined with excellent compilers and hardware that uses pipelines to execute commands, you can use a smaller crystal area to produce faster processors. This idea was so successful that in 1984, the MIPs computer system company was established to commercialize the mips architecture. Over the next decade, the mips architecture has been developed in many aspects and has been applied in workstations and server systems. The mips architecture also evolved from MIPs I, MIPS II, MIPS III, MIPS IV, MIPS V, and mips32 to mips64. John Hennessy and David pattern, the leader of the concept of "computer architecture-quantitative research methods", a textbook with a wide influence on the computer field, have been published in the fifth version.
The Chinese godson processor adopts the mips architecture. The processor to be implemented in this book also uses the mips architecture, which involves two problems.
(1) Why should we adopt an existing instruction set architecture?
This is because the existing instruction set architecture has formed a complete environment, including mature compilers and a large number of applications. These environments can be directly used using the existing instruction set architecture. On the contrary, if you design your own unique set of instruction set architecture, you need to re-develop the compiler and application software on your own, resulting in a huge workload. In terms of language, a person can certainly invent and use his own unique language, but how can he communicate with others? If you cannot communicate with others, then good languages are doomed to disappear.
(2) Why the mips architecture?
First, the design of MIPs is a classic in the mips architecture. Many processors have absorbed the design ideas. Second, the patent period of instructions in the mips architecture has passed and can be freely used.
This chapter will focus on the MIPs instruction set architecture.
Continue tomorrow!