3 ms·
> 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 i
by 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.