#if OS_WINDOWS
#include <intrin.h>

int cpu_max_feature_leaf () {
  int cpuInfo[4];

  __cpuid(cpuInfo, 0);
  int maxLeaf = cpuInfo[0];

  return maxLeaf;
}

int CPU_Base_Frequency () {
  int cpuInfo[4] = {0};
    
  // Call CPUID with EAX = 0x16 (Base CPU Frequency)
  if (cpu_max_feature_leaf() >= 0x16)
    __cpuid(cpuInfo, 0x16);
  
  return cpuInfo[0];
}
#endif

#if OS_IS_UNIX
#include <cpuid.h>

  int CPU_Base_Frequency () {
    unsigned int eax, ebx, ecx, edx;
    if (__get_cpuid(0x16, &eax, &ebx, &ecx, &edx)) {
      return eax;
    }
    
    return 0; // not found or supported
  }
#endif
