[libc-commits] [libc] [libc][math][c23] Add f16div{, l, f128} C23 math functions (PR #97054)
via libc-commits
libc-commits at lists.llvm.org
Fri Jun 28 06:30:27 PDT 2024
https://github.com/overmighty updated https://github.com/llvm/llvm-project/pull/97054
>From ad9e459a8f1d3a49153e48484106b34c4fa7c52e Mon Sep 17 00:00:00 2001
From: OverMighty <its.overmighty at gmail.com>
Date: Fri, 28 Jun 2024 14:53:25 +0200
Subject: [PATCH 1/4] [libc][math][c23] Add f16div C23 math function
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/docs/math/index.rst | 2 +-
libc/spec/stdc.td | 1 +
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/f16div.h | 20 ++++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 13 +++++++++++++
libc/src/math/generic/f16div.cpp | 19 +++++++++++++++++++
libc/test/src/math/CMakeLists.txt | 13 +++++++++++++
libc/test/src/math/f16div_test.cpp | 13 +++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 14 ++++++++++++++
libc/test/src/math/smoke/f16div_test.cpp | 13 +++++++++++++
libc/utils/MPFRWrapper/MPFRUtils.cpp | 6 ++++++
13 files changed, 116 insertions(+), 1 deletion(-)
create mode 100644 libc/src/math/f16div.h
create mode 100644 libc/src/math/generic/f16div.cpp
create mode 100644 libc/test/src/math/f16div_test.cpp
create mode 100644 libc/test/src/math/smoke/f16div_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index fbf8c4b5a7581..8a26536cea9a0 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -507,6 +507,7 @@ 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.f16fmaf
libc.src.math.f16sqrtf
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 9581f7f2604c4..2118b47d074e1 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -537,6 +537,7 @@ 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.f16fma
libc.src.math.f16fmaf
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 56cc8d658257d..b1b246b7d9362 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| | | N/A | | 7.12.14.4 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| f16fma | |check| | |check| | |check| | N/A | |check| | 7.12.14.5 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index adac7d5932428..acb567047a542 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -729,6 +729,7 @@ def StdC : StandardSpec<"stdc"> {
GuardedFunctionSpec<"setpayloadsigf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
+ 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<"f16sqrtf", RetValSpec<Float16Type>, [ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 3dfc4ac94827d..f0a92372a72e5 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -99,6 +99,7 @@ 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(f16fma)
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/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 3773a2b49c416..ed09cb8530977 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
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<float16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 36d2a2fbfd302..21d3e879cfc90 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
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/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index ee6f1595fe0fd..14a15cd5aaf5d 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
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/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index d69309077e099..f4e468f181e66 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -935,6 +935,8 @@ 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);
#endif
template <typename InputType, typename OutputType>
@@ -1104,6 +1106,10 @@ 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);
#endif
template <typename InputType, typename OutputType>
>From a49c582f72ce2174f4ad413bd83b6ed82e5d236d Mon Sep 17 00:00:00 2001
From: OverMighty <its.overmighty at gmail.com>
Date: Fri, 28 Jun 2024 14:58:59 +0200
Subject: [PATCH 2/4] [libc][math][c23] Add f16divf128 C23 math function
---
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/docs/math/index.rst | 2 +-
libc/spec/stdc.td | 1 +
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/f16divf128.h | 20 ++++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 13 +++++++++++++
libc/src/math/generic/f16divf128.cpp | 19 +++++++++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 14 ++++++++++++++
libc/test/src/math/smoke/f16divf128_test.cpp | 13 +++++++++++++
9 files changed, 83 insertions(+), 1 deletion(-)
create mode 100644 libc/src/math/f16divf128.h
create mode 100644 libc/src/math/generic/f16divf128.cpp
create mode 100644 libc/test/src/math/smoke/f16divf128_test.cpp
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 2118b47d074e1..da8fb253c3e78 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -596,6 +596,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 b1b246b7d9362..6687e2892b3d8 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| | |check| | | N/A | | 7.12.14.4 | F.10.11 |
+| f16div | |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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index acb567047a542..e1c7b8b4f1abc 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -731,6 +731,7 @@ def StdC : StandardSpec<"stdc"> {
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<"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 f0a92372a72e5..7f6de0d152659 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -101,6 +101,7 @@ add_math_entrypoint_object(expm1f)
add_math_entrypoint_object(f16div)
add_math_entrypoint_object(f16divf)
+add_math_entrypoint_object(f16divf128)
add_math_entrypoint_object(f16fma)
add_math_entrypoint_object(f16fmaf)
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/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index ed09cb8530977..44c4eee165920 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3802,6 +3802,19 @@ add_entrypoint_object(
-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/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<float16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 14a15cd5aaf5d..dfef0c8010dcb 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3658,6 +3658,20 @@ add_fp_unittest(
libc.src.math.f16divf
)
+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/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)
>From 2ff4ae6224914c2e73e26cfd728cad90f319d808 Mon Sep 17 00:00:00 2001
From: OverMighty <its.overmighty at gmail.com>
Date: Fri, 28 Jun 2024 15:03:51 +0200
Subject: [PATCH 3/4] [libc][math][c23] Add f16divl C23 math function
---
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/docs/math/index.rst | 2 +-
libc/spec/stdc.td | 1 +
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/f16divl.h | 20 ++++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 13 +++++++++++++
libc/src/math/generic/f16divl.cpp | 19 +++++++++++++++++++
libc/test/src/math/CMakeLists.txt | 13 +++++++++++++
libc/test/src/math/f16divl_test.cpp | 13 +++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 14 ++++++++++++++
libc/test/src/math/smoke/f16divl_test.cpp | 13 +++++++++++++
libc/utils/MPFRWrapper/MPFRUtils.cpp | 5 +++++
12 files changed, 114 insertions(+), 1 deletion(-)
create mode 100644 libc/src/math/f16divl.h
create mode 100644 libc/src/math/generic/f16divl.cpp
create mode 100644 libc/test/src/math/f16divl_test.cpp
create mode 100644 libc/test/src/math/smoke/f16divl_test.cpp
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index da8fb253c3e78..e1922ca94b97e 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -539,6 +539,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
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
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 6687e2892b3d8..4aa7a327a7f73 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| | |check| | | N/A | |check| | 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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index e1c7b8b4f1abc..673661cd3d3a7 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -731,6 +731,7 @@ def StdC : StandardSpec<"stdc"> {
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">,
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 7f6de0d152659..fb0d971e88733 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -101,6 +101,7 @@ 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)
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 44c4eee165920..0e4893cd42ee1 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3802,6 +3802,19 @@ 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
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<float16>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 21d3e879cfc90..061feeadb40d5 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1928,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/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 dfef0c8010dcb..e3d8a14191ad2 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3658,6 +3658,20 @@ 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
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 f4e468f181e66..0bfe49984e7d2 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -937,6 +937,8 @@ 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>
@@ -1110,6 +1112,9 @@ 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>
>From 3dd9f998f657048a450f907c55397250e708ce6a Mon Sep 17 00:00:00 2001
From: OverMighty <its.overmighty at gmail.com>
Date: Fri, 28 Jun 2024 15:20:16 +0200
Subject: [PATCH 4/4] [libc][math][c23] Enable f16div{l,f128} C23 math
functions on AArch64 Linux
---
libc/config/linux/aarch64/entrypoints.txt | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 8a26536cea9a0..579d720ebeded 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -509,6 +509,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
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
@@ -561,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)
More information about the libc-commits
mailing list