github.com/ltltlt/go-source-code@v0.0.0-20190830023027-95be009773aa/internal/cpu/cpu_ppc64x.go (about)

     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  
     7  package cpu
     8  
     9  const CacheLineSize = 128
    10  
    11  // ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
    12  // These are linknamed in runtime/os_linux_ppc64x.go and are initialized by
    13  // archauxv().
    14  var ppc64x_hwcap uint
    15  var ppc64x_hwcap2 uint
    16  
    17  // HWCAP/HWCAP2 bits. These are exposed by the kernel.
    18  const (
    19  	// ISA Level
    20  	_PPC_FEATURE2_ARCH_2_07 = 0x80000000
    21  	_PPC_FEATURE2_ARCH_3_00 = 0x00800000
    22  
    23  	// CPU features
    24  	_PPC_FEATURE_HAS_ALTIVEC     = 0x10000000
    25  	_PPC_FEATURE_HAS_DFP         = 0x00000400
    26  	_PPC_FEATURE_HAS_VSX         = 0x00000080
    27  	_PPC_FEATURE2_HAS_HTM        = 0x40000000
    28  	_PPC_FEATURE2_HAS_ISEL       = 0x08000000
    29  	_PPC_FEATURE2_HAS_VEC_CRYPTO = 0x02000000
    30  	_PPC_FEATURE2_HTM_NOSC       = 0x01000000
    31  	_PPC_FEATURE2_DARN           = 0x00200000
    32  	_PPC_FEATURE2_SCV            = 0x00100000
    33  )
    34  
    35  func init() {
    36  	// HWCAP feature bits
    37  	PPC64.HasVMX = isSet(ppc64x_hwcap, _PPC_FEATURE_HAS_ALTIVEC)
    38  	PPC64.HasDFP = isSet(ppc64x_hwcap, _PPC_FEATURE_HAS_DFP)
    39  	PPC64.HasVSX = isSet(ppc64x_hwcap, _PPC_FEATURE_HAS_VSX)
    40  
    41  	// HWCAP2 feature bits
    42  	PPC64.IsPOWER8 = isSet(ppc64x_hwcap2, _PPC_FEATURE2_ARCH_2_07)
    43  	PPC64.HasHTM = isSet(ppc64x_hwcap2, _PPC_FEATURE2_HAS_HTM)
    44  	PPC64.HasISEL = isSet(ppc64x_hwcap2, _PPC_FEATURE2_HAS_ISEL)
    45  	PPC64.HasVCRYPTO = isSet(ppc64x_hwcap2, _PPC_FEATURE2_HAS_VEC_CRYPTO)
    46  	PPC64.HasHTMNOSC = isSet(ppc64x_hwcap2, _PPC_FEATURE2_HTM_NOSC)
    47  	PPC64.IsPOWER9 = isSet(ppc64x_hwcap2, _PPC_FEATURE2_ARCH_3_00)
    48  	PPC64.HasDARN = isSet(ppc64x_hwcap2, _PPC_FEATURE2_DARN)
    49  	PPC64.HasSCV = isSet(ppc64x_hwcap2, _PPC_FEATURE2_SCV)
    50  }
    51  
    52  func isSet(hwc uint, value uint) bool {
    53  	return hwc&value != 0
    54  }