github.com/FISCO-BCOS/crypto@v0.0.0-20200202032121-bd8ab0b5d4f1/internal/cpu/cpu_arm64.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  package cpu
     6  
     7  const CacheLinePadSize = 64
     8  
     9  // arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
    10  // These are initialized by archauxv in runtime/os_linux_arm64.go.
    11  // These should not be changed after they are initialized.
    12  var HWCap uint
    13  var HWCap2 uint
    14  
    15  // HWCAP/HWCAP2 bits. These are exposed by Linux.
    16  const (
    17  	hwcap_FP       = 1 << 0
    18  	hwcap_ASIMD    = 1 << 1
    19  	hwcap_EVTSTRM  = 1 << 2
    20  	hwcap_AES      = 1 << 3
    21  	hwcap_PMULL    = 1 << 4
    22  	hwcap_SHA1     = 1 << 5
    23  	hwcap_SHA2     = 1 << 6
    24  	hwcap_CRC32    = 1 << 7
    25  	hwcap_ATOMICS  = 1 << 8
    26  	hwcap_FPHP     = 1 << 9
    27  	hwcap_ASIMDHP  = 1 << 10
    28  	hwcap_CPUID    = 1 << 11
    29  	hwcap_ASIMDRDM = 1 << 12
    30  	hwcap_JSCVT    = 1 << 13
    31  	hwcap_FCMA     = 1 << 14
    32  	hwcap_LRCPC    = 1 << 15
    33  	hwcap_DCPOP    = 1 << 16
    34  	hwcap_SHA3     = 1 << 17
    35  	hwcap_SM3      = 1 << 18
    36  	hwcap_SM4      = 1 << 19
    37  	hwcap_ASIMDDP  = 1 << 20
    38  	hwcap_SHA512   = 1 << 21
    39  	hwcap_SVE      = 1 << 22
    40  	hwcap_ASIMDFHM = 1 << 23
    41  )
    42  
    43  func doinit() {
    44  	options = []option{
    45  		{Name: "evtstrm", Feature: &ARM64.HasEVTSTRM},
    46  		{Name: "aes", Feature: &ARM64.HasAES},
    47  		{Name: "pmull", Feature: &ARM64.HasPMULL},
    48  		{Name: "sha1", Feature: &ARM64.HasSHA1},
    49  		{Name: "sha2", Feature: &ARM64.HasSHA2},
    50  		{Name: "crc32", Feature: &ARM64.HasCRC32},
    51  		{Name: "atomics", Feature: &ARM64.HasATOMICS},
    52  		{Name: "fphp", Feature: &ARM64.HasFPHP},
    53  		{Name: "asimdhp", Feature: &ARM64.HasASIMDHP},
    54  		{Name: "cpuid", Feature: &ARM64.HasCPUID},
    55  		{Name: "asimdrdm", Feature: &ARM64.HasASIMDRDM},
    56  		{Name: "jscvt", Feature: &ARM64.HasJSCVT},
    57  		{Name: "fcma", Feature: &ARM64.HasFCMA},
    58  		{Name: "lrcpc", Feature: &ARM64.HasLRCPC},
    59  		{Name: "dcpop", Feature: &ARM64.HasDCPOP},
    60  		{Name: "sha3", Feature: &ARM64.HasSHA3},
    61  		{Name: "sm3", Feature: &ARM64.HasSM3},
    62  		{Name: "sm4", Feature: &ARM64.HasSM4},
    63  		{Name: "asimddp", Feature: &ARM64.HasASIMDDP},
    64  		{Name: "sha512", Feature: &ARM64.HasSHA512},
    65  		{Name: "sve", Feature: &ARM64.HasSVE},
    66  		{Name: "asimdfhm", Feature: &ARM64.HasASIMDFHM},
    67  
    68  		// These capabilities should always be enabled on arm64:
    69  		{Name: "fp", Feature: &ARM64.HasFP, Required: true},
    70  		{Name: "asimd", Feature: &ARM64.HasASIMD, Required: true},
    71  	}
    72  
    73  	// HWCAP feature bits
    74  	ARM64.HasFP = isSet(HWCap, hwcap_FP)
    75  	ARM64.HasASIMD = isSet(HWCap, hwcap_ASIMD)
    76  	ARM64.HasEVTSTRM = isSet(HWCap, hwcap_EVTSTRM)
    77  	ARM64.HasAES = isSet(HWCap, hwcap_AES)
    78  	ARM64.HasPMULL = isSet(HWCap, hwcap_PMULL)
    79  	ARM64.HasSHA1 = isSet(HWCap, hwcap_SHA1)
    80  	ARM64.HasSHA2 = isSet(HWCap, hwcap_SHA2)
    81  	ARM64.HasCRC32 = isSet(HWCap, hwcap_CRC32)
    82  	ARM64.HasATOMICS = isSet(HWCap, hwcap_ATOMICS)
    83  	ARM64.HasFPHP = isSet(HWCap, hwcap_FPHP)
    84  	ARM64.HasASIMDHP = isSet(HWCap, hwcap_ASIMDHP)
    85  	ARM64.HasCPUID = isSet(HWCap, hwcap_CPUID)
    86  	ARM64.HasASIMDRDM = isSet(HWCap, hwcap_ASIMDRDM)
    87  	ARM64.HasJSCVT = isSet(HWCap, hwcap_JSCVT)
    88  	ARM64.HasFCMA = isSet(HWCap, hwcap_FCMA)
    89  	ARM64.HasLRCPC = isSet(HWCap, hwcap_LRCPC)
    90  	ARM64.HasDCPOP = isSet(HWCap, hwcap_DCPOP)
    91  	ARM64.HasSHA3 = isSet(HWCap, hwcap_SHA3)
    92  	ARM64.HasSM3 = isSet(HWCap, hwcap_SM3)
    93  	ARM64.HasSM4 = isSet(HWCap, hwcap_SM4)
    94  	ARM64.HasASIMDDP = isSet(HWCap, hwcap_ASIMDDP)
    95  	ARM64.HasSHA512 = isSet(HWCap, hwcap_SHA512)
    96  	ARM64.HasSVE = isSet(HWCap, hwcap_SVE)
    97  	ARM64.HasASIMDFHM = isSet(HWCap, hwcap_ASIMDFHM)
    98  }
    99  
   100  func isSet(hwc uint, value uint) bool {
   101  	return hwc&value != 0
   102  }