一呼百應, "one call, a hundred responses"
Loading...
Searching...
No Matches
cpuid.cpp
Go to the documentation of this file.
1
9#include <array>
10#include <cstdint>
11#include <string_view>
12#include <cpuid.h>
13#include "attributes/common.hpp"
14#include "cpuid.hpp"
15
16namespace ein {
17
19ein_pure cpuid_t cpuid(int32_t eax, int32_t ecx) noexcept {
20 cpuid_t result;
21 __cpuid_count(eax, ecx, result.eax, result.ebx, result.ecx, result.edx);
22 return result;
23}
24
26const enum cpu_vendor cpu_vendor = [] static noexcept {
27 auto result = cpuid(0, 0);
28 std::array<int32_t, 3> data = { result.ebx, result.edx, result.ecx };
29 std::string_view vendor {reinterpret_cast<char const *>(begin(data)), 12};
30 using enum cpu_vendor;
31 if (vendor == "GenuineIntel") return intel;
32 else if (vendor == "AuthenticAMD") return amd;
33 else return unknown;
34}();
35
36} // end namespace ein
#define ein_pure
[[pure]]
Definition common.hpp:102
Definition cpuid.cpp:16
cpu_vendor
CPU vendor id.
Definition cpuid.hpp:34
@ intel
CPUID reported "GenuineIntel"
@ amd
CPUID reported "AuthenticAMD"
@ unknown
CPUID reported something else
int32_t ebx
Definition cpuid.hpp:20
int32_t eax
Definition cpuid.hpp:20
int32_t ecx
Definition cpuid.hpp:20
cpuid_t cpuid(int32_t eax, int32_t ecx) noexcept
calls CPUID and returns all of the registers that it responds with.
Definition cpuid.cpp:19
int32_t edx
Definition cpuid.hpp:20
result from calling the CPUID instruction
Definition cpuid.hpp:19