Dear all,
I stumbled over a strange performance degradation when using unsafe
pointers. I took a look at the assembly and was surprised to see a number
seemingly redundant nil checks using the LEAQ and TESTB instructions.
A minimal reproducer is the following function:
func getOff(a *uint64, i int) uint64 {
return *(*uint64)(Pointer(uintptr(Pointer(a)) + uintptr(i)*8))
}
, which generates this assembly (removed the boilerplate):
AX: i int
CX: a *uint64
v16 00005 (55) LEAQ (CX)(AX*8), DX
v18 00006 (55) TESTB AX, (DX)
v19 00007 (55) MOVQ (CX)(AX*8), AX
AX: return value uint64
As you can see the MOVQ (7) is preceeded by LEAQ (5) calculating the same
address and then TESTB (6) on said address. This is presumably a nil check,
but I do not understand what this accomplishes.
I'm confused what's going on here. I attached the ssa.html for further
analysis.
Another question: Why does the nil check take two instructions. Can't it be
done using MOVQ?
Best regards,
Florian
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.