The Computer Is A Lie

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.

Complicating Factors

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.

Advertisements

One thought on “The Computer Is A Lie

  1. Models are certainly useful, especially at KS4. I remember being taught the simple “solar system” model of the atom at GCSE and how this was amended in A-Level Physics. The process of applying our new knowledge (e.g. the orbiting electrons would have to accelerate to maintain a constant velocity; accelerating charges emit electromagnetic radiation, leading to atomic collapse) to critiquing the simplistic GCSE model was a useful learning process.

    Similarly, by teaching the simple von Neumann architecture (perhaps contrasting with the Harvard model), we can introduce a basic model of a computer and how it executes instructions and processes data…and introduce instruction-level parallelism et al. when it is appropriate!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s