diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index d224cef2a8..db2ac1f2a6 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -732,6 +732,8 @@ func runInstall(pkg string, ch chan struct{}) { pathf("%s/src/runtime/funcdata.h", goroot), 0) copyfile(pathf("%s/pkg/include/asm_ppc64x.h", goroot), pathf("%s/src/runtime/asm_ppc64x.h", goroot), 0) + copyfile(pathf("%s/pkg/include/asm_amd64.h", goroot), + pathf("%s/src/runtime/asm_amd64.h", goroot), 0) } // Generate any missing files; regenerate existing ones. diff --git a/src/runtime/asm_amd64.h b/src/runtime/asm_amd64.h new file mode 100644 index 0000000000..49e0ee2323 --- /dev/null +++ b/src/runtime/asm_amd64.h @@ -0,0 +1,14 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Define features that are guaranteed to be supported by setting the AMD64 variable. +// If a feature is supported, there's no need to check it at runtime every time. + +#ifdef GOAMD64_v3 +#define hasAVX2 +#endif + +#ifdef GOAMD64_v4 +#define hasAVX2 +#endif diff --git a/src/runtime/memclr_amd64.s b/src/runtime/memclr_amd64.s index 700bbd7b9b..26a6205e61 100644 --- a/src/runtime/memclr_amd64.s +++ b/src/runtime/memclr_amd64.s @@ -6,6 +6,7 @@ #include "go_asm.h" #include "textflag.h" +#include "asm_amd64.h" // See memclrNoHeapPointers Go doc for important implementation constraints. @@ -39,6 +40,8 @@ tail: JBE _65through128 CMPQ BX, $256 JBE _129through256 + +#ifndef hasAVX2 CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1 JE loop_preheader_avx2 // TODO: for really big clears, use MOVNTDQ, even without AVX2. @@ -65,6 +68,7 @@ loop: CMPQ BX, $256 JAE loop JMP tail +#endif loop_preheader_avx2: VPXOR Y0, Y0, Y0