4 ms·
Author here - I just want to drop in to reiterate how awesome register renaming is. It's a bit weird to try and understand, but it is crucial to how these out-o
by brucedawson 8y ago
Author here - I just want to drop in to reiterate how awesome register renaming is. It's a bit weird to try and understand, but it is crucial to how these out-of-order processors run, and it is the trick which lets the register zeroing run so efficiently.
An x86-64 CPU has sixteen integer registers, but 100-200 physical integer registers. Every time an instruction writes to, say, RAX the renamer chooses an available physical register and does the write to it, recording the fact that RAX is now physical-register #137. This allows the breaking of dependency chains, thus allowing execution parallelism.
In the case of the zeroing instructions the register renamer says "RAX now maps to physical-register #0" where that is a register reserved for the purpose of being zero. No execution is needed. It's beautiful.
For more details read up on out-of-order execution and register renaming.
- theoh 8y agoThis is a good place to start: https://en.wikipedia.org/wiki/Tomasulo_algorithm https://en.wikipedia.org/wiki/Tomasulo_algorithm. Butler Lampson mentions register renaming as one of a dozen paradigmatic neat techniques in this 2015 presentation: http://bwlampson.site/Slides/Hints%20and%20principles%20(HLF%202015)%20abstract.htm http://bwlampson.site/Slides/Hints%20and%20principles%20(HLF... Edit: corrected link It's easy for software people not to ever encounter it!
- brucedawson 8y ago> It's easy for software people not to ever encounter it! Yep, because it does its magic without any intervention required. One concrete example that I like is this: mov rax,[rsi+0] mov [rdi+0],rax mov rax,[rsi+8] mov [rdi+8],rax This moves sixteen bytes of memory, all of it going through rax. Without register renaming the third instruction can't run until the second instruction completes, because they're both using rax. With register renaming the third instruction uses a different physical register for rax, and the out-of-order engine can do the loads in parallel and the stores in parallel. Before anybody freaks out - register renaming doesn't change the semantics of your program. It just makes your program run faster. It just means that you can write code like the above - there's no need to rearrange the instructions and use multiple temporary registers, because the CPU will do it for you, and will dirty fewer architectural registers.
- stcredzero 8y agoI wonder how often (golang, let's say) x, y = y, x Just becomes register renaming? What about array[i], array[j] = array[j], array[i] ?
- theoh 8y agoRegister renaming doesn't mean changing the name of registers you already have (which isn't really possible), it just adds new "virtual"/concurrent registers that conserve the semantics of operations. So what you say doesn't sound right to me: register renaming is actually a way of (re)labelling the results of small ALU jobs to be distributed for concurrent execution. It's not in any way about switching references around on live data as you suggest. Not 100% sure about this but the flavour of what I've read doesn't involve that kind of fancy footwork.
- brucedawson 8y agoIf the "x, y = y, x" is implemented using the x86 "swap" instruction then the CPU could implement the swap using register renaming, I think - with no execution unit activity required. I don't know if it does. But everything that golang (or C or C++ or whatever) does has to be expressed in assembly language, and assembly language doesn't directly control register renaming - it's a hidden implementation detail.
- stcredzero 8y agoThanks. That clarifies things.