From 062a44052db13d4260a3225603b5b501907478f5 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 1 Mar 2020 22:28:46 +0100 Subject: [PATCH] cpu: add mips64x feature detection Follow CL 200579 Change-Id: Ibedd6569bda3d7836ccb77a7746ed0e5df13c633 Reviewed-on: https://go-review.googlesource.com/c/sys/+/221698 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- cpu/cpu.go | 9 +++++++++ cpu/cpu_linux_mips64x.go | 22 ++++++++++++++++++++++ cpu/cpu_linux_noinit.go | 2 +- cpu/cpu_test.go | 8 ++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 cpu/cpu_linux_mips64x.go diff --git a/cpu/cpu.go b/cpu/cpu.go index b4e6ecb2..e44deb75 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -114,6 +114,15 @@ var ARM struct { _ CacheLinePad } +// MIPS64X contains the supported CPU features of the current mips64/mips64le +// platforms. If the current platform is not mips64/mips64le or the current +// operating system is not Linux then all feature flags are false. +var MIPS64X struct { + _ CacheLinePad + HasMSA bool // MIPS SIMD architecture + _ CacheLinePad +} + // PPC64 contains the supported CPU features of the current ppc64/ppc64le platforms. // If the current platform is not ppc64/ppc64le then all feature flags are false. // diff --git a/cpu/cpu_linux_mips64x.go b/cpu/cpu_linux_mips64x.go new file mode 100644 index 00000000..eb24e507 --- /dev/null +++ b/cpu/cpu_linux_mips64x.go @@ -0,0 +1,22 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build mips64 mips64le + +package cpu + +// HWCAP bits. These are exposed by the Linux kernel 5.4. +const ( + // CPU features + hwcap_MIPS_MSA = 1 << 1 +) + +func doinit() { + // HWCAP feature bits + MIPS64X.HasMSA = isSet(hwCap, hwcap_MIPS_MSA) +} + +func isSet(hwc uint, value uint) bool { + return hwc&value != 0 +} diff --git a/cpu/cpu_linux_noinit.go b/cpu/cpu_linux_noinit.go index f65134f6..42b5d33c 100644 --- a/cpu/cpu_linux_noinit.go +++ b/cpu/cpu_linux_noinit.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux,!arm,!arm64,!ppc64,!ppc64le,!s390x +// +build linux,!arm,!arm64,!mips64,!mips64le,!ppc64,!ppc64le,!s390x package cpu diff --git a/cpu/cpu_test.go b/cpu/cpu_test.go index d37f097c..83fa5ef1 100644 --- a/cpu/cpu_test.go +++ b/cpu/cpu_test.go @@ -42,6 +42,14 @@ func TestARM64minimalFeatures(t *testing.T) { } } +func TestMIPS64Initialized(t *testing.T) { + if runtime.GOARCH == "mips64" || runtime.GOARCH == "mips64le" { + if !cpu.Initialized { + t.Fatal("Initialized expected true, got false") + } + } +} + // On ppc64x, the ISA bit for POWER8 should always be set on POWER8 and beyond. func TestPPC64minimalFeatures(t *testing.T) { // Do not run this with gccgo on ppc64, as it doesn't have POWER8 as a minimum