Skip to content

Commit 8f33f1d

Browse files
[libc][math][c23] Add dadd{l,f128} and ddiv{l,f128} C23 math functions (#100456)
- fadd removed because I need to add for different input types - finishing rest of basic operations - noticed duplicates will remove --------- Co-authored-by: OverMighty <[email protected]>
1 parent 97f723b commit 8f33f1d

24 files changed

+282
-2
lines changed

libc/config/darwin/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ set(TARGET_LIBM_ENTRYPOINTS
148148
libc.src.math.cospif
149149
libc.src.math.dfmal
150150
libc.src.math.dsqrtl
151+
libc.src.math.daddl
151152
libc.src.math.dsubl
152153
libc.src.math.erff
153154
libc.src.math.exp

libc/config/darwin/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ set(TARGET_LIBM_ENTRYPOINTS
119119
#libc.src.math.ceill
120120
#libc.src.math.coshf
121121
#libc.src.math.cosf
122+
#libc.src.math.daddl
122123
#libc.src.math.dfmal
123124
#libc.src.math.dsqrtl
124125
#libc.src.math.dsubl

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ set(TARGET_LIBM_ENTRYPOINTS
363363
libc.src.math.cosf
364364
libc.src.math.coshf
365365
libc.src.math.cospif
366+
libc.src.math.daddl
366367
libc.src.math.dfmal
367368
libc.src.math.dmull
368369
libc.src.math.dsqrtl
@@ -618,6 +619,8 @@ if(LIBC_TYPES_HAS_FLOAT128)
618619
# math.h C23 _Float128 entrypoints
619620
libc.src.math.ceilf128
620621
libc.src.math.copysignf128
622+
libc.src.math.daddf128
623+
libc.src.math.ddivf128
621624
libc.src.math.dfmaf128
622625
libc.src.math.dsqrtf128
623626
libc.src.math.dsubf128

libc/config/linux/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ set(TARGET_LIBM_ENTRYPOINTS
228228
libc.src.math.cos
229229
libc.src.math.cosf
230230
libc.src.math.coshf
231+
libc.src.math.daddl
231232
libc.src.math.dfmal
232233
libc.src.math.dsqrtl
233234
libc.src.math.erff

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ set(TARGET_LIBM_ENTRYPOINTS
386386
libc.src.math.cosf
387387
libc.src.math.coshf
388388
libc.src.math.cospif
389+
libc.src.math.daddl
389390
libc.src.math.dfmal
390391
libc.src.math.dmull
391392
libc.src.math.dsqrtl

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ set(TARGET_LIBM_ENTRYPOINTS
389389
libc.src.math.dfmal
390390
libc.src.math.dmull
391391
libc.src.math.dsqrtl
392+
libc.src.math.daddl
392393
libc.src.math.dsubl
393394
libc.src.math.erff
394395
libc.src.math.exp
@@ -660,6 +661,8 @@ if(LIBC_TYPES_HAS_FLOAT128)
660661
libc.src.math.canonicalizef128
661662
libc.src.math.ceilf128
662663
libc.src.math.copysignf128
664+
libc.src.math.daddf128
665+
libc.src.math.ddivf128
663666
libc.src.math.dfmaf128
664667
libc.src.math.dmulf128
665668
libc.src.math.dsqrtf128

libc/config/windows/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ set(TARGET_LIBM_ENTRYPOINTS
133133
libc.src.math.cos
134134
libc.src.math.cosf
135135
libc.src.math.coshf
136+
libc.src.math.daddl
136137
libc.src.math.dfmal
137138
libc.src.math.dsubl
138139
libc.src.math.erff

libc/docs/math/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ Basic Operations
114114
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
115115
| copysign | |check| | |check| | |check| | |check| | |check| | 7.12.11.1 | F.10.8.1 |
116116
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
117-
| dadd | N/A | N/A | | N/A | | 7.12.14.1 | F.10.11 |
117+
| dadd | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.1 | F.10.11 |
118118
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
119-
| ddiv | N/A | N/A | | N/A | | 7.12.14.4 | F.10.11 |
119+
| ddiv | N/A | N/A | | N/A | |check|\* | 7.12.14.4 | F.10.11 |
120120
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
121121
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
122122
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/llvm_libc_ext.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
5757
[], // Types
5858
[], // Enumerations
5959
[
60+
GuardedFunctionSpec<"daddf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
61+
GuardedFunctionSpec<"ddivf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
6062
GuardedFunctionSpec<"dfmaf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
6163
GuardedFunctionSpec<"dsqrtf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
6264
GuardedFunctionSpec<"dsubf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,

libc/spec/stdc.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ def StdC : StandardSpec<"stdc"> {
396396
FunctionSpec<"ceill", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
397397
GuardedFunctionSpec<"ceilf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
398398
GuardedFunctionSpec<"ceilf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
399+
400+
FunctionSpec<"daddl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
399401

400402
FunctionSpec<"dfmal", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
401403
FunctionSpec<"dsubl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ add_math_entrypoint_object(cosh)
8686
add_math_entrypoint_object(coshf)
8787
add_math_entrypoint_object(cospif)
8888

89+
add_math_entrypoint_object(daddl)
90+
add_math_entrypoint_object(daddf128)
91+
add_math_entrypoint_object(ddivf128)
8992
add_math_entrypoint_object(dmull)
9093
add_math_entrypoint_object(dmulf128)
9194

libc/src/math/daddf128.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for daddf128 ----------------------*- 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_DADDF128_H
10+
#define LLVM_LIBC_SRC_MATH_DADDF128_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+
double daddf128(float128 x, float128 y);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_DADDF128_H

libc/src/math/daddl.h

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

libc/src/math/ddivf128.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for ddivf128 ----------------------*- 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_DDIVF128_H
10+
#define LLVM_LIBC_SRC_MATH_DDIVF128_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+
double ddivf128(float128 x, float128 y);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_DDIVF128_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,44 @@ add_entrypoint_object(
129129
libc.src.__support.FPUtil.nearest_integer_operations
130130
)
131131

132+
add_entrypoint_object(
133+
daddl
134+
SRCS
135+
daddl.cpp
136+
HDRS
137+
../daddl.h
138+
COMPILE_OPTIONS
139+
-O3
140+
DEPENDS
141+
libc.src.__support.FPUtil.generic.add_sub
142+
)
143+
144+
add_entrypoint_object(
145+
daddf128
146+
SRCS
147+
daddf128.cpp
148+
HDRS
149+
../daddf128.h
150+
COMPILE_OPTIONS
151+
-O3
152+
DEPENDS
153+
libc.src.__support.macros.properties.types
154+
libc.src.__support.FPUtil.generic.add_sub
155+
)
156+
157+
add_entrypoint_object(
158+
ddivf128
159+
SRCS
160+
ddivf128.cpp
161+
HDRS
162+
../ddivf128.h
163+
COMPILE_OPTIONS
164+
-O3
165+
DEPENDS
166+
libc.src.__support.macros.properties.types
167+
libc.src.__support.FPUtil.generic.div
168+
)
169+
132170
add_entrypoint_object(
133171
dfmaf128
134172
SRCS

libc/src/math/generic/daddf128.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of daddf128 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/daddf128.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(double, daddf128, (float128 x, float128 y)) {
17+
return fputil::generic::add<double>(x, y);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/generic/daddl.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of daddl 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/daddl.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(double, daddl, (long double x, long double y)) {
17+
return fputil::generic::add<double>(x, y);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/generic/ddivf128.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of ddivf128 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/ddivf128.h"
10+
#include "src/__support/FPUtil/generic/div.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(double, ddivf128, (float128 x, float128 y)) {
17+
return fputil::generic::div<double>(x, y);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/math/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ add_fp_unittest(
4444
libc.src.__support.FPUtil.fp_bits
4545
)
4646

47+
48+
add_fp_unittest(
49+
daddl_test
50+
NEED_MPFR
51+
SUITE
52+
libc-math-unittests
53+
SRCS
54+
daddl_test.cpp
55+
HDRS
56+
AddTest.h
57+
DEPENDS
58+
libc.src.math.daddl
59+
)
60+
4761
add_fp_unittest(
4862
sinf_test
4963
NEED_MPFR

libc/test/src/math/daddl_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for daddl -----------------------------------------------===//
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/daddl.h"
12+
13+
LIST_ADD_TESTS(double, long double, LIBC_NAMESPACE::daddl)

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,3 +4385,39 @@ add_fp_unittest(
43854385
libc.src.__support.FPUtil.basic_operations
43864386
libc.src.math.f16mulf128
43874387
)
4388+
4389+
add_fp_unittest(
4390+
daddl
4391+
SUITE
4392+
libc-math-smoke-tests
4393+
SRCS
4394+
daddl_test.cpp
4395+
HDRS
4396+
AddTest.h
4397+
DEPENDS
4398+
libc.src.math.daddl
4399+
)
4400+
4401+
add_fp_unittest(
4402+
daddf128
4403+
SUITE
4404+
libc-math-smoke-tests
4405+
SRCS
4406+
daddf128_test.cpp
4407+
HDRS
4408+
AddTest.h
4409+
DEPENDS
4410+
libc.src.math.daddf128
4411+
)
4412+
4413+
add_fp_unittest(
4414+
ddivf128
4415+
SUITE
4416+
libc-math-smoke-tests
4417+
SRCS
4418+
ddivf128_test.cpp
4419+
HDRS
4420+
DivTest.h
4421+
DEPENDS
4422+
libc.src.math.ddivf128
4423+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for daddf128 --------------------------------------------===//
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/daddf128.h"
12+
13+
LIST_ADD_TESTS(double, float128, LIBC_NAMESPACE::daddf128)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for daddl -----------------------------------------------===//
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/daddl.h"
12+
13+
LIST_ADD_TESTS(double, long double, LIBC_NAMESPACE::daddl)

0 commit comments

Comments
 (0)