]> Cypherpunks repositories - gostls13.git/commitdiff
internal/cpu: add options and warnings for required cpu features
authorMartin Möhrmann <moehrmann@google.com>
Tue, 23 Oct 2018 21:39:29 +0000 (23:39 +0200)
committerMartin Möhrmann <martisch@uos.de>
Wed, 24 Oct 2018 06:27:53 +0000 (06:27 +0000)
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>
src/internal/cpu/cpu.go
src/internal/cpu/cpu_arm64.go
src/internal/cpu/cpu_ppc64x.go
src/internal/cpu/cpu_test.go
src/internal/cpu/cpu_x86.go

index 925e4f7f6e786bbe3ca32ef49f8d1088e40aede1..5e38ff7703b577bf3b00fe4713cfd0202d957d2e 100644 (file)
@@ -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
        }
 }
index 25482a1f7ef1a4a9d0006018e5595fd0dbd901b9..0b3ee8e069f33a634e1925bdc648cee7df98b75d 100644 (file)
@@ -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
index b39f5f5bbbb7af9a133988e07f48ee608e14d38a..f59bb9dc8d0064e9460f78756dc03c2f55a1efd2 100644 (file)
@@ -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
index 6b4baa169412cdace0e8e4f555bf6e975cde3f26..46a351cfbc7f29966aa8e172930e2f0b514e9486 100644 (file)
@@ -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)
                }
        }
 }
index 014c8018f3660fc74f4d988840ce411795a85c50..5d357be62b2cc100a40a17d611a06f6f01e34c0a 100644 (file)
@@ -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)