-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Reading the Go 1.18 release notes, there are sort of two naive models that you could have about this:
Go 1.18 introduces the new GOAMD64 environment variable, which selects a mininum target version of the AMD64 architecture. Allowed values are v1, v2, v3, or v4. Each higher level requires, and takes advantage of, additional processor features. A detailed description can be found here.
The GOAMD64 environment variable defaults to v1.
Model 1: Setting these variables at compile time means Go will replace the worse CPU instructions with the better CPU instructions in the generated binary.
Model 2: Both instructions are compiled into the binary, and at runtime Go will read the GOAMD64 environment variable and use the better CPU instructions instead of the worse CPU instructions, if they are available.
I would guess that Model 1 is what you are going for. But that's also a little confusing to me because I believe that the compiler does CPU feature detection already to determine which instructions are supported, at least I think I've seen commits to that effect. So reading the documentation, I am confused why we now need an environment variable. My colleague also tried to read through the code to figure out where Go was using any of the new CPU instructions and couldn't find anything.
I think the doc could benefit from another sentence or two explaining a bit more context about why this is necessary now, or linking to more information.