[libc-commits] [libc] [libc][math] Add setpayloadl function. (PR #102408)

Job Henandez Lara via libc-commits libc-commits at lists.llvm.org
Wed Aug 7 18:13:10 PDT 2024


https://github.com/Jobhdez created https://github.com/llvm/llvm-project/pull/102408

Hey so far in this pr I have only added the entrypoints to make `setpayloadl` run. will debug shortly. thanks.

>From 02ea6c143b2d1f055edc0e7c9e2b6e589fa7754c Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Wed, 7 Aug 2024 18:05:44 -0700
Subject: [PATCH] add config

---
 libc/config/linux/aarch64/entrypoints.txt     |  1 +
 libc/config/linux/arm/entrypoints.txt         |  1 +
 libc/config/linux/riscv/entrypoints.txt       |  1 +
 libc/config/linux/x86_64/entrypoints.txt      |  1 +
 libc/src/math/CMakeLists.txt                  |  1 +
 libc/src/math/generic/CMakeLists.txt          | 12 +++++++++++
 libc/src/math/generic/setpayloadl.cpp         | 20 +++++++++++++++++++
 libc/src/math/setpayloadl.h                   | 20 +++++++++++++++++++
 libc/test/src/math/smoke/CMakeLists.txt       | 12 +++++++++++
 libc/test/src/math/smoke/setpayloadl_test.cpp | 13 ++++++++++++
 10 files changed, 82 insertions(+)
 create mode 100644 libc/src/math/generic/setpayloadl.cpp
 create mode 100644 libc/src/math/setpayloadl.h
 create mode 100644 libc/test/src/math/smoke/setpayloadl_test.cpp

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index b705b82c70f39..83d3d924522f8 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -544,6 +544,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadl
     libc.src.math.sin
     libc.src.math.sincos
     libc.src.math.sincosf
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 36e940af4fb6b..fe1afa1fd8908 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -374,6 +374,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadl
     libc.src.math.sin
     libc.src.math.sincos
     libc.src.math.sincosf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index f117c5fc608fa..69aa36afcb00f 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -547,6 +547,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadl
     libc.src.math.sin
     libc.src.math.sincos
     libc.src.math.sincosf
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 39d90bf06a0cf..c7c0d1745194e 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -547,6 +547,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.scalbnl
     libc.src.math.setpayload
     libc.src.math.setpayloadf
+    libc.src.math.setpayloadl
     libc.src.math.sin
     libc.src.math.sincos
     libc.src.math.sincosf
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index a3c9b5473c290..ac19431eb8f0a 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -431,6 +431,7 @@ add_math_entrypoint_object(scalbnf128)
 
 add_math_entrypoint_object(setpayload)
 add_math_entrypoint_object(setpayloadf)
+add_math_entrypoint_object(setpayloadl)
 add_math_entrypoint_object(setpayloadf16)
 add_math_entrypoint_object(setpayloadf128)
 
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 77f7f4fef007b..773a62558f233 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4423,6 +4423,18 @@ add_entrypoint_object(
     -O3
 )
 
+add_entrypoint_object(
+  setpayloadl
+  SRCS
+    setpayloadl.cpp
+  HDRS
+    ../setpayloadl.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_entrypoint_object(
   setpayloadf16
   SRCS
diff --git a/libc/src/math/generic/setpayloadl.cpp b/libc/src/math/generic/setpayloadl.cpp
new file mode 100644
index 0000000000000..fd0633804783a
--- /dev/null
+++ b/libc/src/math/generic/setpayloadl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of setpayloadl 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/setpayloadl.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, setpayloadl, (long double *res, long double  pl)) {
+  return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/setpayloadl.h b/libc/src/math/setpayloadl.h
new file mode 100644
index 0000000000000..f0df62f8f22f5
--- /dev/null
+++ b/libc/src/math/setpayloadl.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for setpayloadl -------------------*- 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_SETPAYLOADL_H
+#define LLVM_LIBC_SRC_MATH_SETPAYLOADL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int setpayloadl(long double *res, long double pl);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADL_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 9aa5399aae9d3..23967a47f6702 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3933,6 +3933,18 @@ add_fp_unittest(
     libc.src.math.setpayloadf
 )
 
+add_fp_unittest(
+  setpayloadl_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    setpayloadl_test.cpp
+  HDRS
+    SetPayloadTest.h
+  DEPENDS
+    libc.src.math.setpayloadl
+)
+
 add_fp_unittest(
   setpayloadf16_test
   SUITE
diff --git a/libc/test/src/math/smoke/setpayloadl_test.cpp b/libc/test/src/math/smoke/setpayloadl_test.cpp
new file mode 100644
index 0000000000000..45bc6fd2bb9fd
--- /dev/null
+++ b/libc/test/src/math/smoke/setpayloadl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for setpayloadl -----------------------------------------===//
+//
+// 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 "SetPayloadTest.h"
+
+#include "src/math/setpayloadl.h"
+
+LIST_SETPAYLOAD_TESTS(long double, LIBC_NAMESPACE::setpayloadl)



More information about the libc-commits mailing list