diff options
Diffstat (limited to 'libc')
-rw-r--r-- | libc/config/linux/aarch64/entrypoints.txt | 9 | ||||
-rw-r--r-- | libc/config/linux/x86_64/entrypoints.txt | 3 | ||||
-rw-r--r-- | libc/docs/math/index.rst | 3 | ||||
-rw-r--r-- | libc/spec/llvm_libc_ext.td | 13 | ||||
-rw-r--r-- | libc/spec/stdc.td | 2 | ||||
-rw-r--r-- | libc/src/math/CMakeLists.txt | 3 | ||||
-rw-r--r-- | libc/src/math/f16div.h | 20 | ||||
-rw-r--r-- | libc/src/math/f16divf128.h | 20 | ||||
-rw-r--r-- | libc/src/math/f16divl.h | 20 | ||||
-rw-r--r-- | libc/src/math/generic/CMakeLists.txt | 39 | ||||
-rw-r--r-- | libc/src/math/generic/f16div.cpp | 19 | ||||
-rw-r--r-- | libc/src/math/generic/f16divf128.cpp | 19 | ||||
-rw-r--r-- | libc/src/math/generic/f16divl.cpp | 19 | ||||
-rw-r--r-- | libc/test/src/math/CMakeLists.txt | 26 | ||||
-rw-r--r-- | libc/test/src/math/f16div_test.cpp | 13 | ||||
-rw-r--r-- | libc/test/src/math/f16divl_test.cpp | 13 | ||||
-rw-r--r-- | libc/test/src/math/smoke/CMakeLists.txt | 42 | ||||
-rw-r--r-- | libc/test/src/math/smoke/f16div_test.cpp | 13 | ||||
-rw-r--r-- | libc/test/src/math/smoke/f16divf128_test.cpp | 13 | ||||
-rw-r--r-- | libc/test/src/math/smoke/f16divl_test.cpp | 13 | ||||
-rw-r--r-- | libc/utils/MPFRWrapper/MPFRUtils.cpp | 11 |
21 files changed, 331 insertions, 2 deletions
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index fbf8c4b..579d720 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 9581f7f..e1922ca 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 56cc8d6..1bc75a9 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 ca61d4ef..ed1a17e 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<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16divf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16divl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">, + ] + >; + let Headers = [ Assert, + Math, Sched, Strings, ]; diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index adac7d5..481515a 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -729,7 +729,7 @@ def StdC : StandardSpec<"stdc"> { GuardedFunctionSpec<"setpayloadsigf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">, - GuardedFunctionSpec<"f16divf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16divf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">, GuardedFunctionSpec<"f16sqrtf", RetValSpec<Float16Type>, [ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">, ] diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 3dfc4ac..fb0d971 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 0000000..3807bc0 --- /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 0000000..2f63535 --- /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 0000000..ad99991 --- /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 3773a2b..0e4893c 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -3777,6 +3777,19 @@ add_entrypoint_object( ) 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 f16divf.cpp @@ -3790,6 +3803,32 @@ add_entrypoint_object( ) 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 f16fma.cpp diff --git a/libc/src/math/generic/f16div.cpp b/libc/src/math/generic/f16div.cpp new file mode 100644 index 0000000..2ff0ff7 --- /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<float16>(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 0000000..1d37ad8 --- /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<float16>(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 0000000..3fb9c78 --- /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<float16>(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index 36d2a2f..061feea 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1903,6 +1903,19 @@ add_fp_unittest( ) 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 SUITE @@ -1916,6 +1929,19 @@ add_fp_unittest( ) 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 SUITE diff --git a/libc/test/src/math/f16div_test.cpp b/libc/test/src/math/f16div_test.cpp new file mode 100644 index 0000000..0bfa69f --- /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 0000000..bad3e70 --- /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 ee6f159..e3d8a14 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -3631,6 +3631,20 @@ add_fp_unittest( ) 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 libc-math-smoke-tests @@ -3645,6 +3659,34 @@ add_fp_unittest( ) 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 libc-math-smoke-tests 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 0000000..0bfa69f --- /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 0000000..d2ea971 --- /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 0000000..bad3e70 --- /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 d693090..0bfe499 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<float> &, float16, double, RoundingMode); +template void explain_binary_operation_one_output_error( + Operation, const BinaryInput<double> &, float16, double, RoundingMode); +template void explain_binary_operation_one_output_error( + Operation, const BinaryInput<long double> &, float16, double, RoundingMode); #endif template <typename InputType, typename OutputType> @@ -1104,6 +1108,13 @@ template bool compare_binary_operation_one_output(Operation, const BinaryInput<float> &, float16, double, RoundingMode); +template bool compare_binary_operation_one_output(Operation, + const BinaryInput<double> &, + float16, double, + RoundingMode); +template bool +compare_binary_operation_one_output(Operation, const BinaryInput<long double> &, + float16, double, RoundingMode); #endif template <typename InputType, typename OutputType> |