Skip to content

Commit 4e56724

Browse files
authored
[libc][math][c23] Add f16{add,sub}{,l,f128} C23 math functions (#97072)
Part of #93566.
1 parent 4b28b3f commit 4e56724

31 files changed

+605
-2
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,14 @@ if(LIBC_TYPES_HAS_FLOAT16)
508508
libc.src.math.canonicalizef16
509509
libc.src.math.ceilf16
510510
libc.src.math.copysignf16
511+
libc.src.math.f16add
511512
libc.src.math.f16addf
512513
libc.src.math.f16div
513514
libc.src.math.f16divf
514515
libc.src.math.f16fmaf
515516
libc.src.math.f16sqrt
516517
libc.src.math.f16sqrtf
518+
libc.src.math.f16sub
517519
libc.src.math.f16subf
518520
libc.src.math.fabsf16
519521
libc.src.math.fdimf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,9 @@ if(LIBC_TYPES_HAS_FLOAT16)
538538
libc.src.math.canonicalizef16
539539
libc.src.math.ceilf16
540540
libc.src.math.copysignf16
541+
libc.src.math.f16add
541542
libc.src.math.f16addf
543+
libc.src.math.f16addl
542544
libc.src.math.f16div
543545
libc.src.math.f16divf
544546
libc.src.math.f16divl
@@ -548,7 +550,9 @@ if(LIBC_TYPES_HAS_FLOAT16)
548550
libc.src.math.f16sqrt
549551
libc.src.math.f16sqrtf
550552
libc.src.math.f16sqrtl
553+
libc.src.math.f16sub
551554
libc.src.math.f16subf
555+
libc.src.math.f16subl
552556
libc.src.math.fabsf16
553557
libc.src.math.fdimf16
554558
libc.src.math.floorf16
@@ -601,9 +605,11 @@ if(LIBC_TYPES_HAS_FLOAT16)
601605
if(LIBC_TYPES_HAS_FLOAT128)
602606
list(APPEND TARGET_LIBM_ENTRYPOINTS
603607
# math.h C23 mixed _Float16 and _Float128 entrypoints
608+
libc.src.math.f16addf128
604609
libc.src.math.f16divf128
605610
libc.src.math.f16fmaf128
606611
libc.src.math.f16sqrtf128
612+
libc.src.math.f16subf128
607613
)
608614
endif()
609615
endif()

libc/docs/math/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ Basic Operations
124124
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
125125
| dsub | N/A | N/A | | N/A | | 7.12.14.2 | F.10.11 |
126126
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
127-
| f16add | |check|\* | | | N/A | | 7.12.14.1 | F.10.11 |
127+
| f16add | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.1 | F.10.11 |
128128
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
129129
| f16div | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.4 | F.10.11 |
130130
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
131131
| f16fma | |check| | |check| | |check| | N/A | |check| | 7.12.14.5 | F.10.11 |
132132
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
133-
| f16sub | |check|\* | | | N/A | | 7.12.14.2 | F.10.11 |
133+
| f16sub | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.2 | F.10.11 |
134134
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
135135
| fabs | |check| | |check| | |check| | |check| | |check| | 7.12.7.3 | F.10.4.3 |
136136
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/llvm_libc_ext.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
5757
[], // Types
5858
[], // Enumerations
5959
[
60+
GuardedFunctionSpec<"f16add", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
6061
GuardedFunctionSpec<"f16addf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
62+
GuardedFunctionSpec<"f16addl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
6163

64+
GuardedFunctionSpec<"f16sub", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
6265
GuardedFunctionSpec<"f16subf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
66+
GuardedFunctionSpec<"f16subl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
6367

6468
GuardedFunctionSpec<"f16div", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
6569
GuardedFunctionSpec<"f16divf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,

libc/spec/stdc.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,10 @@ def StdC : StandardSpec<"stdc"> {
729729

730730
GuardedFunctionSpec<"setpayloadsigf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
731731

732+
GuardedFunctionSpec<"f16addf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
733+
734+
GuardedFunctionSpec<"f16subf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
735+
732736
GuardedFunctionSpec<"f16divf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
733737

734738
GuardedFunctionSpec<"f16sqrtf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,

libc/src/math/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ add_math_entrypoint_object(exp10f)
9999
add_math_entrypoint_object(expm1)
100100
add_math_entrypoint_object(expm1f)
101101

102+
add_math_entrypoint_object(f16add)
102103
add_math_entrypoint_object(f16addf)
104+
add_math_entrypoint_object(f16addl)
105+
add_math_entrypoint_object(f16addf128)
103106

104107
add_math_entrypoint_object(f16div)
105108
add_math_entrypoint_object(f16divf)
@@ -116,7 +119,10 @@ add_math_entrypoint_object(f16sqrtf)
116119
add_math_entrypoint_object(f16sqrtl)
117120
add_math_entrypoint_object(f16sqrtf128)
118121

122+
add_math_entrypoint_object(f16sub)
119123
add_math_entrypoint_object(f16subf)
124+
add_math_entrypoint_object(f16subl)
125+
add_math_entrypoint_object(f16subf128)
120126

121127
add_math_entrypoint_object(fabs)
122128
add_math_entrypoint_object(fabsf)

libc/src/math/f16add.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for f16add ------------------------*- 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_F16ADD_H
10+
#define LLVM_LIBC_SRC_MATH_F16ADD_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 f16add(double x, double y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_F16ADD_H

libc/src/math/f16addf128.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for f16addf128 --------------------*- 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_F16ADDF128_H
10+
#define LLVM_LIBC_SRC_MATH_F16ADDF128_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 f16addf128(float128 x, float128 y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_F16ADDF128_H

libc/src/math/f16addl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for f16addl -----------------------*- 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_F16ADDL_H
10+
#define LLVM_LIBC_SRC_MATH_F16ADDL_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 f16addl(long double x, long double y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_F16ADDL_H

libc/src/math/f16sub.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for f16sub ------------------------*- 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_F16SUB_H
10+
#define LLVM_LIBC_SRC_MATH_F16SUB_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 f16sub(double x, double y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_F16SUB_H

libc/src/math/f16subf128.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for f16subf128 --------------------*- 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_F16SUBF128_H
10+
#define LLVM_LIBC_SRC_MATH_F16SUBF128_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 f16subf128(float128 x, float128 y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_F16SUBF128_H

libc/src/math/f16subl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for f16subl -----------------------*- 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_F16SUBL_H
10+
#define LLVM_LIBC_SRC_MATH_F16SUBL_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 f16subl(long double x, long double y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_F16SUBL_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3795,6 +3795,19 @@ add_entrypoint_object(
37953795
-O3
37963796
)
37973797

3798+
add_entrypoint_object(
3799+
f16add
3800+
SRCS
3801+
f16add.cpp
3802+
HDRS
3803+
../f16add.h
3804+
DEPENDS
3805+
libc.src.__support.macros.properties.types
3806+
libc.src.__support.FPUtil.generic.add_sub
3807+
COMPILE_OPTIONS
3808+
-O3
3809+
)
3810+
37983811
add_entrypoint_object(
37993812
f16addf
38003813
SRCS
@@ -3808,6 +3821,45 @@ add_entrypoint_object(
38083821
-O3
38093822
)
38103823

3824+
add_entrypoint_object(
3825+
f16addl
3826+
SRCS
3827+
f16addl.cpp
3828+
HDRS
3829+
../f16addl.h
3830+
DEPENDS
3831+
libc.src.__support.macros.properties.types
3832+
libc.src.__support.FPUtil.generic.add_sub
3833+
COMPILE_OPTIONS
3834+
-O3
3835+
)
3836+
3837+
add_entrypoint_object(
3838+
f16addf128
3839+
SRCS
3840+
f16addf128.cpp
3841+
HDRS
3842+
../f16addf128.h
3843+
DEPENDS
3844+
libc.src.__support.macros.properties.types
3845+
libc.src.__support.FPUtil.generic.add_sub
3846+
COMPILE_OPTIONS
3847+
-O3
3848+
)
3849+
3850+
add_entrypoint_object(
3851+
f16sub
3852+
SRCS
3853+
f16sub.cpp
3854+
HDRS
3855+
../f16sub.h
3856+
DEPENDS
3857+
libc.src.__support.macros.properties.types
3858+
libc.src.__support.FPUtil.generic.add_sub
3859+
COMPILE_OPTIONS
3860+
-O3
3861+
)
3862+
38113863
add_entrypoint_object(
38123864
f16subf
38133865
SRCS
@@ -3821,6 +3873,32 @@ add_entrypoint_object(
38213873
-O3
38223874
)
38233875

3876+
add_entrypoint_object(
3877+
f16subl
3878+
SRCS
3879+
f16subl.cpp
3880+
HDRS
3881+
../f16subl.h
3882+
DEPENDS
3883+
libc.src.__support.macros.properties.types
3884+
libc.src.__support.FPUtil.generic.add_sub
3885+
COMPILE_OPTIONS
3886+
-O3
3887+
)
3888+
3889+
add_entrypoint_object(
3890+
f16subf128
3891+
SRCS
3892+
f16subf128.cpp
3893+
HDRS
3894+
../f16subf128.h
3895+
DEPENDS
3896+
libc.src.__support.macros.properties.types
3897+
libc.src.__support.FPUtil.generic.add_sub
3898+
COMPILE_OPTIONS
3899+
-O3
3900+
)
3901+
38243902
add_entrypoint_object(
38253903
f16div
38263904
SRCS

libc/src/math/generic/f16add.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of f16add 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/f16add.h"
10+
#include "src/__support/FPUtil/generic/add_sub.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, f16add, (double x, double y)) {
16+
return fputil::generic::add<float16>(x, y);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/math/generic/f16addf128.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of f16addf128 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/f16addf128.h"
10+
#include "src/__support/FPUtil/generic/add_sub.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, f16addf128, (float128 x, float128 y)) {
16+
return fputil::generic::add<float16>(x, y);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/math/generic/f16addl.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of f16addl 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/f16addl.h"
10+
#include "src/__support/FPUtil/generic/add_sub.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, f16addl, (long double x, long double y)) {
16+
return fputil::generic::add<float16>(x, y);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

0 commit comments

Comments
 (0)