blob: 7d258f7ee33e59070f5fe5dced21fba47c645237 [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
334static 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}
343BIONIC_BENCHMARK(BM_math_powf_speccpu2006);
344
345static 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}
354BIONIC_BENCHMARK(BM_math_powf_speccpu2017_latency);
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300355
356#include "logf_input.cpp"
357
Adhemerval Zanella56f45112018-08-08 11:02:26 -0300358static const std::vector<double> log_input (logf_input.begin(),
359 logf_input.end());
360
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300361static void BM_math_logf_speccpu2017(benchmark::State& state) {
362 f = 0.0;
363 auto cin = logf_input.cbegin();
364 for (auto _ : state) {
365 f = logf(*cin);
366 if (++cin == logf_input.cend())
367 cin = logf_input.cbegin();
368 }
369}
370BIONIC_BENCHMARK(BM_math_logf_speccpu2017);
371
372static void BM_math_logf_speccpu2017_latency(benchmark::State& state) {
373 f = 0.0;
374 auto cin = logf_input.cbegin();
375 for (auto _ : state) {
376 f = logf(f * zero + *cin);
377 if (++cin == logf_input.cend())
378 cin = logf_input.cbegin();
379 }
380}
381BIONIC_BENCHMARK(BM_math_logf_speccpu2017_latency);
382
Adhemerval Zanella56f45112018-08-08 11:02:26 -0300383static void BM_math_log_speccpu2017(benchmark::State& state) {
384 d = 0.0;
385 auto cin = log_input.cbegin();
386 for (auto _ : state) {
387 d = log(*cin);
388 if (++cin == log_input.cend())
389 cin = log_input.cbegin();
390 }
391}
392BIONIC_BENCHMARK(BM_math_log_speccpu2017);
393
394static void BM_math_log_speccpu2017_latency(benchmark::State& state) {
395 d = 0.0;
396 auto cin = log_input.cbegin();
397 for (auto _ : state) {
398 d = log(d * zerod + *cin);
399 if (++cin == log_input.cend())
400 cin = log_input.cbegin();
401 }
402}
403BIONIC_BENCHMARK(BM_math_log_speccpu2017_latency);
404
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300405static void BM_math_log2f_speccpu2017(benchmark::State& state) {
406 f = 0.0;
407 auto cin = logf_input.cbegin();
408 for (auto _ : state) {
409 f = log2f(*cin);
410 if (++cin == logf_input.cend())
411 cin = logf_input.cbegin();
412 }
413}
414BIONIC_BENCHMARK(BM_math_log2f_speccpu2017);
415
Adhemerval Zanella56f45112018-08-08 11:02:26 -0300416static void BM_math_log2_speccpu2017_latency(benchmark::State& state) {
417 d = 0.0;
418 auto cin = log_input.cbegin();
419 for (auto _ : state) {
420 d = log2(d * zerod + *cin);
421 if (++cin == log_input.cend())
422 cin = log_input.cbegin();
423 }
424}
425BIONIC_BENCHMARK(BM_math_log2_speccpu2017_latency);
426
427static void BM_math_log2_speccpu2017(benchmark::State& state) {
428 d = 0.0;
429 auto cin = log_input.cbegin();
430 for (auto _ : state) {
431 d = log2(*cin);
432 if (++cin == log_input.cend())
433 cin = log_input.cbegin();
434 }
435}
436BIONIC_BENCHMARK(BM_math_log2_speccpu2017);
437
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300438static void BM_math_log2f_speccpu2017_latency(benchmark::State& state) {
439 f = 0.0;
440 auto cin = logf_input.cbegin();
441 for (auto _ : state) {
442 f = log2f(f * zero + *cin);
443 if (++cin == logf_input.cend())
444 cin = logf_input.cbegin();
445 }
446}
447BIONIC_BENCHMARK(BM_math_log2f_speccpu2017_latency);
Adhemerval Zanella7871ca12018-06-08 11:18:32 -0300448
449// Four ranges of values are checked:
450// * 0.0 <= x < 0.1
451// * 0.1 <= x < 0.7
452// * 0.7 <= x < 3.1
453// * -3.1 <= x < 3.1
454// * 3.3 <= x < 33.3
455// * 100.0 <= x < 1000.0
456// * 1e6 <= x < 1e32
457// * 1e32 < x < FLT_MAX
458
459#include "sincosf_input.cpp"
460
461static void BM_math_sinf(benchmark::State& state) {
462 auto range = sincosf_input[state.range(0)];
463 auto cin = range.values.cbegin();
464 f = 0.0;
465 for (auto _ : state) {
466 f = sinf(*cin);
467 if (++cin == range.values.cend())
468 cin = range.values.cbegin();
469 }
470 state.SetLabel(range.label);
471}
472BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf, "MATH_SINCOS_COMMON");
473
474static void BM_math_sinf_latency(benchmark::State& state) {
475 auto range = sincosf_input[state.range(0)];
476 auto cin = range.values.cbegin();
477 f = 0.0;
478 for (auto _ : state) {
479 f = sinf(f * zero + *cin);
480 if (++cin == range.values.cend())
481 cin = range.values.cbegin();
482 }
483 state.SetLabel(range.label);
484}
485BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf_latency, "MATH_SINCOS_COMMON");
486
487static void BM_math_cosf(benchmark::State& state) {
488 auto range = sincosf_input[state.range(0)];
489 auto cin = range.values.cbegin();
490 f = 0.0;
491 for (auto _ : state) {
492 f = cosf(*cin);
493 if (++cin == range.values.cend())
494 cin = range.values.cbegin();
495 }
496 state.SetLabel(range.label);
497}
498BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf, "MATH_SINCOS_COMMON");
499
500static void BM_math_cosf_latency(benchmark::State& state) {
501 auto range = sincosf_input[state.range(0)];
502 auto cin = range.values.cbegin();
503 f = 0.0;
504 for (auto _ : state) {
505 f = cosf(f * zero + *cin);
506 if (++cin == range.values.cend())
507 cin = range.values.cbegin();
508 }
509 state.SetLabel(range.label);
510}
511BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf_latency, "MATH_SINCOS_COMMON");
512
513static void BM_math_sincosf(benchmark::State& state) {
514 auto range = sincosf_input[state.range(0)];
515 auto cin = range.values.cbegin();
516 f = 0.0;
517 for (auto _ : state) {
518 float s, c;
519 sincosf(*cin, &s, &c);
520 f += s;
521 if (++cin == range.values.cend())
522 cin = range.values.cbegin();
523 }
524 state.SetLabel(range.label);
525}
526BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf, "MATH_SINCOS_COMMON");
527
528static void BM_math_sincosf_latency(benchmark::State& state) {
529 auto range = sincosf_input[state.range(0)];
530 auto cin = range.values.cbegin();
531 f = 0.0;
532 for (auto _ : state) {
533 float s, c;
534 sincosf(f * zero + *cin, &s, &c);
535 f += s;
536 if (++cin == range.values.cend())
537 cin = range.values.cbegin();
538 }
539 state.SetLabel(range.label);
540}
541BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf_latency, "MATH_SINCOS_COMMON");