It is good for programmers to understand what goes on inside a processor. The CPU is at the heart of our career.
What goes on inside the CPU? How long does it take for one instruction to run? What does it mean when a new CPU has a 12-stage pipeline, or 18-stage pipeline, or even a "deep" 31-stage pipeline?
Programs generally treat the CPU as a black box. Instructions go into the box in order, instructions come out of the box in order, and some processing magic happens inside.
As a programmer, it is useful to learn what happens inside the box. This is especially true if you will be working on tasks like program optimization. If you don't know what is going on inside the CPU, how can you optimize for it?
A primer for those with a less formal background.
(Score: 2) by shortscreen on Saturday October 31 2015, @08:37AM
On old CPUs (old as in '80s) branching usually took more cycles than not branching. So you might arrange your code so that conditional branches would usually fail. Of course, at the end of your loop there is always a branch back to the beginning of the loop that is likely to be taken. So later on, there were some CPUs with a simplistic branch prediction that assumed backwards-pointing branches would be taken. There were also CPUs that avoided a pipeline stall by continuing to execute instructions following a branch instruction regardless of whether it ended up being taken (delayed branch).
Pentium 4s have a "hint" opcode. Newer CPUs just ignore it though because they have so many other features to mitigate stalls that it's not even a big deal anymore.
(Score: 0) by Anonymous Coward on Saturday October 31 2015, @09:49PM
Thanks, I was wondering if it possible for me to do something like this:
If I know a priori that x is less than y about 25% of the time, it seems this info should be able to translate into some kind of performance improvement.
(Score: 2) by maxwell demon on Monday November 02 2015, @12:24AM
There's a __builtin_expect in gcc which however doesn't use a percentage.
The Tao of math: The numbers you can count are not the real numbers.