| 1 | //===-- Performance test for maximum and minimum functions ----------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "PerfTest.h" |
| 10 | #include "src/math/fmaxf.h" |
| 11 | #include "src/math/fmaxf16.h" |
| 12 | #include "src/math/fmaximum_numf.h" |
| 13 | #include "src/math/fmaximum_numf16.h" |
| 14 | #include "src/math/fmaximumf.h" |
| 15 | #include "src/math/fmaximumf16.h" |
| 16 | #include "src/math/fminf.h" |
| 17 | #include "src/math/fminf16.h" |
| 18 | #include "src/math/fminimum_numf.h" |
| 19 | #include "src/math/fminimum_numf16.h" |
| 20 | #include "src/math/fminimumf.h" |
| 21 | #include "src/math/fminimumf16.h" |
| 22 | |
| 23 | #include <math.h> |
| 24 | |
| 25 | static constexpr size_t FLOAT16_ROUNDS = 20'000; |
| 26 | static constexpr size_t FLOAT_ROUNDS = 40; |
| 27 | |
| 28 | // LLVM libc might be the only libc implementation with support for float16 math |
| 29 | // functions currently. We can't compare our float16 functions against the |
| 30 | // system libc, so we compare them against this placeholder function. |
| 31 | float16 placeholder_binaryf16(float16 x, float16 y) { return x; } |
| 32 | |
| 33 | // The system libc might not provide the fmaximum* and fminimum* C23 math |
| 34 | // functions either. |
| 35 | float placeholder_binaryf(float x, float y) { return x; } |
| 36 | |
| 37 | int main() { |
| 38 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX(float16, float16, LIBC_NAMESPACE::fmaxf16, |
| 39 | placeholder_binaryf16, FLOAT16_ROUNDS, |
| 40 | "fmaxf16_perf.log" ) |
| 41 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX(float16, float16, LIBC_NAMESPACE::fminf16, |
| 42 | placeholder_binaryf16, FLOAT16_ROUNDS, |
| 43 | "fminf16_perf.log" ) |
| 44 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX( |
| 45 | float16, float16, LIBC_NAMESPACE::fmaximumf16, placeholder_binaryf16, |
| 46 | FLOAT16_ROUNDS, "fmaximumf16_perf.log" ) |
| 47 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX( |
| 48 | float16, float16, LIBC_NAMESPACE::fminimumf16, placeholder_binaryf16, |
| 49 | FLOAT16_ROUNDS, "fminimumf16_perf.log" ) |
| 50 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX( |
| 51 | float16, float16, LIBC_NAMESPACE::fmaximum_numf16, placeholder_binaryf16, |
| 52 | FLOAT16_ROUNDS, "fmaximum_numf16_perf.log" ) |
| 53 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX( |
| 54 | float16, float16, LIBC_NAMESPACE::fminimum_numf16, placeholder_binaryf16, |
| 55 | FLOAT16_ROUNDS, "fminimum_numf16_perf.log" ) |
| 56 | |
| 57 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX(float, float, LIBC_NAMESPACE::fmaxf, |
| 58 | ::fmaxf, FLOAT_ROUNDS, "fmaxf_perf.log" ) |
| 59 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX(float, float, LIBC_NAMESPACE::fminf, |
| 60 | ::fminf, FLOAT_ROUNDS, "fminf_perf.log" ) |
| 61 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX(float, float, LIBC_NAMESPACE::fmaximumf, |
| 62 | placeholder_binaryf, FLOAT_ROUNDS, |
| 63 | "fmaximumf_perf.log" ) |
| 64 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX(float, float, LIBC_NAMESPACE::fminimumf, |
| 65 | placeholder_binaryf, FLOAT_ROUNDS, |
| 66 | "fminimumf_perf.log" ) |
| 67 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX( |
| 68 | float, float, LIBC_NAMESPACE::fmaximum_numf, placeholder_binaryf, |
| 69 | FLOAT_ROUNDS, "fmaximum_numf_perf.log" ) |
| 70 | BINARY_INPUT_SINGLE_OUTPUT_PERF_EX( |
| 71 | float, float, LIBC_NAMESPACE::fminimum_numf, placeholder_binaryf, |
| 72 | FLOAT_ROUNDS, "fminimum_numf_perf.log" ) |
| 73 | return 0; |
| 74 | } |
| 75 | |