cpu_linux_arm64.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2018 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. package cpu
  5. // HWCAP/HWCAP2 bits. These are exposed by Linux.
  6. const (
  7. hwcap_FP = 1 << 0
  8. hwcap_ASIMD = 1 << 1
  9. hwcap_EVTSTRM = 1 << 2
  10. hwcap_AES = 1 << 3
  11. hwcap_PMULL = 1 << 4
  12. hwcap_SHA1 = 1 << 5
  13. hwcap_SHA2 = 1 << 6
  14. hwcap_CRC32 = 1 << 7
  15. hwcap_ATOMICS = 1 << 8
  16. hwcap_FPHP = 1 << 9
  17. hwcap_ASIMDHP = 1 << 10
  18. hwcap_CPUID = 1 << 11
  19. hwcap_ASIMDRDM = 1 << 12
  20. hwcap_JSCVT = 1 << 13
  21. hwcap_FCMA = 1 << 14
  22. hwcap_LRCPC = 1 << 15
  23. hwcap_DCPOP = 1 << 16
  24. hwcap_SHA3 = 1 << 17
  25. hwcap_SM3 = 1 << 18
  26. hwcap_SM4 = 1 << 19
  27. hwcap_ASIMDDP = 1 << 20
  28. hwcap_SHA512 = 1 << 21
  29. hwcap_SVE = 1 << 22
  30. hwcap_ASIMDFHM = 1 << 23
  31. )
  32. func doinit() {
  33. if err := readHWCAP(); err != nil {
  34. // failed to read /proc/self/auxv, try reading registers directly
  35. readARM64Registers()
  36. return
  37. }
  38. // HWCAP feature bits
  39. ARM64.HasFP = isSet(hwCap, hwcap_FP)
  40. ARM64.HasASIMD = isSet(hwCap, hwcap_ASIMD)
  41. ARM64.HasEVTSTRM = isSet(hwCap, hwcap_EVTSTRM)
  42. ARM64.HasAES = isSet(hwCap, hwcap_AES)
  43. ARM64.HasPMULL = isSet(hwCap, hwcap_PMULL)
  44. ARM64.HasSHA1 = isSet(hwCap, hwcap_SHA1)
  45. ARM64.HasSHA2 = isSet(hwCap, hwcap_SHA2)
  46. ARM64.HasCRC32 = isSet(hwCap, hwcap_CRC32)
  47. ARM64.HasATOMICS = isSet(hwCap, hwcap_ATOMICS)
  48. ARM64.HasFPHP = isSet(hwCap, hwcap_FPHP)
  49. ARM64.HasASIMDHP = isSet(hwCap, hwcap_ASIMDHP)
  50. ARM64.HasCPUID = isSet(hwCap, hwcap_CPUID)
  51. ARM64.HasASIMDRDM = isSet(hwCap, hwcap_ASIMDRDM)
  52. ARM64.HasJSCVT = isSet(hwCap, hwcap_JSCVT)
  53. ARM64.HasFCMA = isSet(hwCap, hwcap_FCMA)
  54. ARM64.HasLRCPC = isSet(hwCap, hwcap_LRCPC)
  55. ARM64.HasDCPOP = isSet(hwCap, hwcap_DCPOP)
  56. ARM64.HasSHA3 = isSet(hwCap, hwcap_SHA3)
  57. ARM64.HasSM3 = isSet(hwCap, hwcap_SM3)
  58. ARM64.HasSM4 = isSet(hwCap, hwcap_SM4)
  59. ARM64.HasASIMDDP = isSet(hwCap, hwcap_ASIMDDP)
  60. ARM64.HasSHA512 = isSet(hwCap, hwcap_SHA512)
  61. ARM64.HasSVE = isSet(hwCap, hwcap_SVE)
  62. ARM64.HasASIMDFHM = isSet(hwCap, hwcap_ASIMDFHM)
  63. }
  64. func isSet(hwc uint, value uint) bool {
  65. return hwc&value != 0
  66. }