The purpose/use of the speculations of computers/laptops.

1.68K views

I’ve always just seen the most mainstream processors or the most popular graphics card to use but little do you know, I have no idea what their functions are and their purpose.

In: Technology

2 Answers

Anonymous 0 Comments

By “speculations” did you mean “specifications”, aka specs?

Anonymous 0 Comments

If you’re talking about [speculative execution](https://en.wikipedia.org/wiki/Speculative_execution), its purpose is to speed up processors.

Processors are actually doing many things at a time in a process called pipelining. A common analogy is [laundry](https://cs.stanford.edu/people/eroberts/courses/soco/projects/risc/pipelining/index.html) – if you’re trying to do many loads of laundry in one set of machines, you could wash, dry, and fold an entire load before moving on to the next one, but then you’d be wasting time. To speed up the process, you can wash one load, and then once it’s drying start washing the second load. Because you have multiple resources available to you, you can cut the total time to do your four loads of laundry by having multiple things going on in parallel.

Processors do this because, most of the time, it lets you speed up the processor by a lot. Instructions are broken into pieces (e.g. get the instruction, do all memory operations, do all arithmetic operations, do all write operations). By allowing multiple instructions to be happening at the same time, you can have each sub-step be faster, allowing you to increase your clock speed.

However, there comes an issue when instructions depend on past instructions. For example, if you do one thing when some value is positive, and something else once it’s negative, you have to first wait for that value to be calculated before deciding which action to do. One solution is just to leave a gap in the pipeline, and waste a few cycles. Naturally, CPU designers didn’t want to do this, and this is where speculative execution comes in. The CPU makes an informed guess of what the result will probably be, and then starts doing those actions. For example, it’ll just guess that the value turned out less than 0, and goes on to do that.

If the prediction was correct, great! The speculative work turns out to have been useful. However, if the prediction was wrong, the CPU has to switch tracks, and throw away the work. We lose those cycles, but on average we’ll be doing faster than if we had left the pipeline empty, so it’s a net win. The better the prediction, the better the win.

What researchers have recently discovered is that this work was not fully discarded. It turns out that the CPU, while doing the speculation, left behind small traces that could then be used by the program to extract information it shouldn’t be allowed to know. It takes advantage that a lot of protections are built into software, while the speculation happens on the CPU, bypassing protections in the software until the program ‘catches up’ to the speculation.