Skip to content

doc/go1.18: clarify when/why to set GOAMD64 architecture values #50589

@kevinburkesegment

Description

@kevinburkesegment

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions