cpu_arm.odin 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #+build arm32, arm64
  2. package sysinfo
  3. import "core:sys/unix"
  4. _ :: unix
  5. CPU_Feature :: enum u64 {
  6. // Advanced SIMD & floating-point capabilities:
  7. asimd, // General support for Advanced SIMD instructions/neon.
  8. floatingpoint, // General support for floating-point instructions.
  9. asimdhp, // Advanced SIMD half-precision conversion instructions.
  10. bf16, // Storage and arithmetic instructions of the Brain Floating Point (BFloat16) data type.
  11. fcma, // Floating-point complex number instructions.
  12. fhm, // Floating-point half-precision multiplication instructions.
  13. fp16, // General half-precision floating-point data processing instructions.
  14. frint, // Floating-point to integral valued floating-point number rounding instructions.
  15. i8mm, // Advanced SIMD int8 matrix multiplication instructions.
  16. jscvt, // JavaScript conversion instruction.
  17. rdm, // Advanced SIMD rounding double multiply accumulate instructions.
  18. flagm, // Condition flag manipulation instructions.
  19. flagm2, // Enhancements to condition flag manipulation instructions.
  20. crc32, // CRC32 instructions.
  21. lse, // Atomic instructions to support large systems.
  22. lse2, // Changes to single-copy atomicity and alignment requirements for loads and stores for large systems.
  23. lrcpc, // Load-acquire Release Consistency processor consistent (RCpc) instructions.
  24. lrcpc2, // Load-acquire Release Consistency processor consistent (RCpc) instructions version 2.
  25. aes,
  26. pmull,
  27. sha1,
  28. sha256,
  29. sha512,
  30. sha3,
  31. sb, // Barrier instruction to control speculation.
  32. ssbs, // Instructions to control speculation of loads and stores.
  33. }
  34. CPU_Features :: distinct bit_set[CPU_Feature; u64]
  35. CPU :: struct {
  36. name: Maybe(string),
  37. features: Maybe(CPU_Features),
  38. physical_cores: int,
  39. logical_cores: int,
  40. }
  41. cpu: CPU
  42. @(private)
  43. cpu_name_buf: [128]byte
  44. @(init, private)
  45. init_cpu_name :: proc "contextless" () {
  46. generic := true
  47. when ODIN_OS == .Darwin {
  48. if unix.sysctlbyname("machdep.cpu.brand_string", &cpu_name_buf) {
  49. cpu.name = string(cstring(rawptr(&cpu_name_buf)))
  50. generic = false
  51. }
  52. }
  53. if generic {
  54. when ODIN_ARCH == .arm64 {
  55. copy(cpu_name_buf[:], "ARM64")
  56. cpu.name = string(cpu_name_buf[:len("ARM64")])
  57. } else {
  58. copy(cpu_name_buf[:], "ARM")
  59. cpu.name = string(cpu_name_buf[:len("ARM")])
  60. }
  61. }
  62. }