diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index fbf8c4b5a7581..579d720ebeded 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -507,7 +507,9 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.canonicalizef16 libc.src.math.ceilf16 libc.src.math.copysignf16 + libc.src.math.f16div libc.src.math.f16divf + libc.src.math.f16divl libc.src.math.f16fmaf libc.src.math.f16sqrtf libc.src.math.fabsf16 @@ -560,6 +562,13 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.ufromfpf16 libc.src.math.ufromfpxf16 ) + + if(LIBC_TYPES_HAS_FLOAT128) + list(APPEND TARGET_LIBM_ENTRYPOINTS + # math.h C23 mixed _Float16 and _Float128 entrypoints + libc.src.math.f16divf128 + ) + endif() endif() if(LIBC_TYPES_HAS_FLOAT128) diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 9581f7f2604c4..e1922ca94b97e 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -537,7 +537,9 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.canonicalizef16 libc.src.math.ceilf16 libc.src.math.copysignf16 + libc.src.math.f16div libc.src.math.f16divf + libc.src.math.f16divl libc.src.math.f16fma libc.src.math.f16fmaf libc.src.math.f16fmal @@ -595,6 +597,7 @@ if(LIBC_TYPES_HAS_FLOAT16) list(APPEND TARGET_LIBM_ENTRYPOINTS # math.h C23 mixed _Float16 and _Float128 entrypoints libc.src.math.f16fmaf128 + libc.src.math.f16divf128 ) endif() endif() diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 56cc8d658257d..1bc75a9e0517f 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -124,7 +124,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | dsub | N/A | N/A | | N/A | | 7.12.14.2 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| f16div | |check| | | | N/A | | 7.12.14.4 | F.10.11 | +| f16div | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.4 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | f16fma | |check| | |check| | |check| | N/A | |check| | 7.12.14.5 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ @@ -350,6 +350,7 @@ Legends: tie-to-even). * x ULPs: largest errors recorded. * N/A: Not defined in the standard or will not be added. +* \*: LLVM libc extension. .. TODO(lntue): Add a new page to discuss about the algorithms used in the diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td index ca61d4ef371a2..ed1a17ec91904 100644 --- a/libc/spec/llvm_libc_ext.td +++ b/libc/spec/llvm_libc_ext.td @@ -51,8 +51,21 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> { ] >; + HeaderSpec Math = HeaderSpec< + "math.h", + [], // Macros + [], // Types + [], // Enumerations + [ + GuardedFunctionSpec<"f16div", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16divf", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16divl", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + ] + >; + let Headers = [ Assert, + Math, Sched, Strings, ]; diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index adac7d5932428..481515ad439ed 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -729,7 +729,7 @@ def StdC : StandardSpec<"stdc"> { GuardedFunctionSpec<"setpayloadsigf16", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, - GuardedFunctionSpec<"f16divf", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16divf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">, GuardedFunctionSpec<"f16sqrtf", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, ] diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 3dfc4ac94827d..fb0d971e88733 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -99,7 +99,10 @@ add_math_entrypoint_object(exp10f) add_math_entrypoint_object(expm1) add_math_entrypoint_object(expm1f) +add_math_entrypoint_object(f16div) add_math_entrypoint_object(f16divf) +add_math_entrypoint_object(f16divl) +add_math_entrypoint_object(f16divf128) add_math_entrypoint_object(f16fma) add_math_entrypoint_object(f16fmaf) diff --git a/libc/src/math/f16div.h b/libc/src/math/f16div.h new file mode 100644 index 0000000000000..3807bc02276c9 --- /dev/null +++ b/libc/src/math/f16div.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16div ------------------------*- 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_F16DIV_H +#define LLVM_LIBC_SRC_MATH_F16DIV_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16div(double x, double y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16DIV_H diff --git a/libc/src/math/f16divf128.h b/libc/src/math/f16divf128.h new file mode 100644 index 0000000000000..2f63535ca27ce --- /dev/null +++ b/libc/src/math/f16divf128.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16divf128 --------------------*- 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_F16DIVF128_H +#define LLVM_LIBC_SRC_MATH_F16DIVF128_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16divf128(float128 x, float128 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16DIVF128_H diff --git a/libc/src/math/f16divl.h b/libc/src/math/f16divl.h new file mode 100644 index 0000000000000..ad9999135b588 --- /dev/null +++ b/libc/src/math/f16divl.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16divl -----------------------*- 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_F16DIVL_H +#define LLVM_LIBC_SRC_MATH_F16DIVL_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16divl(long double x, long double y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16DIVL_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 3773a2b49c416..0e4893cd42ee1 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -3776,6 +3776,19 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + f16div + SRCS + f16div.cpp + HDRS + ../f16div.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.div + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( f16divf SRCS @@ -3789,6 +3802,32 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + f16divl + SRCS + f16divl.cpp + HDRS + ../f16divl.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.div + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( + f16divf128 + SRCS + f16divf128.cpp + HDRS + ../f16divf128.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.div + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( f16fma SRCS diff --git a/libc/src/math/generic/f16div.cpp b/libc/src/math/generic/f16div.cpp new file mode 100644 index 0000000000000..2ff0ff7865539 --- /dev/null +++ b/libc/src/math/generic/f16div.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16div 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/f16div.h" +#include "src/__support/FPUtil/generic/div.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16div, (double x, double y)) { + return fputil::generic::div(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/f16divf128.cpp b/libc/src/math/generic/f16divf128.cpp new file mode 100644 index 0000000000000..1d37ad8aa2366 --- /dev/null +++ b/libc/src/math/generic/f16divf128.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16divf128 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/f16divf128.h" +#include "src/__support/FPUtil/generic/div.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16divf128, (float128 x, float128 y)) { + return fputil::generic::div(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/f16divl.cpp b/libc/src/math/generic/f16divl.cpp new file mode 100644 index 0000000000000..3fb9c7891f5d1 --- /dev/null +++ b/libc/src/math/generic/f16divl.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16divl 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/f16divl.h" +#include "src/__support/FPUtil/generic/div.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16divl, (long double x, long double y)) { + return fputil::generic::div(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index 36d2a2fbfd302..061feeadb40d5 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1902,6 +1902,19 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + f16div_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + f16div_test.cpp + HDRS + DivTest.h + DEPENDS + libc.src.math.f16div +) + add_fp_unittest( f16divf_test NEED_MPFR @@ -1915,6 +1928,19 @@ add_fp_unittest( libc.src.math.f16divf ) +add_fp_unittest( + f16divl_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + f16divl_test.cpp + HDRS + DivTest.h + DEPENDS + libc.src.math.f16divl +) + add_fp_unittest( f16fma_test NEED_MPFR diff --git a/libc/test/src/math/f16div_test.cpp b/libc/test/src/math/f16div_test.cpp new file mode 100644 index 0000000000000..0bfa69f9b8028 --- /dev/null +++ b/libc/test/src/math/f16div_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16div ----------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/math/f16div.h" + +LIST_DIV_TESTS(float16, double, LIBC_NAMESPACE::f16div) diff --git a/libc/test/src/math/f16divl_test.cpp b/libc/test/src/math/f16divl_test.cpp new file mode 100644 index 0000000000000..bad3e70a477b4 --- /dev/null +++ b/libc/test/src/math/f16divl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16divl ---------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/math/f16divl.h" + +LIST_DIV_TESTS(float16, long double, LIBC_NAMESPACE::f16divl) diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index ee6f1595fe0fd..e3d8a14191ad2 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -3630,6 +3630,20 @@ add_fp_unittest( libc.src.math.setpayloadsigf16 ) +add_fp_unittest( + f16div_test + SUITE + libc-math-smoke-tests + SRCS + f16div_test.cpp + HDRS + DivTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16div +) + add_fp_unittest( f16divf_test SUITE @@ -3644,6 +3658,34 @@ add_fp_unittest( libc.src.math.f16divf ) +add_fp_unittest( + f16divl_test + SUITE + libc-math-smoke-tests + SRCS + f16divl_test.cpp + HDRS + DivTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16divl +) + +add_fp_unittest( + f16divf128_test + SUITE + libc-math-smoke-tests + SRCS + f16divf128_test.cpp + HDRS + DivTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16divf128 +) + add_fp_unittest( f16fma_test SUITE diff --git a/libc/test/src/math/smoke/f16div_test.cpp b/libc/test/src/math/smoke/f16div_test.cpp new file mode 100644 index 0000000000000..0bfa69f9b8028 --- /dev/null +++ b/libc/test/src/math/smoke/f16div_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16div ----------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/math/f16div.h" + +LIST_DIV_TESTS(float16, double, LIBC_NAMESPACE::f16div) diff --git a/libc/test/src/math/smoke/f16divf128_test.cpp b/libc/test/src/math/smoke/f16divf128_test.cpp new file mode 100644 index 0000000000000..d2ea971824621 --- /dev/null +++ b/libc/test/src/math/smoke/f16divf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16divf128 ------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/math/f16divf128.h" + +LIST_DIV_TESTS(float16, float128, LIBC_NAMESPACE::f16divf128) diff --git a/libc/test/src/math/smoke/f16divl_test.cpp b/libc/test/src/math/smoke/f16divl_test.cpp new file mode 100644 index 0000000000000..bad3e70a477b4 --- /dev/null +++ b/libc/test/src/math/smoke/f16divl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16divl ---------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/math/f16divl.h" + +LIST_DIV_TESTS(float16, long double, LIBC_NAMESPACE::f16divl) diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp index d69309077e099..0bfe49984e7d2 100644 --- a/libc/utils/MPFRWrapper/MPFRUtils.cpp +++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp @@ -935,6 +935,10 @@ template void explain_binary_operation_one_output_error( template void explain_binary_operation_one_output_error(Operation, const BinaryInput &, float16, double, RoundingMode); +template void explain_binary_operation_one_output_error( + Operation, const BinaryInput &, float16, double, RoundingMode); +template void explain_binary_operation_one_output_error( + Operation, const BinaryInput &, float16, double, RoundingMode); #endif template @@ -1104,6 +1108,13 @@ template bool compare_binary_operation_one_output(Operation, const BinaryInput &, float16, double, RoundingMode); +template bool compare_binary_operation_one_output(Operation, + const BinaryInput &, + float16, double, + RoundingMode); +template bool +compare_binary_operation_one_output(Operation, const BinaryInput &, + float16, double, RoundingMode); #endif template