Skip to content

Commit 52ef221

Browse files
committed
[libc][math][c23] Add f16{add,sub}{,l,f128} C23 math functions
1 parent 1f7d31e commit 52ef221

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

0 commit comments

Comments
 (0)