1// Copyright 2017 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build ppc64 ppc64le
6
7package cpu
8
9// ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
10// These are initialized by archauxv in runtime/os_linux_ppc64x.go.
11// These should not be changed after they are initialized.
12// On aix/ppc64, these values are initialized early in the runtime in runtime/os_aix.go.
13var HWCap uint
14var HWCap2 uint
15
16// HWCAP/HWCAP2 bits. These are exposed by the kernel.
17const (
18	// ISA Level
19	PPC_FEATURE2_ARCH_2_07 = 0x80000000
20	PPC_FEATURE2_ARCH_3_00 = 0x00800000
21
22	// CPU features
23	PPC_FEATURE2_DARN = 0x00200000
24	PPC_FEATURE2_SCV  = 0x00100000
25)
26
27func doinit() {
28	options = []option{
29		{Name: "darn", Feature: &PPC64.HasDARN},
30		{Name: "scv", Feature: &PPC64.HasSCV},
31		{Name: "power9", Feature: &PPC64.IsPOWER9},
32		{Name: "power8", Feature: &PPC64.IsPOWER8},
33	}
34
35	// HWCAP2 feature bits
36	PPC64.IsPOWER8 = isSet(HWCap2, PPC_FEATURE2_ARCH_2_07)
37	PPC64.IsPOWER9 = isSet(HWCap2, PPC_FEATURE2_ARCH_3_00)
38	PPC64.HasDARN = isSet(HWCap2, PPC_FEATURE2_DARN)
39	PPC64.HasSCV = isSet(HWCap2, PPC_FEATURE2_SCV)
40}
41
42func isSet(hwc uint, value uint) bool {
43	return hwc&value != 0
44}
45