[libc-commits] [libc] [libc][math] Adds entrypoint and test for `nextafterf128` (PR #84882)

via libc-commits libc-commits at lists.llvm.org
Tue Mar 12 00:32:05 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Michael Flanders (Flandini)

<details>
<summary>Changes</summary>

Continuing #<!-- -->84689. Wanted to make sure this looks okay before repeating for the others. 

I am not sure how the optimization level is decided on in [libc/src/math/generic/CMakeLists.txt](https://github.com/llvm/llvm-project/compare/main...Flandini:nextafterf128?expand=1#diff-7f0c9267147f9b892c5f01e0dd0bc3ccc0cb71a088b1e16378680e987a4dc992), so I went with `-O2` like the other `nextafter*` functions.

cc @<!-- -->lntue for review.

---
Full diff: https://github.com/llvm/llvm-project/pull/84882.diff


13 Files Affected:

- (modified) libc/config/linux/aarch64/entrypoints.txt (+1) 
- (modified) libc/config/linux/riscv/entrypoints.txt (+1) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+1) 
- (modified) libc/docs/math/index.rst (+2) 
- (modified) libc/spec/stdc.td (+1) 
- (modified) libc/src/math/CMakeLists.txt (+1) 
- (modified) libc/src/math/generic/CMakeLists.txt (+13) 
- (added) libc/src/math/generic/nextafterf128.cpp (+19) 
- (added) libc/src/math/nextafterf128.h (+20) 
- (modified) libc/test/src/math/CMakeLists.txt (+15) 
- (added) libc/test/src/math/nextafterf128_test.cpp (+13) 
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+15) 
- (added) libc/test/src/math/smoke/nextafterf128_test.cpp (+13) 


``````````diff
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index c24703840183af..24e5e86559a4d9 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -435,6 +435,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.lrintf128
     libc.src.math.lroundf128
     libc.src.math.modff128
+    libc.src.math.nextafterf128
     libc.src.math.rintf128
     libc.src.math.roundf128
     libc.src.math.sqrtf128
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index f7a65615115f34..cb3eaee18eca9d 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -443,6 +443,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.lrintf128
     libc.src.math.lroundf128
     libc.src.math.modff128
+    libc.src.math.nextafterf128
     libc.src.math.rintf128
     libc.src.math.roundf128
     libc.src.math.sqrtf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index b51227e5f25d74..0fca5d49aaaacf 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -478,6 +478,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.lrintf128
     libc.src.math.lroundf128
     libc.src.math.modff128
+    libc.src.math.nextafterf128
     libc.src.math.rintf128
     libc.src.math.roundf128
     libc.src.math.sqrtf128
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 7f2a1b2f3e2824..7467135d301e45 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -269,6 +269,8 @@ Basic Operations
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | nextafterl   | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| nextafterf128| |check| | |check| |         | |check| |         |         |         |         |         |         |         |         |
++--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | nexttoward   | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | nexttowardf  | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index d91f5c1f723345..9d0519a5bb0090 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -529,6 +529,7 @@ def StdC : StandardSpec<"stdc"> {
           FunctionSpec<"nextafterf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
           FunctionSpec<"nextafter", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
           FunctionSpec<"nextafterl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
+          GuardedFunctionSpec<"nextafterf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
 
           FunctionSpec<"nexttowardf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<LongDoubleType>]>,
           FunctionSpec<"nexttoward", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<LongDoubleType>]>,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 6c06d383ec2b04..938411518a0df8 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -196,6 +196,7 @@ add_math_entrypoint_object(nearbyintl)
 add_math_entrypoint_object(nextafter)
 add_math_entrypoint_object(nextafterf)
 add_math_entrypoint_object(nextafterl)
+add_math_entrypoint_object(nextafterf128)
 
 add_math_entrypoint_object(nexttoward)
 add_math_entrypoint_object(nexttowardf)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 933a05dad157c9..3bdbd06699e515 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1816,6 +1816,19 @@ add_entrypoint_object(
     -O2
 )
 
+add_entrypoint_object(
+  nextafterf128
+  SRCS
+    nextafterf128.cpp
+  HDRS
+    ../nextafterf128.h
+  DEPENDS
+    libc.src.__support.macros.properties.types
+    libc.src.__support.FPUtil.manipulation_functions
+  COMPILE_OPTIONS
+    -O2
+)
+
 add_entrypoint_object(
   nexttoward
   SRCS
diff --git a/libc/src/math/generic/nextafterf128.cpp b/libc/src/math/generic/nextafterf128.cpp
new file mode 100644
index 00000000000000..905c89022ba108
--- /dev/null
+++ b/libc/src/math/generic/nextafterf128.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of nextafterf128 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/nextafterf128.h"
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(float128, nextafterf128, (float128 x, float128 y)) {
+  return fputil::nextafter(x, y);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/nextafterf128.h b/libc/src/math/nextafterf128.h
new file mode 100644
index 00000000000000..a404d33810ec2d
--- /dev/null
+++ b/libc/src/math/nextafterf128.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for nextafterf128 ------------------*- 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_NEXTAFTERF128_H
+#define LLVM_LIBC_SRC_MATH_NEXTAFTERF128_H
+
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE {
+
+float128 nextafterf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_NEXTAFTERF128_H
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index ad7dfdb3dfd9ec..33dda185287eb2 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1273,6 +1273,21 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  nextafterf128_test
+  SUITE
+    libc-math-unittests
+  SRCS
+    nextafterf128_test.cpp
+  HDRS
+    NextAfterTest.h
+  DEPENDS
+    libc.include.math
+    libc.src.math.nextafterf128
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.fp_bits
+)
+
 # TODO(lntue): The current implementation of fputil::general::fma<float> is only
 # correctly rounded for the default rounding mode round-to-nearest tie-to-even.
 add_fp_unittest(
diff --git a/libc/test/src/math/nextafterf128_test.cpp b/libc/test/src/math/nextafterf128_test.cpp
new file mode 100644
index 00000000000000..a8d000ff4de387
--- /dev/null
+++ b/libc/test/src/math/nextafterf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for nextafterf128 ---------------------------------------===//
+//
+// 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 "NextAfterTest.h"
+
+#include "src/math/nextafterf128.h"
+
+LIST_NEXTAFTER_TESTS(float128, LIBC_NAMESPACE::nextafterf128)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 8d3871dd427aaa..157297361a6b77 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1551,6 +1551,21 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  nextafterf128_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    nextafterf128_test.cpp
+  HDRS
+    NextAfterTest.h
+  DEPENDS
+    libc.include.math
+    libc.src.math.nextafterf128
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.fp_bits
+)
+
 # FIXME: These tests are currently spurious for the GPU.
 if(NOT LIBC_TARGET_OS_IS_GPU)
   add_fp_unittest(
diff --git a/libc/test/src/math/smoke/nextafterf128_test.cpp b/libc/test/src/math/smoke/nextafterf128_test.cpp
new file mode 100644
index 00000000000000..a8d000ff4de387
--- /dev/null
+++ b/libc/test/src/math/smoke/nextafterf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for nextafterf128 ---------------------------------------===//
+//
+// 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 "NextAfterTest.h"
+
+#include "src/math/nextafterf128.h"
+
+LIST_NEXTAFTER_TESTS(float128, LIBC_NAMESPACE::nextafterf128)

``````````

</details>


https://github.com/llvm/llvm-project/pull/84882


More information about the libc-commits mailing list