diff --git a/base/cpuid.cpp b/base/cpuid.cpp index 132202962a..1621b1c4a0 100644 --- a/base/cpuid.cpp +++ b/base/cpuid.cpp @@ -1,7 +1,7 @@ #include "base/cpuid.hpp" -#include #include +#include #include "base/macros.hpp" // 🧙 For PRINCIPIA_COMPILER_MSVC. #if PRINCIPIA_COMPILER_MSVC @@ -10,15 +10,22 @@ #include #endif +#include "base/not_null.hpp" #include "glog/logging.h" namespace principia { namespace base { namespace _cpuid { namespace internal { + +using namespace principia::base::_not_null; + namespace { -std::vector CPUIDFlags; +std::vector& CPUIDFlags() { + static std::vector result; + return result; +} CPUIDResult CPUID(std::uint32_t const eax, std::uint32_t const ecx) { #if PRINCIPIA_COMPILER_MSVC @@ -45,7 +52,7 @@ CPUIDFeatureFlag::CPUIDFeatureFlag(std::string_view const name, : name_(name), leaf_(leaf), sub_leaf_(sub_leaf), field_(field), bit_(bit) { CHECK_GE(bit, 0); CHECK_LT(bit, 32); - CPUIDFlags.emplace_back(*this); + CPUIDFlags().push_back(*this); } std::string_view CPUIDFeatureFlag::name() const { @@ -79,7 +86,7 @@ std::string ProcessorBrandString() { std::string CPUFeatures() { std::string result; - for (auto const& flag : CPUIDFlags) { + for (auto const flag : CPUIDFlags()) { if (flag.IsSet()) { if (!result.empty()) { result += " "; diff --git a/base/cpuid_test.cpp b/base/cpuid_test.cpp index 3a6be0d9ad..557d417448 100644 --- a/base/cpuid_test.cpp +++ b/base/cpuid_test.cpp @@ -23,7 +23,10 @@ TEST_F(CPUIDTest, Vendor) { } TEST_F(CPUIDTest, Brand) { - EXPECT_THAT(ProcessorBrandString(), AnyOf(HasSubstr("Intel(R) Xeon(R)"))); + EXPECT_THAT(ProcessorBrandString(), + AnyOf(HasSubstr("Intel(R) Xeon(R)"), + HasSubstr("AMD Ryzen"), + HasSubstr("VirtualApple"))); } TEST_F(CPUIDTest, CPUFeatureFlags) {