1
0
mirror of https://github.com/golang/go synced 2024-11-24 09:50:17 -07:00

internal/cpu: remove option to mark cpu features required

With the removal of SSE2 runtime detection made in
golang.org/cl/344350 we can remove this mechanism as there
are no required features anymore.

For making sure CPUs running a go program support all
the minimal hardware requirements the go runtime should
do feature checks early in the runtime initialization
before it is likely any compiler emitted but unsupported
instructions are used. This is already the case for e.g.
checking MMX support on 386 arch targets.

Change-Id: If7b1cb6f43233841e917d37a18314d06a334a734
Reviewed-on: https://go-review.googlesource.com/c/go/+/354209
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Martin Möhrmann <martin@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Martin Möhrmann 2021-10-06 05:27:52 +02:00
parent 415f0a3375
commit 195945a40d
2 changed files with 2 additions and 26 deletions

View File

@ -136,7 +136,6 @@ type option struct {
Feature *bool
Specified bool // whether feature value was specified in GODEBUG
Enable bool // whether feature should be enabled
Required bool // whether feature is mandatory and can not be disabled
}
// processOptions enables or disables CPU feature values based on the parsed env string.
@ -179,7 +178,7 @@ field:
if key == "all" {
for i := range options {
options[i].Specified = true
options[i].Enable = enable || options[i].Required
options[i].Enable = enable
}
continue field
}
@ -205,11 +204,6 @@ field:
continue
}
if !o.Enable && o.Required {
print("GODEBUG: can not disable \"", o.Name, "\", required CPU feature\n")
continue
}
*o.Feature = o.Enable
}
}

View File

@ -9,28 +9,10 @@ import (
"internal/testenv"
"os"
"os/exec"
"runtime"
"strings"
"testing"
)
func TestMinimalFeatures(t *testing.T) {
// TODO: maybe do MustSupportFeatureDectection(t) ?
if runtime.GOARCH == "arm64" {
switch runtime.GOOS {
case "linux", "android", "darwin":
default:
t.Skipf("%s/%s is not supported", runtime.GOOS, runtime.GOARCH)
}
}
for _, o := range Options {
if o.Required && !*o.Feature {
t.Errorf("%v expected true, got false", o.Name)
}
}
}
func MustHaveDebugOptionsSupport(t *testing.T) {
if !DebugOptions {
t.Skipf("skipping test: cpu feature options not supported by OS")
@ -75,7 +57,7 @@ func TestAllCapabilitiesDisabled(t *testing.T) {
}
for _, o := range Options {
want := o.Required
want := false
if got := *o.Feature; got != want {
t.Errorf("%v: expected %v, got %v", o.Name, want, got)
}