diff --git a/libc/shared/math.h b/libc/shared/math.h index 90c4f7397b79a..a2a2bddd3576e 100644 --- a/libc/shared/math.h +++ b/libc/shared/math.h @@ -186,12 +186,18 @@ #include "math/fmaximumf16.h" #include "math/fmaximuml.h" #include "math/fmaxl.h" +#include "math/fmin.h" +#include "math/fminbf16.h" +#include "math/fminf.h" +#include "math/fminf128.h" +#include "math/fminf16.h" #include "math/fminimum.h" #include "math/fminimumbf16.h" #include "math/fminimumf.h" #include "math/fminimumf128.h" #include "math/fminimumf16.h" #include "math/fminimuml.h" +#include "math/fminl.h" #include "math/frexpf.h" #include "math/frexpf128.h" #include "math/frexpf16.h" diff --git a/libc/shared/math/fmin.h b/libc/shared/math/fmin.h new file mode 100644 index 0000000000000..3266b6650f653 --- /dev/null +++ b/libc/shared/math/fmin.h @@ -0,0 +1,23 @@ +//===-- Shared fmin function ------------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_MATH_FMIN_H +#define LLVM_LIBC_SHARED_MATH_FMIN_H + +#include "shared/libc_common.h" +#include "src/__support/math/fmin.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::fmin; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_FMIN_H diff --git a/libc/shared/math/fminbf16.h b/libc/shared/math/fminbf16.h new file mode 100644 index 0000000000000..b8660cb72d39c --- /dev/null +++ b/libc/shared/math/fminbf16.h @@ -0,0 +1,23 @@ +//===-- Shared fminbf16 function --------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_MATH_FMINBF16_H +#define LLVM_LIBC_SHARED_MATH_FMINBF16_H + +#include "shared/libc_common.h" +#include "src/__support/math/fminbf16.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::fminbf16; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_FMINBF16_H diff --git a/libc/shared/math/fminf.h b/libc/shared/math/fminf.h new file mode 100644 index 0000000000000..aa6c04fb8c154 --- /dev/null +++ b/libc/shared/math/fminf.h @@ -0,0 +1,23 @@ +//===-- Shared fminf function -----------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_MATH_FMINF_H +#define LLVM_LIBC_SHARED_MATH_FMINF_H + +#include "shared/libc_common.h" +#include "src/__support/math/fminf.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::fminf; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_FMINF_H diff --git a/libc/shared/math/fminf128.h b/libc/shared/math/fminf128.h new file mode 100644 index 0000000000000..2970bc3fd1c4c --- /dev/null +++ b/libc/shared/math/fminf128.h @@ -0,0 +1,29 @@ +//===-- Shared fminf128 function --------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_MATH_FMINF128_H +#define LLVM_LIBC_SHARED_MATH_FMINF128_H + +#include "include/llvm-libc-types/float128.h" + +#ifdef LIBC_TYPES_HAS_FLOAT128 + +#include "shared/libc_common.h" +#include "src/__support/math/fminf128.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::fminf128; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_HAS_FLOAT128 + +#endif // LLVM_LIBC_SHARED_MATH_FMINF128_H diff --git a/libc/shared/math/fminf16.h b/libc/shared/math/fminf16.h new file mode 100644 index 0000000000000..c9be529060c0d --- /dev/null +++ b/libc/shared/math/fminf16.h @@ -0,0 +1,29 @@ +//===-- Shared fminf16 function ---------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_MATH_FMINF16_H +#define LLVM_LIBC_SHARED_MATH_FMINF16_H + +#include "include/llvm-libc-macros/float16-macros.h" + +#ifdef LIBC_TYPES_HAS_FLOAT16 + +#include "shared/libc_common.h" +#include "src/__support/math/fminf16.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::fminf16; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_HAS_FLOAT16 + +#endif // LLVM_LIBC_SHARED_MATH_FMINF16_H diff --git a/libc/shared/math/fminl.h b/libc/shared/math/fminl.h new file mode 100644 index 0000000000000..cef534ff287e7 --- /dev/null +++ b/libc/shared/math/fminl.h @@ -0,0 +1,23 @@ +//===-- Shared fminl function -----------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_MATH_FMINL_H +#define LLVM_LIBC_SHARED_MATH_FMINL_H + +#include "shared/libc_common.h" +#include "src/__support/math/fminl.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::fminl; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_FMINL_H diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h index 7587439d4eb05..bbdba52e129cf 100644 --- a/libc/src/__support/FPUtil/BasicOperations.h +++ b/libc/src/__support/FPUtil/BasicOperations.h @@ -141,7 +141,7 @@ template <> LIBC_INLINE constexpr double min(double x, double y) { } // namespace internal template , int> = 0> -LIBC_INLINE T fmin(T x, T y) { +LIBC_INLINE constexpr T fmin(T x, T y) { const FPBits bitx(x), bity(y); if (bitx.is_nan()) diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt index dd9c350c507d9..a1ffac95a3434 100644 --- a/libc/src/__support/math/CMakeLists.txt +++ b/libc/src/__support/math/CMakeLists.txt @@ -883,6 +883,62 @@ add_header_library( libc.src.__support.FPUtil.basic_operations libc.src.__support.macros.config ) +add_header_library( + fmin + HDRS + fmin.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + libc.src.__support.macros.config + FLAGS + MISC_MATH_BASIC_OPS_OPT +) + +add_header_library( + fminbf16 + HDRS + fminbf16.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.config + FLAGS + MISC_MATH_BASIC_OPS_OPT +) + +add_header_library( + fminf + HDRS + fminf.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + libc.src.__support.macros.config + FLAGS + MISC_MATH_BASIC_OPS_OPT +) + +add_header_library( + fminf128 + HDRS + fminf128.h + DEPENDS + libc.include.llvm-libc-types.float128 + libc.src.__support.FPUtil.basic_operations + libc.src.__support.macros.config +) + +add_header_library( + fminf16 + HDRS + fminf16.h + DEPENDS + libc.include.llvm-libc-macros.float16_macros + libc.src.__support.FPUtil.basic_operations + libc.src.__support.macros.config + FLAGS + MISC_MATH_BASIC_OPS_OPT +) + add_header_library( fminimum @@ -949,6 +1005,15 @@ add_header_library( libc.src.__support.macros.config ) +add_header_library( + fminl + HDRS + fminl.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + libc.src.__support.macros.config +) + add_header_library( llogbbf16 diff --git a/libc/src/__support/math/fmin.h b/libc/src/__support/math/fmin.h new file mode 100644 index 0000000000000..5bce93c1e7488 --- /dev/null +++ b/libc/src/__support/math/fmin.h @@ -0,0 +1,25 @@ +//===-- Implementation header for fmin --------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMIN_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_FMIN_H + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE constexpr double fmin(double x, double y) { + return fputil::fmin(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMIN_H diff --git a/libc/src/__support/math/fminbf16.h b/libc/src/__support/math/fminbf16.h new file mode 100644 index 0000000000000..c7b1f89398dd5 --- /dev/null +++ b/libc/src/__support/math/fminbf16.h @@ -0,0 +1,26 @@ +//===-- Implementation header for fminbf16 ----------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINBF16_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINBF16_H + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE constexpr bfloat16 fminbf16(bfloat16 x, bfloat16 y) { + return fputil::fmin(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINBF16_H diff --git a/libc/src/__support/math/fminf.h b/libc/src/__support/math/fminf.h new file mode 100644 index 0000000000000..9280e77000929 --- /dev/null +++ b/libc/src/__support/math/fminf.h @@ -0,0 +1,25 @@ +//===-- Implementation header for fminf -------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINF_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINF_H + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE constexpr float fminf(float x, float y) { + return fputil::fmin(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINF_H diff --git a/libc/src/__support/math/fminf128.h b/libc/src/__support/math/fminf128.h new file mode 100644 index 0000000000000..ccea1a7ee11d5 --- /dev/null +++ b/libc/src/__support/math/fminf128.h @@ -0,0 +1,31 @@ +//===-- Implementation header for fminf128 ----------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINF128_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINF128_H + +#include "include/llvm-libc-types/float128.h" + +#ifdef LIBC_TYPES_HAS_FLOAT128 + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE constexpr float128 fminf128(float128 x, float128 y) { + return fputil::fmin(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_HAS_FLOAT128 + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINF128_H diff --git a/libc/src/__support/math/fminf16.h b/libc/src/__support/math/fminf16.h new file mode 100644 index 0000000000000..f379688b3da8d --- /dev/null +++ b/libc/src/__support/math/fminf16.h @@ -0,0 +1,31 @@ +//===-- Implementation header for fminf16 -----------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINF16_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINF16_H + +#include "include/llvm-libc-macros/float16-macros.h" + +#ifdef LIBC_TYPES_HAS_FLOAT16 + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE constexpr float16 fminf16(float16 x, float16 y) { + return fputil::fmin(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LIBC_TYPES_HAS_FLOAT16 + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINF16_H diff --git a/libc/src/__support/math/fminl.h b/libc/src/__support/math/fminl.h new file mode 100644 index 0000000000000..0a87782d20da7 --- /dev/null +++ b/libc/src/__support/math/fminl.h @@ -0,0 +1,25 @@ +//===-- Implementation header for fminl -------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINL_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINL_H + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE constexpr long double fminl(long double x, long double y) { + return fputil::fmin(x, y); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINL_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index dce67f3929288..b29110cca7062 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -2068,9 +2068,7 @@ add_entrypoint_object( HDRS ../fmin.h DEPENDS - libc.src.__support.FPUtil.basic_operations - FLAGS - MISC_MATH_BASIC_OPS_OPT + libc.src.__support.math.fmin ) add_entrypoint_object( @@ -2080,9 +2078,7 @@ add_entrypoint_object( HDRS ../fminf.h DEPENDS - libc.src.__support.FPUtil.basic_operations - FLAGS - MISC_MATH_BASIC_OPS_OPT + libc.src.__support.math.fminf ) add_entrypoint_object( @@ -2092,7 +2088,7 @@ add_entrypoint_object( HDRS ../fminl.h DEPENDS - libc.src.__support.FPUtil.basic_operations + libc.src.__support.math.fminl ) add_entrypoint_object( @@ -2102,8 +2098,7 @@ add_entrypoint_object( HDRS ../fminf128.h DEPENDS - libc.src.__support.macros.properties.types - libc.src.__support.FPUtil.basic_operations + libc.src.__support.math.fminf128 ) add_entrypoint_object( @@ -2113,10 +2108,7 @@ add_entrypoint_object( HDRS ../fminf16.h DEPENDS - libc.src.__support.macros.properties.types - libc.src.__support.FPUtil.basic_operations - FLAGS - MISC_MATH_BASIC_OPS_OPT + libc.src.__support.math.fminf16 ) add_entrypoint_object( @@ -2126,13 +2118,7 @@ add_entrypoint_object( HDRS ../fminbf16.h DEPENDS - libc.src.__support.common - libc.src.__support.FPUtil.basic_operations - libc.src.__support.FPUtil.bfloat16 - libc.src.__support.macros.config - libc.src.__support.macros.properties.types - FLAGS - MISC_MATH_BASIC_OPS_OPT + libc.src.__support.math.fminbf16 ) add_entrypoint_object( diff --git a/libc/src/math/generic/fmin.cpp b/libc/src/math/generic/fmin.cpp index 2351874029c72..b3bb623dc414b 100644 --- a/libc/src/math/generic/fmin.cpp +++ b/libc/src/math/generic/fmin.cpp @@ -7,14 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/math/fmin.h" -#include "src/__support/FPUtil/BasicOperations.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/fmin.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(double, fmin, (double x, double y)) { - return fputil::fmin(x, y); + return math::fmin(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/fminbf16.cpp b/libc/src/math/generic/fminbf16.cpp index c3e29ee10c8b6..514f38f55cacd 100644 --- a/libc/src/math/generic/fminbf16.cpp +++ b/libc/src/math/generic/fminbf16.cpp @@ -7,15 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/math/fminbf16.h" -#include "src/__support/FPUtil/BasicOperations.h" -#include "src/__support/FPUtil/bfloat16.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/fminbf16.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(bfloat16, fminbf16, (bfloat16 x, bfloat16 y)) { - return fputil::fmin(x, y); + return math::fminbf16(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/fminf.cpp b/libc/src/math/generic/fminf.cpp index 83dd0aa66b54a..495f2d1f9cfba 100644 --- a/libc/src/math/generic/fminf.cpp +++ b/libc/src/math/generic/fminf.cpp @@ -7,14 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/math/fminf.h" -#include "src/__support/FPUtil/BasicOperations.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/fminf.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(float, fminf, (float x, float y)) { - return fputil::fmin(x, y); + return math::fminf(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/fminf128.cpp b/libc/src/math/generic/fminf128.cpp index 184b7e3c21532..fa5591ad5941e 100644 --- a/libc/src/math/generic/fminf128.cpp +++ b/libc/src/math/generic/fminf128.cpp @@ -7,14 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/math/fminf128.h" -#include "src/__support/FPUtil/BasicOperations.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/fminf128.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(float128, fminf128, (float128 x, float128 y)) { - return fputil::fmin(x, y); + return math::fminf128(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/fminf16.cpp b/libc/src/math/generic/fminf16.cpp index 8b69273a906ec..00ff5dd6138fb 100644 --- a/libc/src/math/generic/fminf16.cpp +++ b/libc/src/math/generic/fminf16.cpp @@ -7,14 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/math/fminf16.h" -#include "src/__support/FPUtil/BasicOperations.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/fminf16.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(float16, fminf16, (float16 x, float16 y)) { - return fputil::fmin(x, y); + return math::fminf16(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/fminl.cpp b/libc/src/math/generic/fminl.cpp index aa15de74ebd57..d0c4401b27908 100644 --- a/libc/src/math/generic/fminl.cpp +++ b/libc/src/math/generic/fminl.cpp @@ -7,14 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/math/fminl.h" -#include "src/__support/FPUtil/BasicOperations.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/fminl.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(long double, fminl, (long double x, long double y)) { - return fputil::fmin(x, y); + return math::fminl(x, y); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt index 5539aff926648..1f8eca7567fe2 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -183,12 +183,18 @@ add_fp_unittest( libc.src.__support.math.fmaximumf16 libc.src.__support.math.fmaximuml libc.src.__support.math.fmaxl + libc.src.__support.math.fmin + libc.src.__support.math.fminbf16 + libc.src.__support.math.fminf + libc.src.__support.math.fminf128 + libc.src.__support.math.fminf16 libc.src.__support.math.fminimum libc.src.__support.math.fminimumbf16 libc.src.__support.math.fminimumf libc.src.__support.math.fminimumf128 libc.src.__support.math.fminimumf16 libc.src.__support.math.fminimuml + libc.src.__support.math.fminl libc.src.__support.math.frexpf libc.src.__support.math.frexpf128 libc.src.__support.math.frexpf16 @@ -359,12 +365,18 @@ add_fp_unittest( libc.src.__support.math.fmaximumf128 libc.src.__support.math.fmaximumf16 libc.src.__support.math.fmaximuml + libc.src.__support.math.fmin + libc.src.__support.math.fminbf16 + libc.src.__support.math.fminf + libc.src.__support.math.fminf128 + libc.src.__support.math.fminf16 libc.src.__support.math.fminimum libc.src.__support.math.fminimumbf16 libc.src.__support.math.fminimumf libc.src.__support.math.fminimumf128 libc.src.__support.math.fminimumf16 libc.src.__support.math.fminimuml + libc.src.__support.math.fminl libc.src.__support.math.llogbbf16 libc.src.__support.math.log libc.src.__support.math.logbbf16 diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp index b0d9e36b2f3a6..a048b5f58d6ad 100644 --- a/libc/test/shared/shared_math_constexpr_test.cpp +++ b/libc/test/shared/shared_math_constexpr_test.cpp @@ -25,6 +25,7 @@ static_assert(2.0 == LIBC_NAMESPACE::shared::fmaximum_mag_num(1.0, 2.0)); static_assert(0.0 == LIBC_NAMESPACE::shared::log(1.0)); static_assert(0.0 == LIBC_NAMESPACE::shared::fmaximum(0.0, 0.0)); static_assert(0.0 == LIBC_NAMESPACE::shared::fminimum(0.0, 0.0)); +static_assert(0.0 == LIBC_NAMESPACE::shared::fmin(0.0, 0.0)); //===----------------------------------------------------------------------===// // Float Tests @@ -38,6 +39,7 @@ static_assert(2.0f == LIBC_NAMESPACE::shared::fmaximum_mag_numf(1.0f, 2.0f)); static_assert(0.0f == LIBC_NAMESPACE::shared::floorf(0.0f)); static_assert(0.0f == LIBC_NAMESPACE::shared::fmaximumf(0.0f, 0.0f)); static_assert(0.0f == LIBC_NAMESPACE::shared::fminimumf(0.0f, 0.0f)); +static_assert(0.0f == LIBC_NAMESPACE::shared::fminf(0.0f, 0.0f)); //===----------------------------------------------------------------------===// // Float16 Tests @@ -52,6 +54,7 @@ static_assert(1.0f16 == LIBC_NAMESPACE::shared::fdimf16(1.0f16, 0.0f16)); static_assert(3.0f16 == LIBC_NAMESPACE::shared::floorf16(3.7f16)); static_assert(0.0f16 == LIBC_NAMESPACE::shared::fmaximumf16(0.0f16, 0.0f16)); static_assert(0.0f16 == LIBC_NAMESPACE::shared::fminimumf16(0.0f16, 0.0f16)); +static_assert(0.0f16 == LIBC_NAMESPACE::shared::fminf16(0.0f16, 0.0f16)); #endif // LIBC_TYPES_HAS_FLOAT16 @@ -74,6 +77,7 @@ static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::bf16subl(0.0L, 0.0L)); static_assert(0.0L == LIBC_NAMESPACE::shared::sqrtl(0.0L)); static_assert(0.0L == LIBC_NAMESPACE::shared::fmaximuml(0.0L, 0.0L)); static_assert(0.0L == LIBC_NAMESPACE::shared::fminimuml(0.0L, 0.0L)); +static_assert(0.0L == LIBC_NAMESPACE::shared::fminl(0.0L, 0.0L)); #endif @@ -105,6 +109,8 @@ static_assert(float128(0.0) == static_assert(float128(0.0) == LIBC_NAMESPACE::shared::fminimumf128(float128(0.0), float128(0.0))); +static_assert(float128(0.0) == + LIBC_NAMESPACE::shared::fminf128(float128(0.0), float128(0.0))); #endif // LIBC_TYPES_HAS_FLOAT128 @@ -136,5 +142,7 @@ static_assert(bfloat16(0.0) == static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::fminimumbf16(bfloat16(0.0), bfloat16(0.0))); +static_assert(bfloat16(0.0) == + LIBC_NAMESPACE::shared::fminbf16(bfloat16(0.0), bfloat16(0.0))); TEST(LlvmLibcSharedMathTest, ConstantEvaluation) {} diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp index 34644f86d2646..8b53394606580 100644 --- a/libc/test/shared/shared_math_test.cpp +++ b/libc/test/shared/shared_math_test.cpp @@ -105,6 +105,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) { EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::fmaximumf16(0.0f16, 0.0f16)); EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::fminimumf16(0.0f16, 0.0f16)); + EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::fminf16(0.0f16, 0.0f16)); } #endif // LIBC_TYPES_HAS_FLOAT16 @@ -218,6 +219,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) { EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fmaximumf(0.0f, 0.0f)); EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fminimumf(0.0f, 0.0f)); + EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fminf(0.0f, 0.0f)); } TEST(LlvmLibcSharedMathTest, AllDouble) { @@ -307,6 +309,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) { EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmaximum(0.0, 0.0)); EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fminimum(0.0, 0.0)); + EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmin(0.0, 0.0)); } // TODO: Enable the tests when double-double type is supported. @@ -377,6 +380,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) { EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::sqrtl(0.0L)); EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fmaximuml(0.0L, 0.0L)); EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fminimuml(0.0L, 0.0L)); + EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fminl(0.0L, 0.0L)); } #endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE @@ -488,6 +492,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) { float128(0.0), float128(0.0))); EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::fminimumf128( float128(0.0), float128(0.0))); + EXPECT_FP_EQ(float128(0.0), + LIBC_NAMESPACE::shared::fminf128(float128(0.0), float128(0.0))); } #endif // LIBC_TYPES_HAS_FLOAT128 @@ -563,4 +569,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) { bfloat16(0.0), bfloat16(0.0))); EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::fminimumbf16( bfloat16(0.0), bfloat16(0.0))); + EXPECT_FP_EQ(bfloat16(0.0), + LIBC_NAMESPACE::shared::fminbf16(bfloat16(0.0), bfloat16(0.0))); } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 4d3670353c793..9cde408bed804 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -4003,6 +4003,54 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_math_fmin", + hdrs = ["src/__support/math/fmin.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_macros_config", + ], +) + +libc_support_library( + name = "__support_math_fminbf16", + hdrs = ["src/__support/math/fminbf16.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_fputil_bfloat16", + ":__support_macros_config", + ], +) + +libc_support_library( + name = "__support_math_fminf", + hdrs = ["src/__support/math/fminf.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_macros_config", + ], +) + +libc_support_library( + name = "__support_math_fminf128", + hdrs = ["src/__support/math/fminf128.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_macros_config", + ":llvm_libc_types_float128", + ], +) + +libc_support_library( + name = "__support_math_fminf16", + hdrs = ["src/__support/math/fminf16.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_macros_config", + ":llvm_libc_macros_float16_macros", + ], +) + libc_support_library( name = "__support_math_fminimum", hdrs = ["src/__support/math/fminimum.h"], @@ -4060,6 +4108,15 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_math_fminl", + hdrs = ["src/__support/math/fminl.h"], + deps = [ + ":__support_fputil_basic_operations", + ":__support_macros_config", + ], +) + libc_support_library( name = "__support_math_ilogbbf16", hdrs = ["src/__support/math/ilogbbf16.h"], @@ -7344,6 +7401,13 @@ libc_math_function( ], ) +libc_math_function( + name = "fminbf16", + additional_deps = [ + ":__support_math_fminbf16", + ], +) + libc_math_function( name = "fminimumbf16", additional_deps = [ @@ -8244,18 +8308,39 @@ libc_math_function( name = "fmaximum_numf16", ) -libc_math_function(name = "fmin") +libc_math_function( + name = "fmin", + additional_deps = [ + ":__support_math_fmin", + ], +) -libc_math_function(name = "fminf") +libc_math_function( + name = "fminf", + additional_deps = [ + ":__support_math_fminf", + ], +) -libc_math_function(name = "fminl") +libc_math_function( + name = "fminl", + additional_deps = [ + ":__support_math_fminl", + ], +) libc_math_function( name = "fminf128", + additional_deps = [ + ":__support_math_fminf128", + ], ) libc_math_function( name = "fminf16", + additional_deps = [ + ":__support_math_fminf16", + ], ) libc_math_function(