Skip to content

Commit 30b5d4a

Browse files
[libc][math][c23] Add dfma{l,f128} and dsub{l,f128} C23 math functions (llvm#101089)
Co-authored-by: OverMighty <[email protected]>
1 parent 3626443 commit 30b5d4a

30 files changed

+421
-7
lines changed

libc/config/darwin/arm/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ set(TARGET_LIBM_ENTRYPOINTS
136136
libc.src.math.cos
137137
libc.src.math.cosf
138138
libc.src.math.cospif
139+
libc.src.math.dfmal
139140
libc.src.math.dsqrtl
141+
libc.src.math.dsubl
140142
libc.src.math.erff
141143
libc.src.math.exp
142144
libc.src.math.expf

libc/config/darwin/x86_64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ set(TARGET_LIBM_ENTRYPOINTS
119119
#libc.src.math.ceill
120120
#libc.src.math.coshf
121121
#libc.src.math.cosf
122+
#libc.src.math.dfmal
122123
#libc.src.math.dsqrtl
124+
#libc.src.math.dsubl
123125
#libc.src.math.expf
124126
#libc.src.math.exp2f
125127
#libc.src.math.expm1f

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,10 @@ set(TARGET_LIBM_ENTRYPOINTS
361361
libc.src.math.cosf
362362
libc.src.math.coshf
363363
libc.src.math.cospif
364+
libc.src.math.dfmal
364365
libc.src.math.dmull
365366
libc.src.math.dsqrtl
367+
libc.src.math.dsubl
366368
libc.src.math.erff
367369
libc.src.math.exp
368370
libc.src.math.exp10
@@ -612,7 +614,9 @@ if(LIBC_TYPES_HAS_FLOAT128)
612614
# math.h C23 _Float128 entrypoints
613615
libc.src.math.ceilf128
614616
libc.src.math.copysignf128
617+
libc.src.math.dfmaf128
615618
libc.src.math.dsqrtf128
619+
libc.src.math.dsubf128
616620
libc.src.math.fabsf128
617621
libc.src.math.fdimf128
618622
libc.src.math.floorf128

libc/config/linux/arm/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ set(TARGET_LIBM_ENTRYPOINTS
228228
libc.src.math.cos
229229
libc.src.math.cosf
230230
libc.src.math.coshf
231+
libc.src.math.dfmal
231232
libc.src.math.dsqrtl
233+
libc.src.math.dsubl
232234
libc.src.math.erff
233235
libc.src.math.exp
234236
libc.src.math.exp10

libc/config/linux/riscv/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@ set(TARGET_LIBM_ENTRYPOINTS
383383
libc.src.math.cosf
384384
libc.src.math.coshf
385385
libc.src.math.cospif
386+
libc.src.math.dfmal
386387
libc.src.math.dmull
387388
libc.src.math.dsqrtl
389+
libc.src.math.dsubl
388390
libc.src.math.erff
389391
libc.src.math.exp
390392
libc.src.math.exp10

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@ set(TARGET_LIBM_ENTRYPOINTS
383383
libc.src.math.cosf
384384
libc.src.math.coshf
385385
libc.src.math.cospif
386+
libc.src.math.dfmal
386387
libc.src.math.dmull
387388
libc.src.math.dsqrtl
389+
libc.src.math.dsubl
388390
libc.src.math.erff
389391
libc.src.math.exp
390392
libc.src.math.exp10
@@ -653,8 +655,10 @@ if(LIBC_TYPES_HAS_FLOAT128)
653655
libc.src.math.canonicalizef128
654656
libc.src.math.ceilf128
655657
libc.src.math.copysignf128
658+
libc.src.math.dfmaf128
656659
libc.src.math.dmulf128
657660
libc.src.math.dsqrtf128
661+
libc.src.math.dsubf128
658662
libc.src.math.fabsf128
659663
libc.src.math.fdimf128
660664
libc.src.math.floorf128

libc/config/windows/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ set(TARGET_LIBM_ENTRYPOINTS
133133
libc.src.math.cos
134134
libc.src.math.cosf
135135
libc.src.math.coshf
136+
libc.src.math.dfmal
137+
libc.src.math.dsubl
136138
libc.src.math.erff
137139
libc.src.math.exp
138140
libc.src.math.expf

libc/docs/math/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ Basic Operations
118118
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
119119
| ddiv | N/A | N/A | | N/A | | 7.12.14.4 | F.10.11 |
120120
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
121-
| dfma | N/A | N/A | | N/A | | 7.12.14.5 | F.10.11 |
121+
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
122122
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
123123
| dmul | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.3 | F.10.11 |
124124
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
125-
| dsub | N/A | N/A | | N/A | | 7.12.14.2 | F.10.11 |
125+
| dsub | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.2 | F.10.11 |
126126
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
127127
| f16add | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.1 | F.10.11 |
128128
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/llvm_libc_ext.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
5757
[], // Types
5858
[], // Enumerations
5959
[
60+
GuardedFunctionSpec<"dfmaf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
6061
GuardedFunctionSpec<"dsqrtf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
62+
GuardedFunctionSpec<"dsubf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
63+
6164

6265
GuardedFunctionSpec<"f16add", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
6366
GuardedFunctionSpec<"f16addf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,

libc/spec/stdc.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ def StdC : StandardSpec<"stdc"> {
397397
GuardedFunctionSpec<"ceilf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
398398
GuardedFunctionSpec<"ceilf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
399399

400+
FunctionSpec<"dfmal", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
401+
FunctionSpec<"dsubl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
402+
400403
FunctionSpec<"fabs", RetValSpec<DoubleType>, [ArgSpec<DoubleType>], [ConstAttr]>,
401404
FunctionSpec<"fabsf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
402405
FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,15 @@ add_math_entrypoint_object(cospif)
8989
add_math_entrypoint_object(dmull)
9090
add_math_entrypoint_object(dmulf128)
9191

92+
add_math_entrypoint_object(dfmal)
93+
add_math_entrypoint_object(dfmaf128)
94+
9295
add_math_entrypoint_object(dsqrtl)
9396
add_math_entrypoint_object(dsqrtf128)
9497

98+
add_math_entrypoint_object(dsubl)
99+
add_math_entrypoint_object(dsubf128)
100+
95101
add_math_entrypoint_object(erf)
96102
add_math_entrypoint_object(erff)
97103

libc/src/math/dfmaf128.h

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

libc/src/math/dfmal.h

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

libc/src/math/dsubf128.h

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

libc/src/math/dsubl.h

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

libc/src/math/generic/CMakeLists.txt

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

132+
add_entrypoint_object(
133+
dfmaf128
134+
SRCS
135+
dfmaf128.cpp
136+
HDRS
137+
../dfmaf128.h
138+
DEPENDS
139+
libc.src.__support.FPUtil.fma
140+
libc.src.__support.macros.properties.types
141+
COMPILE_OPTIONS
142+
-O3
143+
)
144+
145+
add_entrypoint_object(
146+
dfmal
147+
SRCS
148+
dfmal.cpp
149+
HDRS
150+
../dfmal.h
151+
DEPENDS
152+
libc.src.__support.FPUtil.fma
153+
COMPILE_OPTIONS
154+
-O3
155+
)
156+
132157
add_entrypoint_object(
133158
dsqrtl
134159
SRCS
@@ -154,6 +179,32 @@ add_entrypoint_object(
154179
-O3
155180
)
156181

182+
183+
add_entrypoint_object(
184+
dsubf128
185+
SRCS
186+
dsubf128.cpp
187+
HDRS
188+
../dsubf128.h
189+
DEPENDS
190+
libc.src.__support.FPUtil.generic.add_sub
191+
libc.src.__support.macros.properties.types
192+
COMPILE_OPTIONS
193+
-O3
194+
)
195+
196+
add_entrypoint_object(
197+
dsubl
198+
SRCS
199+
dsubl.cpp
200+
HDRS
201+
../dsubl.h
202+
DEPENDS
203+
libc.src.__support.FPUtil.generic.add_sub
204+
COMPILE_OPTIONS
205+
-O3
206+
)
207+
157208
add_header_library(
158209
range_reduction
159210
HDRS

libc/src/math/generic/dfmaf128.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Implementation of dfmaf128 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_DFMAf128_H
10+
#define LLVM_LIBC_SRC_MATH_DFMAf128_H
11+
12+
#include "src/math/dfmaf128.h"
13+
#include "src/__support/FPUtil/FMA.h"
14+
#include "src/__support/common.h"
15+
#include "src/__support/macros/config.h"
16+
17+
namespace LIBC_NAMESPACE_DECL {
18+
19+
LLVM_LIBC_FUNCTION(double, dfmaf128, (float128 x, float128 y, float128 z)) {
20+
return fputil::fma<double>(x, y, z);
21+
}
22+
23+
} // namespace LIBC_NAMESPACE_DECL
24+
25+
#endif // LLVM_LIBC_SRC_MATH_DFMAf128_H

libc/src/math/generic/dfmal.cpp

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

libc/src/math/generic/dsubf128.cpp

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

libc/src/math/generic/dsubl.cpp

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

0 commit comments

Comments
 (0)