pytorch / cpuinfo

CPU INFOrmation library (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)
BSD 2-Clause "Simplified" License
996 stars 314 forks source link

Add avx10 detect #250

Open fbarchard opened 3 months ago

fbarchard commented 3 months ago

Add AVX10.1 detect

I tested the basic cpuid in libyuv with this logic:

#if defined(_MSC_VER)
#include <intrin.h>  // For __cpuidex()
#endif
static SAFEBUFFERS int GetCpuFlags(void) {
  int cpu_info = 0;
#if !defined(__pnacl__) && !defined(__CLR_VER) &&                   \
    (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
     defined(_M_IX86))
  int cpu_info0[4] = {0, 0, 0, 0};
  int cpu_info1[4] = {0, 0, 0, 0};
  int cpu_info7[4] = {0, 0, 0, 0};
  int cpu_einfo7[4] = {0, 0, 0, 0};
  CpuId(0, 0, cpu_info0);
  CpuId(1, 0, cpu_info1);
  if (cpu_info0[0] >= 7) {
    CpuId(7, 0, cpu_info7);
    CpuId(7, 1, cpu_einfo7);
  }

  // AVX requires OS saves YMM registers.
  if (((cpu_info1[2] & 0x1c000000) == 0x1c000000) &&  // AVX and OSXSave
      ((GetXCR0() & 6) == 6)) {  // Test AVX registers are supports (YMM)
    if ((GetXCR0() & 0xe0) == 0xe0) {   // Test OS saves 32 registers
      cpu_info |= (cpu_einfo7[3] & 0x00080000) ? kCpuHasAVX10 : 0;   /// <---- AVX10
    }
  }

 where CpuId wraps the cpuid instruction as inline where necessary
// Low level cpuid for X86.
void CpuId(int info_eax, int info_ecx, int* cpu_info) {
  int info_ebx, info_edx;
  asm volatile(
      "cpuid                                     \n"
      : "=b"(info_ebx),
        "+a"(info_eax), "+c"(info_ecx), "=d"(info_edx));
  cpu_info[0] = info_eax;
  cpu_info[1] = info_ebx;
  cpu_info[2] = info_ecx;
  cpu_info[3] = info_edx;
}