cpuinfo.go 820 B

12345678910111213141516171819202122232425262728293031323334
  1. // Package cpuinfo gives runtime info about the current CPU.
  2. //
  3. // This is a very limited module meant for use internally
  4. // in this project. For more versatile solution check
  5. // https://github.com/klauspost/cpuid.
  6. package cpuinfo
  7. // HasBMI1 checks whether an x86 CPU supports the BMI1 extension.
  8. func HasBMI1() bool {
  9. return hasBMI1
  10. }
  11. // HasBMI2 checks whether an x86 CPU supports the BMI2 extension.
  12. func HasBMI2() bool {
  13. return hasBMI2
  14. }
  15. // DisableBMI2 will disable BMI2, for testing purposes.
  16. // Call returned function to restore previous state.
  17. func DisableBMI2() func() {
  18. old := hasBMI2
  19. hasBMI2 = false
  20. return func() {
  21. hasBMI2 = old
  22. }
  23. }
  24. // HasBMI checks whether an x86 CPU supports both BMI1 and BMI2 extensions.
  25. func HasBMI() bool {
  26. return HasBMI1() && HasBMI2()
  27. }
  28. var hasBMI1 bool
  29. var hasBMI2 bool