From 1dbed4b3a6ead310acf74fd30a4de51716ec418e Mon Sep 17 00:00:00 2001 From: Ayabusa Date: Thu, 4 Jun 2026 20:44:40 +0200 Subject: [PATCH] Started implementing the CPU specs detection --- src/cpu.c | 20 ++++++++++++++++++++ src/cpu.h | 14 ++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/cpu.c create mode 100644 src/cpu.h diff --git a/src/cpu.c b/src/cpu.c new file mode 100644 index 0000000..33cfdeb --- /dev/null +++ b/src/cpu.c @@ -0,0 +1,20 @@ +#include +#include "cpu.h" + +// Great article https://wiki.osdev.org/CPUID +// GCC ref in gcc/config/i386/cpuid.h +enum CPU_opti CPU_fetch_opti() { + unsigned int eax, ebx, ecx, edx; + __get_cpuid(1, &eax, &ebx, &ecx, &edx); // We gather the CPU specs + + if (ebx & bit_AVX2) // gold tier + return AVX2; + else if (ecx & bit_AVX) + return AVX; + else if ((ecx & bit_SSE4_1) || (ecx & bit_SSE4_2)) // No idea why there are two lol + return SSE4; + else if (ecx & bit_SSE3) // Not a complete piece of trash + return SSE3; + else + return POTATO; // Bruh... You in the 50s or wat ? +} diff --git a/src/cpu.h b/src/cpu.h new file mode 100644 index 0000000..b6ee415 --- /dev/null +++ b/src/cpu.h @@ -0,0 +1,14 @@ +#ifndef CPU_H +#define CPU_H + +enum CPU_opti { + POTATO, + SSE3, + SSE4, + AVX, + AVX2, +}; + +enum CPU_opti CPU_fetch_opti(); + +#endif -- 2.43.0