NO

Author Topic: Check with _cpuid()  (Read 258 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1612
Check with _cpuid()
« on: January 23, 2017, 05:23:33 PM »
https://en.wikipedia.org/wiki/CPUID

Example to check if AVX is available.
Code: [Select]
#include <intrin.h>

void __cdecl exit(int status);
int printf(const char * restrict format, ...);

#pragma comment(lib, "msvcrt.lib")
//#pragma comment(linker,"/subsystem:console,5.1")
void __cdecl mainCRTStartup(void)
{
int __cdecl main(void);
void __cdecl exit(int status);
exit(main());
}

int CheckAVX(void) {
int r[4]; // EAX, EBX, ECX and EDX
_cpuid(r, 1);
return (r[2] & 0x10000000) ? 1 : 0;
}

int main(void)
{
printf("AVX support: %s\n", CheckAVX()?"Yes":"No");
exit(0);
}
Why not some string too
Code: [Select]
#include <intrin.h>

void __cdecl exit(int status);
int printf(const char * restrict format, ...);

#pragma comment(lib, "msvcrt.lib")
//#pragma comment(linker,"/subsystem:console,5.1")
void __cdecl mainCRTStartup(void)
{
int __cdecl main(void);
void __cdecl exit(int status);
exit(main());
}

//"    AuthcAMDenti" -> "AuthenticAMD"
char *CheckVendor(void) {
static char s[17];
_cpuid((int*)s, 0);
*(int*)s = *(int*)(s+4);
*(int*)(s+4) = *(int*)(s+12);
*(s+12) = 0;
return s;
}

char *CheckBrand(void) {
static char s[50];
_cpuid((int*)s, 0x80000000);
if (*(unsigned int*)s >= 0x80000004) {
_cpuid((int*)s, 0x80000002);
_cpuid((int*)(s+16), 0x80000003);
_cpuid((int*)(s+32), 0x80000004);
}
return s;
}

int main(void)
{
printf("%s\n",CheckVendor());
printf("%s\n",CheckBrand());
exit(0);
}
« Last Edit: January 24, 2017, 09:42:02 AM by TimoVJL »
May the source be with you