72 changes: 54 additions & 18 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2077,7 +2079,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2089,7 +2093,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
)

add_entrypoint_object(
Expand All @@ -2116,6 +2120,8 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)


Expand All @@ -2128,7 +2134,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2140,7 +2148,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2152,7 +2162,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
)

add_entrypoint_object(
Expand All @@ -2179,6 +2189,8 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2190,7 +2202,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2202,7 +2216,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2214,7 +2230,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
)

add_entrypoint_object(
Expand All @@ -2228,6 +2244,8 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2252,7 +2270,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2264,7 +2284,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2276,7 +2298,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
)

add_entrypoint_object(
Expand All @@ -2290,6 +2312,8 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand Down Expand Up @@ -2438,7 +2462,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2450,7 +2476,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2462,7 +2490,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
)

add_entrypoint_object(
Expand All @@ -2476,6 +2504,8 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2500,7 +2530,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2512,7 +2544,9 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand All @@ -2524,7 +2558,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O2
-O3
)

add_entrypoint_object(
Expand All @@ -2538,6 +2572,8 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_entrypoint_object(
Expand Down
22 changes: 22 additions & 0 deletions libc/test/src/math/performance_testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,25 @@ add_perf_binary(
COMPILE_OPTIONS
-fno-builtin
)

add_perf_binary(
max_min_funcs_perf
SRCS
max_min_funcs_perf.cpp
DEPENDS
.binary_op_single_output_diff
libc.src.math.fmaxf
libc.src.math.fmaxf16
libc.src.math.fmaximumf
libc.src.math.fmaximumf16
libc.src.math.fmaximum_numf
libc.src.math.fmaximum_numf16
libc.src.math.fminf
libc.src.math.fminf16
libc.src.math.fminimumf
libc.src.math.fminimumf16
libc.src.math.fminimum_numf
libc.src.math.fminimum_numf16
COMPILE_OPTIONS
-fno-builtin
)
75 changes: 75 additions & 0 deletions libc/test/src/math/performance_testing/max_min_funcs_perf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//===-- Performance test for maximum and minimum functions ----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "BinaryOpSingleOutputPerf.h"
#include "src/math/fmaxf.h"
#include "src/math/fmaxf16.h"
#include "src/math/fmaximum_numf.h"
#include "src/math/fmaximum_numf16.h"
#include "src/math/fmaximumf.h"
#include "src/math/fmaximumf16.h"
#include "src/math/fminf.h"
#include "src/math/fminf16.h"
#include "src/math/fminimum_numf.h"
#include "src/math/fminimum_numf16.h"
#include "src/math/fminimumf.h"
#include "src/math/fminimumf16.h"

#include <math.h>

static constexpr size_t FLOAT16_ROUNDS = 20'000;
static constexpr size_t FLOAT_ROUNDS = 40;

// LLVM libc might be the only libc implementation with support for float16 math
// functions currently. We can't compare our float16 functions against the
// system libc, so we compare them against this placeholder function.
float16 placeholder_binaryf16(float16 x, float16 y) { return x; }

// The system libc might not provide the fmaximum* and fminimum* C23 math
// functions either.
float placeholder_binaryf(float x, float y) { return x; }

int main() {
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float16, LIBC_NAMESPACE::fmaxf16,
placeholder_binaryf16, FLOAT16_ROUNDS,
"fmaxf16_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float16, LIBC_NAMESPACE::fminf16,
placeholder_binaryf16, FLOAT16_ROUNDS,
"fminf16_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float16, LIBC_NAMESPACE::fmaximumf16,
placeholder_binaryf16, FLOAT16_ROUNDS,
"fmaximumf16_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float16, LIBC_NAMESPACE::fminimumf16,
placeholder_binaryf16, FLOAT16_ROUNDS,
"fminimumf16_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float16, LIBC_NAMESPACE::fmaximum_numf16,
placeholder_binaryf16, FLOAT16_ROUNDS,
"fmaximum_numf16_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float16, LIBC_NAMESPACE::fminimum_numf16,
placeholder_binaryf16, FLOAT16_ROUNDS,
"fminimum_numf16_perf.log")

BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, LIBC_NAMESPACE::fmaxf, ::fmaxf,
FLOAT_ROUNDS, "fmaxf_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, LIBC_NAMESPACE::fminf, ::fminf,
FLOAT_ROUNDS, "fminf_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, LIBC_NAMESPACE::fmaximumf,
placeholder_binaryf, FLOAT_ROUNDS,
"fmaximumf_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, LIBC_NAMESPACE::fminimumf,
placeholder_binaryf, FLOAT_ROUNDS,
"fminimumf_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, LIBC_NAMESPACE::fmaximum_numf,
placeholder_binaryf, FLOAT_ROUNDS,
"fmaximum_numf_perf.log")
BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, LIBC_NAMESPACE::fminimum_numf,
placeholder_binaryf, FLOAT_ROUNDS,
"fminimum_numf_perf.log")

return 0;
}