mirror of
https://github.com/golang/go
synced 2024-11-07 12:26:16 -07:00
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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
1e38ecdbbe
commit
980340ade7
@ -155,8 +155,9 @@ var options []option
|
||||
type option struct {
|
||||
Name string
|
||||
Feature *bool
|
||||
Specified bool // Stores if feature value was specified in GODEBUGCPU.
|
||||
Enable bool // Stores if feature should be enabled.
|
||||
Specified bool // whether feature value was specified in GODEBUGCPU
|
||||
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.
|
||||
@ -196,7 +197,7 @@ field:
|
||||
if key == "all" {
|
||||
for i := range options {
|
||||
options[i].Specified = true
|
||||
options[i].Enable = enable
|
||||
options[i].Enable = enable || options[i].Required
|
||||
}
|
||||
continue field
|
||||
}
|
||||
@ -222,6 +223,11 @@ field:
|
||||
continue
|
||||
}
|
||||
|
||||
if !o.Enable && o.Required {
|
||||
print("GODEBUGCPU: can not disable \"", o.Name, "\", required feature\n")
|
||||
continue
|
||||
}
|
||||
|
||||
*o.Feature = o.Enable
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ func doinit() {
|
||||
{Name: "asimdfhm", Feature: &ARM64.HasASIMDFHM},
|
||||
|
||||
// These capabilities should always be enabled on arm64:
|
||||
// {Name: "fp", Feature: &ARM64.HasFP},
|
||||
// {Name: "asimd", Feature: &ARM64.HasASIMD},
|
||||
{Name: "fp", Feature: &ARM64.HasFP, Required: true},
|
||||
{Name: "asimd", Feature: &ARM64.HasASIMD, Required: true},
|
||||
}
|
||||
|
||||
// HWCAP feature bits
|
||||
|
@ -40,11 +40,11 @@ func doinit() {
|
||||
{Name: "scv", Feature: &PPC64.HasSCV},
|
||||
|
||||
// These capabilities should always be enabled on ppc64 and ppc64le:
|
||||
// {Name: "vmx", Feature: &PPC64.HasVMX},
|
||||
// {Name: "dfp", Feature: &PPC64.HasDFP},
|
||||
// {Name: "vsx", Feature: &PPC64.HasVSX},
|
||||
// {Name: "isel", Feature: &PPC64.HasISEL},
|
||||
// {Name: "vcrypto", Feature: &PPC64.HasVCRYPTO},
|
||||
{Name: "vmx", Feature: &PPC64.HasVMX, Required: true},
|
||||
{Name: "dfp", Feature: &PPC64.HasDFP, Required: true},
|
||||
{Name: "vsx", Feature: &PPC64.HasVSX, Required: true},
|
||||
{Name: "isel", Feature: &PPC64.HasISEL, Required: true},
|
||||
{Name: "vcrypto", Feature: &PPC64.HasVCRYPTO, Required: true},
|
||||
}
|
||||
|
||||
// HWCAP feature bits
|
||||
|
@ -52,8 +52,9 @@ func TestAllCapabilitiesDisabled(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, o := range Options {
|
||||
if got := *o.Feature; got != false {
|
||||
t.Errorf("%v: expected false, got %v", o.Name, got)
|
||||
want := o.Required
|
||||
if got := *o.Feature; got != want {
|
||||
t.Errorf("%v: expected %v, got %v", o.Name, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,13 +55,8 @@ func doinit() {
|
||||
{Name: "sse42", Feature: &X86.HasSSE42},
|
||||
{Name: "ssse3", Feature: &X86.HasSSSE3},
|
||||
|
||||
// sse2 set as last element so it can easily be removed again. See code below.
|
||||
{Name: "sse2", Feature: &X86.HasSSE2},
|
||||
}
|
||||
|
||||
// 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]
|
||||
// These capabilities should always be enabled on amd64(p32):
|
||||
{Name: "sse2", Feature: &X86.HasSSE2, Required: GOARCH == "amd64" || GOARCH == "amd64p32"},
|
||||
}
|
||||
|
||||
maxID, _, _, _ := cpuid(0, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user