Skip to content

[libc][math][c23] Add fsub{,l,f128} and remainderf128 C23 math functions #101576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
00592ad
script
aaryanshukla Aug 1, 2024
56f0497
finished generic and headers
aaryanshukla Aug 1, 2024
c999ff3
going to add to header spec
aaryanshukla Aug 1, 2024
10f8772
[libc][math][c23]:
aaryanshukla Aug 1, 2024
ac942e0
removed fsubf128 from unittests
aaryanshukla Aug 2, 2024
0537314
updated index.rst
aaryanshukla Aug 2, 2024
7ea12c9
Update libc/test/src/math/smoke/CMakeLists.txt
aaryanshukla Aug 5, 2024
99ac8a1
Update libc/docs/math/index.rst
aaryanshukla Aug 5, 2024
3c41447
Update libc/test/src/math/CMakeLists.txt
aaryanshukla Aug 5, 2024
d13eec9
Update libc/test/src/math/CMakeLists.txt
aaryanshukla Aug 5, 2024
a48b621
Update libc/test/src/math/smoke/CMakeLists.txt
aaryanshukla Aug 5, 2024
921d587
Update libc/test/src/math/smoke/CMakeLists.txt
aaryanshukla Aug 5, 2024
f2750ef
Merge branch 'main' into remaining_basic_operations
aaryanshukla Aug 5, 2024
f84aabf
added headers to oldheadergen
aaryanshukla Aug 5, 2024
694bd80
Update libc/src/math/generic/CMakeLists.txt
aaryanshukla Aug 6, 2024
1e28c71
Update libc/config/linux/aarch64/entrypoints.txt
aaryanshukla Aug 6, 2024
f3a26d6
fixed whitespaces
aaryanshukla Aug 6, 2024
38d76bc
Merge branch 'main' into remaining_basic_operations
aaryanshukla Aug 6, 2024
b53f728
Update MPFRUtils.cpp
aaryanshukla Aug 6, 2024
92367b3
fixed hdrgen
aaryanshukla Aug 7, 2024
3537c88
Merge branch 'main' into remaining_basic_operations
aaryanshukla Aug 7, 2024
b1ec79c
updated stdc.td
aaryanshukla Aug 7, 2024
f62a56d
reverted changes to yaml testing
aaryanshukla Aug 7, 2024
a39816d
Update test_small.yaml
aaryanshukla Aug 7, 2024
b22edad
Update llvm_libc_ext.td
aaryanshukla Aug 7, 2024
23da4b0
Update stdc.td
aaryanshukla Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc/config/darwin/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.frexp
libc.src.math.frexpf
libc.src.math.frexpl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.hypot
libc.src.math.hypotf
libc.src.math.ilogb
Expand Down
2 changes: 2 additions & 0 deletions libc/config/darwin/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.frexp
#libc.src.math.frexpf
#libc.src.math.frexpl
#libc.src.math.fsub
#libc.src.math.fsubl
#libc.src.math.hypot
#libc.src.math.hypotf
#libc.src.math.ilogb
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpxl
libc.src.math.fsqrt
libc.src.math.fsqrtl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl
Expand Down Expand Up @@ -701,6 +703,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
libc.src.math.fsqrtf128
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.ldexpf128
Expand All @@ -716,6 +719,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.nextafterf128
libc.src.math.nextdownf128
libc.src.math.nextupf128
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
Expand Down
2 changes: 2 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpx
libc.src.math.fromfpxf
libc.src.math.fromfpxl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpxl
libc.src.math.fsqrt
libc.src.math.fsqrtl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl
Expand Down Expand Up @@ -608,6 +610,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
libc.src.math.fsqrtf128
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.ldexpf128
Expand All @@ -623,6 +626,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.nextafterf128
libc.src.math.nextdownf128
libc.src.math.nextupf128
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpxl
libc.src.math.fsqrt
libc.src.math.fsqrtl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl
Expand Down Expand Up @@ -697,6 +699,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
libc.src.math.fsqrtf128
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.ldexpf128
Expand All @@ -712,6 +715,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.nextafterf128
libc.src.math.nextdownf128
libc.src.math.nextupf128
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
Expand Down
2 changes: 2 additions & 0 deletions libc/config/windows/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.frexp
libc.src.math.frexpf
libc.src.math.frexpl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.hypot
libc.src.math.hypotf
libc.src.math.ilogb
Expand Down
6 changes: 3 additions & 3 deletions libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| ddiv | N/A | N/A | | N/A | |check|\* | 7.12.14.4 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dmul | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.3 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down Expand Up @@ -176,7 +176,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fromfpx | |check| | |check| | |check| | |check| | |check| | 7.12.9.11 | F.10.6.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fsub | N/A | | | N/A | | 7.12.14.2 | F.10.11 |
| fsub | N/A | |check| | |check| | N/A | |check|\* | 7.12.14.2 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| getpayload | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down Expand Up @@ -210,7 +210,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| nextup | |check| | |check| | |check| | |check| | |check| | 7.12.11.5 | F.10.8.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| remainder | |check| | |check| | |check| | |check| | | 7.12.10.2 | F.10.7.2 |
| remainder | |check| | |check| | |check| | |check| | |check| | 7.12.10.2 | F.10.7.2 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| remquo | |check| | |check| | |check| | |check| | |check| | 7.12.10.3 | F.10.7.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down
32 changes: 31 additions & 1 deletion libc/newhdrgen/yaml/math.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,14 @@ functions:
arguments:
- type: long double
- type: long double
- name: remainderf128
standards:
- stdc
return_type: float128
arguments:
- type: float128
- type: float128
guard: LIBC_TYPES_HAS_FLOAT128
- name: remquo
standards:
- stdc
Expand Down Expand Up @@ -1540,6 +1548,28 @@ functions:
- type: int
- type: unsigned int
guard: LIBC_TYPES_HAS_FLOAT16
- name: fsub
standards:
- stdc
return_type: float
arguments:
- type: double
- type: double
- name: fsubl
standards:
- stdc
return_type: float
arguments:
- type: long double
- type: long double
- name: fsubf128
standards:
- llvm_libc_ext
return_type: float
arguments:
- type: float128
- type: float128
guard: LIBC_TYPES_HAS_FLOAT128
- name: getpayload
standards:
- stdc
Expand All @@ -1557,7 +1587,7 @@ functions:
- stdc
return_type: float
arguments:
- type: float *
- type: float *
- name: getpayloadf16
standards:
- stdc
Expand Down
4 changes: 3 additions & 1 deletion libc/spec/llvm_libc_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {

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

FunctionSpec<"fsubf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
]
>;

