Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 17 | #include <fenv.h> |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 18 | #include <math.h> |
| 19 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 20 | #include <benchmark/benchmark.h> |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 21 | #include "util.h" |
Christopher Ferris | df4942c | 2015-02-17 19:58:53 -0800 | [diff] [blame] | 22 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 23 | static const double values[] = { 1234.0, nan(""), HUGE_VAL, 0.0 }; |
| 24 | static const char* names[] = { "1234.0", "nan", "HUGE_VAL", "0.0" }; |
| 25 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 26 | static void SetLabel(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 27 | state.SetLabel(names[state.range(0)]); |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 28 | } |
Christopher Ferris | df4942c | 2015-02-17 19:58:53 -0800 | [diff] [blame] | 29 | |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 30 | // Avoid optimization. |
Dan Albert | 055a59c | 2014-09-25 15:43:48 -0700 | [diff] [blame] | 31 | volatile double d; |
| 32 | volatile double v; |
Adhemerval Zanella | 357f6c1 | 2018-06-05 09:28:40 -0300 | [diff] [blame] | 33 | volatile float f; |
| 34 | |
| 35 | static float zero = 0.0f; |
Adhemerval Zanella | 10d330a | 2018-08-08 10:54:53 -0300 | [diff] [blame] | 36 | static double zerod = 0.0f; |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 37 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 38 | static void BM_math_sqrt(benchmark::State& state) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 39 | d = 0.0; |
| 40 | v = 2.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 41 | while (state.KeepRunning()) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 42 | d += sqrt(v); |
| 43 | } |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 44 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 45 | BIONIC_BENCHMARK(BM_math_sqrt); |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 46 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 47 | static void BM_math_log10(benchmark::State& state) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 48 | d = 0.0; |
| 49 | v = 1234.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 50 | while (state.KeepRunning()) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 51 | d += log10(v); |
| 52 | } |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 53 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 54 | BIONIC_BENCHMARK(BM_math_log10); |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 55 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 56 | static void BM_math_logb(benchmark::State& state) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 57 | d = 0.0; |
| 58 | v = 1234.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 59 | while (state.KeepRunning()) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 60 | d += logb(v); |
| 61 | } |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 62 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 63 | BIONIC_BENCHMARK(BM_math_logb); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 64 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 65 | static void BM_math_isfinite_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 66 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 67 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 68 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 69 | d += isfinite(v); |
| 70 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 71 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 72 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 73 | BIONIC_BENCHMARK_WITH_ARG(BM_math_isfinite_macro, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 74 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 75 | static void BM_math_isfinite(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 76 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 77 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 78 | while (state.KeepRunning()) { |
Elliott Hughes | 5c6a7bf | 2017-10-19 13:56:28 -0700 | [diff] [blame] | 79 | d += isfinite(v); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 80 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 81 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 82 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 83 | BIONIC_BENCHMARK_WITH_ARG(BM_math_isfinite, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 84 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 85 | static void BM_math_isinf_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 86 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 87 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 88 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 89 | d += isinf(v); |
| 90 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 91 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 92 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 93 | BIONIC_BENCHMARK_WITH_ARG(BM_math_isinf_macro, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 94 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 95 | static void BM_math_isinf(benchmark::State& state) { |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 96 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 97 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 98 | while (state.KeepRunning()) { |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 99 | d += (isinf)(v); |
| 100 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 101 | SetLabel(state); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 102 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 103 | BIONIC_BENCHMARK_WITH_ARG(BM_math_isinf, "MATH_COMMON"); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 104 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 105 | static void BM_math_isnan_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 106 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 107 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 108 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 109 | d += isnan(v); |
| 110 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 111 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 112 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 113 | BIONIC_BENCHMARK_WITH_ARG(BM_math_isnan_macro, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 114 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 115 | static void BM_math_isnan(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 116 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 117 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 118 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 119 | d += (isnan)(v); |
| 120 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 121 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 122 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 123 | BIONIC_BENCHMARK_WITH_ARG(BM_math_isnan, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 124 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 125 | static void BM_math_isnormal_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 126 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 127 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 128 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 129 | d += isnormal(v); |
| 130 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 131 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 132 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 133 | BIONIC_BENCHMARK_WITH_ARG(BM_math_isnormal_macro, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 134 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 135 | static void BM_math_isnormal(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 136 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 137 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 138 | while (state.KeepRunning()) { |
Elliott Hughes | 5c6a7bf | 2017-10-19 13:56:28 -0700 | [diff] [blame] | 139 | d += isnormal(v); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 140 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 141 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 142 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 143 | BIONIC_BENCHMARK_WITH_ARG(BM_math_isnormal, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 144 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 145 | static void BM_math_sin_fast(benchmark::State& state) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 146 | d = 1.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 147 | while (state.KeepRunning()) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 148 | d += sin(d); |
| 149 | } |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 150 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 151 | BIONIC_BENCHMARK(BM_math_sin_fast); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 152 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 153 | static void BM_math_sin_feupdateenv(benchmark::State& state) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 154 | d = 1.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 155 | while (state.KeepRunning()) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 156 | fenv_t __libc_save_rm; |
| 157 | feholdexcept(&__libc_save_rm); |
| 158 | fesetround(FE_TONEAREST); |
| 159 | d += sin(d); |
| 160 | feupdateenv(&__libc_save_rm); |
| 161 | } |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 162 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 163 | BIONIC_BENCHMARK(BM_math_sin_feupdateenv); |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 164 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 165 | static void BM_math_sin_fesetenv(benchmark::State& state) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 166 | d = 1.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 167 | while (state.KeepRunning()) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 168 | fenv_t __libc_save_rm; |
| 169 | feholdexcept(&__libc_save_rm); |
| 170 | fesetround(FE_TONEAREST); |
| 171 | d += sin(d); |
| 172 | fesetenv(&__libc_save_rm); |
| 173 | } |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 174 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 175 | BIONIC_BENCHMARK(BM_math_sin_fesetenv); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 176 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 177 | static void BM_math_fpclassify(benchmark::State& state) { |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 178 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 179 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 180 | while (state.KeepRunning()) { |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 181 | d += fpclassify(v); |
| 182 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 183 | SetLabel(state); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 184 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 185 | BIONIC_BENCHMARK_WITH_ARG(BM_math_fpclassify, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 186 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 187 | static void BM_math_signbit_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 188 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 189 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 190 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 191 | d += signbit(v); |
| 192 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 193 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 194 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 195 | BIONIC_BENCHMARK_WITH_ARG(BM_math_signbit_macro, "MATH_COMMON"); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 196 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 197 | static void BM_math_signbit(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 198 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 199 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 200 | while (state.KeepRunning()) { |
Elliott Hughes | 5c6a7bf | 2017-10-19 13:56:28 -0700 | [diff] [blame] | 201 | d += signbit(v); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 202 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 203 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 204 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 205 | BIONIC_BENCHMARK_WITH_ARG(BM_math_signbit, "MATH_COMMON"); |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 206 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 207 | static void BM_math_fabs_macro(benchmark::State& state) { |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 208 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 209 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 210 | while (state.KeepRunning()) { |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 211 | d += fabs(v); |
| 212 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 213 | SetLabel(state); |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 214 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 215 | BIONIC_BENCHMARK_WITH_ARG(BM_math_fabs_macro, "MATH_COMMON"); |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 216 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 217 | static void BM_math_fabs(benchmark::State& state) { |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 218 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 219 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 220 | while (state.KeepRunning()) { |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 221 | d += (fabs)(v); |
| 222 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 223 | SetLabel(state); |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 224 | } |
Christopher Ferris | 858e336 | 2017-11-30 08:53:15 -0800 | [diff] [blame] | 225 | BIONIC_BENCHMARK_WITH_ARG(BM_math_fabs, "MATH_COMMON"); |
Elliott Hughes | e332f65 | 2018-05-08 15:07:43 -0700 | [diff] [blame] | 226 | |
| 227 | static void BM_math_sincos(benchmark::State& state) { |
| 228 | d = 1.0; |
| 229 | while (state.KeepRunning()) { |
| 230 | double s, c; |
| 231 | sincos(d, &s, &c); |
| 232 | d += s + c; |
| 233 | } |
| 234 | } |
| 235 | BIONIC_BENCHMARK(BM_math_sincos); |
Adhemerval Zanella | 357f6c1 | 2018-06-05 09:28:40 -0300 | [diff] [blame] | 236 | |
| 237 | #include "expf_input.cpp" |
| 238 | |
| 239 | static void BM_math_expf_speccpu2017(benchmark::State& state) { |
| 240 | f = 0.0; |
| 241 | auto cin = expf_input.cbegin(); |
| 242 | for (auto _ : state) { |
| 243 | f = expf(*cin); |
| 244 | if (++cin == expf_input.cend()) |
| 245 | cin = expf_input.cbegin(); |
| 246 | } |
| 247 | } |
| 248 | BIONIC_BENCHMARK(BM_math_expf_speccpu2017); |
| 249 | |
| 250 | static void BM_math_expf_speccpu2017_latency(benchmark::State& state) { |
| 251 | f = 0.0; |
| 252 | auto cin = expf_input.cbegin(); |
| 253 | for (auto _ : state) { |
| 254 | f = expf(f * zero + *cin); |
| 255 | if (++cin == expf_input.cend()) |
| 256 | cin = expf_input.cbegin(); |
| 257 | } |
| 258 | } |
| 259 | BIONIC_BENCHMARK(BM_math_expf_speccpu2017_latency); |
| 260 | |
Adhemerval Zanella | 10d330a | 2018-08-08 10:54:53 -0300 | [diff] [blame] | 261 | // Create a double version of expf_input to avoid overhead of float to |
| 262 | // double conversion. |
| 263 | static const std::vector<double> exp_input (expf_input.begin(), |
| 264 | expf_input.end()); |
| 265 | |
| 266 | static void BM_math_exp_speccpu2017(benchmark::State& state) { |
| 267 | d = 0.0; |
| 268 | auto cin = exp_input.cbegin(); |
| 269 | for (auto _ : state) { |
| 270 | d = exp(*cin); |
| 271 | if (++cin == exp_input.cend()) |
| 272 | cin = exp_input.cbegin(); |
| 273 | } |
| 274 | } |
| 275 | BIONIC_BENCHMARK(BM_math_exp_speccpu2017); |
| 276 | |
| 277 | static void BM_math_exp_speccpu2017_latency(benchmark::State& state) { |
| 278 | d = 0.0; |
| 279 | auto cin = exp_input.cbegin(); |
| 280 | for (auto _ : state) { |
| 281 | d = exp(d * zerod + *cin); |
| 282 | if (++cin == exp_input.cend()) |
| 283 | cin = exp_input.cbegin(); |
| 284 | } |
| 285 | } |
| 286 | BIONIC_BENCHMARK(BM_math_exp_speccpu2017_latency); |
| 287 | |
Adhemerval Zanella | 357f6c1 | 2018-06-05 09:28:40 -0300 | [diff] [blame] | 288 | static void BM_math_exp2f_speccpu2017(benchmark::State& state) { |
| 289 | f = 0.0; |
| 290 | auto cin = expf_input.cbegin(); |
| 291 | for (auto _ : state) { |
| 292 | f = exp2f(*cin); |
| 293 | if (++cin == expf_input.cend()) |
| 294 | cin = expf_input.cbegin(); |
| 295 | } |
| 296 | } |
| 297 | BIONIC_BENCHMARK(BM_math_exp2f_speccpu2017); |
| 298 | |
| 299 | static void BM_math_exp2f_speccpu2017_latency(benchmark::State& state) { |
| 300 | f = 0.0; |
| 301 | auto cin = expf_input.cbegin(); |
| 302 | for (auto _ : state) { |
| 303 | f = exp2f(f * zero + *cin); |
| 304 | if (++cin == expf_input.cend()) |
| 305 | cin = expf_input.cbegin(); |
| 306 | } |
| 307 | } |
| 308 | BIONIC_BENCHMARK(BM_math_exp2f_speccpu2017_latency); |
Adhemerval Zanella | 872c8b5 | 2018-06-05 13:57:03 -0300 | [diff] [blame] | 309 | |
Adhemerval Zanella | 10d330a | 2018-08-08 10:54:53 -0300 | [diff] [blame] | 310 | static void BM_math_exp2_speccpu2017(benchmark::State& state) { |
| 311 | d = 0.0; |
| 312 | auto cin = exp_input.cbegin(); |
| 313 | for (auto _ : state) { |
| 314 | f = exp2(*cin); |
| 315 | if (++cin == exp_input.cend()) |
| 316 | cin = exp_input.cbegin(); |
| 317 | } |
| 318 | } |
| 319 | BIONIC_BENCHMARK(BM_math_exp2_speccpu2017); |
| 320 | |
| 321 | static void BM_math_exp2_speccpu2017_latency(benchmark::State& state) { |
| 322 | d = 0.0; |
| 323 | auto cin = exp_input.cbegin(); |
| 324 | for (auto _ : state) { |
| 325 | f = exp2(d * zero + *cin); |
| 326 | if (++cin == exp_input.cend()) |
| 327 | cin = exp_input.cbegin(); |
| 328 | } |
| 329 | } |
| 330 | BIONIC_BENCHMARK(BM_math_exp2_speccpu2017_latency); |
| 331 | |
Adhemerval Zanella | 872c8b5 | 2018-06-05 13:57:03 -0300 | [diff] [blame] | 332 | #include "powf_input.cpp" |
| 333 | |
| 334 | static void BM_math_powf_speccpu2006(benchmark::State& state) { |
| 335 | f = 0.0; |
| 336 | auto cin = powf_input.cbegin(); |
| 337 | for (auto _ : state) { |
| 338 | f = powf(cin->first, cin->second); |
| 339 | if (++cin == powf_input.cend()) |
| 340 | cin = powf_input.cbegin(); |
| 341 | } |
| 342 | } |
| 343 | BIONIC_BENCHMARK(BM_math_powf_speccpu2006); |
| 344 | |
| 345 | static void BM_math_powf_speccpu2017_latency(benchmark::State& state) { |
| 346 | f = 0.0; |
| 347 | auto cin = powf_input.cbegin(); |
| 348 | for (auto _ : state) { |
| 349 | f = powf(f * zero + cin->first, cin->second); |
| 350 | if (++cin == powf_input.cend()) |
| 351 | cin = powf_input.cbegin(); |
| 352 | } |
| 353 | } |
| 354 | BIONIC_BENCHMARK(BM_math_powf_speccpu2017_latency); |
Adhemerval Zanella | ff5a353 | 2018-06-05 15:47:06 -0300 | [diff] [blame] | 355 | |
| 356 | #include "logf_input.cpp" |
| 357 | |
| 358 | static void BM_math_logf_speccpu2017(benchmark::State& state) { |
| 359 | f = 0.0; |
| 360 | auto cin = logf_input.cbegin(); |
| 361 | for (auto _ : state) { |
| 362 | f = logf(*cin); |
| 363 | if (++cin == logf_input.cend()) |
| 364 | cin = logf_input.cbegin(); |
| 365 | } |
| 366 | } |
| 367 | BIONIC_BENCHMARK(BM_math_logf_speccpu2017); |
| 368 | |
| 369 | static void BM_math_logf_speccpu2017_latency(benchmark::State& state) { |
| 370 | f = 0.0; |
| 371 | auto cin = logf_input.cbegin(); |
| 372 | for (auto _ : state) { |
| 373 | f = logf(f * zero + *cin); |
| 374 | if (++cin == logf_input.cend()) |
| 375 | cin = logf_input.cbegin(); |
| 376 | } |
| 377 | } |
| 378 | BIONIC_BENCHMARK(BM_math_logf_speccpu2017_latency); |
| 379 | |
| 380 | static void BM_math_log2f_speccpu2017(benchmark::State& state) { |
| 381 | f = 0.0; |
| 382 | auto cin = logf_input.cbegin(); |
| 383 | for (auto _ : state) { |
| 384 | f = log2f(*cin); |
| 385 | if (++cin == logf_input.cend()) |
| 386 | cin = logf_input.cbegin(); |
| 387 | } |
| 388 | } |
| 389 | BIONIC_BENCHMARK(BM_math_log2f_speccpu2017); |
| 390 | |
| 391 | static void BM_math_log2f_speccpu2017_latency(benchmark::State& state) { |
| 392 | f = 0.0; |
| 393 | auto cin = logf_input.cbegin(); |
| 394 | for (auto _ : state) { |
| 395 | f = log2f(f * zero + *cin); |
| 396 | if (++cin == logf_input.cend()) |
| 397 | cin = logf_input.cbegin(); |
| 398 | } |
| 399 | } |
| 400 | BIONIC_BENCHMARK(BM_math_log2f_speccpu2017_latency); |
Adhemerval Zanella | 7871ca1 | 2018-06-08 11:18:32 -0300 | [diff] [blame] | 401 | |
| 402 | // Four ranges of values are checked: |
| 403 | // * 0.0 <= x < 0.1 |
| 404 | // * 0.1 <= x < 0.7 |
| 405 | // * 0.7 <= x < 3.1 |
| 406 | // * -3.1 <= x < 3.1 |
| 407 | // * 3.3 <= x < 33.3 |
| 408 | // * 100.0 <= x < 1000.0 |
| 409 | // * 1e6 <= x < 1e32 |
| 410 | // * 1e32 < x < FLT_MAX |
| 411 | |
| 412 | #include "sincosf_input.cpp" |
| 413 | |
| 414 | static void BM_math_sinf(benchmark::State& state) { |
| 415 | auto range = sincosf_input[state.range(0)]; |
| 416 | auto cin = range.values.cbegin(); |
| 417 | f = 0.0; |
| 418 | for (auto _ : state) { |
| 419 | f = sinf(*cin); |
| 420 | if (++cin == range.values.cend()) |
| 421 | cin = range.values.cbegin(); |
| 422 | } |
| 423 | state.SetLabel(range.label); |
| 424 | } |
| 425 | BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf, "MATH_SINCOS_COMMON"); |
| 426 | |
| 427 | static void BM_math_sinf_latency(benchmark::State& state) { |
| 428 | auto range = sincosf_input[state.range(0)]; |
| 429 | auto cin = range.values.cbegin(); |
| 430 | f = 0.0; |
| 431 | for (auto _ : state) { |
| 432 | f = sinf(f * zero + *cin); |
| 433 | if (++cin == range.values.cend()) |
| 434 | cin = range.values.cbegin(); |
| 435 | } |
| 436 | state.SetLabel(range.label); |
| 437 | } |
| 438 | BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf_latency, "MATH_SINCOS_COMMON"); |
| 439 | |
| 440 | static void BM_math_cosf(benchmark::State& state) { |
| 441 | auto range = sincosf_input[state.range(0)]; |
| 442 | auto cin = range.values.cbegin(); |
| 443 | f = 0.0; |
| 444 | for (auto _ : state) { |
| 445 | f = cosf(*cin); |
| 446 | if (++cin == range.values.cend()) |
| 447 | cin = range.values.cbegin(); |
| 448 | } |
| 449 | state.SetLabel(range.label); |
| 450 | } |
| 451 | BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf, "MATH_SINCOS_COMMON"); |
| 452 | |
| 453 | static void BM_math_cosf_latency(benchmark::State& state) { |
| 454 | auto range = sincosf_input[state.range(0)]; |
| 455 | auto cin = range.values.cbegin(); |
| 456 | f = 0.0; |
| 457 | for (auto _ : state) { |
| 458 | f = cosf(f * zero + *cin); |
| 459 | if (++cin == range.values.cend()) |
| 460 | cin = range.values.cbegin(); |
| 461 | } |
| 462 | state.SetLabel(range.label); |
| 463 | } |
| 464 | BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf_latency, "MATH_SINCOS_COMMON"); |
| 465 | |
| 466 | static void BM_math_sincosf(benchmark::State& state) { |
| 467 | auto range = sincosf_input[state.range(0)]; |
| 468 | auto cin = range.values.cbegin(); |
| 469 | f = 0.0; |
| 470 | for (auto _ : state) { |
| 471 | float s, c; |
| 472 | sincosf(*cin, &s, &c); |
| 473 | f += s; |
| 474 | if (++cin == range.values.cend()) |
| 475 | cin = range.values.cbegin(); |
| 476 | } |
| 477 | state.SetLabel(range.label); |
| 478 | } |
| 479 | BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf, "MATH_SINCOS_COMMON"); |
| 480 | |
| 481 | static void BM_math_sincosf_latency(benchmark::State& state) { |
| 482 | auto range = sincosf_input[state.range(0)]; |
| 483 | auto cin = range.values.cbegin(); |
| 484 | f = 0.0; |
| 485 | for (auto _ : state) { |
| 486 | float s, c; |
| 487 | sincosf(f * zero + *cin, &s, &c); |
| 488 | f += s; |
| 489 | if (++cin == range.values.cend()) |
| 490 | cin = range.values.cbegin(); |
| 491 | } |
| 492 | state.SetLabel(range.label); |
| 493 | } |
| 494 | BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf_latency, "MATH_SINCOS_COMMON"); |