cpu.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // Package cpu implements processor feature detection
  5. // used by the Go standard library.
  6. package cpu
  7. var X86 x86
  8. // The booleans in x86 contain the correspondingly named cpuid feature bit.
  9. // HasAVX and HasAVX2 are only set if the OS does support XMM and YMM registers
  10. // in addition to the cpuid feature bit being set.
  11. // The struct is padded to avoid false sharing.
  12. type x86 struct {
  13. _ [CacheLineSize]byte
  14. HasAES bool
  15. HasADX bool
  16. HasAVX bool
  17. HasAVX2 bool
  18. HasBMI1 bool
  19. HasBMI2 bool
  20. HasERMS bool
  21. HasFMA bool
  22. HasOSXSAVE bool
  23. HasPCLMULQDQ bool
  24. HasPOPCNT bool
  25. HasSSE2 bool
  26. HasSSE3 bool
  27. HasSSSE3 bool
  28. HasSSE41 bool
  29. HasSSE42 bool
  30. _ [CacheLineSize]byte
  31. }
  32. var PPC64 ppc64
  33. // For ppc64x, it is safe to check only for ISA level starting on ISA v3.00,
  34. // since there are no optional categories. There are some exceptions that also
  35. // require kernel support to work (darn, scv), so there are capability bits for
  36. // those as well. The minimum processor requirement is POWER8 (ISA 2.07), so we
  37. // maintain some of the old capability checks for optional categories for
  38. // safety.
  39. // The struct is padded to avoid false sharing.
  40. type ppc64 struct {
  41. _ [CacheLineSize]byte
  42. HasVMX bool // Vector unit (Altivec)
  43. HasDFP bool // Decimal Floating Point unit
  44. HasVSX bool // Vector-scalar unit
  45. HasHTM bool // Hardware Transactional Memory
  46. HasISEL bool // Integer select
  47. HasVCRYPTO bool // Vector cryptography
  48. HasHTMNOSC bool // HTM: kernel-aborted transaction in syscalls
  49. HasDARN bool // Hardware random number generator (requires kernel enablement)
  50. HasSCV bool // Syscall vectored (requires kernel enablement)
  51. IsPOWER8 bool // ISA v2.07 (POWER8)
  52. IsPOWER9 bool // ISA v3.00 (POWER9)
  53. _ [CacheLineSize]byte
  54. }
  55. var ARM64 arm64
  56. // The booleans in arm64 contain the correspondingly named cpu feature bit.
  57. // The struct is padded to avoid false sharing.
  58. type arm64 struct {
  59. _ [CacheLineSize]byte
  60. HasFP bool
  61. HasASIMD bool
  62. HasEVTSTRM bool
  63. HasAES bool
  64. HasPMULL bool
  65. HasSHA1 bool
  66. HasSHA2 bool
  67. HasCRC32 bool
  68. HasATOMICS bool
  69. _ [CacheLineSize]byte
  70. }