diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index a1486ac689812..8357c625b52cf 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -375,6 +375,8 @@ if(LIBC_COMPILER_HAS_FLOAT128) libc.src.math.copysignf128 libc.src.math.fabsf128 libc.src.math.sqrtf128 + libc.src.math.fmaxf128 + libc.src.math.fminf128 ) endif() diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index e28b8e8798844..748247bb85d79 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -146,12 +146,16 @@ Basic Operations +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fmaxf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | | +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| fmaxf128 | |check| | | | | | | | | | | | | ++--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fmaxl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | | +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fmin | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | | +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fminf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | | +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| fminf128 | |check| | | | | | | | | | | | | ++--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fminl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | | +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fmod | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | | diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 8c2feba23adbf..5b6f344588b78 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -380,10 +380,12 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"fmin", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fminf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fminl", RetValSpec, [ArgSpec, ArgSpec]>, + FunctionSpec<"fminf128", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmax", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmaxf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmaxl", RetValSpec, [ArgSpec, ArgSpec]>, + FunctionSpec<"fmaxf128", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fma", RetValSpec, [ArgSpec, ArgSpec, ArgSpec]>, FunctionSpec<"fmaf", RetValSpec, [ArgSpec, ArgSpec, ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 3097c4b3a82cc..2b7eb3a05396b 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -121,10 +121,12 @@ add_math_entrypoint_object(fmaf) add_math_entrypoint_object(fmax) add_math_entrypoint_object(fmaxf) add_math_entrypoint_object(fmaxl) +add_math_entrypoint_object(fmaxf128) add_math_entrypoint_object(fmin) add_math_entrypoint_object(fminf) add_math_entrypoint_object(fminl) +add_math_entrypoint_object(fminf128) add_math_entrypoint_object(fmod) add_math_entrypoint_object(fmodf) diff --git a/libc/src/math/fmaxf128.h b/libc/src/math/fmaxf128.h new file mode 100644 index 0000000000000..39eaaf616dd5d --- /dev/null +++ b/libc/src/math/fmaxf128.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fmaxf128 ----------------------*- 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_MATH_FMAXF128_H +#define LLVM_LIBC_SRC_MATH_FMAXF128_H + +#include "src/__support/macros/properties/float.h" + +namespace LIBC_NAMESPACE { + +float128 fmaxf128(float128 x, float128 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMAXF128_H diff --git a/libc/src/math/fminf128.h b/libc/src/math/fminf128.h new file mode 100644 index 0000000000000..b3d1bec8e2ad9 --- /dev/null +++ b/libc/src/math/fminf128.h @@ -0,0 +1,20 @@ +//===-- 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_MATH_FMINF128_H +#define LLVM_LIBC_SRC_MATH_FMINF128_H + +#include "src/__support/macros/properties/float.h" + +namespace LIBC_NAMESPACE { + +float128 fminf128(float128 x, float128 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMINF128_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 8b32a3296bb87..2521435bffb4e 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1243,6 +1243,18 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + fminf128 + SRCS + fminf128.cpp + HDRS + ../fminf128.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( fmax SRCS @@ -1279,6 +1291,18 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + fmaxf128 + SRCS + fmaxf128.cpp + HDRS + ../fmaxf128.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( sqrt SRCS diff --git a/libc/src/math/generic/fmaxf128.cpp b/libc/src/math/generic/fmaxf128.cpp new file mode 100644 index 0000000000000..096e4befeb79a --- /dev/null +++ b/libc/src/math/generic/fmaxf128.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fmaxf128 function -------------------------------===// +// +// 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 "src/math/fmaxf128.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float128, fmaxf128, (float128 x, float128 y)) { + return fputil::fmax(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fminf128.cpp b/libc/src/math/generic/fminf128.cpp new file mode 100644 index 0000000000000..084ed4c9931bc --- /dev/null +++ b/libc/src/math/generic/fminf128.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fminf128 function -------------------------------===// +// +// 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 "src/math/fminf128.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float128, fminf128, (float128 x, float128 y)) { + return fputil::fmin(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 03526e019c3e9..05f5a39beed5b 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -984,7 +984,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) HDRS FMinTest.h DEPENDS - libc.include.math libc.src.math.fminf libc.src.__support.FPUtil.fp_bits ) @@ -998,7 +997,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) HDRS FMinTest.h DEPENDS - libc.include.math libc.src.math.fmin libc.src.__support.FPUtil.fp_bits ) @@ -1012,11 +1010,23 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) HDRS FMinTest.h DEPENDS - libc.include.math libc.src.math.fminl libc.src.__support.FPUtil.fp_bits ) + add_fp_unittest( + fminf128_test + SUITE + libc-math-smoke-tests + SRCS + fminf128_test.cpp + HDRS + FMinTest.h + DEPENDS + libc.src.math.fminf128 + libc.src.__support.FPUtil.fp_bits + ) + add_fp_unittest( fmaxf_test SUITE @@ -1026,7 +1036,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) HDRS FMaxTest.h DEPENDS - libc.include.math libc.src.math.fmaxf libc.src.__support.FPUtil.fp_bits ) @@ -1040,7 +1049,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) HDRS FMaxTest.h DEPENDS - libc.include.math libc.src.math.fmax libc.src.__support.FPUtil.fp_bits ) @@ -1054,10 +1062,22 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) HDRS FMaxTest.h DEPENDS - libc.include.math libc.src.math.fmaxl libc.src.__support.FPUtil.fp_bits ) + + add_fp_unittest( + fmaxf128_test + SUITE + libc-math-smoke-tests + SRCS + fmaxf128_test.cpp + HDRS + FMaxTest.h + DEPENDS + libc.src.math.fmaxf128 + libc.src.__support.FPUtil.fp_bits + ) endif() add_fp_unittest( diff --git a/libc/test/src/math/smoke/FMaxTest.h b/libc/test/src/math/smoke/FMaxTest.h index 98edc8e971e81..1a376af2e0b7b 100644 --- a/libc/test/src/math/smoke/FMaxTest.h +++ b/libc/test/src/math/smoke/FMaxTest.h @@ -9,8 +9,6 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include - template class FMaxTest : public LIBC_NAMESPACE::testing::Test { DECLARE_SPECIAL_CONSTANTS(T) @@ -56,11 +54,13 @@ template class FMaxTest : public LIBC_NAMESPACE::testing::Test { constexpr StorageType STEP = STORAGE_MAX / COUNT; for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT; ++i, v += STEP, w -= STEP) { - T x = FPBits(v).get_val(), y = FPBits(w).get_val(); - if (isnan(x) || isinf(x)) + FPBits xbits(v), ybits(w); + if (xbits.is_inf_or_nan()) continue; - if (isnan(y) || isinf(y)) + if (ybits.is_inf_or_nan()) continue; + T x = xbits.get_val(); + T y = ybits.get_val(); if ((x == 0) && (y == 0)) continue; diff --git a/libc/test/src/math/smoke/FMinTest.h b/libc/test/src/math/smoke/FMinTest.h index 834d757c85d04..add2544424a01 100644 --- a/libc/test/src/math/smoke/FMinTest.h +++ b/libc/test/src/math/smoke/FMinTest.h @@ -9,8 +9,6 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include - template class FMinTest : public LIBC_NAMESPACE::testing::Test { DECLARE_SPECIAL_CONSTANTS(T) @@ -56,11 +54,13 @@ template class FMinTest : public LIBC_NAMESPACE::testing::Test { constexpr StorageType STEP = STORAGE_MAX / COUNT; for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT; ++i, v += STEP, w -= STEP) { - T x = FPBits(v).get_val(), y = FPBits(w).get_val(); - if (isnan(x) || isinf(x)) + FPBits xbits(v), ybits(w); + if (xbits.is_inf_or_nan()) continue; - if (isnan(y) || isinf(y)) + if (ybits.is_inf_or_nan()) continue; + T x = xbits.get_val(); + T y = ybits.get_val(); if ((x == 0) && (y == 0)) continue; diff --git a/libc/test/src/math/smoke/fmaxf128_test.cpp b/libc/test/src/math/smoke/fmaxf128_test.cpp new file mode 100644 index 0000000000000..497cd05c62391 --- /dev/null +++ b/libc/test/src/math/smoke/fmaxf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fmaxf128 --------------------------------------------===// +// +// 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 "FMaxTest.h" + +#include "src/math/fmaxf128.h" + +LIST_FMAX_TESTS(float128, LIBC_NAMESPACE::fmaxf128) diff --git a/libc/test/src/math/smoke/fminf128_test.cpp b/libc/test/src/math/smoke/fminf128_test.cpp new file mode 100644 index 0000000000000..f1e9ed4e6ac8e --- /dev/null +++ b/libc/test/src/math/smoke/fminf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fminf128 --------------------------------------------===// +// +// 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 "FMinTest.h" + +#include "src/math/fminf128.h" + +LIST_FMIN_TESTS(float128, LIBC_NAMESPACE::fminf128)