18 Commits

Author SHA1 Message Date
khr@golang.org
2f44229755 sys/cpu: add symbolic constants for remaining cpuid bits
Change-Id: Ia6afa8f69598fc929c1ea21465e656b5a95e656e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/731322
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-12-19 08:52:28 -08:00
khr@golang.org
e5770d27b7 sys/cpu: use symbolic names for masks
Masks declarations are copied from internal/cpu. All the 1<<N masks
that have a corresponding named constant are swapped out.

Change-Id: I6cfb053179a16611f4404719d92c182464a67d7f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/731321
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-12-19 08:52:22 -08:00
khr@golang.org
714a44c845 sys/cpu: modify x86 port to match what internal/cpu does
The way we call isSet is different in the two. Normalize x/sys
to match internal/cpu.

This was done using (mostly) gopls' quick fix, to ensure we
don't miss any of the transpositions.

Change-Id: I0b66152e194d46ed9299550e12641cc798f8b11b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/731320
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-12-19 08:52:16 -08:00
Grigorii Khvatskii
c75621413d cpu: add support for AVX-VNNI and IFMA detection
Added detection for x86 AVX-VNNI (VEX-coded Vector Neural Network
Instructions) and AVX-IFMA (VEX-coded Integer Fused Multiply Add),
including both the base VNNI set and the Int8 extention.

Fixes golang/go#71142

Change-Id: I9e8d18b2e8bf81d5d4313a4a47fdf731fb3d44dd
GitHub-Last-Rev: 32ea443fc2
GitHub-Pull-Request: golang/sys#242
Reviewed-on: https://go-review.googlesource.com/c/sys/+/641155
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-01-10 12:06:19 -08:00
Vaughn Iverson
8f2aa9fb48 cpu: conditionally re-enable AVX512 support on darwin/amd64
Darwin opmask clobbering bug was fixed in kernel version 21.3.0
as released in MacOS 12.2.0. This commit resolves issue by
checking for Darwin AVX512 support via a sysctl call with the
addition of a kernel minimum version check.

The kernel version check is completed without adding new
dependencies to x/sys/cpu. A sysctl call is accomplished by
copying a minimal amount of code from x/sys/unix, to retrieve
only the needed KERN_OSRELEASE value. This code is structured
in the same manner as an existing analogous AIX/PPC64 syscall.

The resulting dotted version string value is then parsed for
numeric comparison with a dependency free function.

All code in this contribution is structured to ease removal of
the special darwin/amd64 codepaths when that OS/arch combination
is eventually no longer supported by golang.

Resolves issue: golang/go#49233, reinstates fix for issue: golang/go#43089

Change-Id: I4755fc8b3865eb6562b0959ecc910e2c46ac6cb4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/620256
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: vsivsi@yahoo.com <vsivsi@yahoo.com>
2024-11-04 23:17:32 +00:00
Dmitri Shuralyov
1bfbee0e20 all: update go directive to 1.18
Done with:

go get go@1.18
go mod tidy
go fix ./...

Using go1.21.3.

Also update code generators to use only the new go:build lines,
not the old +build ones.

For golang/go#60268.

Change-Id: I6aabc42efb6ab3329981100e1db2263aac5e92a6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/534222
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-11 21:54:30 +00:00
Anton Kuklin
eabbd5c036 cpu: add support for amx detection
Added detection for x86 AMX,
including AMX-Tile, AMX-INT8 and AMX-BF16
instruction sets.

Change-Id: Ib3d663430b64d46b46b22bdd05d40f1992e37ee0
GitHub-Last-Rev: 7986ed6d4f
GitHub-Pull-Request: golang/sys#170
Reviewed-on: https://go-review.googlesource.com/c/sys/+/516815
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-08-14 16:42:18 +00:00
Keith Randall
7861aae155 cpu: pretend AVX-512 is disabled on Darwin
Darwin doesn't save/restore the AVX-512 mask registers when
processing a signal. Go generates lots of signals, which cause
the mask registers to randomly get clobbered. Better to pretend
that AVX-512 isn't supported.

Update golang/go#49233

