You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the non-dumb versions working as fast as the dumb one.
What did you see instead?
The dumb one is much faster. Judging by the output of --gcflags '-S', the dumb version compiles to two register moves (MOVQ and MOVW), while the other two call runtime.memmove.
Go does not currently unroll loops, which is why anonLoop is slower.
We do however detect zeroing loops like this:
x := ip[6:]
for i := range x {
x[i] = 0
}
With that, you'll get one call to memclrNoHeapPointers instead of a loop.
anonCopy is just the prove pass not being able to determine that the size is constant. (Or not having a way to push that info downstream.) We do optimize small, constant-sized memmoves to direct instructions.
If you do copy(ip[6:16], a[:]), it works. (Although it is still a move, not a zero. That might be fixable as well.)
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, see the second line of
go version
output.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/QAzxEwqCboZ
The “dumb” zeroing version:
The non-dumb versions:
What did you expect to see?
One of the non-dumb versions working as fast as the dumb one.
What did you see instead?
The dumb one is much faster. Judging by the output of
--gcflags '-S'
, the dumb version compiles to two register moves (MOVQ
andMOVW
), while the other two callruntime.memmove
.The text was updated successfully, but these errors were encountered: