Skip to content

Commit 2c74237

Browse files
[libc][math][c23] Add fsub{,l,f128} and remainderf128 C23 math functions (#101576)
Co-authored-by: OverMighty <[email protected]>
1 parent 07ddf19 commit 2c74237

28 files changed

+413
-6
lines changed

libc/config/darwin/arm/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ set(TARGET_LIBM_ENTRYPOINTS
185185
libc.src.math.frexp
186186
libc.src.math.frexpf
187187
libc.src.math.frexpl
188+
libc.src.math.fsub
189+
libc.src.math.fsubl
188190
libc.src.math.hypot
189191
libc.src.math.hypotf
190192
libc.src.math.ilogb

libc/config/darwin/x86_64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ set(TARGET_LIBM_ENTRYPOINTS
152152
#libc.src.math.frexp
153153
#libc.src.math.frexpf
154154
#libc.src.math.frexpl
155+
#libc.src.math.fsub
156+
#libc.src.math.fsubl
155157
#libc.src.math.hypot
156158
#libc.src.math.hypotf
157159
#libc.src.math.ilogb

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ set(TARGET_LIBM_ENTRYPOINTS
461461
libc.src.math.fromfpxl
462462
libc.src.math.fsqrt
463463
libc.src.math.fsqrtl
464+
libc.src.math.fsub
465+
libc.src.math.fsubl
464466
libc.src.math.getpayload
465467
libc.src.math.getpayloadf
466468
libc.src.math.getpayloadl
@@ -701,6 +703,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
701703
libc.src.math.fromfpf128
702704
libc.src.math.fromfpxf128
703705
libc.src.math.fsqrtf128
706+
libc.src.math.fsubf128
704707
libc.src.math.getpayloadf128
705708
libc.src.math.ilogbf128
706709
libc.src.math.ldexpf128
@@ -716,6 +719,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
716719
libc.src.math.nextafterf128
717720
libc.src.math.nextdownf128
718721
libc.src.math.nextupf128
722+
libc.src.math.remainderf128
719723
libc.src.math.remquof128
720724
libc.src.math.rintf128
721725
libc.src.math.roundevenf128

libc/config/linux/arm/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ set(TARGET_LIBM_ENTRYPOINTS
297297
libc.src.math.fromfpx
298298
libc.src.math.fromfpxf
299299
libc.src.math.fromfpxl
300+
libc.src.math.fsub
301+
libc.src.math.fsubl
300302
libc.src.math.getpayload
301303
libc.src.math.getpayloadf
302304
libc.src.math.getpayloadl

libc/config/linux/riscv/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ set(TARGET_LIBM_ENTRYPOINTS
464464
libc.src.math.fromfpxl
465465
libc.src.math.fsqrt
466466
libc.src.math.fsqrtl
467+
libc.src.math.fsub
468+
libc.src.math.fsubl
467469
libc.src.math.getpayload
468470
libc.src.math.getpayloadf
469471
libc.src.math.getpayloadl
@@ -608,6 +610,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
608610
libc.src.math.fromfpf128
609611
libc.src.math.fromfpxf128
610612
libc.src.math.fsqrtf128
613+
libc.src.math.fsubf128
611614
libc.src.math.getpayloadf128
612615
libc.src.math.ilogbf128
613616
libc.src.math.ldexpf128
@@ -623,6 +626,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
623626
libc.src.math.nextafterf128
624627
libc.src.math.nextdownf128
625628
libc.src.math.nextupf128
629+
libc.src.math.remainderf128
626630
libc.src.math.remquof128
627631
libc.src.math.rintf128
628632
libc.src.math.roundevenf128

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ set(TARGET_LIBM_ENTRYPOINTS
464464
libc.src.math.fromfpxl
465465
libc.src.math.fsqrt
466466
libc.src.math.fsqrtl
467+
libc.src.math.fsub
468+
libc.src.math.fsubl
467469
libc.src.math.getpayload
468470
libc.src.math.getpayloadf
469471
libc.src.math.getpayloadl
@@ -697,6 +699,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
697699
libc.src.math.fromfpf128
698700
libc.src.math.fromfpxf128
699701
libc.src.math.fsqrtf128
702+
libc.src.math.fsubf128
700703
libc.src.math.getpayloadf128
701704
libc.src.math.ilogbf128
702705
libc.src.math.ldexpf128
@@ -712,6 +715,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
712715
libc.src.math.nextafterf128
713716
libc.src.math.nextdownf128
714717
libc.src.math.nextupf128
718+
libc.src.math.remainderf128
715719
libc.src.math.remquof128
716720
libc.src.math.rintf128
717721
libc.src.math.roundevenf128

libc/config/windows/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ set(TARGET_LIBM_ENTRYPOINTS
201201
libc.src.math.frexp
202202
libc.src.math.frexpf
203203
libc.src.math.frexpl
204+
libc.src.math.fsub
205+
libc.src.math.fsubl
204206
libc.src.math.hypot
205207
libc.src.math.hypotf
206208
libc.src.math.ilogb

libc/docs/math/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Basic Operations
118118
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
119119
| ddiv | N/A | N/A | | N/A | |check|\* | 7.12.14.4 | F.10.11 |
120120
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
121-
| dfma | N/A | N/A | |check| | N/A | |check|\* | 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
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -176,7 +176,7 @@ Basic Operations
176176
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
177177
| fromfpx | |check| | |check| | |check| | |check| | |check| | 7.12.9.11 | F.10.6.11 |
178178
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
179-
| fsub | N/A | | | N/A | | 7.12.14.2 | F.10.11 |
179+
| fsub | N/A | |check| | |check| | N/A | |check|\* | 7.12.14.2 | F.10.11 |
180180
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
181181
| getpayload | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A |
182182
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -210,7 +210,7 @@ Basic Operations
210210
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
211211
| nextup | |check| | |check| | |check| | |check| | |check| | 7.12.11.5 | F.10.8.5 |
212212
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
213-
| remainder | |check| | |check| | |check| | |check| | | 7.12.10.2 | F.10.7.2 |
213+
| remainder | |check| | |check| | |check| | |check| | |check| | 7.12.10.2 | F.10.7.2 |
214214
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
215215
| remquo | |check| | |check| | |check| | |check| | |check| | 7.12.10.3 | F.10.7.3 |
216216
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/newhdrgen/yaml/math.yaml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,14 @@ functions:
794794
arguments:
795795
- type: long double
796796
- type: long double
797+
- name: remainderf128
798+
standards:
799+
- stdc
800+
return_type: float128
801+
arguments:
802+
- type: float128
803+
- type: float128
804+
guard: LIBC_TYPES_HAS_FLOAT128
797805
- name: remquo
798806
standards:
799807
- stdc
@@ -1540,6 +1548,28 @@ functions:
15401548
- type: int
15411549
- type: unsigned int
15421550
guard: LIBC_TYPES_HAS_FLOAT16
1551+
- name: fsub
1552+
standards:
1553+
- stdc
1554+
return_type: float
1555+
arguments:
1556+
- type: double
1557+
- type: double
1558+
- name: fsubl
1559+
standards:
1560+
- stdc
1561+
return_type: float
1562+
arguments:
1563+
- type: long double
1564+
- type: long double
1565+
- name: fsubf128
1566+
standards:
1567+
- llvm_libc_ext
1568+
return_type: float
1569+
arguments:
1570+
- type: float128
1571+
- type: float128
1572+
guard: LIBC_TYPES_HAS_FLOAT128
15431573
- name: getpayload
15441574
standards:
15451575
- stdc
@@ -1557,7 +1587,7 @@ functions:
15571587
- stdc
15581588
return_type: float
15591589
arguments:
1560-
- type: float *
1590+
- type: float *
15611591
- name: getpayloadf16
15621592
standards:
15631593
- stdc

libc/spec/llvm_libc_ext.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
9898

9999
GuardedFunctionSpec<"fsqrtf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
100100

101+
FunctionSpec<"fsubf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
102+
101103
FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
102-
FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
104+
FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
103105
]
104106
>;
105107

libc/spec/stdc.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ def StdC : StandardSpec<"stdc"> {
516516
GuardedFunctionSpec<"fromfpxf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT16">,
517517
GuardedFunctionSpec<"fromfpxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT128">,
518518

519+
FunctionSpec<"fsub", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
520+
FunctionSpec<"fsubl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
521+
519522
FunctionSpec<"ufromfp", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
520523
FunctionSpec<"ufromfpf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
521524
FunctionSpec<"ufromfpl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
@@ -603,6 +606,7 @@ def StdC : StandardSpec<"stdc"> {
603606
FunctionSpec<"remainderf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
604607
FunctionSpec<"remainderl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
605608
GuardedFunctionSpec<"remainderf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
609+
GuardedFunctionSpec<"remainderf128", RetValSpec<Float128Type, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
606610

607611
FunctionSpec<"remquo", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,
608612
FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
@@ -751,7 +755,7 @@ def StdC : StandardSpec<"stdc"> {
751755
FunctionSpec<"getpayloadl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoublePtr>]>,
752756
GuardedFunctionSpec<"getpayloadf16", RetValSpec<Float16Type>, [ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
753757
GuardedFunctionSpec<"getpayloadf128", RetValSpec<Float128Type>, [ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
754-
758+
755759
FunctionSpec<"setpayload", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,
756760
FunctionSpec<"setpayloadf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>]>,
757761
GuardedFunctionSpec<"setpayloadf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,

libc/src/math/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ add_math_entrypoint_object(fromfpxl)
273273
add_math_entrypoint_object(fromfpxf16)
274274
add_math_entrypoint_object(fromfpxf128)
275275

276+
add_math_entrypoint_object(fsub)
277+
add_math_entrypoint_object(fsubl)
278+
add_math_entrypoint_object(fsubf128)
279+
276280
add_math_entrypoint_object(getpayload)
277281
add_math_entrypoint_object(getpayloadf)
278282
add_math_entrypoint_object(getpayloadl)
@@ -396,6 +400,7 @@ add_math_entrypoint_object(remainder)
396400
add_math_entrypoint_object(remainderf)
397401
add_math_entrypoint_object(remainderl)
398402
add_math_entrypoint_object(remainderf16)
403+
add_math_entrypoint_object(remainderf128)
399404

400405
add_math_entrypoint_object(remquo)
401406
add_math_entrypoint_object(remquof)

libc/src/math/fsub.h

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

libc/src/math/fsubf128.h

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

libc/src/math/fsubl.h

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

libc/src/math/generic/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,43 @@ add_entrypoint_object(
29312931
-O3
29322932
)
29332933

2934+
add_entrypoint_object(
2935+
fsub
2936+
SRCS
2937+
fsub.cpp
2938+
HDRS
2939+
../fsub.h
2940+
DEPENDS
2941+
libc.src.__support.FPUtil.generic.add_sub
2942+
COMPILE_OPTIONS
2943+
-O3
2944+
)
2945+
2946+
add_entrypoint_object(
2947+
fsubl
2948+
SRCS
2949+
fsubl.cpp
2950+
HDRS
2951+
../fsubl.h
2952+
DEPENDS
2953+
libc.src.__support.FPUtil.generic.add_sub
2954+
COMPILE_OPTIONS
2955+
-O3
2956+
)
2957+
2958+
add_entrypoint_object(
2959+
fsubf128
2960+
SRCS
2961+
fsubf128.cpp
2962+
HDRS
2963+
../fsubf128.h
2964+
DEPENDS
2965+
libc.src.__support.macros.properties.types
2966+
libc.src.__support.FPUtil.generic.add_sub
2967+
COMPILE_OPTIONS
2968+
-O3
2969+
)
2970+
29342971
add_entrypoint_object(
29352972
sqrt
29362973
SRCS
@@ -3091,6 +3128,19 @@ add_entrypoint_object(
30913128
-O3
30923129
)
30933130

3131+
add_entrypoint_object(
3132+
remainderf128
3133+
SRCS
3134+
remainderf128.cpp
3135+
HDRS
3136+
../remainderf128.h
3137+
DEPENDS
3138+
libc.src.__support.macros.properties.types
3139+
libc.src.__support.FPUtil.division_and_remainder_operations
3140+
COMPILE_OPTIONS
3141+
-O3
3142+
)
3143+
30943144
add_entrypoint_object(
30953145
hypotf
30963146
SRCS

libc/src/math/generic/fsub.cpp

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

0 commit comments

Comments
 (0)