Change-Id: I0dda77a6f205e10eefccd82e6f4f0f184dae42d9
Reviewed-on: https://go-review.googlesource.com/c/sys/+/361255
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Martin Möhrmann <martin@golang.org>
2021-11-03 23:57:46 +00:00
zhangyunhao
63515b42dc cpu: add support for detecting cmpxchg16b
Change-Id: I892de938e85205c0506aa82e31297b7a99e48e44
Reviewed-on: https://go-review.googlesource.com/c/sys/+/329450
Trust: Martin Möhrmann <martin@golang.org>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Martin Möhrmann <martin@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <martin@golang.org>
2021-08-23 07:06:55 +00:00
Vaughn Iverson
b677753862 cpu: fix AVX512 support detection on Darwin
Summary: On darwin/amd64, it is not adequate to use OSXSAVE
bits to determine AVX512 availabilty. The reason is involved.
See github issue for details.

The fix consists of implementing Apple's recommended approach
using the process commpage cpu_capabilities bits to determine
availability of AVX512.

Fixes golang/go#43089

Change-Id: I1ba89965498863d268fbf2e427dbfd6429c7409f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/285572
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2021-05-03 07:37:44 +00:00
Russ Cox
9a76102bfb all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: I01667f826428426a39c84717d02efa25fa44553c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/294490
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Russ Cox <rsc@golang.org>
2021-02-20 05:07:31 +00:00
Anton Kuklin
006507a758 cpu: add support for detecting AVX-512
The existing implementation hasn't AVX-512 detection support.
This patch extends cpu package with such a functionality.

Fixes golang/go#41288

Change-Id: Iaddd57c5ff6d73360b77886458b9210b6c446859
Reviewed-on: https://go-review.googlesource.com/c/sys/+/257937
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2020-09-28 20:51:50 +00:00
Polina Osadcha
0cf7623e9d cpu: add GODEBUG options to disable use of instruction set extensions
The GODEBUG environment variable can be used to disable usage of
specific processor features of Go programs that use the sys/cpu package.
This is useful for testing and benchmarking different code paths that
are guarded by sys/cpu variable checks.

Use of processor features can not be enabled through GODEBUG.

To disable usage of AVX and SSE41 cpu features on GOARCH amd64 use:
GODEBUG=cpu.avx=off,cpu.sse41=off

The special "all" option can be used to disable all options:
GODEBUG=all=off

This aligns the support of GODEBUG for sys/cpu with existing support
for GODEBUG in the Go standard library package internal/cpu.

Fixes golang/go#33963

Change-Id: I618b71af397bf06c57a49b2a300d032a16d05664
Reviewed-on: https://go-review.googlesource.com/c/sys/+/245237
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2020-08-05 06:55:43 +00:00
Tobias Klauser
92a0ff1e1e cpu: don't panic on error reading /proc/self/auxv
On Android /proc/self/auxv is not readable, leading to a panic in init.
Instead of panic'ing in this case, introduce the Initialized global bool
to report whether the CPU features were initialized i.e. /proc/self/auxv
was successfullly read.

Fixes golang/go#30413

Change-Id: Ib520f202990614a76bceb0bf9d19a88eadd13e10
Reviewed-on: https://go-review.googlesource.com/c/164057
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-28 07:16:10 +00:00
Tobias Klauser
2970a3744d cpu: detect RDRAND and RDSEED instructions on x86
Change-Id: I2d0094d64ba12f888758aeebdb43aed353ddeeb9
Reviewed-on: https://go-review.googlesource.com/c/160577
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-01 07:34:06 +00:00
Ian Lance Taylor
9527bec266 cpu: fix gccgo build
Current versions of gccgo report a redefinition error for both a
declaration and definition, as of https://golang.org/cl/93083.
Fix the last change to work with this.

Change-Id: Iae6a664fcc9fe97d4e3b7845a05dab3a8ad56830
Reviewed-on: https://go-review.googlesource.com/116776
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-06 20:27:47 +00:00
Alex Vaghin
bc2ef10f1b cpu: add gccgo implementation
It uses __get_cpuid_count, provided by cpuid.h.
The xgetbv is implemented after its counterpart in cpu_x86.s.

Change-Id: I97624d7da67ab4ec3c9a53b0bfc4dfcdf7d12c87
Reviewed-on: https://go-review.googlesource.com/116155
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-06 16:53:29 +00:00
Andreas Auernhammer
4adea008a5 cpu: new package
This CL introduces a new cpu package for CPU/platform feature detection.
The cpu package is basically a copy of `internal/cpu` of the standard library.
Revision: bf86aec25972f3a100c3aa58a6abcbcc35bdea49

This CL does not export ARM64 and PPC64 feature detection since at the moment
ARM64/PPC64 requires standard library support.

Updates golang/go#24843

Change-Id: I11bc1ca60b116e902c941b5887c00870dbb1f899
Reviewed-on: https://go-review.googlesource.com/107015
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-30 17:35:09 +00:00