mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
sys/info: retrieve better CPU description on Darwin
Previously either `ARM` or `ARM64`, now you get something like `Apple M1`
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
//+build arm32, arm64
|
//+build arm32, arm64
|
||||||
package sysinfo
|
package sysinfo
|
||||||
|
|
||||||
|
import "core:sys/unix"
|
||||||
|
|
||||||
|
_ :: unix
|
||||||
|
|
||||||
CPU_Feature :: enum u64 {
|
CPU_Feature :: enum u64 {
|
||||||
// Advanced SIMD & floating-point capabilities:
|
// Advanced SIMD & floating-point capabilities:
|
||||||
asimd, // General support for Advanced SIMD instructions/neon.
|
asimd, // General support for Advanced SIMD instructions/neon.
|
||||||
@@ -45,11 +49,22 @@ cpu_name_buf: [128]byte
|
|||||||
|
|
||||||
@(init, private)
|
@(init, private)
|
||||||
init_cpu_name :: proc "contextless" () {
|
init_cpu_name :: proc "contextless" () {
|
||||||
when ODIN_ARCH == .arm64 {
|
generic := true
|
||||||
copy(cpu_name_buf[:], "ARM64")
|
|
||||||
cpu_name = string(cpu_name_buf[:len("ARM64")])
|
when ODIN_OS == .Darwin {
|
||||||
} else {
|
if unix.sysctlbyname("machdep.cpu.brand_string", &cpu_name_buf) {
|
||||||
copy(cpu_name_buf[:], "ARM")
|
cpu_name = string(cstring(rawptr(&cpu_name_buf)))
|
||||||
cpu_name = string(cpu_name_buf[:len("ARM")])
|
generic = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if generic {
|
||||||
|
when ODIN_ARCH == .arm64 {
|
||||||
|
copy(cpu_name_buf[:], "ARM64")
|
||||||
|
cpu_name = string(cpu_name_buf[:len("ARM64")])
|
||||||
|
} else {
|
||||||
|
copy(cpu_name_buf[:], "ARM")
|
||||||
|
cpu_name = string(cpu_name_buf[:len("ARM")])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-7
@@ -204,14 +204,27 @@ gb_internal void report_cpu_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(GB_CPU_ARM)
|
#elif defined(GB_CPU_ARM)
|
||||||
/*
|
bool generic = true;
|
||||||
TODO(Jeroen): On *nix, perhaps query `/proc/cpuinfo`.
|
|
||||||
*/
|
#if defined(GB_SYSTEM_OSX)
|
||||||
#if defined(GB_ARCH_64_BIT)
|
char cpu_name[128] = {};
|
||||||
gb_printf("ARM64\n");
|
size_t cpu_name_size = 128;
|
||||||
#else
|
if (sysctlbyname("machdep.cpu.brand_string", &cpu_name, &cpu_name_size, nullptr, 0) == 0) {
|
||||||
gb_printf("ARM\n");
|
generic = false;
|
||||||
|
gb_printf("%s\n", (char *)&cpu_name[0]);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (generic) {
|
||||||
|
/*
|
||||||
|
TODO(Jeroen): On *nix, perhaps query `/proc/cpuinfo`.
|
||||||
|
*/
|
||||||
|
#if defined(GB_ARCH_64_BIT)
|
||||||
|
gb_printf("ARM64\n");
|
||||||
|
#else
|
||||||
|
gb_printf("ARM\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
gb_printf("Unknown\n");
|
gb_printf("Unknown\n");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user