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 | |
| 27 | static void SetLabel(benchmark::State& state) { |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 28 | state.SetLabel(names[state.range(0)]); |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 29 | } |
Christopher Ferris | df4942c | 2015-02-17 19:58:53 -0800 | [diff] [blame] | 30 | |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 31 | // Avoid optimization. |
Dan Albert | 055a59c | 2014-09-25 15:43:48 -0700 | [diff] [blame] | 32 | volatile double d; |
| 33 | volatile double v; |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 34 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 35 | static void BM_math_sqrt(benchmark::State& state) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 36 | d = 0.0; |
| 37 | v = 2.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 38 | while (state.KeepRunning()) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 39 | d += sqrt(v); |
| 40 | } |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 41 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 42 | BIONIC_BENCHMARK(BM_math_sqrt); |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 43 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 44 | static void BM_math_log10(benchmark::State& state) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 45 | d = 0.0; |
| 46 | v = 1234.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 47 | while (state.KeepRunning()) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 48 | d += log10(v); |
| 49 | } |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 50 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 51 | BIONIC_BENCHMARK(BM_math_log10); |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 52 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 53 | static void BM_math_logb(benchmark::State& state) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 54 | d = 0.0; |
| 55 | v = 1234.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 56 | while (state.KeepRunning()) { |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 57 | d += logb(v); |
| 58 | } |
Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 59 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 60 | BIONIC_BENCHMARK(BM_math_logb); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 61 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 62 | static void BM_math_isfinite_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 63 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 64 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 65 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 66 | d += isfinite(v); |
| 67 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 68 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 69 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 70 | BIONIC_BENCHMARK(BM_math_isfinite_macro); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 71 | |
| 72 | #if defined(__BIONIC__) |
| 73 | #define test_isfinite __isfinite |
| 74 | #else |
| 75 | #define test_isfinite __finite |
| 76 | #endif |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 77 | static void BM_math_isfinite(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 78 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 79 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 80 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 81 | d += test_isfinite(v); |
| 82 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 83 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 84 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 85 | BIONIC_BENCHMARK(BM_math_isfinite); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 86 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 87 | static void BM_math_isinf_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 88 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 89 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 90 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 91 | d += isinf(v); |
| 92 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 93 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 94 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 95 | BIONIC_BENCHMARK(BM_math_isinf_macro); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 96 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 97 | static void BM_math_isinf(benchmark::State& state) { |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 98 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 99 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 100 | while (state.KeepRunning()) { |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 101 | d += (isinf)(v); |
| 102 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 103 | SetLabel(state); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 104 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 105 | BIONIC_BENCHMARK(BM_math_isinf); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 106 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 107 | static void BM_math_isnan_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 108 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 109 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 110 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 111 | d += isnan(v); |
| 112 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 113 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 114 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 115 | BIONIC_BENCHMARK(BM_math_isnan_macro); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 116 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 117 | static void BM_math_isnan(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 118 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 119 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 120 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 121 | d += (isnan)(v); |
| 122 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 123 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 124 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 125 | BIONIC_BENCHMARK(BM_math_isnan); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 126 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 127 | static void BM_math_isnormal_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 128 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 129 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 130 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 131 | d += isnormal(v); |
| 132 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 133 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 134 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 135 | BIONIC_BENCHMARK(BM_math_isnormal_macro); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 136 | |
| 137 | #if defined(__BIONIC__) |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 138 | static void BM_math_isnormal(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 139 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 140 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 141 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 142 | d += (__isnormal)(v); |
| 143 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 144 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 145 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 146 | BIONIC_BENCHMARK(BM_math_isnormal); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 147 | #endif |
| 148 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 149 | static void BM_math_sin_fast(benchmark::State& state) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 150 | d = 1.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 151 | while (state.KeepRunning()) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 152 | d += sin(d); |
| 153 | } |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 154 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 155 | BIONIC_BENCHMARK(BM_math_sin_fast); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 156 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 157 | static void BM_math_sin_feupdateenv(benchmark::State& state) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 158 | d = 1.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 159 | while (state.KeepRunning()) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 160 | fenv_t __libc_save_rm; |
| 161 | feholdexcept(&__libc_save_rm); |
| 162 | fesetround(FE_TONEAREST); |
| 163 | d += sin(d); |
| 164 | feupdateenv(&__libc_save_rm); |
| 165 | } |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 166 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 167 | BIONIC_BENCHMARK(BM_math_sin_feupdateenv); |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 168 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 169 | static void BM_math_sin_fesetenv(benchmark::State& state) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 170 | d = 1.0; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 171 | while (state.KeepRunning()) { |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 172 | fenv_t __libc_save_rm; |
| 173 | feholdexcept(&__libc_save_rm); |
| 174 | fesetround(FE_TONEAREST); |
| 175 | d += sin(d); |
| 176 | fesetenv(&__libc_save_rm); |
| 177 | } |
Serban Constantinescu | a147a1d | 2014-06-08 16:55:22 +0100 | [diff] [blame] | 178 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 179 | BIONIC_BENCHMARK(BM_math_sin_fesetenv); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 180 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 181 | static void BM_math_fpclassify(benchmark::State& state) { |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 182 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 183 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 184 | while (state.KeepRunning()) { |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 185 | d += fpclassify(v); |
| 186 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 187 | SetLabel(state); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame] | 188 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 189 | BIONIC_BENCHMARK(BM_math_fpclassify); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 190 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 191 | static void BM_math_signbit_macro(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 192 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 193 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 194 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 195 | d += signbit(v); |
| 196 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 197 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 198 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 199 | BIONIC_BENCHMARK(BM_math_signbit_macro); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 200 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 201 | static void BM_math_signbit(benchmark::State& state) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 202 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 203 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 204 | while (state.KeepRunning()) { |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 205 | d += (__signbit)(v); |
| 206 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 207 | SetLabel(state); |
Elliott Hughes | b662280 | 2015-08-14 14:04:30 -0700 | [diff] [blame] | 208 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 209 | BIONIC_BENCHMARK(BM_math_signbit); |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 210 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 211 | static void BM_math_fabs_macro(benchmark::State& state) { |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 212 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 213 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 214 | while (state.KeepRunning()) { |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 215 | d += fabs(v); |
| 216 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 217 | SetLabel(state); |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 218 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 219 | BIONIC_BENCHMARK(BM_math_fabs_macro); |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 220 | |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 221 | static void BM_math_fabs(benchmark::State& state) { |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 222 | d = 0.0; |
Martijn Coenen | be763d8 | 2016-11-14 14:16:08 +0100 | [diff] [blame] | 223 | v = values[state.range(0)]; |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 224 | while (state.KeepRunning()) { |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 225 | d += (fabs)(v); |
| 226 | } |
Elliott Hughes | 281e06b | 2016-02-17 10:23:52 -0800 | [diff] [blame] | 227 | SetLabel(state); |
Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 228 | } |
Anders Lewis | a7b0f88 | 2017-07-24 20:01:13 -0700 | [diff] [blame] | 229 | BIONIC_BENCHMARK(BM_math_fabs); |