blob: d64830a9c267b58c8f078cd54df6a310f0cad259 [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;
Elliott Hughes9edb3e02013-02-06 15:47:09 -080036
Elliott Hughes281e06b2016-02-17 10:23:52 -080037static void BM_math_sqrt(benchmark::State& state) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080038 d = 0.0;
39 v = 2.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -080040 while (state.KeepRunning()) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080041 d += sqrt(v);
42 }
Elliott Hughes9edb3e02013-02-06 15:47:09 -080043}
Anders Lewisa7b0f882017-07-24 20:01:13 -070044BIONIC_BENCHMARK(BM_math_sqrt);
Elliott Hughes9edb3e02013-02-06 15:47:09 -080045
Elliott Hughes281e06b2016-02-17 10:23:52 -080046static void BM_math_log10(benchmark::State& state) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080047 d = 0.0;
48 v = 1234.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -080049 while (state.KeepRunning()) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080050 d += log10(v);
51 }
Elliott Hughes9edb3e02013-02-06 15:47:09 -080052}
Anders Lewisa7b0f882017-07-24 20:01:13 -070053BIONIC_BENCHMARK(BM_math_log10);
Elliott Hughes9edb3e02013-02-06 15:47:09 -080054
Elliott Hughes281e06b2016-02-17 10:23:52 -080055static void BM_math_logb(benchmark::State& state) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080056 d = 0.0;
57 v = 1234.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -080058 while (state.KeepRunning()) {
Elliott Hughes9edb3e02013-02-06 15:47:09 -080059 d += logb(v);
60 }
Elliott Hughes9edb3e02013-02-06 15:47:09 -080061}
Anders Lewisa7b0f882017-07-24 20:01:13 -070062BIONIC_BENCHMARK(BM_math_logb);
Elliott Hughes02c78a32014-04-11 17:02:20 -070063
Elliott Hughes281e06b2016-02-17 10:23:52 -080064static void BM_math_isfinite_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -070065 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +010066 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -080067 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -070068 d += isfinite(v);
69 }
Elliott Hughes281e06b2016-02-17 10:23:52 -080070 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -070071}
Christopher Ferris858e3362017-11-30 08:53:15 -080072BIONIC_BENCHMARK_WITH_ARG(BM_math_isfinite_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -070073
Elliott Hughes281e06b2016-02-17 10:23:52 -080074static void BM_math_isfinite(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -070075 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +010076 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -080077 while (state.KeepRunning()) {
Elliott Hughes5c6a7bf2017-10-19 13:56:28 -070078 d += isfinite(v);
Elliott Hughesb6622802015-08-14 14:04:30 -070079 }
Elliott Hughes281e06b2016-02-17 10:23:52 -080080 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -070081}
Christopher Ferris858e3362017-11-30 08:53:15 -080082BIONIC_BENCHMARK_WITH_ARG(BM_math_isfinite, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -070083
Elliott Hughes281e06b2016-02-17 10:23:52 -080084static void BM_math_isinf_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -070085 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +010086 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -080087 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -070088 d += isinf(v);
89 }
Elliott Hughes281e06b2016-02-17 10:23:52 -080090 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -070091}
Christopher Ferris858e3362017-11-30 08:53:15 -080092BIONIC_BENCHMARK_WITH_ARG(BM_math_isinf_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -070093
Elliott Hughes281e06b2016-02-17 10:23:52 -080094static void BM_math_isinf(benchmark::State& state) {
Elliott Hughes02c78a32014-04-11 17:02:20 -070095 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +010096 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -080097 while (state.KeepRunning()) {
Elliott Hughes02c78a32014-04-11 17:02:20 -070098 d += (isinf)(v);
99 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800100 SetLabel(state);
Elliott Hughes02c78a32014-04-11 17:02:20 -0700101}
Christopher Ferris858e3362017-11-30 08:53:15 -0800102BIONIC_BENCHMARK_WITH_ARG(BM_math_isinf, "MATH_COMMON");
Elliott Hughes02c78a32014-04-11 17:02:20 -0700103
Elliott Hughes281e06b2016-02-17 10:23:52 -0800104static void BM_math_isnan_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700105 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100106 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800107 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700108 d += isnan(v);
109 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800110 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700111}
Christopher Ferris858e3362017-11-30 08:53:15 -0800112BIONIC_BENCHMARK_WITH_ARG(BM_math_isnan_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700113
Elliott Hughes281e06b2016-02-17 10:23:52 -0800114static void BM_math_isnan(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700115 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100116 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800117 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700118 d += (isnan)(v);
119 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800120 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700121}
Christopher Ferris858e3362017-11-30 08:53:15 -0800122BIONIC_BENCHMARK_WITH_ARG(BM_math_isnan, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700123
Elliott Hughes281e06b2016-02-17 10:23:52 -0800124static void BM_math_isnormal_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700125 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100126 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800127 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700128 d += isnormal(v);
129 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800130 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700131}
Christopher Ferris858e3362017-11-30 08:53:15 -0800132BIONIC_BENCHMARK_WITH_ARG(BM_math_isnormal_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700133
Elliott Hughes281e06b2016-02-17 10:23:52 -0800134static void BM_math_isnormal(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700135 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100136 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800137 while (state.KeepRunning()) {
Elliott Hughes5c6a7bf2017-10-19 13:56:28 -0700138 d += isnormal(v);
Elliott Hughesb6622802015-08-14 14:04:30 -0700139 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800140 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700141}
Christopher Ferris858e3362017-11-30 08:53:15 -0800142BIONIC_BENCHMARK_WITH_ARG(BM_math_isnormal, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700143
Elliott Hughes281e06b2016-02-17 10:23:52 -0800144static void BM_math_sin_fast(benchmark::State& state) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100145 d = 1.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -0800146 while (state.KeepRunning()) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100147 d += sin(d);
148 }
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100149}
Anders Lewisa7b0f882017-07-24 20:01:13 -0700150BIONIC_BENCHMARK(BM_math_sin_fast);
Elliott Hughes02c78a32014-04-11 17:02:20 -0700151
Elliott Hughes281e06b2016-02-17 10:23:52 -0800152static void BM_math_sin_feupdateenv(benchmark::State& state) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100153 d = 1.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -0800154 while (state.KeepRunning()) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100155 fenv_t __libc_save_rm;
156 feholdexcept(&__libc_save_rm);
157 fesetround(FE_TONEAREST);
158 d += sin(d);
159 feupdateenv(&__libc_save_rm);
160 }
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100161}
Anders Lewisa7b0f882017-07-24 20:01:13 -0700162BIONIC_BENCHMARK(BM_math_sin_feupdateenv);
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100163
Elliott Hughes281e06b2016-02-17 10:23:52 -0800164static void BM_math_sin_fesetenv(benchmark::State& state) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100165 d = 1.0;
Elliott Hughes281e06b2016-02-17 10:23:52 -0800166 while (state.KeepRunning()) {
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100167 fenv_t __libc_save_rm;
168 feholdexcept(&__libc_save_rm);
169 fesetround(FE_TONEAREST);
170 d += sin(d);
171 fesetenv(&__libc_save_rm);
172 }
Serban Constantinescua147a1d2014-06-08 16:55:22 +0100173}
Anders Lewisa7b0f882017-07-24 20:01:13 -0700174BIONIC_BENCHMARK(BM_math_sin_fesetenv);
Elliott Hughes02c78a32014-04-11 17:02:20 -0700175
Elliott Hughes281e06b2016-02-17 10:23:52 -0800176static void BM_math_fpclassify(benchmark::State& state) {
Elliott Hughes02c78a32014-04-11 17:02:20 -0700177 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100178 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800179 while (state.KeepRunning()) {
Elliott Hughes02c78a32014-04-11 17:02:20 -0700180 d += fpclassify(v);
181 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800182 SetLabel(state);
Elliott Hughes02c78a32014-04-11 17:02:20 -0700183}
Christopher Ferris858e3362017-11-30 08:53:15 -0800184BIONIC_BENCHMARK_WITH_ARG(BM_math_fpclassify, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700185
Elliott Hughes281e06b2016-02-17 10:23:52 -0800186static void BM_math_signbit_macro(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700187 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100188 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800189 while (state.KeepRunning()) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700190 d += signbit(v);
191 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800192 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700193}
Christopher Ferris858e3362017-11-30 08:53:15 -0800194BIONIC_BENCHMARK_WITH_ARG(BM_math_signbit_macro, "MATH_COMMON");
Elliott Hughesb6622802015-08-14 14:04:30 -0700195
Elliott Hughes281e06b2016-02-17 10:23:52 -0800196static void BM_math_signbit(benchmark::State& state) {
Elliott Hughesb6622802015-08-14 14:04:30 -0700197 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100198 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800199 while (state.KeepRunning()) {
Elliott Hughes5c6a7bf2017-10-19 13:56:28 -0700200 d += signbit(v);
Elliott Hughesb6622802015-08-14 14:04:30 -0700201 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800202 SetLabel(state);
Elliott Hughesb6622802015-08-14 14:04:30 -0700203}
Christopher Ferris858e3362017-11-30 08:53:15 -0800204BIONIC_BENCHMARK_WITH_ARG(BM_math_signbit, "MATH_COMMON");
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000205
Elliott Hughes281e06b2016-02-17 10:23:52 -0800206static void BM_math_fabs_macro(benchmark::State& state) {
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000207 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100208 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800209 while (state.KeepRunning()) {
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000210 d += fabs(v);
211 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800212 SetLabel(state);
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000213}
Christopher Ferris858e3362017-11-30 08:53:15 -0800214BIONIC_BENCHMARK_WITH_ARG(BM_math_fabs_macro, "MATH_COMMON");
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000215
Elliott Hughes281e06b2016-02-17 10:23:52 -0800216static void BM_math_fabs(benchmark::State& state) {
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000217 d = 0.0;
Martijn Coenenbe763d82016-11-14 14:16:08 +0100218 v = values[state.range(0)];
Elliott Hughes281e06b2016-02-17 10:23:52 -0800219 while (state.KeepRunning()) {
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000220 d += (fabs)(v);
221 }
Elliott Hughes281e06b2016-02-17 10:23:52 -0800222 SetLabel(state);
Elliott Hughesf9f4a432015-08-24 22:57:08 +0000223}
Christopher Ferris858e3362017-11-30 08:53:15 -0800224BIONIC_BENCHMARK_WITH_ARG(BM_math_fabs, "MATH_COMMON");
Elliott Hughese332f652018-05-08 15:07:43 -0700225
226static void BM_math_sincos(benchmark::State& state) {
227 d = 1.0;
228 while (state.KeepRunning()) {
229 double s, c;
230 sincos(d, &s, &c);
231 d += s + c;
232 }
233}
234BIONIC_BENCHMARK(BM_math_sincos);
Adhemerval Zanella357f6c12018-06-05 09:28:40 -0300235
236#include "expf_input.cpp"
237
238static void BM_math_expf_speccpu2017(benchmark::State& state) {
239 f = 0.0;
240 auto cin = expf_input.cbegin();
241 for (auto _ : state) {
242 f = expf(*cin);
243 if (++cin == expf_input.cend())
244 cin = expf_input.cbegin();
245 }
246}
247BIONIC_BENCHMARK(BM_math_expf_speccpu2017);
248
249static void BM_math_expf_speccpu2017_latency(benchmark::State& state) {
250 f = 0.0;
251 auto cin = expf_input.cbegin();
252 for (auto _ : state) {
253 f = expf(f * zero + *cin);
254 if (++cin == expf_input.cend())
255 cin = expf_input.cbegin();
256 }
257}
258BIONIC_BENCHMARK(BM_math_expf_speccpu2017_latency);
259
260static void BM_math_exp2f_speccpu2017(benchmark::State& state) {
261 f = 0.0;
262 auto cin = expf_input.cbegin();
263 for (auto _ : state) {
264 f = exp2f(*cin);
265 if (++cin == expf_input.cend())
266 cin = expf_input.cbegin();
267 }
268}
269BIONIC_BENCHMARK(BM_math_exp2f_speccpu2017);
270
271static void BM_math_exp2f_speccpu2017_latency(benchmark::State& state) {
272 f = 0.0;
273 auto cin = expf_input.cbegin();
274 for (auto _ : state) {
275 f = exp2f(f * zero + *cin);
276 if (++cin == expf_input.cend())
277 cin = expf_input.cbegin();
278 }
279}
280BIONIC_BENCHMARK(BM_math_exp2f_speccpu2017_latency);
Adhemerval Zanella872c8b52018-06-05 13:57:03 -0300281
282#include "powf_input.cpp"
283
284static void BM_math_powf_speccpu2006(benchmark::State& state) {
285 f = 0.0;
286 auto cin = powf_input.cbegin();
287 for (auto _ : state) {
288 f = powf(cin->first, cin->second);
289 if (++cin == powf_input.cend())
290 cin = powf_input.cbegin();
291 }
292}
293BIONIC_BENCHMARK(BM_math_powf_speccpu2006);
294
295static void BM_math_powf_speccpu2017_latency(benchmark::State& state) {
296 f = 0.0;
297 auto cin = powf_input.cbegin();
298 for (auto _ : state) {
299 f = powf(f * zero + cin->first, cin->second);
300 if (++cin == powf_input.cend())
301 cin = powf_input.cbegin();
302 }
303}
304BIONIC_BENCHMARK(BM_math_powf_speccpu2017_latency);
Adhemerval Zanellaff5a3532018-06-05 15:47:06 -0300305
306#include "logf_input.cpp"
307
308static void BM_math_logf_speccpu2017(benchmark::State& state) {
309 f = 0.0;
310 auto cin = logf_input.cbegin();
311 for (auto _ : state) {
312 f = logf(*cin);
313 if (++cin == logf_input.cend())
314 cin = logf_input.cbegin();
315 }
316}
317BIONIC_BENCHMARK(BM_math_logf_speccpu2017);
318
319static void BM_math_logf_speccpu2017_latency(benchmark::State& state) {
320 f = 0.0;
321 auto cin = logf_input.cbegin();
322 for (auto _ : state) {
323 f = logf(f * zero + *cin);
324 if (++cin == logf_input.cend())
325 cin = logf_input.cbegin();
326 }
327}
328BIONIC_BENCHMARK(BM_math_logf_speccpu2017_latency);
329
330static void BM_math_log2f_speccpu2017(benchmark::State& state) {
331 f = 0.0;
332 auto cin = logf_input.cbegin();
333 for (auto _ : state) {
334 f = log2f(*cin);
335 if (++cin == logf_input.cend())
336 cin = logf_input.cbegin();
337 }
338}
339BIONIC_BENCHMARK(BM_math_log2f_speccpu2017);
340
341static void BM_math_log2f_speccpu2017_latency(benchmark::State& state) {
342 f = 0.0;
343 auto cin = logf_input.cbegin();
344 for (auto _ : state) {
345 f = log2f(f * zero + *cin);
346 if (++cin == logf_input.cend())
347 cin = logf_input.cbegin();
348 }
349}
350BIONIC_BENCHMARK(BM_math_log2f_speccpu2017_latency);
Adhemerval Zanella7871ca12018-06-08 11:18:32 -0300351
352// Four ranges of values are checked:
353// * 0.0 <= x < 0.1
354// * 0.1 <= x < 0.7
355// * 0.7 <= x < 3.1
356// * -3.1 <= x < 3.1
357// * 3.3 <= x < 33.3
358// * 100.0 <= x < 1000.0
359// * 1e6 <= x < 1e32
360// * 1e32 < x < FLT_MAX
361
362#include "sincosf_input.cpp"
363
364static void BM_math_sinf(benchmark::State& state) {
365 auto range = sincosf_input[state.range(0)];
366 auto cin = range.values.cbegin();
367 f = 0.0;
368 for (auto _ : state) {
369 f = sinf(*cin);
370 if (++cin == range.values.cend())
371 cin = range.values.cbegin();
372 }
373 state.SetLabel(range.label);
374}
375BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf, "MATH_SINCOS_COMMON");
376
377static void BM_math_sinf_latency(benchmark::State& state) {
378 auto range = sincosf_input[state.range(0)];
379 auto cin = range.values.cbegin();
380 f = 0.0;
381 for (auto _ : state) {
382 f = sinf(f * zero + *cin);
383 if (++cin == range.values.cend())
384 cin = range.values.cbegin();
385 }
386 state.SetLabel(range.label);
387}
388BIONIC_BENCHMARK_WITH_ARG(BM_math_sinf_latency, "MATH_SINCOS_COMMON");
389
390static void BM_math_cosf(benchmark::State& state) {
391 auto range = sincosf_input[state.range(0)];
392 auto cin = range.values.cbegin();
393 f = 0.0;
394 for (auto _ : state) {
395 f = cosf(*cin);
396 if (++cin == range.values.cend())
397 cin = range.values.cbegin();
398 }
399 state.SetLabel(range.label);
400}
401BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf, "MATH_SINCOS_COMMON");
402
403static void BM_math_cosf_latency(benchmark::State& state) {
404 auto range = sincosf_input[state.range(0)];
405 auto cin = range.values.cbegin();
406 f = 0.0;
407 for (auto _ : state) {
408 f = cosf(f * zero + *cin);
409 if (++cin == range.values.cend())
410 cin = range.values.cbegin();
411 }
412 state.SetLabel(range.label);
413}
414BIONIC_BENCHMARK_WITH_ARG(BM_math_cosf_latency, "MATH_SINCOS_COMMON");
415
416static void BM_math_sincosf(benchmark::State& state) {
417 auto range = sincosf_input[state.range(0)];
418 auto cin = range.values.cbegin();
419 f = 0.0;
420 for (auto _ : state) {
421 float s, c;
422 sincosf(*cin, &s, &c);
423 f += s;
424 if (++cin == range.values.cend())
425 cin = range.values.cbegin();
426 }
427 state.SetLabel(range.label);
428}
429BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf, "MATH_SINCOS_COMMON");
430
431static void BM_math_sincosf_latency(benchmark::State& state) {
432 auto range = sincosf_input[state.range(0)];
433 auto cin = range.values.cbegin();
434 f = 0.0;
435 for (auto _ : state) {
436 float s, c;
437 sincosf(f * zero + *cin, &s, &c);
438 f += s;
439 if (++cin == range.values.cend())
440 cin = range.values.cbegin();
441 }
442 state.SetLabel(range.label);
443}
444BIONIC_BENCHMARK_WITH_ARG(BM_math_sincosf_latency, "MATH_SINCOS_COMMON");