Matt Godbolt: Five things you didn't realise your CPU did for you
youtube.com
youtube.com
- Prefetches predictable load patterns.
- Converts to micro-code.
- Does OoO execution.
- Renames registers to SSA-like form.
- Predicts branches.
(Man, seeing how much work the processor goes through to hammer x86 into something vaguely optimized, I really wish something like the Mill architecture had taken over so we'd get an instructions set made for compilers, not one that requires its own invisible compiler in the chip.)
The Mill architecture supposedly does this; the ISA has three variants for different product lines.
It is however not secure in many cases, but I also think that newer implementations do better in this regard so it is probably not a fundamental issue.
And about targeting microcode directly, that would be a new ISA which is not desireable and also decoding instructions is not that big of a deal compared to the rest of the core so it is not worth the hassle of switching ISAs.
If compilers had more direct control of the microcode opcodes, speculative execution wouldn't even be so necessary. LLVM is quite good at doing SSA for itself without support for it in the processor as well.
We're now emulating a 40 year old architecture even for non legacy software, for what? Heating up silicon? That doesn't seem very energy efficient.
Besides taking less memory, if you can “decompress” the ISA faster than memory bandwidth would otherwise allow, it’s a net win.
There are many other downsides to x86, like variable length instructions, of course, but it’s something to consider.
It’s a lot more complex and potentially dangerous, but all high performance cores do this so it’s obviously worth it.
The machinery to instrument and calculate probabilities on branches. Maintaining state enough that speculatively executed branches can be rolled back. That sounds non-trivial and I imagine it would take a lot of real estate, energy, etc.
Agreed.