Skip to content

Commit

Permalink
runtime: Handle auxv data for ppc64 and ppc64le
Browse files Browse the repository at this point in the history
This commit saves the values of AT_HWCAP and AT_HWCAP2 from the auxiliary
vector, so they can be used later for runtime checking the ISA level and
hardware capabilities to enable some instructions. It also defines a few
hwcap/hwcap2 masks that will be commonly used for such runtime checks, and also
provides a function for these verifications.

These checks will be used more often as new POWER8/POWER9 optimizations are
added to the ppc64x runtime, so they do not break compatibility with older
processors.
  • Loading branch information
ceseo committed Aug 16, 2016
1 parent 40cf4ad commit ca09310
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/os_linux_noauxv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// +build !amd64,!arm,!arm64,!mips64,!mips64le,!ppc64,!ppc64le

package runtime

Expand Down
46 changes: 46 additions & 0 deletions src/runtime/os_linux_ppc64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.

package runtime

const (
_AT_HWCAP = 16
_AT_HWCAP2 = 26

// Golang currently requires POWER5 as a minimum for ppc64, so we need
// to check for ISA 2.03 and beyond.
// Since we support only POWER server processors, we will assume that
// each processor generation implements the full ISA — i.e. POWER7
// implies VSX support, POWER8 implies HTM support, etc. The only
// exception is the POWER6x (ISA 2.05 + mffgpr/mftgpr extension).
_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)
_PPC_FEATURE2_ARCH_3_00 = 0x00800000 // ISA 3.0 (POWER9)
)

var hwcap uint32
var hwcap2 uint32

// Function for runtime capability checks.
// mask = hwcap or hwcap2
// supports = feature mask (see __PPC_FEATURE* constants above)
func checkppc64supports(mask uint32, supports uint32) bool {
if (mask & supports) == 0 {
return false
} else {
return true
}
}

func archauxv(tag, val uintptr) {
switch tag {
case _AT_HWCAP:
hwcap = uint32(val)
case _AT_HWCAP2:
hwcap2 = uint32(val)
}
}
35 changes: 35 additions & 0 deletions src/runtime/os_linux_ppc64le.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.

package runtime

const (
_AT_HWCAP2 = 26

// Golang currently requires POWER8 as a minimum for ppc64le. Therefore,
// there is no need to check for any capabilities that were introduced
// before ISA 2.07 (Altivec/VMX, VSX, DFP, etc). Hence, only HWCAP2 is
// required and we start checking from ISA 3.0 and beyond.
_PPC_FEATURE2_ARCH_3_00 = 0x00800000 // ISA 3.0 (POWER9)
)

var hwcap2 uint32

// Function for runtime capability checks.
// supports = feature mask (see __PPC_FEATURE2 constants above)
func checkppc64lesupports(supports uint32) bool {
if (hwcap2 & supports) == 0 {
return false
} else {
return true
}
}


func archauxv(tag, val uintptr) {
switch tag {
case _AT_HWCAP2:
hwcap2 = uint32(val)
}
}

0 comments on commit ca09310

Please sign in to comment.