From 28b0084e621a220ad97085ff07338acf5f66e1ed Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Tue, 14 Feb 2023 00:33:18 +0100 Subject: [PATCH] compiler(amd64): return false on SSE4 unsupported CPUs (#1121) Signed-off-by: Edoardo Vacchi Co-authored-by: Takeshi Yoneda --- internal/platform/platform.go | 11 ++++------- internal/platform/platform_amd64.go | 7 +++++++ internal/platform/platform_arm64.go | 7 +++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 internal/platform/platform_amd64.go create mode 100644 internal/platform/platform_arm64.go diff --git a/internal/platform/platform.go b/internal/platform/platform.go index ebc19a9b..0156e35c 100644 --- a/internal/platform/platform.go +++ b/internal/platform/platform.go @@ -10,6 +10,9 @@ import ( "runtime" ) +// archRequirementsVerified is set by platform-specific init to true if the platform is supported +var archRequirementsVerified bool + // CompilerSupported is exported for tests and includes constraints here and also the assembler. func CompilerSupported() bool { switch runtime.GOOS { @@ -18,13 +21,7 @@ func CompilerSupported() bool { return false } - switch runtime.GOARCH { - case "amd64", "arm64": - default: - return false - } - - return true + return archRequirementsVerified } // MmapCodeSegment copies the code into the executable region and returns the byte slice of the region. diff --git a/internal/platform/platform_amd64.go b/internal/platform/platform_amd64.go new file mode 100644 index 00000000..4437e98f --- /dev/null +++ b/internal/platform/platform_amd64.go @@ -0,0 +1,7 @@ +package platform + +// init verifies that the current CPU supports the required AMD64 instructions +func init() { + // Ensure SSE4.1 is supported. + archRequirementsVerified = CpuFeatures.Has(CpuFeatureSSE4_1) +} diff --git a/internal/platform/platform_arm64.go b/internal/platform/platform_arm64.go new file mode 100644 index 00000000..caac58a3 --- /dev/null +++ b/internal/platform/platform_arm64.go @@ -0,0 +1,7 @@ +package platform + +// init verifies that the current CPU supports the required ARM64 features +func init() { + // No further checks currently needed. + archRequirementsVerified = true +}