[libc-commits] [libc] [libc][math]fadd implementation (PR #99694)
via libc-commits
libc-commits at lists.llvm.org
Fri Jul 19 13:52:54 PDT 2024
https://github.com/aaryanshukla updated https://github.com/llvm/llvm-project/pull/99694
>From 5748a9d7b27adf6c15049e249f9daf04e77ffd00 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Thu, 18 Jul 2024 23:29:41 +0000
Subject: [PATCH 1/4] [libc] math fadd
---
libc/config/gpu/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/config/windows/entrypoints.txt | 1 +
libc/spec/stdc.td | 1 +
libc/src/math/fadd.h | 20 ++++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 13 +++++++++++++
libc/src/math/generic/fadd.cpp | 23 +++++++++++++++++++++++
libc/test/src/math/CMakeLists.txt | 14 ++++++++++++++
libc/test/src/math/fadd_test.cpp | 13 +++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 14 ++++++++++++++
libc/test/src/math/smoke/fadd_test.cpp | 14 ++++++++++++++
11 files changed, 115 insertions(+)
create mode 100644 libc/src/math/fadd.h
create mode 100644 libc/src/math/generic/fadd.cpp
create mode 100644 libc/test/src/math/fadd_test.cpp
create mode 100644 libc/test/src/math/smoke/fadd_test.cpp
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index b8eb743cf587a..506c7d6d7b314 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -266,6 +266,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.expm1f
libc.src.math.fabs
libc.src.math.fabsf
+ libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.floor
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index cbdee084aa199..7309e95644c74 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -396,6 +396,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index afc9ca87ff094..b6aced83c5815 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -144,6 +144,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 18592e92d330a..285166ef0be78 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -402,6 +402,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"fabsf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"fabsf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+ FunctionSpec<"fadd", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fdim", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fdimf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
diff --git a/libc/src/math/fadd.h b/libc/src/math/fadd.h
new file mode 100644
index 0000000000000..701834cc2e806
--- /dev/null
+++ b/libc/src/math/fadd.h
@@ -0,0 +1,20 @@
+//===-- Implementation of fadd 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/__support/macros/config.h"
+
+#ifndef LLVM_LIBC_SRC_MATH_FADD_H
+#define LLVM_LIBC_SRC_MATH_FADD_H
+
+namespace LIBC_NAMESPACE_DECL {
+
+float fadd(double x, double y);
+
+} // namesapce LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FADD_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 9c86bac4a0cb7..83e621e11e6b4 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -452,6 +452,19 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ fadd
+ SRCS
+ fadd.cpp
+ HDRS
+ ../fadd.h
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.basic_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
add_entrypoint_object(
trunc
SRCS
diff --git a/libc/src/math/generic/fadd.cpp b/libc/src/math/generic/fadd.cpp
new file mode 100644
index 0000000000000..966954ade8717
--- /dev/null
+++ b/libc/src/math/generic/fadd.cpp
@@ -0,0 +1,23 @@
+//===-- Implementation of fadd 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/fadd.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/common.h"
+
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, fadd, (double x, double y)) {
+ return fputil::generic::add<float>(x,y);
+
+}
+
+
+} // namespace LIBC_NAMESPACE_DECLS
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index c28385f620cfd..f69b0d9b1b666 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -174,6 +174,20 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ fadd_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ fadd_test.cpp
+ HDRS
+ AddTest.h
+ DEPENDS
+ libc.src.math.fadd
+ libc.src.__support.FPUtil.basic_operations
+)
+
add_fp_unittest(
trunc_test
NEED_MPFR
diff --git a/libc/test/src/math/fadd_test.cpp b/libc/test/src/math/fadd_test.cpp
new file mode 100644
index 0000000000000..fe9ac8b252ed3
--- /dev/null
+++ b/libc/test/src/math/fadd_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fadd ----------------------------------------------===//
+//
+// 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 "AddTest.h"
+
+#include "src/math/fadd.h"
+
+LIST_ADD_TESTS(float, double, LIBC_NAMESPACE::fadd)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index c57aa9638ed30..deeb723cfefc5 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -141,6 +141,20 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ fadd_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fadd_test.cpp
+ HDRS
+ AddTest.h
+ DEPENDS
+ libc.src.math.fadd
+ libc.src.__support.FPUtil.basic_operations
+
+)
+
add_fp_unittest(
trunc_test
SUITE
diff --git a/libc/test/src/math/smoke/fadd_test.cpp b/libc/test/src/math/smoke/fadd_test.cpp
new file mode 100644
index 0000000000000..24f53dcbd424e
--- /dev/null
+++ b/libc/test/src/math/smoke/fadd_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for fadd ----------------------------------------------===//
+//
+// 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 "AddTest.h"
+
+#include "src/math/fadd.h"
+
+
+LIST_ADD_TESTS(float, double, LIBC_NAMESPACE::fadd)
>From ef487a5327f53054f59fe97247c32f4f83c65b53 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Fri, 19 Jul 2024 17:25:42 +0000
Subject: [PATCH 2/4] [libc][math] implemented fadd
- will implement all basic operations in another pr
---
libc/src/math/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index c4e33130e9090..050bf0f1ebf22 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -141,6 +141,7 @@ add_math_entrypoint_object(fabsf)
add_math_entrypoint_object(fabsl)
add_math_entrypoint_object(fabsf16)
add_math_entrypoint_object(fabsf128)
+add_math_entrypoint_object(fadd)
add_math_entrypoint_object(fdim)
add_math_entrypoint_object(fdimf)
>From 72c3165f94be34f5f369b3715dae5c28ff454b0b Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Fri, 19 Jul 2024 20:12:19 +0000
Subject: [PATCH 3/4] added under linux archs and formatting
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/arm/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/src/math/fadd.h | 4 ++--
libc/src/math/generic/CMakeLists.txt | 1 -
libc/src/math/generic/fadd.cpp | 11 ++++-------
libc/test/src/math/smoke/fadd_test.cpp | 1 -
7 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 208889ba34a59..e2f6bd74bb694 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -370,6 +370,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index a72f8668808a5..0d09e4c22953c 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -239,6 +239,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 266c94d54a9df..33dd8d06173b2 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -371,6 +371,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
diff --git a/libc/src/math/fadd.h b/libc/src/math/fadd.h
index 701834cc2e806..ec3ce18bb676a 100644
--- a/libc/src/math/fadd.h
+++ b/libc/src/math/fadd.h
@@ -12,9 +12,9 @@
#define LLVM_LIBC_SRC_MATH_FADD_H
namespace LIBC_NAMESPACE_DECL {
-
+
float fadd(double x, double y);
-} // namesapce LIBC_NAMESPACE_DECL
+} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_MATH_FADD_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 83e621e11e6b4..297eb73c61e07 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -459,7 +459,6 @@ add_entrypoint_object(
HDRS
../fadd.h
DEPENDS
- libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
diff --git a/libc/src/math/generic/fadd.cpp b/libc/src/math/generic/fadd.cpp
index 966954ade8717..66e5188cbcfd4 100644
--- a/libc/src/math/generic/fadd.cpp
+++ b/libc/src/math/generic/fadd.cpp
@@ -5,19 +5,16 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-
+
#include "src/math/fadd.h"
-#include "src/__support/macros/config.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/common.h"
-
+#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, fadd, (double x, double y)) {
- return fputil::generic::add<float>(x,y);
-
+ return fputil::generic::add<float>(x, y);
}
-
-} // namespace LIBC_NAMESPACE_DECLS
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/smoke/fadd_test.cpp b/libc/test/src/math/smoke/fadd_test.cpp
index 24f53dcbd424e..fe9ac8b252ed3 100644
--- a/libc/test/src/math/smoke/fadd_test.cpp
+++ b/libc/test/src/math/smoke/fadd_test.cpp
@@ -10,5 +10,4 @@
#include "src/math/fadd.h"
-
LIST_ADD_TESTS(float, double, LIBC_NAMESPACE::fadd)
>From 177ec86d00150cb65b7b4eb16be65db0198465af Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Fri, 19 Jul 2024 20:52:25 +0000
Subject: [PATCH 4/4] updated math status for fadd
---
libc/docs/math/index.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 5fab9ce4df949..cff7f69deb7f8 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -136,7 +136,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fabs | |check| | |check| | |check| | |check| | |check| | 7.12.7.3 | F.10.4.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| fadd | N/A | | | N/A | | 7.12.14.1 | F.10.11 |
+| fadd | N/A | |check| | |check| | N/A | |check| | 7.12.14.1 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fdim | |check| | |check| | |check| | |check| | |check| | 7.12.12.1 | F.10.9.1 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
More information about the libc-commits
mailing list