blob: c3f14c8f7ace047dcf9487b8b0cea1e075ab3467 [file] [log] [blame]
Elliott Hughes9edb3e02013-02-06 15:47:09 -08001/*
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 Constantinescua147a1d2014-06-08 16:55:22 +010017#include <fenv.h>
Elliott Hughes9edb3e02013-02-06 15:47:09 -080018#include <math.h>
19
Elliott Hughes281e06b2016-02-17 10:23:52 -080020#include <benchmark/benchmark.h>
Anders Lewisa7b0f882017-07-24 20:01:13 -070021#include "util.h"
Christopher Ferrisdf4942c2015-02-17 19:58:53 -080022
Elliott Hughes281e06b2016-02-17 10:23:52 -080023static const double values[] = { 1234.0, nan(""), HUGE_VAL, 0.0 };
24static const char* names[] = { "1234.0", "nan", "HUGE_VAL", "0.0" };
25
Elliott Hughes281e06b2016-02-17 10:23:52 -080026static void SetLabel(benchmark::State& state) {
Martijn Coenenbe763d82016-11-14 14:16:08 +010027 state.SetLabel(names[state.range(0)]);
Elliott Hughes281e06b2016-02-17 10:23:52 -080028}
Christopher Ferrisdf4942c2015-02-17 19:58:53 -080029
Elliott Hughes9edb3e02013-02-06 15:47:09 -080030// Avoid optimization.
Dan Albert055a59c2014-09-25 15:43:48 -070031volatile double d;
32volatile double v;
Adhemerval Zanella357f6c12018-06-05 09:28:40 -030033volatile float f;
34
35static float zero = 0.0f;
Adhemerval Zanella10d330a2018-08-08 10:54:53 -030036static double zerod = 0.0f;
Elliott Hughes9edb3e02013-02-06 15:47:09 -080037
Elliott Hughes281e06b2016-02-17 10:23:52 -080038static void BM_math_sqrt(benchmark::State& state) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080039 d = 0.0;
40 v = 2.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -080041 while (state.KeepRunning()) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080042 d += sqrt(v);
43 }
Elliott Hughes9edb3e02013-02-06 15:47:09 -080044}
Anders Lewisa7b0f882017-07-24 20:01:13 -070045BIONIC_BENCHMARK(BM_math_sqrt);
Elliott Hughes9edb3e02013-02-06 15:47:09 -080046
Elliott Hughes281e06b2016-02-17 10:23:52 -080047static void BM_math_log10(benchmark::State& state) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080048 d = 0.0;
49 v = 1234.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -080050 while (state.KeepRunning()) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080051 d += log10(v);
52 }
Elliott Hughes9edb3e02013-02-06 15:47:09 -080053}
Anders Lewisa7b0f882017-07-24 20:01:13 -070054BIONIC_BENCHMARK(BM_math_log10);
Elliott Hughes9edb3e02013-02-06 15:47:09 -080055
Elliott Hughes281e06b2016-02-17 10:23:52 -080056static void BM_math_logb(benchmark::State& state) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080057 d = 0.0;
58 v = 1234.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -080059 while (state.KeepRunning()) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080060 d += logb(v);
61 }
Elliott Hughes9edb3e02013-02-06 15:47:09 -080062}
Anders Lewisa7b0f882017-07-24 20:01:13 -070063BIONIC_BENCHMARK(BM_math_logb);
Elliott Hughes02c78a32014-04-11 17:02:20 -070064
Elliott Hughes281e06b2016-02-17 10:23:52 -080065static void BM_math_isfinite_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -070066 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +010067 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -080068 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -070069 d += isfinite(v);
70 }
Elliott Hughes281e06b2016-02-17 10:23:52 -080071 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -070072}
Christopher Ferris858e3362017-11-30 08:53:15 -080073BIONIC_BENCHMARK_WITH_ARG(BM_math_isfinite_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -070074
Elliott Hughes281e06b2016-02-17 10:23:52 -080075static void BM_math_isfinite(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -070076 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +010077 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -080078 while (state.KeepRunning()) {
Elliott Hughes5c6a7bf2017-10-19 13:56:28 -070079 d += isfinite(v);
Elliott Hughesb6622802015-08-14 14:04:30 -070080 }
Elliott Hughes281e06b2016-02-17 10:23:52 -080081 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -070082}
Christopher Ferris858e3362017-11-30 08:53:15 -080083BIONIC_BENCHMARK_WITH_ARG(BM_math_isfinite, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -070084
Elliott Hughes281e06b2016-02-17 10:23:52 -080085static void BM_math_isinf_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -070086 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +010087 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -080088 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -070089 d += isinf(v);
90 }
Elliott Hughes281e06b2016-02-17 10:23:52 -080091 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -070092}
Christopher Ferris858e3362017-11-30 08:53:15 -080093BIONIC_BENCHMARK_WITH_ARG(BM_math_isinf_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -070094
Elliott Hughes281e06b2016-02-17 10:23:52 -080095static void BM_math_isinf(benchmark::State& state) {
Elliott Hughes02c78a32014-04-11 17:02:20 -070096 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +010097 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -080098 while (state.KeepRunning()) {
Elliott Hughes02c78a32014-04-11 17:02:20 -070099 d += (isinf)(v);
100 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800101 SetLabel(state);
Elliott Hughes02c78a32014-04-11 17:02:20 -0700102}
Christopher Ferris858e3362017-11-30 08:53:15 -0800103BIONIC_BENCHMARK_WITH_ARG(BM_math_isinf, "MATH_COMMON");
Elliott Hughes02c78a32014-04-11 17:02:20 -0700104
Elliott Hughes281e06b2016-02-17 10:23:52 -0800105static void BM_math_isnan_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700106 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100107 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800108 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700109 d += isnan(v);
110 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800111 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700112}
Christopher Ferris858e3362017-11-30 08:53:15 -0800113BIONIC_BENCHMARK_WITH_ARG(BM_math_isnan_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700114
Elliott Hughes281e06b2016-02-17 10:23:52 -0800115static void BM_math_isnan(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700116 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100117 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800118 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700119 d += (isnan)(v);
120 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800121 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700122}
Christopher Ferris858e3362017-11-30 08:53:15 -0800123BIONIC_BENCHMARK_WITH_ARG(BM_math_isnan, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700124
Elliott Hughes281e06b2016-02-17 10:23:52 -0800125static void BM_math_isnormal_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700126 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100127 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800128 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700129 d += isnormal(v);
130 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800131 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700132}
Christopher Ferris858e3362017-11-30 08:53:15 -0800133BIONIC_BENCHMARK_WITH_ARG(BM_math_isnormal_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700134
Elliott Hughes281e06b2016-02-17 10:23:52 -0800135static void BM_math_isnormal(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700136 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100137 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800138 while (state.KeepRunning()) {
Elliott Hughes5c6a7bf2017-10-19 13:56:28 -0700139 d += isnormal(v);
Elliott Hughesb6622802015-08-14 14:04:30 -0700140 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800141 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700142}
Christopher Ferris858e3362017-11-30 08:53:15 -0800143BIONIC_BENCHMARK_WITH_ARG(BM_math_isnormal, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700144
Elliott Hughes281e06b2016-02-17 10:23:52 -0800145static void BM_math_sin_fast(benchmark::State& state) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100146 d = 1.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -0800147 while (state.KeepRunning()) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100148 d += sin(d);
149 }
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100150}
Anders Lewisa7b0f882017-07-24 20:01:13 -0700151BIONIC_BENCHMARK(BM_math_sin_fast);
Elliott Hughes02c78a32014-04-11 17:02:20 -0700152
Elliott Hughes281e06b2016-02-17 10:23:52 -0800153static void BM_math_sin_feupdateenv(benchmark::State& state) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100154 d = 1.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -0800155 while (state.KeepRunning()) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100156 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 Constantinescua147a1d2014-06-08 16:55:22 +0100162}
Anders Lewisa7b0f882017-07-24 20:01:13 -0700163BIONIC_BENCHMARK(BM_math_sin_feupdateenv);
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100164
Elliott Hughes281e06b2016-02-17 10:23:52 -0800165static void BM_math_sin_fesetenv(benchmark::State& state) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100166 d = 1.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -0800167 while (state.KeepRunning()) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100168 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 Constantinescua147a1d2014-06-08 16:55:22 +0100174}
Anders Lewisa7b0f882017-07-24 20:01:13 -0700175BIONIC_BENCHMARK(BM_math_sin_fesetenv);
Elliott Hughes02c78a32014-04-11 17:02:20 -0700176
Elliott Hughes281e06b2016-02-17 10:23:52 -0800177static void BM_math_fpclassify(benchmark::State& state) {
Elliott Hughes02c78a32014-04-11 17:02:20 -0700178 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100179 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800180 while (state.KeepRunning()) {
Elliott Hughes02c78a32014-04-11 17:02:20 -0700181 d += fpclassify(v);
182 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800183 SetLabel(state);
Elliott Hughes02c78a32014-04-11 17:02:20 -0700184}
Christopher Ferris858e3362017-11-30 08:53:15 -0800185BIONIC_BENCHMARK_WITH_ARG(BM_math_fpclassify, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700186
Elliott Hughes281e06b2016-02-17 10:23:52 -0800187static void BM_math_signbit_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700188 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100189 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800190 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700191 d += signbit(v);
192 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800193 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700194}
Christopher Ferris858e3362017-11-30 08:53:15 -0800195BIONIC_BENCHMARK_WITH_ARG(BM_math_signbit_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700196
Elliott Hughes281e06b2016-02-17 10:23:52 -0800197static void BM_math_signbit(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700198 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100199 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800200 while (state.KeepRunning()) {
Elliott Hughes5c6a7bf2017-10-19 13:56:28 -0700201 d += signbit(v);
Elliott Hughesb6622802015-08-14 14:04:30 -0700202 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800203 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700204}
Christopher Ferris858e3362017-11-30 08:53:15 -0800205BIONIC_BENCHMARK_WITH_ARG(BM_math_signbit, "MATH_COMMON");
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000206
Elliott Hughes281e06b2016-02-17 10:23:52 -0800207static void BM_math_fabs_macro(benchmark::State& state) {
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000208 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100209 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800210 while (state.KeepRunning()) {
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000211 d += fabs(v);
212 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800213 SetLabel(state);
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000214}
Christopher Ferris858e3362017-11-30 08:53:15 -0800215BIONIC_BENCHMARK_WITH_ARG(BM_math_fabs_macro, "MATH_COMMON");
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000216
Elliott Hughes281e06b2016-02-17 10:23:52 -0800217static void BM_math_fabs(benchmark::State& state) {
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000218 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100219 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800220 while (state.KeepRunning()) {
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000221 d += (fabs)(v);
222 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800223 SetLabel(state);
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000224}
Christopher Ferris858e3362017-11-30 08:53:15 -0800225BIONIC_BENCHMARK_WITH_ARG(BM_math_fabs, "MATH_COMMON");
Elliott Hughese332f652018-05-08 15:07:43 -0700226
227static 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}
235BIONIC_BENCHMARK(BM_math_sincos);
Adhemerval Zanella357f6c12018-06-05 09:28:40 -0300236
237#include "expf_input.cpp"
238
239static 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}
248BIONIC_BENCHMARK(BM_math_expf_speccpu2017);
249
250static 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}
259BIONIC_BENCHMARK(BM_math_expf_speccpu2017_latency);
260
Adhemerval Zanella10d330a2018-08-08 10:54:53 -0300261// Create a double version of expf_input to avoid overhead of float to
262// double conversion.
263static const std::vector<double> exp_input (expf_input.begin(),
264 expf_input.end());
265
266static 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}
275BIONIC_BENCHMARK(BM_math_exp_speccpu2017);
276
277static 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}
286BIONIC_BENCHMARK(BM_math_exp_speccpu2017_latency);
287
Adhemerval Zanella357f6c12018-06-05 09:28:40 -0300288static 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}
297BIONIC_BENCHMARK(BM_math_exp2f_speccpu2017);
298
299static 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}
308BIONIC_BENCHMARK(BM_math_exp2f_speccpu2017_latency);
Adhemerval Zanella872c8b52018-06-05 13:57:03 -0300309
Adhemerval Zanella10d330a2018-08-08 10:54:53 -0300310static 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}
319BIONIC_BENCHMARK(BM_math_exp2_speccpu2017);
320
321static 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}
330BIONIC_BENCHMARK(BM_math_exp2_speccpu2017_latency);
331
Adhemerval Zanella872c8b52018-06-05 13:57:03 -0300332#include "powf_input.cpp"
333
Adhemerval Zanella72fe1c82018-08-08 13:36:14 -0300334static const std::vector<std::pair<double, double>> pow_input
335 (powf_input.begin(), powf_input.end());
336
Adhemerval Zanella872c8b52018-06-05 13:57:03 -0300337static void BM_math_powf_speccpu2006(benchmark::State& state) {
338 f = 0.0;
339 auto cin = powf_input.cbegin();
340 for (auto _ : state) {
341 f = powf(cin->first, cin->second);
342 if (++cin == powf_input.cend())
343 cin = powf_input.cbegin();
344 }
345}
346BIONIC_BENCHMARK(BM_math_powf_speccpu2006);
347
348static void BM_math_powf_speccpu2017_latency(benchmark::State& state) {
349 f = 0.0;
350 auto cin = powf_input.cbegin();
351 for (auto _ : state) {
352 f = powf(f * zero + cin->first, cin->second);
353 if (++cin == powf_input.cend())
354 cin = powf_input.cbegin();
355 }
356}
357BIONIC_BENCHMARK(BM_math_powf_speccpu2017_latency);
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300358
Adhemerval Zanella72fe1c82018-08-08 13:36:14 -0300359static void BM_math_pow_speccpu2006(benchmark::State& state) {
360 d = 0.0;
361 auto cin = pow_input.cbegin();
362 for (auto _ : state) {
363 f = pow(cin->first, cin->second);
364 if (++cin == pow_input.cend())
365 cin = pow_input.cbegin();
366 }
367}
368BIONIC_BENCHMARK(BM_math_pow_speccpu2006);
369
370static void BM_math_pow_speccpu2017_latency(benchmark::State& state) {
371 d = 0.0;
372 auto cin = pow_input.cbegin();
373 for (auto _ : state) {
374 d = powf(d * zero + cin->first, cin->second);
375 if (++cin == pow_input.cend())
376 cin = pow_input.cbegin();
377 }
378}
379BIONIC_BENCHMARK(BM_math_pow_speccpu2017_latency);
380
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300381#include "logf_input.cpp"
382
Adhemerval Zanella56f45112018-08-08 11:02:26 -0300383static const std::vector<double> log_input (logf_input.begin(),
384 logf_input.end());
385
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300386static void BM_math_logf_speccpu2017(benchmark::State& state) {
387 f = 0.0;
388 auto cin = logf_input.cbegin();
389 for (auto _ : state) {
390 f = logf(*cin);
391 if (++cin == logf_input.cend())
392 cin = logf_input.cbegin();
393 }
394}
395BIONIC_BENCHMARK(BM_math_logf_speccpu2017);
396
397static void BM_math_logf_speccpu2017_latency(benchmark::State& state) {
398 f = 0.0;
399 auto cin = logf_input.cbegin();
400 for (auto _ : state) {
401 f = logf(f * zero + *cin);
402 if (++cin == logf_input.cend())
403 cin = logf_input.cbegin();
404 }
405}
406BIONIC_BENCHMARK(BM_math_logf_speccpu2017_latency);
407
Adhemerval Zanella56f45112018-08-08 11:02:26 -0300408static void BM_math_log_speccpu2017(benchmark::State& state) {
409 d = 0.0;
410 auto cin = log_input.cbegin();
411 for (auto _ : state) {
412 d = log(*cin);
413 if (++cin == log_input.cend())
414 cin = log_input.cbegin();
415 }
416}
417BIONIC_BENCHMARK(BM_math_log_speccpu2017);
418
419static void BM_math_log_speccpu2017_latency(benchmark::State& state) {
420 d = 0.0;
421 auto cin = log_input.cbegin();
422 for (auto _ : state) {
423 d = log(d * zerod + *cin);
424 if (++cin == log_input.cend())
425 cin = log_input.cbegin();
426 }
427}
428BIONIC_BENCHMARK(BM_math_log_speccpu2017_latency);
429
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300430static void BM_math_log2f_speccpu2017(benchmark::State& state) {
431 f = 0.0;
432 auto cin = logf_input.cbegin();
433 for (auto _ : state) {
434 f = log2f(*cin);
435 if (++cin == logf_input.cend())
436 cin = logf_input.cbegin();
437 }
438}
439BIONIC_BENCHMARK(BM_math_log2f_speccpu2017);
440
Adhemerval Zanella56f45112018-08-08 11:02:26 -0300441static void BM_math_log2_speccpu2017_latency(benchmark::State& state) {
442 d = 0.0;
443 auto cin = log_input.cbegin();
444 for (auto _ : state) {
445 d = log2(d * zerod + *cin);
446 if (++cin == log_input.cend())
447 cin = log_input.cbegin();
448 }
449}
450BIONIC_BENCHMARK(BM_math_log2_speccpu2017_latency);
451
452static void BM_math_log2_speccpu2017(benchmark::State& state) {
453 d = 0.0;
454 auto cin = log_input.cbegin();
455 for (auto _ : state) {
456 d = log2(*cin);
457 if (++cin == log_input.cend())
458 cin = log_input.cbegin();
459 }
460}
461BIONIC_BENCHMARK(BM_math_log2_speccpu2017);
462
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300463static void BM_math_log2f_speccpu2017_latency(benchmark::State& state) {
464 f = 0.0;
465 auto cin = logf_input.cbegin();
466 for (auto _ : state) {
467 f = log2f(f * zero + *cin);
468 if (++cin == logf_input.cend())
469 cin = logf_input.cbegin();
470 }
471}
472BIONIC_BENCHMARK(BM_math_log2f_speccpu2017_latency);
Adhemerval Zanella7871ca12018-06-08 11:18:32 -0300473
474// Four ranges of values are checked:
475// * 0.0 <= x < 0.1
476// * 0.1 <= x < 0.7
477// * 0.7 <= x < 3.1
478// * -3.1 <= x < 3.1
479// * 3.3 <= x < 33.3
480// * 100.0 <= x < 1000.0
481// * 1e6 <= x < 1e32
482// * 1e32 < x < FLT_MAX
483
484#include "sincosf_input.cpp"
485
486static void BM_math_sinf(benchmark::State& state) {
487 auto range = sincosf_input[state.range(0)];
488 auto cin = range.values.cbegin();
489 f = 0.0;
490 for (auto _ : state) {
491 f = sinf(*cin);
492 if (++cin == range.values.cend())
493 cin = range.values.cbegin();
494 }
495 state.SetLabel(range.label);
496}
497BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf, "MATH_SINCOS_COMMON");
498
499static void BM_math_sinf_latency(benchmark::State& state) {
500 auto range = sincosf_input[state.range(0)];
501 auto cin = range.values.cbegin();
502 f = 0.0;
503 for (auto _ : state) {
504 f = sinf(f * zero + *cin);
505 if (++cin == range.values.cend())
506 cin = range.values.cbegin();
507 }
508 state.SetLabel(range.label);
509}
510BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf_latency, "MATH_SINCOS_COMMON");
511
512static void BM_math_cosf(benchmark::State& state) {
513 auto range = sincosf_input[state.range(0)];
514 auto cin = range.values.cbegin();
515 f = 0.0;
516 for (auto _ : state) {
517 f = cosf(*cin);
518 if (++cin == range.values.cend())
519 cin = range.values.cbegin();
520 }
521 state.SetLabel(range.label);
522}
523BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf, "MATH_SINCOS_COMMON");
524
525static void BM_math_cosf_latency(benchmark::State& state) {
526 auto range = sincosf_input[state.range(0)];
527 auto cin = range.values.cbegin();
528 f = 0.0;
529 for (auto _ : state) {
530 f = cosf(f * zero + *cin);
531 if (++cin == range.values.cend())
532 cin = range.values.cbegin();
533 }
534 state.SetLabel(range.label);
535}
536BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf_latency, "MATH_SINCOS_COMMON");
537
538static void BM_math_sincosf(benchmark::State& state) {
539 auto range = sincosf_input[state.range(0)];
540 auto cin = range.values.cbegin();
541 f = 0.0;
542 for (auto _ : state) {
543 float s, c;
544 sincosf(*cin, &s, &c);
545 f += s;
546 if (++cin == range.values.cend())
547 cin = range.values.cbegin();
548 }
549 state.SetLabel(range.label);
550}
551BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf, "MATH_SINCOS_COMMON");
552
553static void BM_math_sincosf_latency(benchmark::State& state) {
554 auto range = sincosf_input[state.range(0)];
555 auto cin = range.values.cbegin();
556 f = 0.0;
557 for (auto _ : state) {
558 float s, c;
559 sincosf(f * zero + *cin, &s, &c);
560 f += s;
561 if (++cin == range.values.cend())
562 cin = range.values.cbegin();
563 }
564 state.SetLabel(range.label);
565}
566BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf_latency, "MATH_SINCOS_COMMON");