cpu_linux_arm.odin 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #+build arm32, arm64
  2. #+build linux
  3. package sysinfo
  4. import "core:sys/linux"
  5. import "core:strings"
  6. @(init, private)
  7. init_cpu_features :: proc() {
  8. fd, err := linux.open("/proc/cpuinfo", {})
  9. if err != .NONE { return }
  10. defer linux.close(fd)
  11. // This is probably enough right?
  12. buf: [4096]byte
  13. n, rerr := linux.read(fd, buf[:])
  14. if rerr != .NONE || n == 0 { return }
  15. features: CPU_Features
  16. defer cpu_features = features
  17. str := string(buf[:n])
  18. for line in strings.split_lines_iterator(&str) {
  19. key, _, value := strings.partition(line, ":")
  20. key = strings.trim_space(key)
  21. value = strings.trim_space(value)
  22. if key != "Features" { continue }
  23. for feature in strings.split_by_byte_iterator(&value, ' ') {
  24. switch feature {
  25. case "asimd", "neon": features += { .asimd }
  26. case "fp": features += { .floatingpoint }
  27. case "asimdhp": features += { .asimdhp }
  28. case "asimdbf16": features += { .bf16 }
  29. case "fcma": features += { .fcma }
  30. case "asimdfhm": features += { .fhm }
  31. case "fphp", "half": features += { .fp16 }
  32. case "frint": features += { .frint }
  33. case "i8mm": features += { .i8mm }
  34. case "jscvt": features += { .jscvt }
  35. case "asimdrdm": features += { .rdm }
  36. case "flagm": features += { .flagm }
  37. case "flagm2": features += { .flagm2 }
  38. case "crc32": features += { .crc32 }
  39. case "atomics": features += { .lse }
  40. case "lrcpc": features += { .lrcpc }
  41. case "ilrcpc": features += { .lrcpc2 }
  42. case "aes": features += { .aes }
  43. case "pmull": features += { .pmull }
  44. case "sha1": features += { .sha1 }
  45. case "sha2": features += { .sha256 }
  46. case "sha3": features += { .sha3 }
  47. case "sha512": features += { .sha512 }
  48. case "sb": features += { .sb }
  49. case "ssbs": features += { .ssbs }
  50. }
  51. }
  52. break
  53. }
  54. }