diff --git a/src/runtime/asm_386.s b/src/runtime/asm_386.s index a6a81c3f63..725271eec4 100644 --- a/src/runtime/asm_386.s +++ b/src/runtime/asm_386.s @@ -881,7 +881,7 @@ TEXT runtime·stackcheck(SB), NOSPLIT, $0-0 // func cputicks() int64 TEXT runtime·cputicks(SB),NOSPLIT,$0-8 - CMPB runtime·support_sse2(SB), $1 + CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 JNE done CMPB runtime·lfenceBeforeRdtsc(SB), $1 JNE mfence diff --git a/src/runtime/cpuflags.go b/src/runtime/cpuflags.go new file mode 100644 index 0000000000..dee6116a90 --- /dev/null +++ b/src/runtime/cpuflags.go @@ -0,0 +1,17 @@ +// Copyright 2018 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. + +package runtime + +import ( + "internal/cpu" + "unsafe" +) + +// Offsets into internal/cpu records for use in assembly. +const ( + offset_x86_HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) + offset_x86_HasERMS = unsafe.Offsetof(cpu.X86.HasERMS) + offset_x86_HasSSE2 = unsafe.Offsetof(cpu.X86.HasSSE2) +) diff --git a/src/runtime/cpuflags_amd64.go b/src/runtime/cpuflags_amd64.go index 10ab5f5b00..8cca4bca8f 100644 --- a/src/runtime/cpuflags_amd64.go +++ b/src/runtime/cpuflags_amd64.go @@ -6,12 +6,6 @@ package runtime import ( "internal/cpu" - "unsafe" -) - -// Offsets into internal/cpu records for use in assembly. -const ( - offsetX86HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) ) var useAVXmemmove bool diff --git a/src/runtime/memclr_386.s b/src/runtime/memclr_386.s index a6703b3641..318f883964 100644 --- a/src/runtime/memclr_386.s +++ b/src/runtime/memclr_386.s @@ -4,6 +4,7 @@ // +build !plan9 +#include "go_asm.h" #include "textflag.h" // NOTE: Windows externalthreadhandler expects memclr to preserve DX. @@ -28,7 +29,7 @@ tail: JBE _5through8 CMPL BX, $16 JBE _9through16 - CMPB runtime·support_sse2(SB), $1 + CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 JNE nosse2 PXOR X0, X0 CMPL BX, $32 diff --git a/src/runtime/memclr_amd64.s b/src/runtime/memclr_amd64.s index d79078fd00..b64b1477f9 100644 --- a/src/runtime/memclr_amd64.s +++ b/src/runtime/memclr_amd64.s @@ -38,7 +38,7 @@ tail: JBE _65through128 CMPQ BX, $256 JBE _129through256 - CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1 + CMPB internal∕cpu·X86+const_offset_x86_HasAVX2(SB), $1 JE loop_preheader_avx2 // TODO: for really big clears, use MOVNTDQ, even without AVX2. diff --git a/src/runtime/memmove_386.s b/src/runtime/memmove_386.s index 172ea40820..85c622b6b6 100644 --- a/src/runtime/memmove_386.s +++ b/src/runtime/memmove_386.s @@ -25,6 +25,7 @@ // +build !plan9 +#include "go_asm.h" #include "textflag.h" // func memmove(to, from unsafe.Pointer, n uintptr) @@ -51,7 +52,7 @@ tail: JBE move_5through8 CMPL BX, $16 JBE move_9through16 - CMPB runtime·support_sse2(SB), $1 + CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 JNE nosse2 CMPL BX, $32 JBE move_17through32 @@ -72,7 +73,7 @@ nosse2: */ forward: // If REP MOVSB isn't fast, don't use it - CMPB runtime·support_erms(SB), $1 // enhanced REP MOVSB/STOSB + CMPB internal∕cpu·X86+const_offset_x86_HasERMS(SB), $1 // enhanced REP MOVSB/STOSB JNE fwdBy4 // Check alignment diff --git a/src/runtime/memmove_amd64.s b/src/runtime/memmove_amd64.s index cb5cd02e45..c5385a3d43 100644 --- a/src/runtime/memmove_amd64.s +++ b/src/runtime/memmove_amd64.s @@ -25,6 +25,7 @@ // +build !plan9 +#include "go_asm.h" #include "textflag.h" // func memmove(to, from unsafe.Pointer, n uintptr) @@ -83,7 +84,7 @@ forward: JLS move_256through2048 // If REP MOVSB isn't fast, don't use it - CMPB runtime·support_erms(SB), $1 // enhanced REP MOVSB/STOSB + CMPB internal∕cpu·X86+const_offset_x86_HasERMS(SB), $1 // enhanced REP MOVSB/STOSB JNE fwdBy8 // Check alignment diff --git a/src/runtime/proc.go b/src/runtime/proc.go index c9cc7544b8..75d309a9f6 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -507,7 +507,8 @@ func cpuinit() { cpu.Initialize(env) - support_erms = cpu.X86.HasERMS + // Support cpu feature variables are used in code generated by the compiler + // to guard execution of instructions that can not be assumed to be always supported. support_popcnt = cpu.X86.HasPOPCNT support_sse2 = cpu.X86.HasSSE2 support_sse41 = cpu.X86.HasSSE41 diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index bbbe1ee852..9311924942 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -836,16 +836,15 @@ var ( newprocs int32 // Information about what cpu features are available. - // Set on startup in runtime.cpuinit. // Packages outside the runtime should not use these // as they are not an external api. - // TODO: deprecate these; use internal/cpu directly. + // Set on startup in asm_{386,amd64,amd64p32}.s processorVersionInfo uint32 isIntel bool lfenceBeforeRdtsc bool // Set in runtime.cpuinit. - support_erms bool + // TODO: deprecate these; use internal/cpu directly. support_popcnt bool support_sse2 bool support_sse41 bool