cpu_arm.odin 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_features: Maybe(CPU_Features)
  36. cpu_name: Maybe(string)
  37. @(private)
  38. cpu_name_buf: [128]byte
  39. @(init, private)
  40. init_cpu_name :: proc "contextless" () {
  41. generic := true
  42. when ODIN_OS == .Darwin {
  43. if unix.sysctlbyname("machdep.cpu.brand_string", &cpu_name_buf) {
  44. cpu_name = string(cstring(rawptr(&cpu_name_buf)))
  45. generic = false
  46. }
  47. }
  48. if generic {
  49. when ODIN_ARCH == .arm64 {
  50. copy(cpu_name_buf[:], "ARM64")
  51. cpu_name = string(cpu_name_buf[:len("ARM64")])
  52. } else {
  53. copy(cpu_name_buf[:], "ARM")
  54. cpu_name = string(cpu_name_buf[:len("ARM")])
  55. }
  56. }
  57. }