aboutsummaryrefslogtreecommitdiff
path: root/Client/ThirdParty/fpm/benchmarks/power.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-12-01 13:34:22 +0800
committerchai <chaifix@163.com>2021-12-01 13:34:22 +0800
commit09abf1b529b4226f585ecfbb20866715b901755b (patch)
tree16929f2a6bee3ad4667bdd006cfcc1e683ab7210 /Client/ThirdParty/fpm/benchmarks/power.cpp
parent84d961f754c905b37420f4d1b3fee8f4e523e58a (diff)
+fpm
Diffstat (limited to 'Client/ThirdParty/fpm/benchmarks/power.cpp')
-rw-r--r--Client/ThirdParty/fpm/benchmarks/power.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/Client/ThirdParty/fpm/benchmarks/power.cpp b/Client/ThirdParty/fpm/benchmarks/power.cpp
new file mode 100644
index 0000000..7a9c407
--- /dev/null
+++ b/Client/ThirdParty/fpm/benchmarks/power.cpp
@@ -0,0 +1,94 @@
+#include <benchmark/benchmark.h>
+#include <fpm/fixed.hpp>
+#include <fpm/math.hpp>
+#include <cnl/fixed_point.h>
+#include <fixmath.h>
+
+#define BENCHMARK_TEMPLATE1_CAPTURE(func, test_case_name, a, ...) \
+ BENCHMARK_PRIVATE_DECLARE(func) = \
+ (::benchmark::internal::RegisterBenchmarkInternal( \
+ new ::benchmark::internal::FunctionBenchmark( \
+ #func "<" #a ">/" #test_case_name, \
+ [](::benchmark::State& st) { func<a>(st, __VA_ARGS__); })))
+
+template <fix16_t (*func)(fix16_t)>
+static Fix16 fix16_func(Fix16 f)
+{
+ return (*func)(f);
+}
+
+// Constants for our power function arguments.
+// Stored as volatile to force the compiler to read them and
+// not optimize the entire expression into a constant.
+static volatile int16_t s_x = 2734;
+static volatile int16_t s_y = 174;
+
+template <typename TValue>
+static void power1(benchmark::State& state, TValue (*func)(TValue))
+{
+ for (auto _ : state)
+ {
+ TValue x{ static_cast<TValue>(s_x / 256.0) };
+ benchmark::DoNotOptimize(func(x));
+ }
+}
+
+template <typename TValue>
+static void power1(benchmark::State& state, TValue (*func)(const TValue&))
+{
+ for (auto _ : state)
+ {
+ TValue x{ static_cast<TValue>(s_x / 256.0) };
+ benchmark::DoNotOptimize(func(x));
+ }
+}
+
+template <typename TValue>
+static void power2(benchmark::State& state, TValue (*func)(TValue, TValue))
+{
+ for (auto _ : state)
+ {
+ TValue x{ static_cast<TValue>(s_x / 256.0) };
+ TValue y{ static_cast<TValue>(s_y / 256.0) };
+ benchmark::DoNotOptimize(func(x, y));
+ }
+}
+
+using CnlFixed16 = cnl::fixed_point<std::int32_t, -16>;
+
+BENCHMARK_TEMPLATE1_CAPTURE(power1, sqrt, float, &std::sqrt);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, sqrt, double, &std::sqrt);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, sqrt, fpm::fixed_16_16, &fpm::sqrt);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, sqrt, Fix16, fix16_func<&fix16_sqrt>);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, sqrt, CnlFixed16, &cnl::sqrt);
+
+BENCHMARK_TEMPLATE1_CAPTURE(power1, cbrt, float, &std::cbrt);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, cbrt, double, &std::cbrt);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, cbrt, fpm::fixed_16_16, &fpm::cbrt);
+
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log, float, &std::log);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log, double, &std::log);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log, fpm::fixed_16_16, &fpm::log);
+
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log2, float, &std::log2);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log2, double, &std::log2);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log2, fpm::fixed_16_16, &fpm::log2);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log2, Fix16, fix16_func<&fix16_log2>);
+
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log10, float, &std::log10);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log10, double, &std::log10);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, log10, fpm::fixed_16_16, &fpm::log10);
+
+BENCHMARK_TEMPLATE1_CAPTURE(power1, exp, float, &std::exp);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, exp, double, &std::exp);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, exp, fpm::fixed_16_16, &fpm::exp);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, exp, Fix16, fix16_func<&fix16_exp>);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, exp, CnlFixed16, &cnl::exp);
+
+BENCHMARK_TEMPLATE1_CAPTURE(power1, exp2, float, &std::exp2);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, exp2, double, &std::exp2);
+BENCHMARK_TEMPLATE1_CAPTURE(power1, exp2, fpm::fixed_16_16, &fpm::exp2);
+
+BENCHMARK_TEMPLATE1_CAPTURE(power2, pow, float, &std::pow);
+BENCHMARK_TEMPLATE1_CAPTURE(power2, pow, double, &std::pow);
+BENCHMARK_TEMPLATE1_CAPTURE(power2, pow, fpm::fixed_16_16, &fpm::pow);