[go/dev.simd] [dev.simd] internal/cpu: report AVX1 and 2 as supported on macOS 15 Rosetta 2

5 views
Skip to first unread message

Cherry Mui (Gerrit)

unread,
Sep 2, 2025, 10:25:33 AM9/2/25
to goph...@pubsubhelper.golang.org, Austin Clements, David Chase, Junyang Shao, Go LUCI, golang-co...@googlegroups.com
Attention needed from Austin Clements, David Chase and Junyang Shao

New activity on the change

Open in Gerrit

Related details

Attention is currently required from:
  • Austin Clements
  • David Chase
  • Junyang Shao
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: dev.simd
Gerrit-Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
Gerrit-Change-Number: 700055
Gerrit-PatchSet: 2
Gerrit-Owner: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
Gerrit-Attention: Junyang Shao <shaoj...@google.com>
Gerrit-Attention: Austin Clements <aus...@google.com>
Gerrit-Attention: David Chase <drc...@google.com>
Gerrit-Comment-Date: Tue, 02 Sep 2025 14:25:29 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Junyang Shao (Gerrit)

unread,
Sep 2, 2025, 10:45:11 AM9/2/25
to Cherry Mui, goph...@pubsubhelper.golang.org, Austin Clements, David Chase, Go LUCI, golang-co...@googlegroups.com
Attention needed from Austin Clements, Cherry Mui and David Chase

Junyang Shao voted and added 1 comment

Votes added by Junyang Shao

Code-Review+1

1 comment

File src/runtime/testdata/testprog/cpuflags_amd64.s
Line 8, Patchset 2 (Latest): VXORPS X1, X2, X3
Junyang Shao . unresolved

Question from the CL description: does this only sometimes break when runtime does not safe the correct state? Since it's not a SIGILL but a potential value corruption.

I am wondering if we should actually make `checkAVX` return something that relies on a correct AVX instruction set being emulated by Rosetta.

Open in Gerrit

Related details

