cpuid_other.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Minio Cloud Storage, (C) 2021 Minio, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. package sha256
  16. import (
  17. "bytes"
  18. "io/ioutil"
  19. "runtime"
  20. "github.com/klauspost/cpuid/v2"
  21. )
  22. func hasArmSha2() bool {
  23. if cpuid.CPU.Has(cpuid.SHA2) {
  24. return true
  25. }
  26. if runtime.GOARCH != "arm64" || runtime.GOOS != "linux" {
  27. return false
  28. }
  29. // Fall back to hacky cpuinfo parsing...
  30. const procCPUInfo = "/proc/cpuinfo"
  31. // Feature to check for.
  32. const sha256Feature = "sha2"
  33. cpuInfo, err := ioutil.ReadFile(procCPUInfo)
  34. if err != nil {
  35. return false
  36. }
  37. return bytes.Contains(cpuInfo, []byte(sha256Feature))
  38. }