...
Run Format

Source file src/internal/cpu/cpu_arm64.go

Documentation: internal/cpu

     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 CacheLineSize = 64
     8  
     9  // arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
    10  // These are linknamed in runtime/os_linux_arm64.go and are initialized by
    11  // archauxv().
    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  		{"evtstrm", &ARM64.HasEVTSTRM},
    46  		{"aes", &ARM64.HasAES},
    47  		{"pmull", &ARM64.HasPMULL},
    48  		{"sha1", &ARM64.HasSHA1},
    49  		{"sha2", &ARM64.HasSHA2},
    50  		{"crc32", &ARM64.HasCRC32},
    51  		{"atomics", &ARM64.HasATOMICS},
    52  		{"fphp", &ARM64.HasFPHP},
    53  		{"asimdhp", &ARM64.HasASIMDHP},
    54  		{"cpuid", &ARM64.HasCPUID},
    55  		{"asimdrdm", &ARM64.HasASIMDRDM},
    56  		{"jscvt", &ARM64.HasJSCVT},
    57  		{"fcma", &ARM64.HasFCMA},
    58  		{"lrcpc", &ARM64.HasLRCPC},
    59  		{"dcpop", &ARM64.HasDCPOP},
    60  		{"sha3", &ARM64.HasSHA3},
    61  		{"sm3", &ARM64.HasSM3},
    62  		{"sm4", &ARM64.HasSM4},
    63  		{"asimddp", &ARM64.HasASIMDDP},
    64  		{"sha512", &ARM64.HasSHA512},
    65  		{"sve", &ARM64.HasSVE},
    66  		{"asimdfhm", &ARM64.HasASIMDFHM},
    67  
    68  		// These capabilities should always be enabled on arm64:
    69  		//  {"fp", &ARM64.HasFP},
    70  		//  {"asimd", &ARM64.HasASIMD},
    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  }
   103  

View as plain text