]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: get ppc64x ISA level and hardware capabilities from HWCAP/HWCAP2
authorCarlos Eduardo Seo <cseo@linux.vnet.ibm.com>
Fri, 28 Oct 2016 16:42:42 +0000 (14:42 -0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 1 Nov 2016 13:41:04 +0000 (13:41 +0000)
This implements a check that can be done at runtime for the ISA level and
hardware capability. It follows the same implementation as in s390x.

These checks will be important as we enable new instructions and write go
asm implementations using those.

Updates #15403
Fixes #16643

Change-Id: Idfee374a3ffd7cf13a7d8cf0a6c83d247d3bee16
Reviewed-on: https://go-review.googlesource.com/32330
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/os_linux.go
src/runtime/os_linux_noauxv.go
src/runtime/os_linux_ppc64x.go [new file with mode: 0644]

index 4fae7aafcbc90fb92a45dc0967282a95c54387e6..353522f69f2d89ff09e7af3767ee309fff9f73d2 100644 (file)
@@ -184,6 +184,7 @@ const (
        _AT_PAGESZ = 6  // System physical page size
        _AT_HWCAP  = 16 // hardware capability bit vector
        _AT_RANDOM = 25 // introduced in 2.6.29
+       _AT_HWCAP2 = 26 // hardware capability bit vector 2
 )
 
 func sysargs(argc int32, argv **byte) {
index 8f26589e0b07bf4fb53ed5285cf0054357071913..3b0e34a3372d8e80356eda1290ab7763ea95dc99 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !amd64,!arm,!arm64,!mips64,!mips64le,!s390x
+// +build !amd64,!arm,!arm64,!mips64,!mips64le,!s390x,!ppc64,!ppc64le
 
 package runtime
 
diff --git a/src/runtime/os_linux_ppc64x.go b/src/runtime/os_linux_ppc64x.go
new file mode 100644 (file)
index 0000000..b0da98b
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright 2016 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.
+
+// +build ppc64 ppc64le
+
+package runtime
+
+import (
+       "runtime/internal/sys"
+)
+
+const (
+       // ISA level
+       // Go currently requires POWER5 as a minimum for ppc64, so we need
+       // to check for ISA 2.03 and beyond.
+       _PPC_FEATURE_POWER5_PLUS = 0x00020000 // ISA 2.03 (POWER5+)
+       _PPC_FEATURE_ARCH_2_05   = 0x00001000 // ISA 2.05 (POWER6)
+       _PPC_FEATURE_POWER6_EXT  = 0x00000200 // mffgpr/mftgpr extension (POWER6x)
+       _PPC_FEATURE_ARCH_2_06   = 0x00000100 // ISA 2.06 (POWER7)
+       _PPC_FEATURE2_ARCH_2_07  = 0x80000000 // ISA 2.07 (POWER8)
+
+       // Standalone capabilities
+       _PPC_FEATURE_HAS_ALTIVEC = 0x10000000 // SIMD/Vector unit
+       _PPC_FEATURE_HAS_VSX     = 0x00000080 // Vector scalar unit
+)
+
+type facilities struct {
+       _         [sys.CacheLineSize]byte
+       isPOWER5x bool // ISA 2.03
+       isPOWER6  bool // ISA 2.05
+       isPOWER6x bool // ISA 2.05 + mffgpr/mftgpr extension
+       isPOWER7  bool // ISA 2.06
+       isPOWER8  bool // ISA 2.07
+       hasVMX    bool // Vector unit
+       hasVSX    bool // Vector scalar unit
+       _         [sys.CacheLineSize]byte
+}
+
+// cpu can be tested at runtime in go assembler code to check for
+// a certain ISA level or hardware capability, for example:
+//       ·cpu+facilities_hasVSX(SB) for checking the availability of VSX
+//       or
+//       ·cpu+facilities_isPOWER7(SB) for checking if the processor implements
+//       ISA 2.06 instructions.
+var cpu facilities
+
+func archauxv(tag, val uintptr) {
+       switch tag {
+       case _AT_HWCAP:
+               cpu.isPOWER5x = val&_PPC_FEATURE_POWER5_PLUS != 0
+               cpu.isPOWER6 = val&_PPC_FEATURE_ARCH_2_05 != 0
+               cpu.isPOWER6x = val&_PPC_FEATURE_POWER6_EXT != 0
+               cpu.isPOWER7 = val&_PPC_FEATURE_ARCH_2_06 != 0
+               cpu.hasVMX = val&_PPC_FEATURE_HAS_ALTIVEC != 0
+               cpu.hasVSX = val&_PPC_FEATURE_HAS_VSX != 0
+       case _AT_HWCAP2:
+               cpu.isPOWER8 = val&_PPC_FEATURE2_ARCH_2_07 != 0
+       }
+}