Skip to content

Commit 8c81fb6

Browse files
[libc][math][c23] Add fadd{l,f128} C23 math functions (#102531)
Co-authored-by: OverMighty <[email protected]>
1 parent 95820ca commit 8c81fb6

21 files changed

+239
-10
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ set(TARGET_LIBM_ENTRYPOINTS
407407
libc.src.math.fabs
408408
libc.src.math.fabsf
409409
libc.src.math.fabsl
410+
libc.src.math.fadd
411+
libc.src.math.faddl
410412
libc.src.math.fadd
411413
libc.src.math.fdim
412414
libc.src.math.fdimf
@@ -692,6 +694,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
692694
libc.src.math.dsqrtf128
693695
libc.src.math.dsubf128
694696
libc.src.math.fabsf128
697+
libc.src.math.faddf128
695698
libc.src.math.fdimf128
696699
libc.src.math.fdivf128
697700
libc.src.math.ffmaf128

libc/config/linux/arm/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ set(TARGET_LIBM_ENTRYPOINTS
242242
libc.src.math.fabs
243243
libc.src.math.fabsf
244244
libc.src.math.fabsl
245+
libc.src.math.fadd
246+
libc.src.math.faddl
245247
libc.src.math.fadd
246248
libc.src.math.fdim
247249
libc.src.math.fdimf

libc/config/linux/riscv/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ set(TARGET_LIBM_ENTRYPOINTS
406406
libc.src.math.fabs
407407
libc.src.math.fabsf
408408
libc.src.math.fabsl
409+
libc.src.math.fadd
410+
libc.src.math.faddl
409411
libc.src.math.fadd
410412
libc.src.math.fdim
411413
libc.src.math.fdimf
@@ -599,6 +601,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
599601
libc.src.math.dsqrtf128
600602
libc.src.math.dsubf128
601603
libc.src.math.fabsf128
604+
libc.src.math.faddf128
602605
libc.src.math.fdimf128
603606
libc.src.math.fdivf128
604607
libc.src.math.ffmaf128

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ set(TARGET_LIBM_ENTRYPOINTS
406406
libc.src.math.fabs
407407
libc.src.math.fabsf
408408
libc.src.math.fabsl
409+
libc.src.math.fadd
410+
libc.src.math.faddl
409411
libc.src.math.fadd
410412
libc.src.math.fdim
411413
libc.src.math.fdimf
@@ -688,6 +690,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
688690
libc.src.math.dsqrtf128
689691
libc.src.math.dsubf128
690692
libc.src.math.fabsf128
693+
libc.src.math.faddf128
691694
libc.src.math.fdimf128
692695
libc.src.math.fdivf128
693696
libc.src.math.ffmaf128

libc/config/windows/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ set(TARGET_LIBM_ENTRYPOINTS
153153
libc.src.math.fabsf
154154
libc.src.math.fabsl
155155
libc.src.math.fadd
156+
libc.src.math.faddl
156157
libc.src.math.fdim
157158
libc.src.math.fdimf
158159
libc.src.math.fdiml

libc/newhdrgen/yaml/math.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ functions:
7676
return_type: long double
7777
arguments:
7878
- type: long double
79+
- name: fadd
80+
standards:
81+
- stdc
82+
return_type: float
83+
arguments:
84+
- type: double
85+
- type: double
86+
- name: faddl
87+
standards:
88+
- faddl
89+
return_type: float
90+
arguments:
91+
- type: long double
92+
- type: long double
93+
- name: faddf128
94+
standards:
95+
- llvm_libc_ext
96+
return_type: float
97+
arguments:
98+
- type: float128
99+
- type: float128
100+
guard: LIBC_TYPES_HAS_FLOAT128
79101
- name: fdim
80102
standards:
81103
- stdc

libc/spec/llvm_libc_ext.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
7171
GuardedFunctionSpec<"f16sub", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
7272
GuardedFunctionSpec<"f16subf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
7373
GuardedFunctionSpec<"f16subl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
74+
75+
GuardedFunctionSpec<"faddf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
7476

7577
GuardedFunctionSpec<"fdivf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
7678

libc/spec/stdc.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ def StdC : StandardSpec<"stdc"> {
407407
FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
408408
GuardedFunctionSpec<"fabsf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
409409
GuardedFunctionSpec<"fabsf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
410+
410411
FunctionSpec<"fadd", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
412+
FunctionSpec<"faddl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
411413

412414
FunctionSpec<"fdim", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
413415
FunctionSpec<"fdimf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ add_math_entrypoint_object(fabsf)
161161
add_math_entrypoint_object(fabsl)
162162
add_math_entrypoint_object(fabsf16)
163163
add_math_entrypoint_object(fabsf128)
164+
164165
add_math_entrypoint_object(fadd)
166+
add_math_entrypoint_object(faddl)
167+
add_math_entrypoint_object(faddf128)
165168

166169
add_math_entrypoint_object(fdim)
167170
add_math_entrypoint_object(fdimf)

libc/src/math/fadd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
//===-- Implementation of fadd function ----------------------------------===//
1+
//===-- Implementation of fadd function -----------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "src/__support/macros/config.h"
10-
119
#ifndef LLVM_LIBC_SRC_MATH_FADD_H
1210
#define LLVM_LIBC_SRC_MATH_FADD_H
1311

12+
#include "src/__support/macros/config.h"
13+
1414
namespace LIBC_NAMESPACE_DECL {
1515

1616
float fadd(double x, double y);

libc/src/math/faddf128.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of faddf128 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+
#ifndef LLVM_LIBC_SRC_MATH_FADDF128_H
10+
#define LLVM_LIBC_SRC_MATH_FADDF128_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/types.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
float faddf128(float128 x, float128 y);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_FADDF128_H

libc/src/math/faddl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of faddl 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+
#ifndef LLVM_LIBC_SRC_MATH_FADDL_H
10+
#define LLVM_LIBC_SRC_MATH_FADDL_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
float faddl(long double x, long double y);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_MATH_FADDL_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,32 @@ add_entrypoint_object(
593593
HDRS
594594
../fadd.h
595595
DEPENDS
596-
libc.src.__support.FPUtil.basic_operations
596+
libc.src.__support.FPUtil.generic.add_sub
597+
COMPILE_OPTIONS
598+
-O3
599+
)
600+
601+
add_entrypoint_object(
602+
faddl
603+
SRCS
604+
faddl.cpp
605+
HDRS
606+
../faddl.h
607+
DEPENDS
608+
libc.src.__support.FPUtil.generic.add_sub
609+
COMPILE_OPTIONS
610+
-O3
611+
)
612+
613+
add_entrypoint_object(
614+
faddf128
615+
SRCS
616+
faddf128.cpp
617+
HDRS
618+
../faddf128.h
619+
DEPENDS
620+
libc.src.__support.FPUtil.generic.add_sub
621+
libc.src.__support.macros.properties.types
597622
COMPILE_OPTIONS
598623
-O3
599624
)

libc/src/math/generic/fadd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Implementation of fadd function ----------------------------------===//
1+
//===-- Implementation of fadd function -----------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

libc/src/math/generic/faddf128.cpp

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

libc/src/math/generic/faddl.cpp

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

libc/test/src/math/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ add_fp_unittest(
202202
libc.src.__support.FPUtil.basic_operations
203203
)
204204

205+
add_fp_unittest(
206+
faddl_test
207+
NEED_MPFR
208+
SUITE
209+
libc-math-unittests
210+
SRCS
211+
faddl_test.cpp
212+
HDRS
213+
AddTest.h
214+
DEPENDS
215+
libc.src.math.faddl
216+
)
217+
205218
add_fp_unittest(
206219
trunc_test
207220
NEED_MPFR

libc/test/src/math/faddl_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for faddl -----------------------------------------------===//
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 "AddTest.h"
10+
11+
#include "src/math/faddl.h"
12+
13+
LIST_ADD_TESTS(float, long double, LIBC_NAMESPACE::faddl)

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,39 @@ add_fp_unittest(
150150
HDRS
151151
AddTest.h
152152
DEPENDS
153+
libc.hdr.errno_macros
154+
libc.hdr.fenv_macros
153155
libc.src.math.fadd
154-
libc.src.__support.FPUtil.basic_operations
156+
)
155157

158+
add_fp_unittest(
159+
faddl_test
160+
NEED_MPFR
161+
SUITE
162+
libc-math-unittests
163+
SRCS
164+
faddl_test.cpp
165+
HDRS
166+
AddTest.h
167+
DEPENDS
168+
libc.hdr.errno_macros
169+
libc.hdr.fenv_macros
170+
libc.src.math.faddl
171+
)
172+
173+
add_fp_unittest(
174+
faddf128_test
175+
NEED_MPFR
176+
SUITE
177+
libc-math-unittests
178+
SRCS
179+
faddf128_test.cpp
180+
HDRS
181+
AddTest.h
182+
DEPENDS
183+
libc.hdr.errno_macros
184+
libc.hdr.fenv_macros
185+
libc.src.math.faddf128
156186
)
157187

158188
add_fp_unittest(
@@ -4125,7 +4155,6 @@ add_fp_unittest(
41254155
DEPENDS
41264156
libc.hdr.errno_macros
41274157
libc.hdr.fenv_macros
4128-
libc.src.__support.FPUtil.basic_operations
41294158
libc.src.math.f16add
41304159
)
41314160

@@ -4140,7 +4169,6 @@ add_fp_unittest(
41404169
DEPENDS
41414170
libc.hdr.errno_macros
41424171
libc.hdr.fenv_macros
4143-
libc.src.__support.FPUtil.basic_operations
41444172
libc.src.math.f16addf
41454173
)
41464174

@@ -4155,7 +4183,6 @@ add_fp_unittest(
41554183
DEPENDS
41564184
libc.hdr.errno_macros
41574185
libc.hdr.fenv_macros
4158-
libc.src.__support.FPUtil.basic_operations
41594186
libc.src.math.f16addl
41604187
)
41614188

@@ -4170,7 +4197,6 @@ add_fp_unittest(
41704197
DEPENDS
41714198
libc.hdr.errno_macros
41724199
libc.hdr.fenv_macros
4173-
libc.src.__support.FPUtil.basic_operations
41744200
libc.src.math.f16addf128
41754201
)
41764202

@@ -4707,6 +4733,8 @@ add_fp_unittest(
47074733
HDRS
47084734
AddTest.h
47094735
DEPENDS
4736+
libc.hdr.errno_macros
4737+
libc.hdr.fenv_macros
47104738
libc.src.math.daddl
47114739
)
47124740

@@ -4719,6 +4747,8 @@ add_fp_unittest(
47194747
HDRS
47204748
AddTest.h
47214749
DEPENDS
4750+
libc.hdr.errno_macros
4751+
libc.hdr.fenv_macros
47224752
libc.src.math.daddf128
47234753
)
47244754

0 commit comments

Comments
 (0)