Skip to content

Commit

Permalink
After pleroy’s review
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Mar 30, 2024
1 parent 20273e1 commit 7ac2c28
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 23 deletions.
19 changes: 8 additions & 11 deletions base/cpuid.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include "base/cpuid.hpp"

#include <string>
#include <ranges>
#include <vector>

#include "absl/strings/str_join.h"
#include "base/macros.hpp" // 🧙 For PRINCIPIA_COMPILER_MSVC.
#include "glog/logging.h"

#if PRINCIPIA_COMPILER_MSVC
#include <intrin.h>
#else
#include <cpuid.h>
#endif

#include "glog/logging.h"

namespace principia {
namespace base {
Expand All @@ -19,6 +22,8 @@ namespace internal {

namespace {

// This vector is not a static member variable of CPUIDFeatureFlag because we do
// not want to include <vector> in the header.
std::vector<CPUIDFeatureFlag>& CPUIDFlags() {
static std::vector<CPUIDFeatureFlag> result;
return result;
Expand Down Expand Up @@ -82,16 +87,8 @@ std::string ProcessorBrandString() {
}

std::string CPUFeatures() {
std::string result;
for (auto const flag : CPUIDFlags()) {
if (flag.IsSet()) {
if (!result.empty()) {
result += " ";
}
result += flag.name();
}
}
return result;
return absl::StrJoin(
std::ranges::transform_view(CPUIDFlags(), &CPUIDFeatureFlag::name), " ");
}

} // namespace internal
Expand Down
6 changes: 3 additions & 3 deletions geometry/grassmann_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class GrassmannTest : public testing::Test {
using GrassmannDeathTest = GrassmannTest;

TEST_F(GrassmannTest, VectorFMA) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FPU.IsSet()) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FMA.IsSet()) {
GTEST_SKIP() << "Cannot test FMA on a machine without FMA";
}
Length const a = a_.x;
Expand All @@ -101,7 +101,7 @@ TEST_F(GrassmannTest, VectorFMA) {
}

TEST_F(GrassmannTest, BivectorFMA) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FPU.IsSet()) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FMA.IsSet()) {
GTEST_SKIP() << "Cannot test FMA on a machine without FMA";
}
Length const a = a_.x;
Expand All @@ -120,7 +120,7 @@ TEST_F(GrassmannTest, BivectorFMA) {
}

TEST_F(GrassmannTest, TrivectorFMA) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FPU.IsSet()) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FMA.IsSet()) {
GTEST_SKIP() << "Cannot test FMA on a machine without FMA";
}
Length const a = a_.x;
Expand Down
2 changes: 1 addition & 1 deletion geometry/point_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PointTest : public testing::Test {
using PointDeathTest = PointTest;

TEST_F(PointTest, FMA) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FPU.IsSet()) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FMA.IsSet()) {
GTEST_SKIP() << "Cannot test FMA on a machine without FMA";
}
EXPECT_THAT(FusedMultiplyAdd(3 * Litre, 5 * Second / Litre, mjd0),
Expand Down
10 changes: 5 additions & 5 deletions numerics/cbrt_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CubeRootTest : public ::testing::Test {
cbrt_y.rounded_to_nearest) {
++method_3²ᴄZ5¹_misroundings;
}
if (CanEmitFMAInstructions && cpuid_feature_flags::FPU.IsSet()) {
if (CanEmitFMAInstructions && cpuid_feature_flags::FMA.IsSet()) {
EXPECT_THAT(method_5²Z4¹FMA::Cbrt<Rounding::Faithful>(y),
AnyOf(cbrt_y.rounded_down, cbrt_y.rounded_up));
EXPECT_THAT(method_5²Z4¹FMA::Cbrt<Rounding::Correct>(y),
Expand All @@ -113,7 +113,7 @@ class CubeRootTest : public ::testing::Test {
}
}
EXPECT_THAT(method_3²ᴄZ5¹_misroundings, Eq(expected_3²ᴄZ5¹_misroundings));
if (CanEmitFMAInstructions && cpuid_feature_flags::FPU.IsSet()) {
if (CanEmitFMAInstructions && cpuid_feature_flags::FMA.IsSet()) {
EXPECT_THAT(method_5²Z4¹FMA_misroundings,
Eq(expected_5²Z4¹FMA_misroundings));
}
Expand All @@ -140,7 +140,7 @@ TEST_F(CubeRootTest, Rescaling) {
Eq(Cbrt(2)));
EXPECT_THAT(0x1p358 * method_3²ᴄZ5¹::Cbrt<Rounding::Correct>(0x1p-1073),
Eq(Cbrt(2)));
if (CanEmitFMAInstructions && cpuid_feature_flags::FPU.IsSet()) {
if (CanEmitFMAInstructions && cpuid_feature_flags::FMA.IsSet()) {
EXPECT_THAT(0x1p-340 * method_5²Z4¹FMA::Cbrt<Rounding::Correct>(0x1p1021),
Eq(Cbrt(2)));
EXPECT_THAT(0x1p341 * method_5²Z4¹FMA::Cbrt<Rounding::Correct>(0x1p-1022),
Expand Down Expand Up @@ -206,7 +206,7 @@ TEST_F(CubeRootTest, BoundsOfTheRescalingRange) {
Eq(0x1p113 * Cbrt(4)));
EXPECT_THAT(method_3²ᴄZ5¹::Cbrt<Rounding::Correct>(0x1.0'0000'0000'0002p341),
Eq(0x1p113 * Cbrt(0x1.0'0000'0000'0002p2)));
if (CanEmitFMAInstructions && cpuid_feature_flags::FPU.IsSet()) {
if (CanEmitFMAInstructions && cpuid_feature_flags::FMA.IsSet()) {
EXPECT_THAT(method_5²Z4¹FMA::Cbrt<Rounding::Correct>(0x1p-438),
Eq(0x1p-146));
EXPECT_THAT(
Expand Down Expand Up @@ -237,7 +237,7 @@ TEST_F(CubeRootTest, ParticularlyDifficultRounding) {
Eq(cbrt_y.rounded_to_nearest));
EXPECT_THAT(method_3²ᴄZ5¹::Cbrt<Rounding::Faithful>(y),
AllOf(Ne(cbrt_y.rounded_to_nearest), Eq(cbrt_y.rounded_down)));
if (CanEmitFMAInstructions && cpuid_feature_flags::FPU.IsSet()) {
if (CanEmitFMAInstructions && cpuid_feature_flags::FMA.IsSet()) {
EXPECT_THAT(method_5²Z4¹FMA::Cbrt<Rounding::Correct>(y),
Eq(cbrt_y.rounded_to_nearest));
EXPECT_THAT(method_5²Z4¹FMA::Cbrt<Rounding::Faithful>(y),
Expand Down
2 changes: 1 addition & 1 deletion numerics/fma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ constexpr bool CanEmitFMAInstructions = false;

#if PRINCIPIA_USE_FMA_IF_AVAILABLE()
#define PRINCIPIA_USE_HARDWARE_FMA_DEFAULT \
(CanEmitFMAInstructions && cpuid_feature_flags::FPU.IsSet());
(CanEmitFMAInstructions && cpuid_feature_flags::FMA.IsSet());
#else
#define PRINCIPIA_USE_HARDWARE_FMA_DEFAULT false;
#endif
Expand Down
2 changes: 1 addition & 1 deletion numerics/fma_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FMATest : public testing::Test {
protected:
void SetUp() override {
// Note that we test even if |UseHardwareFMA| is false, i.e., even in debug.
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FPU.IsSet()) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FMA.IsSet()) {
GTEST_SKIP() << "Cannot test FMA on a machine without FMA";
}
}
Expand Down
2 changes: 1 addition & 1 deletion quantities/elementary_functions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace principia::testing_utilities::_vanishes_before;
class ElementaryFunctionsTest : public testing::Test {};

TEST_F(ElementaryFunctionsTest, FMA) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FPU.IsSet()) {
if (!CanEmitFMAInstructions || !cpuid_feature_flags::FMA.IsSet()) {
GTEST_SKIP() << "Cannot test FMA on a machine without FMA";
}
EXPECT_EQ(11 * Coulomb,
Expand Down

0 comments on commit 7ac2c28

Please sign in to comment.