Skip to content

Commit

Permalink
Merge pull request #4144 from eggrobin/clang-nanobenchmarks
Browse files Browse the repository at this point in the history
Fix nanobenchmarks on clang
  • Loading branch information
eggrobin authored Dec 30, 2024
2 parents 4e38e35 + 58ad6fc commit 2a4c4ac
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions include_what_you_using_all_the_things.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--project:geometry `
--project:integrators `
--project:journal `
--project:nanobenchmarks `
--project:ksp_plugin `
--project:ksp_plugin_test `
--project:mathematica `
Expand Down
2 changes: 1 addition & 1 deletion nanobenchmarks/examples.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <emmintrin.h>

#include "nanobenchmarks/function_registry.hpp"
#include "nanobenchmarks/function_registry.hpp" // 🧙 For BENCHMARK_FUNCTION etc.
#include "numerics/cbrt.hpp"

namespace principia {
Expand Down
2 changes: 0 additions & 2 deletions nanobenchmarks/function_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <string>
#include <string_view>

#include "base/macros.hpp"

namespace principia {
namespace nanobenchmarks {
namespace _function_registry {
Expand Down
4 changes: 1 addition & 3 deletions nanobenchmarks/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
#include "absl/flags/parse.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "base/array.hpp"
#include "base/cpuid.hpp"
#include "mathematica/logger.hpp"
#include "mathematica/mathematica.hpp"
#include "nanobenchmarks/function_registry.hpp"
#include "nanobenchmarks/microarchitectures.hpp"
#include "nanobenchmarks/performance_settings_controller.hpp"
#include "numerics/cbrt.hpp"
#include "testing_utilities/statistics.hpp"

ABSL_FLAG(std::size_t,
Expand Down
23 changes: 23 additions & 0 deletions nanobenchmarks/microarchitectures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,36 @@
#include <vector>

#include "base/cpuid.hpp"
#include "base/macros.hpp" // 🧙 For PRINCIPIA_COMPILER_CLANG.
#include "glog/logging.h"

BENCHMARK_EXTERN_C_FUNCTION(identity);
BENCHMARK_EXTERN_C_FUNCTION(sqrtps_xmm0_xmm0);
BENCHMARK_EXTERN_C_FUNCTION(sqrtsd_xmm0_xmm0);
BENCHMARK_EXTERN_C_FUNCTION(mulsd_xmm0_xmm0);
BENCHMARK_EXTERN_C_FUNCTION(mulsd_xmm0_xmm0_4x);
#if PRINCIPIA_COMPILER_CLANG
asm(R"(
.intel_syntax
identity:
ret
sqrtps_xmm0_xmm0:
sqrtps xmm0, xmm0
ret
sqrtsd_xmm0_xmm0:
sqrtsd xmm0, xmm0
ret
mulsd_xmm0_xmm0:
mulsd xmm0, xmm0
ret
mulsd_xmm0_xmm0_4x:
mulsd xmm0, xmm0
mulsd xmm0, xmm0
mulsd xmm0, xmm0
mulsd xmm0, xmm0
ret
)");
#endif

namespace principia {
namespace nanobenchmarks {
Expand Down
18 changes: 15 additions & 3 deletions nanobenchmarks/performance_settings_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
#include <utility>
#include <string_view>

#include "absl/flags/flag.h"
#include "base/macros.hpp" // 🧙 For OS_WIN.
#include "glog/logging.h"

#if OS_WIN
#include <windows.h>
#include <powersetting.h>
#include <powrprof.h>

#include "absl/flags/flag.h"
#include "glog/logging.h"

ABSL_FLAG(bool,
keep_perf_boost,
false,
Expand All @@ -23,12 +25,14 @@ ABSL_FLAG(bool,
keep_throttling,
false,
"Whether to allow processor throttling during benchmark execution");
#endif

namespace principia {
namespace nanobenchmarks {
namespace _performance_settings_controller {
namespace internal {

#if OS_WIN
class WindowsPerformanceSettingsController
: public PerformanceSettingsController {
public:
Expand Down Expand Up @@ -295,6 +299,14 @@ WindowsPerformanceSettingsController::ReadAndPrintAllowThrottlingACDC() const {
"PROCESSOR_THROTTLE DC={} ({})", dc, ProcessorThrottleToString(dc));
return {ac, dc};
}
#else

not_null<std::unique_ptr<PerformanceSettingsController>>
PerformanceSettingsController::New() {
return make_not_null_unique<PerformanceSettingsController>();
}

#endif

} // namespace internal
} // namespace _performance_settings_controller
Expand Down

0 comments on commit 2a4c4ac

Please sign in to comment.