From 980340ade7acb057c2e0e244a4002c96274f8a77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20M=C3=B6hrmann?= Date: Tue, 23 Oct 2018 23:39:29 +0200 Subject: [PATCH] internal/cpu: add options and warnings for required cpu features MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Updates #27218 Change-Id: I8603f3a639cdd9ee201c4f1566692e5b88877fc4 Reviewed-on: https://go-review.googlesource.com/c/144107 Run-TryBot: Martin Möhrmann Reviewed-by: Brad Fitzpatrick --- src/internal/cpu/cpu.go | 12 +++++++++--- src/internal/cpu/cpu_arm64.go | 4 ++-- src/internal/cpu/cpu_ppc64x.go | 10 +++++----- src/internal/cpu/cpu_test.go | 5 +++-- src/internal/cpu/cpu_x86.go | 9 ++------- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/internal/cpu/cpu.go b/src/internal/cpu/cpu.go index 925e4f7f6e..5e38ff7703 100644 --- a/src/internal/cpu/cpu.go +++ b/src/internal/cpu/cpu.go @@ -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 } } diff --git a/src/internal/cpu/cpu_arm64.go b/src/internal/cpu/cpu_arm64.go index 25482a1f7e..0b3ee8e069 100644 --- a/src/internal/cpu/cpu_arm64.go +++ b/src/internal/cpu/cpu_arm64.go @@ -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 diff --git a/src/internal/cpu/cpu_ppc64x.go b/src/internal/cpu/cpu_ppc64x.go index b39f5f5bbb..f59bb9dc8d 100644 --- a/src/internal/cpu/cpu_ppc64x.go +++ b/src/internal/cpu/cpu_ppc64x.go @@ -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 diff --git a/src/internal/cpu/cpu_test.go b/src/internal/cpu/cpu_test.go index 6b4baa1694..46a351cfbc 100644 --- a/src/internal/cpu/cpu_test.go +++ b/src/internal/cpu/cpu_test.go @@ -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) } } } diff --git a/src/internal/cpu/cpu_x86.go b/src/internal/cpu/cpu_x86.go index 014c8018f3..5d357be62b 100644 --- a/src/internal/cpu/cpu_x86.go +++ b/src/internal/cpu/cpu_x86.go @@ -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) -- 2.48.1