[libc-commits] [libc] [libc][math][c23] functions (PR #102531)

via libc-commits libc-commits at lists.llvm.org
Thu Aug 8 13:39:05 PDT 2024


https://github.com/aaryanshukla created https://github.com/llvm/llvm-project/pull/102531

None

>From ef9d7304babe38de0aee3720fe1941eff2f9fd46 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Thu, 8 Aug 2024 20:38:29 +0000
Subject: [PATCH] [libc][math][c23] functions

---
 libc/config/linux/aarch64/entrypoints.txt  |  2 ++
 libc/config/linux/arm/entrypoints.txt      |  1 +
 libc/config/linux/riscv/entrypoints.txt    |  2 ++
 libc/config/linux/x86_64/entrypoints.txt   |  2 ++
 libc/config/windows/entrypoints.txt        |  1 +
 libc/spec/stdc.td                          |  1 +
 libc/src/math/CMakeLists.txt               |  3 +++
 libc/src/math/fadd.h                       |  2 +-
 libc/src/math/faddf128.h                   | 22 +++++++++++++++++
 libc/src/math/faddl.h                      | 20 ++++++++++++++++
 libc/src/math/generic/CMakeLists.txt       | 25 +++++++++++++++++++
 libc/src/math/generic/fadd.cpp             |  2 +-
 libc/src/math/generic/faddf128.cpp         | 20 ++++++++++++++++
 libc/src/math/generic/faddl.cpp            | 20 ++++++++++++++++
 libc/test/src/math/CMakeLists.txt          | 14 +++++++++++
 libc/test/src/math/faddl_test.cpp          | 13 ++++++++++
 libc/test/src/math/smoke/CMakeLists.txt    | 28 ++++++++++++++++++++++
 libc/test/src/math/smoke/faddf128_test.cpp | 13 ++++++++++
 libc/test/src/math/smoke/faddl_test.cpp    | 13 ++++++++++
 19 files changed, 202 insertions(+), 2 deletions(-)
 create mode 100644 libc/src/math/faddf128.h
 create mode 100644 libc/src/math/faddl.h
 create mode 100644 libc/src/math/generic/faddf128.cpp
 create mode 100644 libc/src/math/generic/faddl.cpp
 create mode 100644 libc/test/src/math/faddl_test.cpp
 create mode 100644 libc/test/src/math/smoke/faddf128_test.cpp
 create mode 100644 libc/test/src/math/smoke/faddl_test.cpp

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index b92b96c89315e2..34bf671a270925 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -407,6 +407,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fabsf
     libc.src.math.fabsl
     libc.src.math.fadd 
+    libc.src.math.faddl
     libc.src.math.fdim
     libc.src.math.fdimf
     libc.src.math.fdiml
@@ -683,6 +684,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.dsqrtf128
     libc.src.math.dsubf128
     libc.src.math.fabsf128
+    libc.src.math.faddf128
     libc.src.math.fdimf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index c6b7b6cc9acfa2..1f0fd4eb2481b6 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -243,6 +243,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fabsf
     libc.src.math.fabsl
     libc.src.math.fadd 
+    libc.src.math.faddl
     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 a90fdbef31bf2e..1036774f8c7025 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -406,6 +406,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fabsf
     libc.src.math.fabsl
     libc.src.math.fadd 
+    libc.src.math.faddl
     libc.src.math.fdim
     libc.src.math.fdimf
     libc.src.math.fdiml
@@ -590,6 +591,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.dsqrtf128
     libc.src.math.dsubf128
     libc.src.math.fabsf128
+    libc.src.math.faddf128
     libc.src.math.fdimf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 9ec86f13850dbe..9294a57f99d9a3 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -406,6 +406,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fabsf
     libc.src.math.fabsl
     libc.src.math.fadd 
+    libc.src.math.faddl
     libc.src.math.fdim
     libc.src.math.fdimf
     libc.src.math.fdiml
@@ -679,6 +680,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.dsqrtf128
     libc.src.math.dsubf128
     libc.src.math.fabsf128
+    libc.src.math.faddf128
     libc.src.math.fdimf128
     libc.src.math.fdivf128
     libc.src.math.ffmaf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index d28183549647f1..99d0307bfadd84 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -152,6 +152,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fabsf
     libc.src.math.fabsl
     libc.src.math.fadd
+    libc.src.math.faddl
     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 5dde6ac67f5a86..d4f90f29cd1fed 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -408,6 +408,7 @@ def StdC : StandardSpec<"stdc"> {
           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<"faddl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
 
           FunctionSpec<"fdim", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
           FunctionSpec<"fdimf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index a0bd5269169fa3..c9e6a37952fee2 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -160,7 +160,10 @@ 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(faddl)
+add_math_entrypoint_object(faddf128)
 
 add_math_entrypoint_object(fdim)
 add_math_entrypoint_object(fdimf)
diff --git a/libc/src/math/fadd.h b/libc/src/math/fadd.h
index ec3ce18bb676a6..1dead013e3e5ca 100644
--- a/libc/src/math/fadd.h
+++ b/libc/src/math/fadd.h
@@ -1,4 +1,4 @@
-//===-- Implementation of fadd function ----------------------------------===//
+//===-- 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.
diff --git a/libc/src/math/faddf128.h b/libc/src/math/faddf128.h
new file mode 100644
index 00000000000000..37886450e4fd12
--- /dev/null
+++ b/libc/src/math/faddf128.h
@@ -0,0 +1,22 @@
+//===-- Implementation of faddf128 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"
+#include "src/__support/macros/properties/types.h"
+
+
+#ifndef LLVM_LIBC_SRC_MATH_FADDF128_H
+#define LLVM_LIBC_SRC_MATH_FADDF128_H
+
+namespace LIBC_NAMESPACE_DECL {
+
+float faddf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FADDF128_H
diff --git a/libc/src/math/faddl.h b/libc/src/math/faddl.h
new file mode 100644
index 00000000000000..9550f9c112cb02
--- /dev/null
+++ b/libc/src/math/faddl.h
@@ -0,0 +1,20 @@
+//===-- Implementation of faddl 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_FADDL_H
+#define LLVM_LIBC_SRC_MATH_FADDL_H
+
+namespace LIBC_NAMESPACE_DECL {
+
+float faddl(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FADDL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index be5cc2e02635af..91e21194e1fb86 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -586,6 +586,31 @@ add_entrypoint_object(
     -O3
 )
 
+add_entrypoint_object(
+  faddl
+  SRCS
+    faddl.cpp
+  HDRS
+    ../faddl.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+  COMPILE_OPTIONS
+    -O3
+)
+
+add_entrypoint_object(
+  faddf128
+  SRCS
+    faddf128.cpp
+  HDRS
+    ../faddf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.properties.types
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_entrypoint_object(
   trunc
   SRCS
diff --git a/libc/src/math/generic/fadd.cpp b/libc/src/math/generic/fadd.cpp
index 66e5188cbcfd4c..60460f87086570 100644
--- a/libc/src/math/generic/fadd.cpp
+++ b/libc/src/math/generic/fadd.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation of fadd function ----------------------------------===//
+//===-- 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.
diff --git a/libc/src/math/generic/faddf128.cpp b/libc/src/math/generic/faddf128.cpp
new file mode 100644
index 00000000000000..953b1a1ce092ee
--- /dev/null
+++ b/libc/src/math/generic/faddf128.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of faddf128 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/faddf128.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, faddf128, (float128 x, float128 y)) {
+  return fputil::generic::add<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/faddl.cpp b/libc/src/math/generic/faddl.cpp
new file mode 100644
index 00000000000000..b5c6ab4031c383
--- /dev/null
+++ b/libc/src/math/generic/faddl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of faddl 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/faddl.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, faddl, (long double x, long double y)) {
+  return fputil::generic::add<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index f3703eb59999b1..e9be9f7dc815cf 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -202,6 +202,20 @@ add_fp_unittest(
     libc.src.__support.FPUtil.basic_operations
 )
 
+add_fp_unittest(
+  faddl_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    faddl_test.cpp
+  HDRS
+    AddTest.h
+  DEPENDS
+    libc.src.math.faddl
+    libc.src.__support.FPUtil.basic_operations
+)
+
 add_fp_unittest(
   trunc_test
   NEED_MPFR
diff --git a/libc/test/src/math/faddl_test.cpp b/libc/test/src/math/faddl_test.cpp
new file mode 100644
index 00000000000000..9c99b32ee7c422
--- /dev/null
+++ b/libc/test/src/math/faddl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for faddl -----------------------------------------------===//
+//
+// 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/faddl.h"
+
+LIST_ADD_TESTS(float, long double, LIBC_NAMESPACE::faddl)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 21818e4734a682..d3b920b88b8b4f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -155,6 +155,34 @@ add_fp_unittest(
 
 )
 
+add_fp_unittest(
+  faddl_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    faddl_test.cpp
+  HDRS
+    AddTest.h
+  DEPENDS
+    libc.src.math.faddl
+    libc.src.__support.FPUtil.basic_operations
+)
+
+add_fp_unittest(
+  faddf128_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    faddf128_test.cpp
+  HDRS
+    AddTest.h
+  DEPENDS
+    libc.src.math.faddf128
+    libc.src.__support.FPUtil.basic_operations
+)
+
 add_fp_unittest(
   trunc_test
   SUITE
diff --git a/libc/test/src/math/smoke/faddf128_test.cpp b/libc/test/src/math/smoke/faddf128_test.cpp
new file mode 100644
index 00000000000000..5a11b5f419cad2
--- /dev/null
+++ b/libc/test/src/math/smoke/faddf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for faddf128 --------------------------------------------===//
+//
+// 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/faddf128.h"
+
+LIST_ADD_TESTS(float, float128, LIBC_NAMESPACE::faddf128)
diff --git a/libc/test/src/math/smoke/faddl_test.cpp b/libc/test/src/math/smoke/faddl_test.cpp
new file mode 100644
index 00000000000000..9c99b32ee7c422
--- /dev/null
+++ b/libc/test/src/math/smoke/faddl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for faddl -----------------------------------------------===//
+//
+// 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/faddl.h"
+
+LIST_ADD_TESTS(float, long double, LIBC_NAMESPACE::faddl)



More information about the libc-commits mailing list