From adc18ad6ac67658a237ffb345623f4cf78b9c3c8 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Thu, 30 Sep 2021 13:10:45 +0000 Subject: [PATCH] [libc] move benchmark function registration to a different file --- libc/benchmarks/CMakeLists.txt | 1 + libc/benchmarks/LibcDefaultImplementations.cpp | 46 +++++++++++++++++++++++ libc/benchmarks/LibcFunctionPrototypes.h | 38 +++++++++++++++++++ libc/benchmarks/LibcMemoryBenchmark.h | 27 +------------ libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp | 45 +++++++--------------- 5 files changed, 100 insertions(+), 57 deletions(-) create mode 100644 libc/benchmarks/LibcDefaultImplementations.cpp create mode 100644 libc/benchmarks/LibcFunctionPrototypes.h diff --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt index 2f06836..18e5fc0 100644 --- a/libc/benchmarks/CMakeLists.txt +++ b/libc/benchmarks/CMakeLists.txt @@ -183,6 +183,7 @@ add_libc_multi_impl_benchmark(bcmp) add_executable(libc.benchmarks.memory_functions.opt_host EXCLUDE_FROM_ALL LibcMemoryGoogleBenchmarkMain.cpp + LibcDefaultImplementations.cpp ) target_link_libraries(libc.benchmarks.memory_functions.opt_host diff --git a/libc/benchmarks/LibcDefaultImplementations.cpp b/libc/benchmarks/LibcDefaultImplementations.cpp new file mode 100644 index 0000000..bf362f2 --- /dev/null +++ b/libc/benchmarks/LibcDefaultImplementations.cpp @@ -0,0 +1,46 @@ +#include "LibcFunctionPrototypes.h" +#include "llvm/ADT/ArrayRef.h" +#include + +namespace __llvm_libc { + +extern void *memcpy(void *__restrict, const void *__restrict, size_t); +extern void *memset(void *, int, size_t); +extern void bzero(void *, size_t); +extern int memcmp(const void *, const void *, size_t); +extern int bcmp(const void *, const void *, size_t); + +} // namespace __llvm_libc + +// List of implementations to test. + +using llvm::libc_benchmarks::BzeroConfiguration; +using llvm::libc_benchmarks::MemcmpConfiguration; +using llvm::libc_benchmarks::MemcpyConfiguration; +using llvm::libc_benchmarks::MemsetConfiguration; + +llvm::ArrayRef getMemcpyConfigurations() { + static constexpr MemcpyConfiguration kMemcpyConfigurations[] = { + {__llvm_libc::memcpy, "__llvm_libc::memcpy"}}; + return llvm::makeArrayRef(kMemcpyConfigurations); +} +llvm::ArrayRef getMemcmpConfigurations() { + static constexpr MemcmpConfiguration kMemcmpConfigurations[] = { + {__llvm_libc::memcmp, "__llvm_libc::memcmp"}}; + return llvm::makeArrayRef(kMemcmpConfigurations); +} +llvm::ArrayRef getBcmpConfigurations() { + static constexpr MemcmpConfiguration kBcmpConfigurations[] = { + {__llvm_libc::bcmp, "__llvm_libc::bcmp"}}; + return llvm::makeArrayRef(kBcmpConfigurations); +} +llvm::ArrayRef getMemsetConfigurations() { + static constexpr MemsetConfiguration kMemsetConfigurations[] = { + {__llvm_libc::memset, "__llvm_libc::memset"}}; + return llvm::makeArrayRef(kMemsetConfigurations); +} +llvm::ArrayRef getBzeroConfigurations() { + static constexpr BzeroConfiguration kBzeroConfigurations[] = { + {__llvm_libc::bzero, "__llvm_libc::bzero"}}; + return llvm::makeArrayRef(kBzeroConfigurations); +} \ No newline at end of file diff --git a/libc/benchmarks/LibcFunctionPrototypes.h b/libc/benchmarks/LibcFunctionPrototypes.h new file mode 100644 index 0000000..e856c91 --- /dev/null +++ b/libc/benchmarks/LibcFunctionPrototypes.h @@ -0,0 +1,38 @@ +#ifndef LLVM_LIBC_BENCHMARKS_LIBC_FUNCTION_PROTOTYPES_H +#define LLVM_LIBC_BENCHMARKS_LIBC_FUNCTION_PROTOTYPES_H + +#include "llvm/ADT/StringRef.h" + +namespace llvm { +namespace libc_benchmarks { + +/// Memory function prototype and configuration. +using MemcpyFunction = void *(*)(void *__restrict, const void *__restrict, + size_t); +struct MemcpyConfiguration { + MemcpyFunction Function; + llvm::StringRef Name; +}; + +using MemsetFunction = void *(*)(void *, int, size_t); +struct MemsetConfiguration { + MemsetFunction Function; + llvm::StringRef Name; +}; + +using BzeroFunction = void (*)(void *, size_t); +struct BzeroConfiguration { + BzeroFunction Function; + llvm::StringRef Name; +}; + +using MemcmpFunction = int (*)(const void *, const void *, size_t); +struct MemcmpConfiguration { + MemcmpFunction Function; + llvm::StringRef Name; +}; + +} // namespace libc_benchmarks +} // namespace llvm + +#endif /* LLVM_LIBC_BENCHMARKS_LIBC_FUNCTION_PROTOTYPES_H */ diff --git a/libc/benchmarks/LibcMemoryBenchmark.h b/libc/benchmarks/LibcMemoryBenchmark.h index 7badf04..eaba899 100644 --- a/libc/benchmarks/LibcMemoryBenchmark.h +++ b/libc/benchmarks/LibcMemoryBenchmark.h @@ -13,6 +13,7 @@ #define LLVM_LIBC_UTILS_BENCHMARK_MEMORY_BENCHMARK_H #include "LibcBenchmark.h" +#include "LibcFunctionPrototypes.h" #include "MemorySizeDistributions.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Alignment.h" @@ -186,32 +187,6 @@ struct ParameterBatch { std::vector Parameters; }; -/// Memory function prototype and configuration. -using MemcpyFunction = void *(*)(void *__restrict, const void *__restrict, - size_t); -struct MemcpyConfiguration { - MemcpyFunction Function; - llvm::StringRef Name; -}; - -using MemsetFunction = void *(*)(void *, int, size_t); -struct MemsetConfiguration { - MemsetFunction Function; - llvm::StringRef Name; -}; - -using BzeroFunction = void (*)(void *, size_t); -struct BzeroConfiguration { - BzeroFunction Function; - llvm::StringRef Name; -}; - -using MemcmpFunction = int (*)(const void *, const void *, size_t); -struct MemcmpConfiguration { - MemcmpFunction Function; - llvm::StringRef Name; -}; - /// Provides source and destination buffers for the Copy operation as well as /// the associated size distributions. struct CopySetup : public ParameterBatch { diff --git a/libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp b/libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp index e48b3a7..0941c73 100644 --- a/libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp +++ b/libc/benchmarks/LibcMemoryGoogleBenchmarkMain.cpp @@ -22,32 +22,6 @@ using llvm::libc_benchmarks::MemsetConfiguration; using llvm::libc_benchmarks::OffsetDistribution; using llvm::libc_benchmarks::SetSetup; -namespace __llvm_libc { - -extern void *memcpy(void *__restrict, const void *__restrict, size_t); -extern void *memset(void *, int, size_t); -extern void bzero(void *, size_t); -extern int memcmp(const void *, const void *, size_t); -extern int bcmp(const void *, const void *, size_t); - -} // namespace __llvm_libc - -// List of implementations to test. -static constexpr MemcpyConfiguration kMemcpyConfigurations[] = { - {__llvm_libc::memcpy, "__llvm_libc::memcpy"}}; - -static constexpr MemcmpConfiguration kMemcmpConfigurations[] = { - {__llvm_libc::memcmp, "__llvm_libc::memcmp"}}; - -static constexpr MemcmpConfiguration kBcmpConfigurations[] = { - {__llvm_libc::bcmp, "__llvm_libc::bcmp"}}; - -static constexpr MemsetConfiguration kMemsetConfigurations[] = { - {__llvm_libc::memset, "__llvm_libc::memset"}}; - -static constexpr BzeroConfiguration kBzeroConfigurations[] = { - {__llvm_libc::bzero, "__llvm_libc::bzero"}}; - // Alignment to use for when accessing the buffers. static constexpr Align kBenchmarkAlignment = Align::Constant<1>(); @@ -116,13 +90,22 @@ private: benchmark->Args({DistIndex, ConfIndex}); \ }) +extern llvm::ArrayRef getMemcpyConfigurations(); BENCHMARK_MEMORY_FUNCTION(BM_Memcpy, CopySetup, MemcpyConfiguration, - llvm::makeArrayRef(kMemcpyConfigurations)); + getMemcpyConfigurations()); + +extern llvm::ArrayRef getMemcmpConfigurations(); BENCHMARK_MEMORY_FUNCTION(BM_Memcmp, ComparisonSetup, MemcmpConfiguration, - llvm::makeArrayRef(kMemcmpConfigurations)); + getMemcmpConfigurations()); + +extern llvm::ArrayRef getBcmpConfigurations(); BENCHMARK_MEMORY_FUNCTION(BM_Bcmp, ComparisonSetup, MemcmpConfiguration, - llvm::makeArrayRef(kBcmpConfigurations)); + getBcmpConfigurations()); + +extern llvm::ArrayRef getMemsetConfigurations(); BENCHMARK_MEMORY_FUNCTION(BM_Memset, SetSetup, MemsetConfiguration, - llvm::makeArrayRef(kMemsetConfigurations)); + getMemsetConfigurations()); + +extern llvm::ArrayRef getBzeroConfigurations(); BENCHMARK_MEMORY_FUNCTION(BM_Bzero, SetSetup, BzeroConfiguration, - llvm::makeArrayRef(kBzeroConfigurations)); + getBzeroConfigurations()); -- 2.7.4