]> git.ayabusa.dev Git - thoryum.git/commitdiff
Started implementing the CPU specs detection
authorAyabusa <lebgpub@gmail.com>
Thu, 4 Jun 2026 18:44:40 +0000 (20:44 +0200)
committerAyabusa <lebgpub@gmail.com>
Thu, 4 Jun 2026 18:44:40 +0000 (20:44 +0200)
src/cpu.c [new file with mode: 0644]
src/cpu.h [new file with mode: 0644]

diff --git a/src/cpu.c b/src/cpu.c
new file mode 100644 (file)
index 0000000..33cfdeb
--- /dev/null
+++ b/src/cpu.c
@@ -0,0 +1,20 @@
+#include <cpuid.h>
+#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 (file)
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