mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-11-08 18:02:23 +05:30
cpuid_vendor_id.mod.c: use only tabs for scope indentation
This commit is contained in:
parent
ccb438ce00
commit
fc829628d9
@ -39,19 +39,19 @@ typedef unsigned int cpuid_t[4];
|
||||
// https://stackoverflow.com/questions/1666093/cpuid-implementations-in-c
|
||||
static inline void native_cpuid(unsigned int function_id, cpuid_t r) {
|
||||
#ifdef _WIN32
|
||||
__cpuid((int *) r, (int) function_id);
|
||||
__cpuid((int *) r, (int) function_id);
|
||||
#else
|
||||
r[EAX] = function_id;
|
||||
r[ECX] = 0;
|
||||
r[EAX] = function_id;
|
||||
r[ECX] = 0;
|
||||
|
||||
// NOTE:XXX: Register ECX is often an input as well as an output
|
||||
asm volatile("cpuid"
|
||||
: "=a" (r[EAX]),
|
||||
"=b" (r[EBX]),
|
||||
"=c" (r[ECX]),
|
||||
"=d" (r[EDX])
|
||||
: "0" (r[EAX]), "2" (r[ECX])
|
||||
: "memory");
|
||||
// NOTE:XXX: Register ECX is often an input as well as an output
|
||||
asm volatile("cpuid"
|
||||
: "=a" (r[EAX]),
|
||||
"=b" (r[EBX]),
|
||||
"=c" (r[ECX]),
|
||||
"=d" (r[EDX])
|
||||
: "0" (r[EAX]), "2" (r[ECX])
|
||||
: "memory");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -62,21 +62,21 @@ static inline void native_cpuid(unsigned int function_id, cpuid_t r) {
|
||||
* VENDOR_ID_LEN
|
||||
*/
|
||||
static inline void cpuid_vendor_id(char vendor[VENDOR_ID_LEN]) {
|
||||
// Always initialize the result in case of buggy CPU (like ES/QS CPUs)
|
||||
cpuid_t v;
|
||||
native_cpuid(0, v);
|
||||
// Always initialize the result in case of buggy CPU (like ES/QS CPUs)
|
||||
cpuid_t v;
|
||||
native_cpuid(0, v);
|
||||
|
||||
// https://learn.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex
|
||||
// https://learn.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex
|
||||
// ?view=msvc-170#example
|
||||
((unsigned int *) vendor)[0] = v[EBX];
|
||||
((unsigned int *) vendor)[1] = v[EDX];
|
||||
((unsigned int *) vendor)[2] = v[ECX];
|
||||
vendor[VENDOR_ID_LEN - 1] = '\0';
|
||||
((unsigned int *) vendor)[0] = v[EBX];
|
||||
((unsigned int *) vendor)[1] = v[EDX];
|
||||
((unsigned int *) vendor)[2] = v[ECX];
|
||||
vendor[VENDOR_ID_LEN - 1] = '\0';
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char vendor_string[VENDOR_ID_LEN];
|
||||
cpuid_vendor_id(vendor_string);
|
||||
printf("CPU Vendor ID: '%s'\n", vendor_string);
|
||||
return 0;
|
||||
char vendor_string[VENDOR_ID_LEN];
|
||||
cpuid_vendor_id(vendor_string);
|
||||
printf("CPU Vendor ID: '%s'\n", vendor_string);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user