Imagine your task is to explain the operation of a CPU, to someone who has a little familiarity with programming. Here’s how I would be tempted to set about explaining it:
The processor runs a fetch-execute cycle. It fetches a single instruction from memory, which is then executed. For example, a LOAD instruction loads a value from memory into a processor register, an ADD instruction adds two registers, and a STORE instruction stores a value from a register back into memory. Once an instruction has been executed, the next instruction is fetched and executed. The number of instructions that can be executed in a second is known as the clock speed, so 1 Mhz is 1 million instructions per second.
I think that it’s a reasonable explanation of how a processor works, one which we are familiar with, and which gets the gist across to someone not familiar with processors. It’s also, in terms of modern processors, almost completely wrong.
Let’s quickly go through why our processor explanation is wrong:
- Cache: instructions and values are not usually fetched directly from memory — instead there’s a cache (or three) in the way that allow for faster-seeming access to memory.
- Pipelining: instructions are pipelined, so that the second instruction can begin executing before the first is finished.
- Out-Of-Order Execution: related to pipelining, instructions can actually be re-ordered if they are independent and end up executed in a different order to that of the original assembly program.
- Speculative execution: linked to pipelining, instructions can execute speculatively based on a guess as to which branch will be taken in a program, then the results actually have to be rewound (known as a pipeline stall).
- Microcode: the loaded instruction is generally not executed directly, but is instead translated into a lower-level form of code called microcode which is what the processor actually executes.
Between all those issues, it’s almost impossible to map clock speed to instructions, as the speed with which an instruction can execute depends on availability of relevant memory in the cache, the pipelining effects of nearby instructions, and the amount of microcode instructions into which it is translated.
What to do?
So what should we do — should we teach all the nitty-gritty details in our GCSEs? Of course not! Our original explanation is essentially a model of a processor (based on ’70s-era CPUs). Other disciplines, notably chemistry but also physics, have long been teaching simplified models to beginners, and the study of the processor in computing is exactly the same. The model is inaccurate, a lie, but to quote Box on the issue of scientific models: all models are wrong, but some are useful.