golang Duff’s devices
I’m just starting to scratch golang surface, and until now it has been a pleasant experience.
golang feels solid and fast.
Let me share with you a few golang internals on this notes as long as I’m stumbling upon them:
Today I’ve tripped over some golang source code that looks like a copy-paste frenzy, but is a very clever assembler trick to make the processor go as fast as possible:
The code is in runtime/asm_amd64.s and looks like this:
STOSQ
STOSQ
STOSQ
STOSQ
STOSQ
STOSQ
STOSQ
STOSQ
STOSQ
...
… repeated 128 27 times
and later:
MOVQ (SI),CX
ADDQ $8,SI
MOVQ CX,(DI)
ADDQ $8,DI
MOVQ (SI),CX
ADDQ $8,SI
MOVQ CX,(DI)
ADDQ $8,DI
MOVQ (SI),CX
ADDQ $8,SI
MOVQ CX,(DI)
ADDQ $8,DI
...
… repeated, again, 27 times, (512 LOC)
It turns out that this is a...