[libc-commits] [libc] 2c74237 - [libc][math][c23] Add fsub{, l, f128} and remainderf128 C23 math functions (#101576)
via libc-commits
libc-commits at lists.llvm.org
Wed Aug 7 13:04:01 PDT 2024
Author: aaryanshukla
Date: 2024-08-07T13:03:58-07:00
New Revision: 2c74237c0fa5b5289b98c17209f4319b24406e08
URL: https://github.com/llvm/llvm-project/commit/2c74237c0fa5b5289b98c17209f4319b24406e08
DIFF: https://github.com/llvm/llvm-project/commit/2c74237c0fa5b5289b98c17209f4319b24406e08.diff
LOG: [libc][math][c23] Add fsub{,l,f128} and remainderf128 C23 math functions (#101576)
Co-authored-by: OverMighty <its.overmighty at gmail.com>
Added:
libc/src/math/fsub.h
libc/src/math/fsubf128.h
libc/src/math/fsubl.h
libc/src/math/generic/fsub.cpp
libc/src/math/generic/fsubf128.cpp
libc/src/math/generic/fsubl.cpp
libc/src/math/generic/remainderf128.cpp
libc/src/math/remainderf128.h
libc/test/src/math/fsub_test.cpp
libc/test/src/math/fsubl_test.cpp
libc/test/src/math/smoke/fsub_test.cpp
libc/test/src/math/smoke/fsubf128_test.cpp
libc/test/src/math/smoke/fsubl_test.cpp
Modified:
libc/config/darwin/arm/entrypoints.txt
libc/config/darwin/x86_64/entrypoints.txt
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/arm/entrypoints.txt
libc/config/linux/riscv/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/config/windows/entrypoints.txt
libc/docs/math/index.rst
libc/newhdrgen/yaml/math.yaml
libc/spec/llvm_libc_ext.td
libc/spec/stdc.td
libc/src/math/CMakeLists.txt
libc/src/math/generic/CMakeLists.txt
libc/test/src/math/CMakeLists.txt
libc/test/src/math/smoke/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/arm/entrypoints.txt
index 98a9938fd5331..b4af7df177497 100644
--- a/libc/config/darwin/arm/entrypoints.txt
+++ b/libc/config/darwin/arm/entrypoints.txt
@@ -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
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index dd1ee477f1ed3..89f8802446cad 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -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
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index b705b82c70f39..b92b96c89315e 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -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
@@ -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
@@ -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
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 36e940af4fb6b..c6b7b6cc9acfa 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -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
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index f117c5fc608fa..a90fdbef31bf2 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -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
@@ -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
@@ -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
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 39d90bf06a0cf..9ec86f13850db 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -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
@@ -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
@@ -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
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 42095e033f9e7..d28183549647f 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -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
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index ce83571e2b381..c665ce397f9b7 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index 62cde78fcc158..d22546e50b3fe 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -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
@@ -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
@@ -1557,7 +1587,7 @@ functions:
- stdc
return_type: float
arguments:
- - type: float *
+ - type: float *
- name: getpayloadf16
standards:
- stdc
diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td
index 5d1c906b931e0..c4cbca80072bf 100644
--- a/libc/spec/llvm_libc_ext.td
+++ b/libc/spec/llvm_libc_ext.td
@@ -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>]>,
]
>;
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index d24d43526fe5c..d3e8938b197d5 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -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>]>,
@@ -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>]>,
@@ -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">,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index a3c9b5473c290..a0bd5269169fa 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -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)
@@ -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)
diff --git a/libc/src/math/fsub.h b/libc/src/math/fsub.h
new file mode 100644
index 0000000000000..f17f0fd3ec307
--- /dev/null
+++ b/libc/src/math/fsub.h
@@ -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
diff --git a/libc/src/math/fsubf128.h b/libc/src/math/fsubf128.h
new file mode 100644
index 0000000000000..4f41c7d8bb04d
--- /dev/null
+++ b/libc/src/math/fsubf128.h
@@ -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
diff --git a/libc/src/math/fsubl.h b/libc/src/math/fsubl.h
new file mode 100644
index 0000000000000..32570ca3dc0f7
--- /dev/null
+++ b/libc/src/math/fsubl.h
@@ -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
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 77f7f4fef007b..be5cc2e02635a 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -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
@@ -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
diff --git a/libc/src/math/generic/fsub.cpp b/libc/src/math/generic/fsub.cpp
new file mode 100644
index 0000000000000..97e28015c0487
--- /dev/null
+++ b/libc/src/math/generic/fsub.cpp
@@ -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
diff --git a/libc/src/math/generic/fsubf128.cpp b/libc/src/math/generic/fsubf128.cpp
new file mode 100644
index 0000000000000..3efb34992b748
--- /dev/null
+++ b/libc/src/math/generic/fsubf128.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of fsubf128 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/fsubf128.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, fsubf128, (float128 x, float128 y)) {
+ return fputil::generic::sub<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fsubl.cpp b/libc/src/math/generic/fsubl.cpp
new file mode 100644
index 0000000000000..cad5a2d5d452a
--- /dev/null
+++ b/libc/src/math/generic/fsubl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of fsubl 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/fsubl.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, fsubl, (long double x, long double y)) {
+ return fputil::generic::sub<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/remainderf128.cpp b/libc/src/math/generic/remainderf128.cpp
new file mode 100644
index 0000000000000..52b6c5149fdcf
--- /dev/null
+++ b/libc/src/math/generic/remainderf128.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of remainderf128 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/remainderf128.h"
+#include "src/__support/FPUtil/DivisionAndRemainderOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float128, remainderf128, (float128 x, float128 y)) {
+ int quotient;
+ return fputil::remquo(x, y, quotient);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/remainderf128.h b/libc/src/math/remainderf128.h
new file mode 100644
index 0000000000000..57f770a853d68
--- /dev/null
+++ b/libc/src/math/remainderf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for remainderf128 -----------------*- 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_REMAINDERF128_H
+#define LLVM_LIBC_SRC_MATH_REMAINDERF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float128 remainderf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_REMAINDERF128_H
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index d209c9a38499b..f3703eb59999b 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2341,6 +2341,32 @@ add_fp_unittest(
libc.src.math.fsqrtl
)
+add_fp_unittest(
+ fsub_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ fsub_test.cpp
+ HDRS
+ SubTest.h
+ DEPENDS
+ libc.src.math.fsub
+)
+
+add_fp_unittest(
+ fsubl_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ fsubl_test.cpp
+ HDRS
+ SubTest.h
+ DEPENDS
+ libc.src.math.fsubl
+)
+
add_fp_unittest(
dsqrtl_test
NEED_MPFR
diff --git a/libc/test/src/math/fsub_test.cpp b/libc/test/src/math/fsub_test.cpp
new file mode 100644
index 0000000000000..3c825f7f28af4
--- /dev/null
+++ b/libc/test/src/math/fsub_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsub ------------------------------------------------===//
+//
+// 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 "SubTest.h"
+
+#include "src/math/fsub.h"
+
+LIST_SUB_TESTS(float, double, LIBC_NAMESPACE::fsub)
diff --git a/libc/test/src/math/fsubl_test.cpp b/libc/test/src/math/fsubl_test.cpp
new file mode 100644
index 0000000000000..8723432603b00
--- /dev/null
+++ b/libc/test/src/math/fsubl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsubl -----------------------------------------------===//
+//
+// 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 "SubTest.h"
+
+#include "src/math/fsubl.h"
+
+LIST_SUB_TESTS(float, long double, LIBC_NAMESPACE::fsubl)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 9aa5399aae9d3..21818e4734a68 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4352,6 +4352,48 @@ add_fp_unittest(
libc.src.math.fsqrtf128
)
+add_fp_unittest(
+ fsub_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fsub_test.cpp
+ HDRS
+ SubTest.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.fsub
+)
+
+add_fp_unittest(
+ fsubl_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fsubl_test.cpp
+ HDRS
+ SubTest.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.fsubl
+)
+
+add_fp_unittest(
+ fsubf128_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fsubf128_test.cpp
+ HDRS
+ SubTest.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.fsubf128
+)
+
add_fp_unittest(
dsqrtl_test
SUITE
diff --git a/libc/test/src/math/smoke/fsub_test.cpp b/libc/test/src/math/smoke/fsub_test.cpp
new file mode 100644
index 0000000000000..3c825f7f28af4
--- /dev/null
+++ b/libc/test/src/math/smoke/fsub_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsub ------------------------------------------------===//
+//
+// 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 "SubTest.h"
+
+#include "src/math/fsub.h"
+
+LIST_SUB_TESTS(float, double, LIBC_NAMESPACE::fsub)
diff --git a/libc/test/src/math/smoke/fsubf128_test.cpp b/libc/test/src/math/smoke/fsubf128_test.cpp
new file mode 100644
index 0000000000000..8f46d91116bde
--- /dev/null
+++ b/libc/test/src/math/smoke/fsubf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsubf128 --------------------------------------------===//
+//
+// 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 "SubTest.h"
+
+#include "src/math/fsubf128.h"
+
+LIST_SUB_TESTS(float, float128, LIBC_NAMESPACE::fsubf128)
diff --git a/libc/test/src/math/smoke/fsubl_test.cpp b/libc/test/src/math/smoke/fsubl_test.cpp
new file mode 100644
index 0000000000000..8723432603b00
--- /dev/null
+++ b/libc/test/src/math/smoke/fsubl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsubl -----------------------------------------------===//
+//
+// 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 "SubTest.h"
+
+#include "src/math/fsubl.h"
+
+LIST_SUB_TESTS(float, long double, LIBC_NAMESPACE::fsubl)
More information about the libc-commits
mailing list