一呼百應, "one call, a hundred responses"
Loading...
Searching...
No Matches
cpuid.hpp
Go to the documentation of this file.
1#pragma once
2
11#include <cstdint>
12#include "attributes/common.hpp"
13
14using namespace std;
15
16namespace ein {
17
20 int32_t eax, ebx, ecx, edx;
21};
22
31ein_pure extern cpuid_t cpuid(int32_t eax, int32_t ecx) noexcept;
32
34enum class ein_nodiscard cpu_vendor : uint8_t {
35 intel=0,
36 amd=1,
37 unknown=2
38};
39
41extern const enum cpu_vendor cpu_vendor;
42
43} // end namespace ein
44
45#if defined(EIN_TESTING) || defined(EIN_TESTING_CPUID)
46TEST_CASE("cpuid","[cpuid]") {
47 using namespace ein;
48
49 SECTION("CPU vendor enum correctly identifies CPU") {
50 CHECK((cpu_vendor == cpu_vendor::intel || cpu_vendor == cpu_vendor::amd));
51 }
52
53 SECTION("CPUID function retrieves processor info and feature bits") {
54 cpuid_t result = cpuid(1, 0);
55 bool sse2_supported = result.edx & (1 << 26);
56 CHECK(sse2_supported);
57 }
58}
59#endif
#define ein_nodiscard
C++17 [[nodiscard]].
Definition common.hpp:165
#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 eax
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
Definition bf16.cpp:11