Skip to content

Commit 63cda2d

Browse files
authored
[libc][math][c23] Add {nextafter,nexttoward,nextup,nextdown}f16 C23 math functions (#94535)
#93566
1 parent 6ca0f44 commit 63cda2d

22 files changed

+371
-32
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ if(LIBC_TYPES_HAS_FLOAT16)
514514
libc.src.math.lrintf16
515515
libc.src.math.lroundf16
516516
libc.src.math.nearbyintf16
517+
libc.src.math.nextafterf16
518+
libc.src.math.nextdownf16
519+
libc.src.math.nexttowardf16
520+
libc.src.math.nextupf16
517521
libc.src.math.rintf16
518522
libc.src.math.roundf16
519523
libc.src.math.roundevenf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ if(LIBC_TYPES_HAS_FLOAT16)
547547
libc.src.math.lrintf16
548548
libc.src.math.lroundf16
549549
libc.src.math.nearbyintf16
550+
libc.src.math.nextafterf16
551+
libc.src.math.nextdownf16
552+
libc.src.math.nexttowardf16
553+
libc.src.math.nextupf16
550554
libc.src.math.rintf16
551555
libc.src.math.roundf16
552556
libc.src.math.roundevenf16

libc/docs/c23.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Additions:
5959
* ufromfp* |check|
6060
* fromfpx* |check|
6161
* ufromfpx* |check|
62-
* nextup*
63-
* nextdown*
62+
* nextup* |check|
63+
* nextdown* |check|
6464
* canonicalize* |check|
6565
* fmaximum*
6666
* fminimum*

libc/docs/math/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ Basic Operations
190190
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
191191
| nearbyint | |check| | |check| | |check| | |check| | |check| | 7.12.9.3 | F.10.6.3 |
192192
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
193-
| nextafter | |check| | |check| | |check| | | |check| | 7.12.11.3 | F.10.8.3 |
193+
| nextafter | |check| | |check| | |check| | |check| | |check| | 7.12.11.3 | F.10.8.3 |
194194
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
195-
| nextdown | |check| | |check| | |check| | | |check| | 7.12.11.6 | F.10.8.6 |
195+
| nextdown | |check| | |check| | |check| | |check| | |check| | 7.12.11.6 | F.10.8.6 |
196196
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
197-
| nexttoward | |check| | |check| | |check| | | N/A | 7.12.11.4 | F.10.8.4 |
197+
| nexttoward | |check| | |check| | |check| | |check| | N/A | 7.12.11.4 | F.10.8.4 |
198198
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
199-
| nextup | |check| | |check| | |check| | | |check| | 7.12.11.5 | F.10.8.5 |
199+
| nextup | |check| | |check| | |check| | |check| | |check| | 7.12.11.5 | F.10.8.5 |
200200
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
201201
| remainder | |check| | |check| | |check| | | | 7.12.10.2 | F.10.7.2 |
202202
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,20 +634,24 @@ def StdC : StandardSpec<"stdc"> {
634634
FunctionSpec<"nextafterf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
635635
FunctionSpec<"nextafter", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
636636
FunctionSpec<"nextafterl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
637+
GuardedFunctionSpec<"nextafterf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
637638
GuardedFunctionSpec<"nextafterf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
638639

639640
FunctionSpec<"nexttowardf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<LongDoubleType>]>,
640641
FunctionSpec<"nexttoward", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<LongDoubleType>]>,
641642
FunctionSpec<"nexttowardl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
643+
GuardedFunctionSpec<"nexttowardf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
642644

643645
FunctionSpec<"nextdown", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
644646
FunctionSpec<"nextdownf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
645647
FunctionSpec<"nextdownl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
648+
GuardedFunctionSpec<"nextdownf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
646649
GuardedFunctionSpec<"nextdownf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
647650

648651
FunctionSpec<"nextup", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
649652
FunctionSpec<"nextupf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
650653
FunctionSpec<"nextupl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
654+
GuardedFunctionSpec<"nextupf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
651655
GuardedFunctionSpec<"nextupf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
652656

653657
FunctionSpec<"powf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,24 @@ add_math_entrypoint_object(nearbyintf128)
272272
add_math_entrypoint_object(nextafter)
273273
add_math_entrypoint_object(nextafterf)
274274
add_math_entrypoint_object(nextafterl)
275+
add_math_entrypoint_object(nextafterf16)
275276
add_math_entrypoint_object(nextafterf128)
276277

277278
add_math_entrypoint_object(nexttoward)
278279
add_math_entrypoint_object(nexttowardf)
279280
add_math_entrypoint_object(nexttowardl)
281+
add_math_entrypoint_object(nexttowardf16)
280282

281283
add_math_entrypoint_object(nextdown)
282284
add_math_entrypoint_object(nextdownf)
283285
add_math_entrypoint_object(nextdownl)
286+
add_math_entrypoint_object(nextdownf16)
284287
add_math_entrypoint_object(nextdownf128)
285288

286289
add_math_entrypoint_object(nextup)
287290
add_math_entrypoint_object(nextupf)
288291
add_math_entrypoint_object(nextupl)
292+
add_math_entrypoint_object(nextupf16)
289293
add_math_entrypoint_object(nextupf128)
290294

291295
add_math_entrypoint_object(pow)

libc/src/math/generic/CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,19 @@ add_entrypoint_object(
25502550
-O3
25512551
)
25522552

2553+
add_entrypoint_object(
2554+
nextafterf16
2555+
SRCS
2556+
nextafterf16.cpp
2557+
HDRS
2558+
../nextafterf16.h
2559+
DEPENDS
2560+
libc.src.__support.macros.properties.types
2561+
libc.src.__support.FPUtil.manipulation_functions
2562+
COMPILE_OPTIONS
2563+
-O3
2564+
)
2565+
25532566
add_entrypoint_object(
25542567
nextafterf128
25552568
SRCS
@@ -2599,6 +2612,19 @@ add_entrypoint_object(
25992612
-O3
26002613
)
26012614

2615+
add_entrypoint_object(
2616+
nexttowardf16
2617+
SRCS
2618+
nexttowardf16.cpp
2619+
HDRS
2620+
../nexttowardf16.h
2621+
DEPENDS
2622+
libc.src.__support.macros.properties.types
2623+
libc.src.__support.FPUtil.manipulation_functions
2624+
COMPILE_OPTIONS
2625+
-O3
2626+
)
2627+
26022628
add_entrypoint_object(
26032629
nextdown
26042630
SRCS
@@ -2635,6 +2661,19 @@ add_entrypoint_object(
26352661
-O3
26362662
)
26372663

2664+
add_entrypoint_object(
2665+
nextdownf16
2666+
SRCS
2667+
nextdownf16.cpp
2668+
HDRS
2669+
../nextdownf16.h
2670+
DEPENDS
2671+
libc.src.__support.macros.properties.types
2672+
libc.src.__support.FPUtil.manipulation_functions
2673+
COMPILE_OPTIONS
2674+
-O3
2675+
)
2676+
26382677
add_entrypoint_object(
26392678
nextdownf128
26402679
SRCS
@@ -2684,6 +2723,19 @@ add_entrypoint_object(
26842723
-O3
26852724
)
26862725

2726+
add_entrypoint_object(
2727+
nextupf16
2728+
SRCS
2729+
nextupf16.cpp
2730+
HDRS
2731+
../nextupf16.h
2732+
DEPENDS
2733+
libc.src.__support.macros.properties.types
2734+
libc.src.__support.FPUtil.manipulation_functions
2735+
COMPILE_OPTIONS
2736+
-O3
2737+
)
2738+
26872739
add_entrypoint_object(
26882740
nextupf128
26892741
SRCS
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of nextafterf16 function ---------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/nextafterf16.h"
10+
#include "src/__support/FPUtil/ManipulationFunctions.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, nextafterf16, (float16 x, float16 y)) {
16+
return fputil::nextafter(x, y);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/math/generic/nextdownf16.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of nextdownf16 function ----------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/nextdownf16.h"
10+
#include "src/__support/FPUtil/ManipulationFunctions.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, nextdownf16, (float16 x)) {
16+
return fputil::nextupdown</*IsDown=*/true>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of nexttowardf16 function --------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/nexttowardf16.h"
10+
#include "src/__support/FPUtil/ManipulationFunctions.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, nexttowardf16, (float16 x, long double y)) {
16+
// We can reuse the nextafter implementation because the internal nextafter is
17+
// templated on the types of the arguments.
18+
return fputil::nextafter(x, y);
19+
}
20+
21+
} // namespace LIBC_NAMESPACE

libc/src/math/generic/nextupf16.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of nextupf16 function ------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/nextupf16.h"
10+
#include "src/__support/FPUtil/ManipulationFunctions.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, nextupf16, (float16 x)) {
16+
return fputil::nextupdown</*IsDown=*/false>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/math/nextafterf16.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for nextafterf16 ------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_NEXTAFTERF16_H
10+
#define LLVM_LIBC_SRC_MATH_NEXTAFTERF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 nextafterf16(float16 x, float16 y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_NEXTAFTERF16_H

libc/src/math/nextdownf16.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for nextdownf16 -------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_NEXTDOWNF16_H
10+
#define LLVM_LIBC_SRC_MATH_NEXTDOWNF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 nextdownf16(float16 x);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_NEXTDOWNF16_H

libc/src/math/nexttowardf16.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for nexttowardf16 -----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_NEXTTOWARDF16_H
10+
#define LLVM_LIBC_SRC_MATH_NEXTTOWARDF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 nexttowardf16(float16 x, long double y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_NEXTTOWARDF16_H

libc/src/math/nextupf16.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for nextupf16 ---------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_NEXTUPF16_H
10+
#define LLVM_LIBC_SRC_MATH_NEXTUPF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 nextupf16(float16 x);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_NEXTUPF16_H

0 commit comments

Comments
 (0)