2013-02-07 00:47:09 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-06-08 17:55:22 +02:00
|
|
|
#include <fenv.h>
|
2013-02-07 00:47:09 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
#include <benchmark/benchmark.h>
|
2017-07-25 05:01:13 +02:00
|
|
|
#include "util.h"
|
2015-02-18 04:58:53 +01:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static const double values[] = { 1234.0, nan(""), HUGE_VAL, 0.0 };
|
|
|
|
static const char* names[] = { "1234.0", "nan", "HUGE_VAL", "0.0" };
|
|
|
|
|
|
|
|
static void SetLabel(benchmark::State& state) {
|
2016-11-14 14:16:08 +01:00
|
|
|
state.SetLabel(names[state.range(0)]);
|
2016-02-17 19:23:52 +01:00
|
|
|
}
|
2015-02-18 04:58:53 +01:00
|
|
|
|
2013-02-07 00:47:09 +01:00
|
|
|
// Avoid optimization.
|
2014-09-26 00:43:48 +02:00
|
|
|
volatile double d;
|
|
|
|
volatile double v;
|
2018-06-05 14:28:40 +02:00
|
|
|
volatile float f;
|
|
|
|
|
|
|
|
static float zero = 0.0f;
|
2018-08-08 15:54:53 +02:00
|
|
|
static double zerod = 0.0f;
|
2013-02-07 00:47:09 +01:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_sqrt(benchmark::State& state) {
|
2013-02-07 00:47:09 +01:00
|
|
|
d = 0.0;
|
|
|
|
v = 2.0;
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2013-02-07 00:47:09 +01:00
|
|
|
d += sqrt(v);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 05:01:13 +02:00
|
|
|
BIONIC_BENCHMARK(BM_math_sqrt);
|
2013-02-07 00:47:09 +01:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_log10(benchmark::State& state) {
|
2013-02-07 00:47:09 +01:00
|
|
|
d = 0.0;
|
|
|
|
v = 1234.0;
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2013-02-07 00:47:09 +01:00
|
|
|
d += log10(v);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 05:01:13 +02:00
|
|
|
BIONIC_BENCHMARK(BM_math_log10);
|
2013-02-07 00:47:09 +01:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_logb(benchmark::State& state) {
|
2013-02-07 00:47:09 +01:00
|
|
|
d = 0.0;
|
|
|
|
v = 1234.0;
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2013-02-07 00:47:09 +01:00
|
|
|
d += logb(v);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 05:01:13 +02:00
|
|
|
BIONIC_BENCHMARK(BM_math_logb);
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_isfinite_macro(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d += isfinite(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_isfinite_macro, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_isfinite(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2017-10-19 22:56:28 +02:00
|
|
|
d += isfinite(v);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_isfinite, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_isinf_macro(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d += isinf(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_isinf_macro, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_isinf(benchmark::State& state) {
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
d += (isinf)(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_isinf, "MATH_COMMON");
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_isnan_macro(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d += isnan(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_isnan_macro, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_isnan(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d += (isnan)(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_isnan, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_isnormal_macro(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d += isnormal(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_isnormal_macro, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_isnormal(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2017-10-19 22:56:28 +02:00
|
|
|
d += isnormal(v);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_isnormal, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_sin_fast(benchmark::State& state) {
|
2014-06-08 17:55:22 +02:00
|
|
|
d = 1.0;
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2014-06-08 17:55:22 +02:00
|
|
|
d += sin(d);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 05:01:13 +02:00
|
|
|
BIONIC_BENCHMARK(BM_math_sin_fast);
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_sin_feupdateenv(benchmark::State& state) {
|
2014-06-08 17:55:22 +02:00
|
|
|
d = 1.0;
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2014-06-08 17:55:22 +02:00
|
|
|
fenv_t __libc_save_rm;
|
|
|
|
feholdexcept(&__libc_save_rm);
|
|
|
|
fesetround(FE_TONEAREST);
|
|
|
|
d += sin(d);
|
|
|
|
feupdateenv(&__libc_save_rm);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 05:01:13 +02:00
|
|
|
BIONIC_BENCHMARK(BM_math_sin_feupdateenv);
|
2014-06-08 17:55:22 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_sin_fesetenv(benchmark::State& state) {
|
2014-06-08 17:55:22 +02:00
|
|
|
d = 1.0;
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2014-06-08 17:55:22 +02:00
|
|
|
fenv_t __libc_save_rm;
|
|
|
|
feholdexcept(&__libc_save_rm);
|
|
|
|
fesetround(FE_TONEAREST);
|
|
|
|
d += sin(d);
|
|
|
|
fesetenv(&__libc_save_rm);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 05:01:13 +02:00
|
|
|
BIONIC_BENCHMARK(BM_math_sin_fesetenv);
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_fpclassify(benchmark::State& state) {
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
d += fpclassify(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.
Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.
Also add some missing aliases. We now have all of:
isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.
Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-12 02:02:20 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_fpclassify, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_signbit_macro(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d += signbit(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_signbit_macro, "MATH_COMMON");
|
2015-08-14 23:04:30 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_signbit(benchmark::State& state) {
|
2015-08-14 23:04:30 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2017-10-19 22:56:28 +02:00
|
|
|
d += signbit(v);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-14 23:04:30 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_signbit, "MATH_COMMON");
|
2015-08-25 00:57:08 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_fabs_macro(benchmark::State& state) {
|
2015-08-25 00:57:08 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2015-08-25 00:57:08 +02:00
|
|
|
d += fabs(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-25 00:57:08 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_fabs_macro, "MATH_COMMON");
|
2015-08-25 00:57:08 +02:00
|
|
|
|
2016-02-17 19:23:52 +01:00
|
|
|
static void BM_math_fabs(benchmark::State& state) {
|
2015-08-25 00:57:08 +02:00
|
|
|
d = 0.0;
|
2016-11-14 14:16:08 +01:00
|
|
|
v = values[state.range(0)];
|
2016-02-17 19:23:52 +01:00
|
|
|
while (state.KeepRunning()) {
|
2015-08-25 00:57:08 +02:00
|
|
|
d += (fabs)(v);
|
|
|
|
}
|
2016-02-17 19:23:52 +01:00
|
|
|
SetLabel(state);
|
2015-08-25 00:57:08 +02:00
|
|
|
}
|
2017-11-30 17:53:15 +01:00
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_fabs, "MATH_COMMON");
|
2018-05-09 00:07:43 +02:00
|
|
|
|
|
|
|
static void BM_math_sincos(benchmark::State& state) {
|
|
|
|
d = 1.0;
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
double s, c;
|
|
|
|
sincos(d, &s, &c);
|
|
|
|
d += s + c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_sincos);
|
2018-06-05 14:28:40 +02:00
|
|
|
|
|
|
|
#include "expf_input.cpp"
|
|
|
|
|
|
|
|
static void BM_math_expf_speccpu2017(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = expf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = expf(*cin);
|
|
|
|
if (++cin == expf_input.cend())
|
|
|
|
cin = expf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_expf_speccpu2017);
|
|
|
|
|
|
|
|
static void BM_math_expf_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = expf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = expf(f * zero + *cin);
|
|
|
|
if (++cin == expf_input.cend())
|
|
|
|
cin = expf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_expf_speccpu2017_latency);
|
|
|
|
|
2018-08-08 15:54:53 +02:00
|
|
|
// Create a double version of expf_input to avoid overhead of float to
|
|
|
|
// double conversion.
|
|
|
|
static const std::vector<double> exp_input (expf_input.begin(),
|
|
|
|
expf_input.end());
|
|
|
|
|
|
|
|
static void BM_math_exp_speccpu2017(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = exp_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
d = exp(*cin);
|
|
|
|
if (++cin == exp_input.cend())
|
|
|
|
cin = exp_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_exp_speccpu2017);
|
|
|
|
|
|
|
|
static void BM_math_exp_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = exp_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
d = exp(d * zerod + *cin);
|
|
|
|
if (++cin == exp_input.cend())
|
|
|
|
cin = exp_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_exp_speccpu2017_latency);
|
|
|
|
|
2018-06-05 14:28:40 +02:00
|
|
|
static void BM_math_exp2f_speccpu2017(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = expf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = exp2f(*cin);
|
|
|
|
if (++cin == expf_input.cend())
|
|
|
|
cin = expf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_exp2f_speccpu2017);
|
|
|
|
|
|
|
|
static void BM_math_exp2f_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = expf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = exp2f(f * zero + *cin);
|
|
|
|
if (++cin == expf_input.cend())
|
|
|
|
cin = expf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_exp2f_speccpu2017_latency);
|
2018-06-05 18:57:03 +02:00
|
|
|
|
2018-08-08 15:54:53 +02:00
|
|
|
static void BM_math_exp2_speccpu2017(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = exp_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = exp2(*cin);
|
|
|
|
if (++cin == exp_input.cend())
|
|
|
|
cin = exp_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_exp2_speccpu2017);
|
|
|
|
|
|
|
|
static void BM_math_exp2_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = exp_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = exp2(d * zero + *cin);
|
|
|
|
if (++cin == exp_input.cend())
|
|
|
|
cin = exp_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_exp2_speccpu2017_latency);
|
|
|
|
|
2018-06-05 18:57:03 +02:00
|
|
|
#include "powf_input.cpp"
|
|
|
|
|
2018-08-08 18:36:14 +02:00
|
|
|
static const std::vector<std::pair<double, double>> pow_input
|
|
|
|
(powf_input.begin(), powf_input.end());
|
|
|
|
|
2018-06-05 18:57:03 +02:00
|
|
|
static void BM_math_powf_speccpu2006(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = powf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = powf(cin->first, cin->second);
|
|
|
|
if (++cin == powf_input.cend())
|
|
|
|
cin = powf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_powf_speccpu2006);
|
|
|
|
|
|
|
|
static void BM_math_powf_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = powf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = powf(f * zero + cin->first, cin->second);
|
|
|
|
if (++cin == powf_input.cend())
|
|
|
|
cin = powf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_powf_speccpu2017_latency);
|
2018-06-05 20:47:06 +02:00
|
|
|
|
2018-08-08 18:36:14 +02:00
|
|
|
static void BM_math_pow_speccpu2006(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = pow_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = pow(cin->first, cin->second);
|
|
|
|
if (++cin == pow_input.cend())
|
|
|
|
cin = pow_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_pow_speccpu2006);
|
|
|
|
|
|
|
|
static void BM_math_pow_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = pow_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
d = powf(d * zero + cin->first, cin->second);
|
|
|
|
if (++cin == pow_input.cend())
|
|
|
|
cin = pow_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_pow_speccpu2017_latency);
|
|
|
|
|
2018-06-05 20:47:06 +02:00
|
|
|
#include "logf_input.cpp"
|
|
|
|
|
2018-08-08 16:02:26 +02:00
|
|
|
static const std::vector<double> log_input (logf_input.begin(),
|
|
|
|
logf_input.end());
|
|
|
|
|
2018-06-05 20:47:06 +02:00
|
|
|
static void BM_math_logf_speccpu2017(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = logf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = logf(*cin);
|
|
|
|
if (++cin == logf_input.cend())
|
|
|
|
cin = logf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_logf_speccpu2017);
|
|
|
|
|
|
|
|
static void BM_math_logf_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = logf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = logf(f * zero + *cin);
|
|
|
|
if (++cin == logf_input.cend())
|
|
|
|
cin = logf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_logf_speccpu2017_latency);
|
|
|
|
|
2018-08-08 16:02:26 +02:00
|
|
|
static void BM_math_log_speccpu2017(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = log_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
d = log(*cin);
|
|
|
|
if (++cin == log_input.cend())
|
|
|
|
cin = log_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_log_speccpu2017);
|
|
|
|
|
|
|
|
static void BM_math_log_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = log_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
d = log(d * zerod + *cin);
|
|
|
|
if (++cin == log_input.cend())
|
|
|
|
cin = log_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_log_speccpu2017_latency);
|
|
|
|
|
2018-06-05 20:47:06 +02:00
|
|
|
static void BM_math_log2f_speccpu2017(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = logf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = log2f(*cin);
|
|
|
|
if (++cin == logf_input.cend())
|
|
|
|
cin = logf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_log2f_speccpu2017);
|
|
|
|
|
2018-08-08 16:02:26 +02:00
|
|
|
static void BM_math_log2_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = log_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
d = log2(d * zerod + *cin);
|
|
|
|
if (++cin == log_input.cend())
|
|
|
|
cin = log_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_log2_speccpu2017_latency);
|
|
|
|
|
|
|
|
static void BM_math_log2_speccpu2017(benchmark::State& state) {
|
|
|
|
d = 0.0;
|
|
|
|
auto cin = log_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
d = log2(*cin);
|
|
|
|
if (++cin == log_input.cend())
|
|
|
|
cin = log_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_log2_speccpu2017);
|
|
|
|
|
2018-06-05 20:47:06 +02:00
|
|
|
static void BM_math_log2f_speccpu2017_latency(benchmark::State& state) {
|
|
|
|
f = 0.0;
|
|
|
|
auto cin = logf_input.cbegin();
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = log2f(f * zero + *cin);
|
|
|
|
if (++cin == logf_input.cend())
|
|
|
|
cin = logf_input.cbegin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK(BM_math_log2f_speccpu2017_latency);
|
2018-06-08 16:18:32 +02:00
|
|
|
|
|
|
|
// Four ranges of values are checked:
|
|
|
|
// * 0.0 <= x < 0.1
|
|
|
|
// * 0.1 <= x < 0.7
|
|
|
|
// * 0.7 <= x < 3.1
|
|
|
|
// * -3.1 <= x < 3.1
|
|
|
|
// * 3.3 <= x < 33.3
|
|
|
|
// * 100.0 <= x < 1000.0
|
|
|
|
// * 1e6 <= x < 1e32
|
|
|
|
// * 1e32 < x < FLT_MAX
|
|
|
|
|
|
|
|
#include "sincosf_input.cpp"
|
|
|
|
|
|
|
|
static void BM_math_sinf(benchmark::State& state) {
|
|
|
|
auto range = sincosf_input[state.range(0)];
|
|
|
|
auto cin = range.values.cbegin();
|
|
|
|
f = 0.0;
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = sinf(*cin);
|
|
|
|
if (++cin == range.values.cend())
|
|
|
|
cin = range.values.cbegin();
|
|
|
|
}
|
|
|
|
state.SetLabel(range.label);
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf, "MATH_SINCOS_COMMON");
|
|
|
|
|
|
|
|
static void BM_math_sinf_latency(benchmark::State& state) {
|
|
|
|
auto range = sincosf_input[state.range(0)];
|
|
|
|
auto cin = range.values.cbegin();
|
|
|
|
f = 0.0;
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = sinf(f * zero + *cin);
|
|
|
|
if (++cin == range.values.cend())
|
|
|
|
cin = range.values.cbegin();
|
|
|
|
}
|
|
|
|
state.SetLabel(range.label);
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf_latency, "MATH_SINCOS_COMMON");
|
|
|
|
|
|
|
|
static void BM_math_cosf(benchmark::State& state) {
|
|
|
|
auto range = sincosf_input[state.range(0)];
|
|
|
|
auto cin = range.values.cbegin();
|
|
|
|
f = 0.0;
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = cosf(*cin);
|
|
|
|
if (++cin == range.values.cend())
|
|
|
|
cin = range.values.cbegin();
|
|
|
|
}
|
|
|
|
state.SetLabel(range.label);
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf, "MATH_SINCOS_COMMON");
|
|
|
|
|
|
|
|
static void BM_math_cosf_latency(benchmark::State& state) {
|
|
|
|
auto range = sincosf_input[state.range(0)];
|
|
|
|
auto cin = range.values.cbegin();
|
|
|
|
f = 0.0;
|
|
|
|
for (auto _ : state) {
|
|
|
|
f = cosf(f * zero + *cin);
|
|
|
|
if (++cin == range.values.cend())
|
|
|
|
cin = range.values.cbegin();
|
|
|
|
}
|
|
|
|
state.SetLabel(range.label);
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf_latency, "MATH_SINCOS_COMMON");
|
|
|
|
|
|
|
|
static void BM_math_sincosf(benchmark::State& state) {
|
|
|
|
auto range = sincosf_input[state.range(0)];
|
|
|
|
auto cin = range.values.cbegin();
|
|
|
|
f = 0.0;
|
|
|
|
for (auto _ : state) {
|
|
|
|
float s, c;
|
|
|
|
sincosf(*cin, &s, &c);
|
|
|
|
f += s;
|
|
|
|
if (++cin == range.values.cend())
|
|
|
|
cin = range.values.cbegin();
|
|
|
|
}
|
|
|
|
state.SetLabel(range.label);
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf, "MATH_SINCOS_COMMON");
|
|
|
|
|
|
|
|
static void BM_math_sincosf_latency(benchmark::State& state) {
|
|
|
|
auto range = sincosf_input[state.range(0)];
|
|
|
|
auto cin = range.values.cbegin();
|
|
|
|
f = 0.0;
|
|
|
|
for (auto _ : state) {
|
|
|
|
float s, c;
|
|
|
|
sincosf(f * zero + *cin, &s, &c);
|
|
|
|
f += s;
|
|
|
|
if (++cin == range.values.cend())
|
|
|
|
cin = range.values.cbegin();
|
|
|
|
}
|
|
|
|
state.SetLabel(range.label);
|
|
|
|
}
|
|
|
|
BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf_latency, "MATH_SINCOS_COMMON");
|