Skip to content

Commit

Permalink
lint and initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Mar 30, 2024
1 parent 36c3c71 commit 9be3a51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 11 additions & 4 deletions base/cpuid.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "base/cpuid.hpp"

Check warning on line 1 in base/cpuid.cpp

View workflow job for this annotation

GitHub Actions / check-iwyu

Include what you using

include_what_you_using_all_the_things.ps1 modifies this file as follows: diff --git a/base/cpuid.cpp b/base/cpuid.cpp index 1621b1c..fa5a171 100644 --- a/base/cpuid.cpp +++ b/base/cpuid.cpp @@ -4,6 +4,7 @@ #include <vector> #include "base/macros.hpp" // 🧙 For PRINCIPIA_COMPILER_MSVC. +#include "base/not_null.hpp" #if PRINCIPIA_COMPILER_MSVC #include <intrin.h> #else

#include <map>
#include <string>
#include <vector>

#include "base/macros.hpp" // 🧙 For PRINCIPIA_COMPILER_MSVC.
#if PRINCIPIA_COMPILER_MSVC
Expand All @@ -10,15 +10,22 @@
#include <cpuid.h>
#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<CPUIDFeatureFlag> CPUIDFlags;
std::vector<CPUIDFeatureFlag>& CPUIDFlags() {
static std::vector<CPUIDFeatureFlag> result;
return result;
}

CPUIDResult CPUID(std::uint32_t const eax, std::uint32_t const ecx) {
#if PRINCIPIA_COMPILER_MSVC
Expand All @@ -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 {
Expand Down Expand Up @@ -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 += " ";
Expand Down
5 changes: 4 additions & 1 deletion base/cpuid_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9be3a51

Please sign in to comment.