golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.22k stars 17.37k forks source link

x/sys/cpu: ARM64.HasAES = false on Apple Silicon (M1 Max) #68150

Open aadomnicai opened 2 weeks ago

aadomnicai commented 2 weeks ago

What version of Go are you using (go version)?

$ go version
go version go1.22.2 darwin/arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/alexandre.adomnicai/Library/Caches/go-build'
GOENV='/Users/alexandre.adomnicai/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/alexandre.adomnicai/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/alexandre.adomnicai/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/alexandre.adomnicai/Github/test_aes/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/31/w4yrhpr51z15j6f6wml61kvr0000gp/T/go-build1310596040=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOROOT/bin/go version: go version go1.22.2 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.22.2
uname -v: Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
ProductName:        macOS
ProductVersion:     14.5
BuildVersion:       23F79
lldb --version: lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)

What did you do?

Run a simple test to check whether hardware AES is used on my machine. The following is simply run with go test -tags ""

package aes_test

import (
    "fmt"
    "testing"

    "golang.org/x/sys/cpu"
)

func TestEncryptDecryptMessage(t *testing.T) {
    fmt.Printf("Hardware AES is used: %t\n", cpu.ARM64.HasAES)
}

What did you expect to see?

I would have expected Hardware AES is used: true since AES instructions are supported. In go/src/internal/cpu/cpu_arm64_darwin.go, the variable cpu.ARM64.HasAES should be set to true, and I cannot understand why that is not the case since the build conditions //go:build arm64 && darwin && !ios should be satisfied?

What did you see instead?

I get Hardware AES is used: false instead.

gabyhelp commented 2 weeks ago

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

seankhliao commented 2 weeks ago

It looks like x/sys/cpu parses registers https://go.googlesource.com/sys/+/76700875dfcc135287c18189252576117307b695/cpu/cpu_arm64.go#73 While the go repo's internal/cpu just assumes support https://go.googlesource.com/go/+/e8ee1dc4f9e2632ba1018610d1a1187743ae397f/src/internal/cpu/cpu_arm64_darwin.go#20

ericlagergren commented 2 weeks ago

See https://go-review.googlesource.com/c/sys/+/397754

aadomnicai commented 2 weeks ago

See https://go-review.googlesource.com/c/sys/+/397754

Thanks for pointing this out. Any insight on why this has not been merged so far?

ericlagergren commented 2 weeks ago

See https://go-review.googlesource.com/c/sys/+/397754

Thanks for pointing this out.

Any insight on why this has not been merged so far?

I need to make the fixes requested by the reviewers, then it needs to be reviewed again.

ericlagergren commented 2 weeks ago

This is mostly a dupe of https://github.com/golang/go/issues/43046

aadomnicai commented 1 week ago

https://go-review.googlesource.com/c/sys/+/397754

Your responses to the remaining two issues make sense to me, and it seems that it could be merged as it is. Any idea of why the reviewer did not provide feedback?