Expand Down
6 changes: 5 additions & 1 deletion libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ def StdC : StandardSpec<"stdc"> {
GuardedFunctionSpec<"fromfpxf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"fromfpxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"fsub", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fsubl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,

FunctionSpec<"ufromfp", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
FunctionSpec<"ufromfpf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
FunctionSpec<"ufromfpl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
Expand Down Expand Up @@ -603,6 +606,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"remainderf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"remainderl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"remainderf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"remainderf128", RetValSpec<Float128Type, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"remquo", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,
FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
Expand Down Expand Up @@ -751,7 +755,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"getpayloadl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoublePtr>]>,
GuardedFunctionSpec<"getpayloadf16", RetValSpec<Float16Type>, [ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"getpayloadf128", RetValSpec<Float128Type>, [ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"setpayload", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,
FunctionSpec<"setpayloadf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>]>,
GuardedFunctionSpec<"setpayloadf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
Expand Down
5 changes: 5 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ add_math_entrypoint_object(fromfpxl)
add_math_entrypoint_object(fromfpxf16)
add_math_entrypoint_object(fromfpxf128)

add_math_entrypoint_object(fsub)
add_math_entrypoint_object(fsubl)
add_math_entrypoint_object(fsubf128)

add_math_entrypoint_object(getpayload)
add_math_entrypoint_object(getpayloadf)
add_math_entrypoint_object(getpayloadl)
Expand Down Expand Up @@ -396,6 +400,7 @@ add_math_entrypoint_object(remainder)
add_math_entrypoint_object(remainderf)
add_math_entrypoint_object(remainderl)
add_math_entrypoint_object(remainderf16)
add_math_entrypoint_object(remainderf128)

add_math_entrypoint_object(remquo)
add_math_entrypoint_object(remquof)
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/fsub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for fsub --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_FSUB_H
#define LLVM_LIBC_SRC_MATH_FSUB_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float fsub(double x, double y);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_FSUB_H
21 changes: 21 additions & 0 deletions libc/src/math/fsubf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for fsubf128 ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_FSUBF128_H
#define LLVM_LIBC_SRC_MATH_FSUBF128_H

#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE_DECL {

float fsubf128(float128 x, float128 y);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_FSUBF128_H
20 changes: 20 additions & 0 deletions libc/src/math/fsubl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for fsubl -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_FSUBL_H
#define LLVM_LIBC_SRC_MATH_FSUBL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float fsubl(long double x, long double y);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_FSUBL_H
50 changes: 50 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2931,6 +2931,43 @@ add_entrypoint_object(
-O3
)

add_entrypoint_object(
fsub
SRCS
fsub.cpp
HDRS
../fsub.h
DEPENDS
libc.src.__support.FPUtil.generic.add_sub
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
fsubl
SRCS
fsubl.cpp
HDRS
../fsubl.h
DEPENDS
libc.src.__support.FPUtil.generic.add_sub
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
fsubf128
SRCS
fsubf128.cpp
HDRS
../fsubf128.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.generic.add_sub
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
sqrt
SRCS
Expand Down Expand Up @@ -3091,6 +3128,19 @@ add_entrypoint_object(
-O3
)

add_entrypoint_object(
remainderf128
SRCS
remainderf128.cpp
HDRS
../remainderf128.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.division_and_remainder_operations
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
hypotf
SRCS
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/generic/fsub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of fsub function -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/fsub.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, fsub, (double x, double y)) {
return fputil::generic::sub<float>(x, y);
}

} // namespace LIBC_NAMESPACE_DECL
Loading