Commit 980340ad authored by Martin Möhrmann's avatar Martin Möhrmann Committed by Martin Möhrmann

internal/cpu: add options and warnings for required cpu features

Updates #27218

Change-Id: I8603f3a639cdd9ee201c4f1566692e5b88877fc4
Reviewed-on: https://go-review.googlesource.com/c/144107
Run-TryBot: Martin Möhrmann <martisch@uos.de>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 1e38ecdb
...@@ -155,8 +155,9 @@ var options []option ...@@ -155,8 +155,9 @@ var options []option
type option struct { type option struct {
Name string Name string
Feature *bool Feature *bool
Specified bool // Stores if feature value was specified in GODEBUGCPU. Specified bool // whether feature value was specified in GODEBUGCPU
Enable bool // Stores if feature should be enabled. 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. // processOptions enables or disables CPU feature values based on the parsed env string.
...@@ -196,7 +197,7 @@ field: ...@@ -196,7 +197,7 @@ field:
if key == "all" { if key == "all" {
for i := range options { for i := range options {
options[i].Specified = true options[i].Specified = true
options[i].Enable = enable options[i].Enable = enable || options[i].Required
} }
continue field continue field
} }
...@@ -222,6 +223,11 @@ field: ...@@ -222,6 +223,11 @@ field:
continue continue
} }
if !o.Enable && o.Required {
print("GODEBUGCPU: can not disable \"", o.Name, "\", required feature\n")
continue
}
*o.Feature = o.Enable *o.Feature = o.Enable
} }
} }
......
...@@ -66,8 +66,8 @@ func doinit() { ...@@ -66,8 +66,8 @@ func doinit() {
{Name: "asimdfhm", Feature: &ARM64.HasASIMDFHM}, {Name: "asimdfhm", Feature: &ARM64.HasASIMDFHM},
// These capabilities should always be enabled on arm64: // These capabilities should always be enabled on arm64:
// {Name: "fp", Feature: &ARM64.HasFP}, {Name: "fp", Feature: &ARM64.HasFP, Required: true},
// {Name: "asimd", Feature: &ARM64.HasASIMD}, {Name: "asimd", Feature: &ARM64.HasASIMD, Required: true},
} }
// HWCAP feature bits // HWCAP feature bits
......
...@@ -40,11 +40,11 @@ func doinit() { ...@@ -40,11 +40,11 @@ func doinit() {
{Name: "scv", Feature: &PPC64.HasSCV}, {Name: "scv", Feature: &PPC64.HasSCV},
// These capabilities should always be enabled on ppc64 and ppc64le: // These capabilities should always be enabled on ppc64 and ppc64le:
// {Name: "vmx", Feature: &PPC64.HasVMX}, {Name: "vmx", Feature: &PPC64.HasVMX, Required: true},
// {Name: "dfp", Feature: &PPC64.HasDFP}, {Name: "dfp", Feature: &PPC64.HasDFP, Required: true},
// {Name: "vsx", Feature: &PPC64.HasVSX}, {Name: "vsx", Feature: &PPC64.HasVSX, Required: true},
// {Name: "isel", Feature: &PPC64.HasISEL}, {Name: "isel", Feature: &PPC64.HasISEL, Required: true},
// {Name: "vcrypto", Feature: &PPC64.HasVCRYPTO}, {Name: "vcrypto", Feature: &PPC64.HasVCRYPTO, Required: true},
} }
// HWCAP feature bits // HWCAP feature bits
......
...@@ -52,8 +52,9 @@ func TestAllCapabilitiesDisabled(t *testing.T) { ...@@ -52,8 +52,9 @@ func TestAllCapabilitiesDisabled(t *testing.T) {
} }
for _, o := range Options { for _, o := range Options {
if got := *o.Feature; got != false { want := o.Required
t.Errorf("%v: expected false, got %v", o.Name, got) if got := *o.Feature; got != want {
t.Errorf("%v: expected %v, got %v", o.Name, want, got)
} }
} }
} }
...@@ -55,13 +55,8 @@ func doinit() { ...@@ -55,13 +55,8 @@ func doinit() {
{Name: "sse42", Feature: &X86.HasSSE42}, {Name: "sse42", Feature: &X86.HasSSE42},
{Name: "ssse3", Feature: &X86.HasSSSE3}, {Name: "ssse3", Feature: &X86.HasSSSE3},
// sse2 set as last element so it can easily be removed again. See code below. // These capabilities should always be enabled on amd64(p32):
{Name: "sse2", Feature: &X86.HasSSE2}, {Name: "sse2", Feature: &X86.HasSSE2, Required: GOARCH == "amd64" || GOARCH == "amd64p32"},
}
// Remove sse2 from options on amd64(p32) because SSE2 is a mandatory feature for these GOARCHs.
if GOARCH == "amd64" || GOARCH == "amd64p32" {
options = options[:len(options)-1]
} }
maxID, _, _, _ := cpuid(0, 0) maxID, _, _, _ := cpuid(0, 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment