Skip to content

Commit

Permalink
cbrt to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Dec 29, 2024
1 parent 66e5e77 commit 0a811f4
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions nanobenchmarks/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ABSL_FLAG(std::string,
log_to_mathematica,
"",
"File to which to log the measurements");
ABSL_FLAG(double, input, 5, "Input for the benchmarked functions");

// Adding support for flag types only works using ADL (or by being in
// marshalling.h), so we do this, which is UB.
Expand Down Expand Up @@ -142,14 +143,14 @@ __declspec(noinline) LatencyDistributionTable
int registers[4]{};
int leaf = 0;
for (int j = 0; j < sample_count; ++j) {
double x = absl::GetFlag(FLAGS_input);
__cpuid(registers, leaf);
auto const tsc = __rdtsc();
double x = 5 + tsc % 2 + registers[0] % 2;
for (int i = 0; i < loop_iterations; ++i) {
x = f(x);
x += 5 - x;
}
__cpuid(registers, x);
__cpuid(registers, leaf);
double const δtsc = __rdtsc() - tsc;
samples[j] = δtsc / loop_iterations;
}
Expand All @@ -167,25 +168,6 @@ __declspec(noinline) LatencyDistributionTable
return result;
}

BENCHMARK_FUNCTION_WITH_NAME(
"Cbrt 3²ᴄZ5¹ Faithful",
principia::numerics::_cbrt::internal::method_3²ᴄZ5¹::Cbrt<
principia::numerics::_cbrt::internal::Rounding::Faithful>);
BENCHMARK_FUNCTION_WITH_NAME(
"Cbrt 3²ᴄZ5¹ Correct",
principia::numerics::_cbrt::internal::method_3²ᴄZ5¹::Cbrt<
principia::numerics::_cbrt::internal::Rounding::Correct>);
BENCHMARK_FUNCTION_WITH_NAME(
"Cbrt 5²Z4¹FMA Faithful",
principia::numerics::_cbrt::internal::method_5²Z4¹FMA::Cbrt<
principia::numerics::_cbrt::internal::Rounding::Faithful>);
BENCHMARK_FUNCTION_WITH_NAME(
"Cbrt 5²Z4¹FMA Correct",
principia::numerics::_cbrt::internal::method_5²Z4¹FMA::Cbrt<
principia::numerics::_cbrt::internal::Rounding::Correct>);
BENCHMARK_FUNCTION_WITH_NAME("Cbrt",
principia::numerics::_cbrt::Cbrt);

std::size_t FormattedWidth(std::string s) {
// Two columns per code unit is wide enough, since field width is at most 2
// per extended grapheme cluster.
Expand Down

0 comments on commit 0a811f4

Please sign in to comment.