Skip to content

[libc][math] Adds entrypoint and test for nextafterf128 #84882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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| | | |
Expand Down
1 change: 1 addition & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>]>,
Expand Down
1 change: 1 addition & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 16 additions & 3 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.manipulation_functions
COMPILE_OPTIONS
-O2
-O3
)

add_entrypoint_object(
Expand All @@ -1801,7 +1801,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.manipulation_functions
COMPILE_OPTIONS
-O2
-O3
)

add_entrypoint_object(
Expand All @@ -1813,7 +1813,20 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.FPUtil.manipulation_functions
COMPILE_OPTIONS
-O2
-O3
)

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
-O3
)

add_entrypoint_object(
Expand Down
19 changes: 19 additions & 0 deletions libc/src/math/generic/nextafterf128.cpp
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/math/nextafterf128.h
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/nextafterf128_test.cpp
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/nextafterf128_test.cpp
Original file line number Diff line number Diff line change
@@ -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)