From 7ac2c283b145934bdce4bf64c0018884b74ec7da Mon Sep 17 00:00:00 2001 From: Robin Leroy Date: Sat, 30 Mar 2024 20:54:35 +0100 Subject: [PATCH] =?UTF-8?q?After=20pleroy=E2=80=99s=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/cpuid.cpp | 19 ++++++++----------- geometry/grassmann_test.cpp | 6 +++--- geometry/point_test.cpp | 2 +- numerics/cbrt_test.cpp | 10 +++++----- numerics/fma.hpp | 2 +- numerics/fma_test.cpp | 2 +- quantities/elementary_functions_test.cpp | 2 +- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/base/cpuid.cpp b/base/cpuid.cpp index 2d4f06c54b..3731e3f4f0 100644 --- a/base/cpuid.cpp +++ b/base/cpuid.cpp @@ -1,16 +1,19 @@ #include "base/cpuid.hpp" #include +#include #include +#include "absl/strings/str_join.h" #include "base/macros.hpp" // 🧙 For PRINCIPIA_COMPILER_MSVC. +#include "glog/logging.h" + #if PRINCIPIA_COMPILER_MSVC #include #else #include #endif -#include "glog/logging.h" namespace principia { namespace base { @@ -19,6 +22,8 @@ namespace internal { namespace { +// This vector is not a static member variable of CPUIDFeatureFlag because we do +// not want to include in the header. std::vector& CPUIDFlags() { static std::vector result; return result; @@ -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 diff --git a/geometry/grassmann_test.cpp b/geometry/grassmann_test.cpp index e1a8061b8f..217cc55544 100644 --- a/geometry/grassmann_test.cpp +++ b/geometry/grassmann_test.cpp @@ -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; @@ -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; @@ -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; diff --git a/geometry/point_test.cpp b/geometry/point_test.cpp index 169bea09c3..889a1030e2 100644 --- a/geometry/point_test.cpp +++ b/geometry/point_test.cpp @@ -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), diff --git a/numerics/cbrt_test.cpp b/numerics/cbrt_test.cpp index 4f66e0037c..74b4315556 100644 --- a/numerics/cbrt_test.cpp +++ b/numerics/cbrt_test.cpp @@ -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(y), AnyOf(cbrt_y.rounded_down, cbrt_y.rounded_up)); EXPECT_THAT(method_5²Z4¹FMA::Cbrt(y), @@ -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)); } @@ -140,7 +140,7 @@ TEST_F(CubeRootTest, Rescaling) { Eq(Cbrt(2))); EXPECT_THAT(0x1p358 * method_3²ᴄZ5¹::Cbrt(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(0x1p1021), Eq(Cbrt(2))); EXPECT_THAT(0x1p341 * method_5²Z4¹FMA::Cbrt(0x1p-1022), @@ -206,7 +206,7 @@ TEST_F(CubeRootTest, BoundsOfTheRescalingRange) { Eq(0x1p113 * Cbrt(4))); EXPECT_THAT(method_3²ᴄZ5¹::Cbrt(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(0x1p-438), Eq(0x1p-146)); EXPECT_THAT( @@ -237,7 +237,7 @@ TEST_F(CubeRootTest, ParticularlyDifficultRounding) { Eq(cbrt_y.rounded_to_nearest)); EXPECT_THAT(method_3²ᴄZ5¹::Cbrt(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(y), Eq(cbrt_y.rounded_to_nearest)); EXPECT_THAT(method_5²Z4¹FMA::Cbrt(y), diff --git a/numerics/fma.hpp b/numerics/fma.hpp index c04b1e3582..abd0946ed7 100644 --- a/numerics/fma.hpp +++ b/numerics/fma.hpp @@ -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 diff --git a/numerics/fma_test.cpp b/numerics/fma_test.cpp index 476269c2f3..21a56de45b 100644 --- a/numerics/fma_test.cpp +++ b/numerics/fma_test.cpp @@ -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"; } } diff --git a/quantities/elementary_functions_test.cpp b/quantities/elementary_functions_test.cpp index 43b35fd6b8..7a696f977d 100644 --- a/quantities/elementary_functions_test.cpp +++ b/quantities/elementary_functions_test.cpp @@ -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,