Skip to content

Commit

Permalink
internal/cpu: fix cpu cacheLineSize for arm64 darwin(a.k.a. M1)
Browse files Browse the repository at this point in the history
The existing value for M1 is 64, which is the same as other arm64 cpus.
But the correct cacheLineSize for M1 should be 128, which can be
verified using the following command:

$ sysctl -a hw | grep cachelinesize
hw.cachelinesize: 128

Fixes golang#53075
  • Loading branch information
PureWhiteWu committed May 25, 2022
1 parent 7791e93 commit 9b88286
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/internal/cpu/cpu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build arm64 && !darwin

package cpu

const CacheLinePadSize = 64
Expand Down
23 changes: 23 additions & 0 deletions src/internal/cpu/cpu_arm64_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@

package cpu

const CacheLinePadSize = 128

func doinit() {
options = []option{
{Name: "aes", Feature: &ARM64.HasAES},
{Name: "pmull", Feature: &ARM64.HasPMULL},
{Name: "sha1", Feature: &ARM64.HasSHA1},
{Name: "sha2", Feature: &ARM64.HasSHA2},
{Name: "crc32", Feature: &ARM64.HasCRC32},
{Name: "atomics", Feature: &ARM64.HasATOMICS},
{Name: "cpuid", Feature: &ARM64.HasCPUID},
{Name: "isNeoverseN1", Feature: &ARM64.IsNeoverseN1},
{Name: "isZeus", Feature: &ARM64.IsZeus},
}

// arm64 uses different ways to detect CPU features at runtime depending on the operating system.
osInit()
}

func getisar0() uint64

func getMIDR() uint64

func osInit() {
ARM64.HasATOMICS = sysctlEnabled([]byte("hw.optional.armv8_1_atomics\x00"))
ARM64.HasCRC32 = sysctlEnabled([]byte("hw.optional.armv8_crc32\x00"))
Expand Down

0 comments on commit 9b88286

Please sign in to comment.