You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.9 KiB

  1. # cpuid
  2. Package cpuid provides information about the CPU running the current program.
  3. CPU features are detected on startup, and kept for fast access through the life of the application.
  4. Currently x86 / x64 (AMD64) is supported, and no external C (cgo) code is used, which should make the library very easy to use.
  5. You can access the CPU information by accessing the shared CPU variable of the cpuid library.
  6. Package home: https://github.com/klauspost/cpuid
  7. [![GoDoc][1]][2] [![Build Status][3]][4]
  8. [1]: https://godoc.org/github.com/klauspost/cpuid?status.svg
  9. [2]: https://godoc.org/github.com/klauspost/cpuid
  10. [3]: https://travis-ci.org/klauspost/cpuid.svg
  11. [4]: https://travis-ci.org/klauspost/cpuid
  12. # features
  13. ## CPU Instructions
  14. * **CMOV** (i686 CMOV)
  15. * **NX** (NX (No-Execute) bit)
  16. * **AMD3DNOW** (AMD 3DNOW)
  17. * **AMD3DNOWEXT** (AMD 3DNowExt)
  18. * **MMX** (standard MMX)
  19. * **MMXEXT** (SSE integer functions or AMD MMX ext)
  20. * **SSE** (SSE functions)
  21. * **SSE2** (P4 SSE functions)
  22. * **SSE3** (Prescott SSE3 functions)
  23. * **SSSE3** (Conroe SSSE3 functions)
  24. * **SSE4** (Penryn SSE4.1 functions)
  25. * **SSE4A** (AMD Barcelona microarchitecture SSE4a instructions)
  26. * **SSE42** (Nehalem SSE4.2 functions)
  27. * **AVX** (AVX functions)
  28. * **AVX2** (AVX2 functions)
  29. * **FMA3** (Intel FMA 3)
  30. * **FMA4** (Bulldozer FMA4 functions)
  31. * **XOP** (Bulldozer XOP functions)
  32. * **F16C** (Half-precision floating-point conversion)
  33. * **BMI1** (Bit Manipulation Instruction Set 1)
  34. * **BMI2** (Bit Manipulation Instruction Set 2)
  35. * **TBM** (AMD Trailing Bit Manipulation)
  36. * **LZCNT** (LZCNT instruction)
  37. * **POPCNT** (POPCNT instruction)
  38. * **AESNI** (Advanced Encryption Standard New Instructions)
  39. * **CLMUL** (Carry-less Multiplication)
  40. * **HTT** (Hyperthreading (enabled))
  41. * **HLE** (Hardware Lock Elision)
  42. * **RTM** (Restricted Transactional Memory)
  43. * **RDRAND** (RDRAND instruction is available)
  44. * **RDSEED** (RDSEED instruction is available)
  45. * **ADX** (Intel ADX (Multi-Precision Add-Carry Instruction Extensions))
  46. * **SHA** (Intel SHA Extensions)
  47. * **AVX512F** (AVX-512 Foundation)
  48. * **AVX512DQ** (AVX-512 Doubleword and Quadword Instructions)
  49. * **AVX512IFMA** (AVX-512 Integer Fused Multiply-Add Instructions)
  50. * **AVX512PF** (AVX-512 Prefetch Instructions)
  51. * **AVX512ER** (AVX-512 Exponential and Reciprocal Instructions)
  52. * **AVX512CD** (AVX-512 Conflict Detection Instructions)
  53. * **AVX512BW** (AVX-512 Byte and Word Instructions)
  54. * **AVX512VL** (AVX-512 Vector Length Extensions)
  55. * **AVX512VBMI** (AVX-512 Vector Bit Manipulation Instructions)
  56. * **MPX** (Intel MPX (Memory Protection Extensions))
  57. * **ERMS** (Enhanced REP MOVSB/STOSB)
  58. * **RDTSCP** (RDTSCP Instruction)
  59. * **CX16** (CMPXCHG16B Instruction)
  60. * **SGX** (Software Guard Extensions, with activation details)
  61. ## Performance
  62. * **RDTSCP()** Returns current cycle count. Can be used for benchmarking.
  63. * **SSE2SLOW** (SSE2 is supported, but usually not faster)
  64. * **SSE3SLOW** (SSE3 is supported, but usually not faster)
  65. * **ATOM** (Atom processor, some SSSE3 instructions are slower)
  66. * **Cache line** (Probable size of a cache line).
  67. * **L1, L2, L3 Cache size** on newer Intel/AMD CPUs.
  68. ## Cpu Vendor/VM
  69. * **Intel**
  70. * **AMD**
  71. * **VIA**
  72. * **Transmeta**
  73. * **NSC**
  74. * **KVM** (Kernel-based Virtual Machine)
  75. * **MSVM** (Microsoft Hyper-V or Windows Virtual PC)
  76. * **VMware**
  77. * **XenHVM**
  78. # installing
  79. ```go get github.com/klauspost/cpuid```
  80. # example
  81. ```Go
  82. package main
  83. import (
  84. "fmt"
  85. "github.com/klauspost/cpuid"
  86. )
  87. func main() {
  88. // Print basic CPU information:
  89. fmt.Println("Name:", cpuid.CPU.BrandName)
  90. fmt.Println("PhysicalCores:", cpuid.CPU.PhysicalCores)
  91. fmt.Println("ThreadsPerCore:", cpuid.CPU.ThreadsPerCore)
  92. fmt.Println("LogicalCores:", cpuid.CPU.LogicalCores)
  93. fmt.Println("Family", cpuid.CPU.Family, "Model:", cpuid.CPU.Model)
  94. fmt.Println("Features:", cpuid.CPU.Features)
  95. fmt.Println("Cacheline bytes:", cpuid.CPU.CacheLine)
  96. fmt.Println("L1 Data Cache:", cpuid.CPU.Cache.L1D, "bytes")
  97. fmt.Println("L1 Instruction Cache:", cpuid.CPU.Cache.L1D, "bytes")
  98. fmt.Println("L2 Cache:", cpuid.CPU.Cache.L2, "bytes")
  99. fmt.Println("L3 Cache:", cpuid.CPU.Cache.L3, "bytes")
  100. // Test if we have a specific feature:
  101. if cpuid.CPU.SSE() {
  102. fmt.Println("We have Streaming SIMD Extensions")
  103. }
  104. }
  105. ```
  106. Sample output:
  107. ```
  108. >go run main.go
  109. Name: Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz
  110. PhysicalCores: 2
  111. ThreadsPerCore: 2
  112. LogicalCores: 4
  113. Family 6 Model: 42
  114. Features: CMOV,MMX,MMXEXT,SSE,SSE2,SSE3,SSSE3,SSE4.1,SSE4.2,AVX,AESNI,CLMUL
  115. Cacheline bytes: 64
  116. We have Streaming SIMD Extensions
  117. ```
  118. # private package
  119. In the "private" folder you can find an autogenerated version of the library you can include in your own packages.
  120. For this purpose all exports are removed, and functions and constants are lowercased.
  121. This is not a recommended way of using the library, but provided for convenience, if it is difficult for you to use external packages.
  122. # license
  123. This code is published under an MIT license. See LICENSE file for more information.