cpu.go 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 implements processor feature detection for
  5. // various CPU architectures.
  6. package cpu
  7. // CacheLinePad is used to pad structs to avoid false sharing.
  8. type CacheLinePad struct{ _ [cacheLineSize]byte }
  9. // X86 contains the supported CPU features of the
  10. // current X86/AMD64 platform. If the current platform
  11. // is not X86/AMD64 then all feature flags are false.
  12. //
  13. // X86 is padded to avoid false sharing. Further the HasAVX
  14. // and HasAVX2 are only set if the OS supports XMM and YMM
  15. // registers in addition to the CPUID feature bit being set.
  16. var X86 struct {
  17. _ CacheLinePad
  18. HasAES bool // AES hardware implementation (AES NI)
  19. HasADX bool // Multi-precision add-carry instruction extensions
  20. HasAVX bool // Advanced vector extension
  21. HasAVX2 bool // Advanced vector extension 2
  22. HasBMI1 bool // Bit manipulation instruction set 1
  23. HasBMI2 bool // Bit manipulation instruction set 2
  24. HasERMS bool // Enhanced REP for MOVSB and STOSB
  25. HasFMA bool // Fused-multiply-add instructions
  26. HasOSXSAVE bool // OS supports XSAVE/XRESTOR for saving/restoring XMM registers.
  27. HasPCLMULQDQ bool // PCLMULQDQ instruction - most often used for AES-GCM
  28. HasPOPCNT bool // Hamming weight instruction POPCNT.
  29. HasRDRAND bool // RDRAND instruction (on-chip random number generator)
  30. HasRDSEED bool // RDSEED instruction (on-chip random number generator)
  31. HasSSE2 bool // Streaming SIMD extension 2 (always available on amd64)
  32. HasSSE3 bool // Streaming SIMD extension 3
  33. HasSSSE3 bool // Supplemental streaming SIMD extension 3
  34. HasSSE41 bool // Streaming SIMD extension 4 and 4.1
  35. HasSSE42 bool // Streaming SIMD extension 4 and 4.2
  36. _ CacheLinePad
  37. }
  38. // ARM64 contains the supported CPU features of the
  39. // current ARMv8(aarch64) platform. If the current platform
  40. // is not arm64 then all feature flags are false.
  41. var ARM64 struct {
  42. _ CacheLinePad
  43. HasFP bool // Floating-point instruction set (always available)
  44. HasASIMD bool // Advanced SIMD (always available)
  45. HasEVTSTRM bool // Event stream support
  46. HasAES bool // AES hardware implementation
  47. HasPMULL bool // Polynomial multiplication instruction set
  48. HasSHA1 bool // SHA1 hardware implementation
  49. HasSHA2 bool // SHA2 hardware implementation
  50. HasCRC32 bool // CRC32 hardware implementation
  51. HasATOMICS bool // Atomic memory operation instruction set
  52. HasFPHP bool // Half precision floating-point instruction set
  53. HasASIMDHP bool // Advanced SIMD half precision instruction set
  54. HasCPUID bool // CPUID identification scheme registers
  55. HasASIMDRDM bool // Rounding double multiply add/subtract instruction set
  56. HasJSCVT bool // Javascript conversion from floating-point to integer
  57. HasFCMA bool // Floating-point multiplication and addition of complex numbers
  58. HasLRCPC bool // Release Consistent processor consistent support
  59. HasDCPOP bool // Persistent memory support
  60. HasSHA3 bool // SHA3 hardware implementation
  61. HasSM3 bool // SM3 hardware implementation
  62. HasSM4 bool // SM4 hardware implementation
  63. HasASIMDDP bool // Advanced SIMD double precision instruction set
  64. HasSHA512 bool // SHA512 hardware implementation
  65. HasSVE bool // Scalable Vector Extensions
  66. HasASIMDFHM bool // Advanced SIMD multiplication FP16 to FP32
  67. _ CacheLinePad
  68. }
  69. // PPC64 contains the supported CPU features of the current ppc64/ppc64le platforms.
  70. // If the current platform is not ppc64/ppc64le then all feature flags are false.
  71. //
  72. // For ppc64/ppc64le, it is safe to check only for ISA level starting on ISA v3.00,
  73. // since there are no optional categories. There are some exceptions that also
  74. // require kernel support to work (DARN, SCV), so there are feature bits for
  75. // those as well. The minimum processor requirement is POWER8 (ISA 2.07).
  76. // The struct is padded to avoid false sharing.
  77. var PPC64 struct {
  78. _ CacheLinePad
  79. HasDARN bool // Hardware random number generator (requires kernel enablement)
  80. HasSCV bool // Syscall vectored (requires kernel enablement)
  81. IsPOWER8 bool // ISA v2.07 (POWER8)
  82. IsPOWER9 bool // ISA v3.00 (POWER9)
  83. _ CacheLinePad
  84. }