Attention is currently required from:
  • Austin Clements
  • Cherry Mui
  • David Chase
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: dev.simd
    Gerrit-Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
    Gerrit-Change-Number: 700055
    Gerrit-PatchSet: 2
    Gerrit-Owner: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Austin Clements <aus...@google.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
    Gerrit-Attention: Austin Clements <aus...@google.com>
    Gerrit-Attention: David Chase <drc...@google.com>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-Comment-Date: Tue, 02 Sep 2025 14:45:06 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Cherry Mui (Gerrit)

    unread,
    Sep 2, 2025, 12:27:07 PM9/2/25
    to goph...@pubsubhelper.golang.org, Junyang Shao, Austin Clements, David Chase, Go LUCI, golang-co...@googlegroups.com
    Attention needed from Austin Clements, David Chase and Junyang Shao

    Cherry Mui added 1 comment

    File src/runtime/testdata/testprog/cpuflags_amd64.s
    Junyang Shao . resolved

    Question from the CL description: does this only sometimes break when runtime does not safe the correct state? Since it's not a SIGILL but a potential value corruption.

    I am wondering if we should actually make `checkAVX` return something that relies on a correct AVX instruction set being emulated by Rosetta.

    Cherry Mui

    The purpose of this CL is to make the Go runtime's knowledge on AVX availability match the system's, i.e. whether the instruction faults. It's not that Rosetta 2 will run the instruction incorrectly, but that it runs whereas the Go runtime thinks it is not available (i.e. will fault). The data corruption comes from the Go runtime if the information is incorrect, e.g. async preempt doesn't save AVX registers, or it doesn't initialize the zero register correctly.

    This particular test is just to see if it faults, and see if it matches the runtime's HasAVX.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Austin Clements
    • David Chase
    • Junyang Shao
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: dev.simd
      Gerrit-Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
      Gerrit-Change-Number: 700055
      Gerrit-PatchSet: 2
      Gerrit-Owner: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: David Chase <drc...@google.com>
      Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
      Gerrit-Attention: Junyang Shao <shaoj...@google.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Attention: David Chase <drc...@google.com>
      Gerrit-Comment-Date: Tue, 02 Sep 2025 16:27:03 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Junyang Shao <shaoj...@google.com>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Junyang Shao (Gerrit)

      unread,
      Sep 2, 2025, 12:40:16 PM9/2/25
      to Cherry Mui, goph...@pubsubhelper.golang.org, Austin Clements, David Chase, Go LUCI, golang-co...@googlegroups.com
      Attention needed from Austin Clements, Cherry Mui and David Chase

      Junyang Shao added 1 comment

      File src/runtime/testdata/testprog/cpuflags_amd64.s
      Junyang Shao . resolved

      Question from the CL description: does this only sometimes break when runtime does not safe the correct state? Since it's not a SIGILL but a potential value corruption.

      I am wondering if we should actually make `checkAVX` return something that relies on a correct AVX instruction set being emulated by Rosetta.

      Cherry Mui

      The purpose of this CL is to make the Go runtime's knowledge on AVX availability match the system's, i.e. whether the instruction faults. It's not that Rosetta 2 will run the instruction incorrectly, but that it runs whereas the Go runtime thinks it is not available (i.e. will fault). The data corruption comes from the Go runtime if the information is incorrect, e.g. async preempt doesn't save AVX registers, or it doesn't initialize the zero register correctly.

      This particular test is just to see if it faults, and see if it matches the runtime's HasAVX.

      Junyang Shao

      Yeah that's what I meant, does it fault always? It could be that X1/X2/X3 happen to be not in use so not saving them is fine. And async preempt is not always happening.

      Maybe those false negative cases are rare. Anyway this CL is more about the functionality. Thanks! 😄

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Austin Clements
      • Cherry Mui
      • David Chase
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: dev.simd
      Gerrit-Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
      Gerrit-Change-Number: 700055
      Gerrit-PatchSet: 2
      Gerrit-Owner: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: David Chase <drc...@google.com>
      Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Attention: David Chase <drc...@google.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Comment-Date: Tue, 02 Sep 2025 16:40:12 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Junyang Shao <shaoj...@google.com>
      Comment-In-Reply-To: Cherry Mui <cher...@google.com>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      David Chase (Gerrit)

      unread,
      Sep 2, 2025, 2:56:20 PM9/2/25
      to Cherry Mui, goph...@pubsubhelper.golang.org, Junyang Shao, Austin Clements, Go LUCI, golang-co...@googlegroups.com
      Attention needed from Austin Clements and Cherry Mui

      David Chase voted and added 1 comment

      Votes added by David Chase

      Code-Review+2

      1 comment

      Patchset-level comments
      File-level comment, Patchset 2 (Latest):
      David Chase . resolved

      We had desk-to-desk conversation, "does this need a backport", and the conclusion was no, because until Go SIMD extensions are a thing, it's all in assembly language and already reliably gated by feature checks.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Austin Clements
      • Cherry Mui
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: dev.simd
      Gerrit-Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
      Gerrit-Change-Number: 700055
      Gerrit-PatchSet: 2
      Gerrit-Owner: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: David Chase <drc...@google.com>
      Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Comment-Date: Tue, 02 Sep 2025 18:56:17 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      open
      diffy

      Cherry Mui (Gerrit)

      unread,
      Sep 2, 2025, 5:17:26 PM9/2/25
      to goph...@pubsubhelper.golang.org, David Chase, Junyang Shao, Austin Clements, Go LUCI, golang-co...@googlegroups.com
      Attention needed from Austin Clements and Junyang Shao

      Cherry Mui added 2 comments

      Patchset-level comments
      Cherry Mui . resolved

      Thanks.

      File src/runtime/testdata/testprog/cpuflags_amd64.s
      Junyang Shao . resolved

      Question from the CL description: does this only sometimes break when runtime does not safe the correct state? Since it's not a SIGILL but a potential value corruption.

      I am wondering if we should actually make `checkAVX` return something that relies on a correct AVX instruction set being emulated by Rosetta.

      Cherry Mui

      The purpose of this CL is to make the Go runtime's knowledge on AVX availability match the system's, i.e. whether the instruction faults. It's not that Rosetta 2 will run the instruction incorrectly, but that it runs whereas the Go runtime thinks it is not available (i.e. will fault). The data corruption comes from the Go runtime if the information is incorrect, e.g. async preempt doesn't save AVX registers, or it doesn't initialize the zero register correctly.

      This particular test is just to see if it faults, and see if it matches the runtime's HasAVX.

      Junyang Shao

      Yeah that's what I meant, does it fault always? It could be that X1/X2/X3 happen to be not in use so not saving them is fine. And async preempt is not always happening.

      Maybe those false negative cases are rare. Anyway this CL is more about the functionality. Thanks! 😄

      Cherry Mui

      Yes, if it faults, it always faults. I don't think any hardware or VM would implement it as _sometimes_ faults.

      We don't async preempt assembly code, so that would be irrelevant here.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Austin Clements
      • Junyang Shao
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: dev.simd
      Gerrit-Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
      Gerrit-Change-Number: 700055
      Gerrit-PatchSet: 2
      Gerrit-Owner: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: David Chase <drc...@google.com>
      Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
      Gerrit-Attention: Junyang Shao <shaoj...@google.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Comment-Date: Tue, 02 Sep 2025 21:17:23 +0000
      satisfied_requirement
      open
      diffy

      Cherry Mui (Gerrit)

      unread,
      Sep 2, 2025, 5:17:29 PM9/2/25
      to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, David Chase, Junyang Shao, Austin Clements, Go LUCI, golang-co...@googlegroups.com

      Cherry Mui submitted the change

      Change information

      Commit message:
      [dev.simd] internal/cpu: report AVX1 and 2 as supported on macOS 15 Rosetta 2

      Apparently, on macOS 15 or newer, Rosetta 2 supports AVX1 and 2.
      However, neither CPUID nor the Apple-recommended sysctl says it
      has AVX. If AVX is used without checking the CPU feature, it may
      run fine without SIGILL, but the runtime doesn't know AVX is
      available therefore save and restore its states. This may lead to
      value corruption.

      Check if we are running under Rosetta 2 on macOS 15 or newer. If so,
      report AVX1 and 2 as supported.
      Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
      Reviewed-by: David Chase <drc...@google.com>
      Reviewed-by: Junyang Shao <shaoj...@google.com>
      Files:
      • M src/internal/cpu/cpu_arm64_darwin.go
      • A src/internal/cpu/cpu_darwin.go
      • M src/internal/cpu/cpu_x86.go
      • A src/internal/cpu/cpu_x86_darwin.go
      • A src/internal/cpu/cpu_x86_other.go
      • A src/runtime/cpuflags_amd64_test.go
      • M src/runtime/export_test.go
      • M src/runtime/os_darwin.go
      • A src/runtime/testdata/testprog/cpuflags_amd64.go
      • A src/runtime/testdata/testprog/cpuflags_amd64.s
      Change size: M
      Delta: 10 files changed, 170 insertions(+), 25 deletions(-)
      Branch: refs/heads/dev.simd
      Submit Requirements:
      • requirement satisfiedCode-Review: +2 by David Chase, +1 by Junyang Shao
      • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
      Open in Gerrit
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: merged
      Gerrit-Project: go
      Gerrit-Branch: dev.simd
      Gerrit-Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
      Gerrit-Change-Number: 700055
      Gerrit-PatchSet: 3
      open
      diffy
      satisfied_requirement

      Egon Elbre (Gerrit)

      unread,
      Jan 17, 2026, 5:54:47 PM (13 hours ago) Jan 17
      to Cherry Mui, goph...@pubsubhelper.golang.org, David Chase, Junyang Shao, Austin Clements, Go LUCI, golang-co...@googlegroups.com
      Attention needed from Cherry Mui

      Egon Elbre added 1 comment

      File src/internal/cpu/cpu_x86_darwin.go
      Line 15, Patchset 3 (Latest): // TODO: check if any other feature is actually supported.
      Egon Elbre . unresolved

      I was debugging the feature support due to https://go-review.googlesource.com/c/sys/+/737260 and found some additional information about this.

      Rosetta ends up reporting AVX and AVX2 features only when `ROSETTA_ADVERTISE_AVX=1` is set. After it's set, CPUID reading will work as intended.

      For example `golang.org/x/sys/cpu.X86` will then additionally report:

      ```
      HasAVX
      HasAVX2
      HasBMI1
      HasBMI2
      HasFMA
      HasOSXSAVE
      HasRDRAND
      ```

      If I would hazard to guess, the reason they didn't enable these by default is because the performance of SSE code can be faster. AVX uses 256bit instructions, but macs only have 128bit registers -- so the AVX instructions are translated to several neon instructions.

      In other words -- the instructions should still work under Rosetta, however, they might be slower than using SSE.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cherry Mui
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: dev.simd
      Gerrit-Change-Id: Ib981379405b1ae28faa378f051096827d760a4cc
      Gerrit-Change-Number: 700055
      Gerrit-PatchSet: 3
      Gerrit-Owner: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: David Chase <drc...@google.com>
      Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
      Gerrit-CC: Egon Elbre <egon...@gmail.com>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Comment-Date: Sat, 17 Jan 2026 22:54:37 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages