[libc-commits] [libc] 0395bf7 - [libc][math][c23] Add ffma{, l, f128} and fdiv{, l, f128} C23 math functions #101089 (#101253)
via libc-commits
libc-commits at lists.llvm.org
Tue Aug 6 10:20:00 PDT 2024
Author: aaryanshukla
Date: 2024-08-06T10:19:54-07:00
New Revision: 0395bf7636bf0d07f662618107724c28b66c674c
URL: https://github.com/llvm/llvm-project/commit/0395bf7636bf0d07f662618107724c28b66c674c
DIFF: https://github.com/llvm/llvm-project/commit/0395bf7636bf0d07f662618107724c28b66c674c.diff
LOG: [libc][math][c23] Add ffma{,l,f128} and fdiv{,l,f128} C23 math functions #101089 (#101253)
- added all variations of ffma and fdiv
- will add all new headers into yaml for next patch
- only fsub is left then all basic operations for float is complete
---------
Co-authored-by: OverMighty <its.overmighty at gmail.com>
Added:
libc/src/math/fdiv.h
libc/src/math/fdivf128.h
libc/src/math/fdivl.h
libc/src/math/ffma.h
libc/src/math/ffmaf128.h
libc/src/math/ffmal.h
libc/src/math/generic/fdiv.cpp
libc/src/math/generic/fdivf128.cpp
libc/src/math/generic/fdivl.cpp
libc/src/math/generic/ffma.cpp
libc/src/math/generic/ffmaf128.cpp
libc/src/math/generic/ffmal.cpp
libc/test/src/math/fdiv_test.cpp
libc/test/src/math/fdivl_test.cpp
libc/test/src/math/ffma_test.cpp
libc/test/src/math/ffmal_test.cpp
libc/test/src/math/smoke/fdiv_test.cpp
libc/test/src/math/smoke/fdivf128_test.cpp
libc/test/src/math/smoke/fdivl_test.cpp
libc/test/src/math/smoke/ffma_test.cpp
libc/test/src/math/smoke/ffmaf128_test.cpp
libc/test/src/math/smoke/ffmal_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
libc/test/src/math/smoke/DivTest.h
libc/utils/MPFRWrapper/MPFRUtils.cpp
Removed:
################################################################################
diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/arm/entrypoints.txt
index dfbba63d769ee..98a9938fd5331 100644
--- a/libc/config/darwin/arm/entrypoints.txt
+++ b/libc/config/darwin/arm/entrypoints.txt
@@ -165,6 +165,10 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
+ libc.src.math.fdiv
+ libc.src.math.fdivl
+ libc.src.math.ffma
+ libc.src.math.ffmal
libc.src.math.floor
libc.src.math.floorf
libc.src.math.floorl
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 5aa8354a75279..dd1ee477f1ed3 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -132,6 +132,10 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.fdim
#libc.src.math.fdimf
#libc.src.math.fdiml
+ #libc.src.math.fdiv
+ #libc.src.math.fdivl
+ #libc.src.math.ffma
+ #libc.src.math.ffmal
#libc.src.math.floor
#libc.src.math.floorf
#libc.src.math.floorl
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 149c368338276..e211e9a3d557c 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -600,6 +600,10 @@ if(LIBC_TYPES_HAS_FLOAT16)
# libc.src.math.f16subl
libc.src.math.fabsf16
libc.src.math.fdimf16
+ libc.src.math.fdiv
+ libc.src.math.fdivl
+ libc.src.math.ffma
+ libc.src.math.ffmal
libc.src.math.floorf16
libc.src.math.fmaxf16
libc.src.math.fmaximum_mag_numf16
@@ -677,6 +681,8 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.dsubf128
libc.src.math.fabsf128
libc.src.math.fdimf128
+ libc.src.math.fdivf128
+ libc.src.math.ffmaf128
libc.src.math.floorf128
libc.src.math.fmaxf128
libc.src.math.fmaximum_mag_numf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 3dc8aca518305..8a214109f4abc 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -246,6 +246,10 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
+ libc.src.math.fdiv
+ libc.src.math.fdivl
+ libc.src.math.ffma
+ libc.src.math.ffmal
libc.src.math.floor
libc.src.math.floorf
libc.src.math.floorl
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 51fe6f3522d72..8e2eb36f1b89a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -409,6 +409,10 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
+ libc.src.math.fdiv
+ libc.src.math.fdivl
+ libc.src.math.ffma
+ libc.src.math.ffmal
libc.src.math.floor
libc.src.math.floorf
libc.src.math.floorl
@@ -584,6 +588,8 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.dsubf128
libc.src.math.fabsf128
libc.src.math.fdimf128
+ libc.src.math.fdivf128
+ libc.src.math.ffmaf128
libc.src.math.floorf128
libc.src.math.fmaxf128
libc.src.math.fmaximum_mag_numf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 9f36c24ec61ec..2b76487218b13 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -409,6 +409,10 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
+ libc.src.math.fdiv
+ libc.src.math.fdivl
+ libc.src.math.ffma
+ libc.src.math.ffmal
libc.src.math.floor
libc.src.math.floorf
libc.src.math.floorl
@@ -672,6 +676,8 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.dsubf128
libc.src.math.fabsf128
libc.src.math.fdimf128
+ libc.src.math.fdivf128
+ libc.src.math.ffmaf128
libc.src.math.floorf128
libc.src.math.fmaxf128
libc.src.math.fmaximum_mag_numf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index f66438061ef4b..42095e033f9e7 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -155,6 +155,10 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
+ libc.src.math.fdiv
+ libc.src.math.fdivl
+ libc.src.math.ffma
+ libc.src.math.ffmal
libc.src.math.floor
libc.src.math.floorf
libc.src.math.floorl
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 193e0675357ca..92e5fb700d536 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -140,9 +140,9 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fdim | |check| | |check| | |check| | |check| | |check| | 7.12.12.1 | F.10.9.1 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| fdiv | N/A | | | N/A | | 7.12.14.4 | F.10.11 |
+| fdiv | N/A | |check| | |check| | N/A | |check|\* | 7.12.14.4 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| ffma | N/A | | | N/A | | 7.12.14.5 | F.10.11 |
+| ffma | N/A | |check| | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| floor | |check| | |check| | |check| | |check| | |check| | 7.12.9.2 | F.10.6.2 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index 1a5aa0a1d4b59..79d0e9863e9ae 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -1845,6 +1845,53 @@ functions:
- type: float128
- type: float128
guard: LIBC_TYPES_HAS_FLOAT128
+ - name: fdiv
+ standards:
+ - stdc
+ return_type: float
+ arguments:
+ - type: double
+ - type: double
+ - name: fdivl
+ standards:
+ - stdc
+ return_type: float
+ arguments:
+ - type: long double
+ - type: long double
+ - name: fdivf128
+ standards:
+ - llvm_libc_ext
+ return_type: float
+ arguments:
+ - type: float128
+ - type: float128
+ guard: LIBC_TYPES_HAS_FLOAT128
+ - name: ffma
+ standards:
+ - stdc
+ return_type: float
+ arguments:
+ - type: double
+ - type: double
+ - type: double
+ - name: ffmal
+ standards:
+ - stdc
+ return_type: float
+ arguments:
+ - type: long double
+ - type: long double
+ - type: long double
+ - name: ffmaf128
+ standards:
+ - llvm_libc_ext
+ return_type: float
+ arguments:
+ - type: float128
+ - type: float128
+ - type: float128
+ guards: LIBC_TYPES_HAS_FLOAT128
- name: floorf128
standards:
- stdc
diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td
index f86a8c1c6c106..5d1c906b931e0 100644
--- a/libc/spec/llvm_libc_ext.td
+++ b/libc/spec/llvm_libc_ext.td
@@ -71,6 +71,10 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
GuardedFunctionSpec<"f16sub", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"f16subf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"f16subl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
+
+ GuardedFunctionSpec<"fdivf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+
+ GuardedFunctionSpec<"ffmaf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
GuardedFunctionSpec<"fmulf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 400b673953a27..ca7bc5c9b5744 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -414,6 +414,12 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"fdiml", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"fdimf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"fdimf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+
+ FunctionSpec<"fdiv", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
+ FunctionSpec<"fdivl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
+
+ FunctionSpec<"ffma", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
+ FunctionSpec<"ffmal", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"floor", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"floorf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 1730eec181877..6accddb7e5e84 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -167,6 +167,14 @@ add_math_entrypoint_object(fdiml)
add_math_entrypoint_object(fdimf16)
add_math_entrypoint_object(fdimf128)
+add_math_entrypoint_object(fdiv)
+add_math_entrypoint_object(fdivl)
+add_math_entrypoint_object(fdivf128)
+
+add_math_entrypoint_object(ffma)
+add_math_entrypoint_object(ffmal)
+add_math_entrypoint_object(ffmaf128)
+
add_math_entrypoint_object(floor)
add_math_entrypoint_object(floorf)
add_math_entrypoint_object(floorl)
diff --git a/libc/src/math/fdiv.h b/libc/src/math/fdiv.h
new file mode 100644
index 0000000000000..4d60afaf469f3
--- /dev/null
+++ b/libc/src/math/fdiv.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for fdiv --------------------------*- 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_FDIV_H
+#define LLVM_LIBC_SRC_MATH_FDIV_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float fdiv(double x, double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FDIV_H
diff --git a/libc/src/math/fdivf128.h b/libc/src/math/fdivf128.h
new file mode 100644
index 0000000000000..1a150389b6859
--- /dev/null
+++ b/libc/src/math/fdivf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for fdivf128 ----------------------*- 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_FDIVF128_H
+#define LLVM_LIBC_SRC_MATH_FDIVF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float fdivf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FDIVF128_H
diff --git a/libc/src/math/fdivl.h b/libc/src/math/fdivl.h
new file mode 100644
index 0000000000000..1943eaae7783c
--- /dev/null
+++ b/libc/src/math/fdivl.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for fdivl -------------------------*- 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_FDIVL_H
+#define LLVM_LIBC_SRC_MATH_FDIVL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float fdivl(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FDIVL_H
diff --git a/libc/src/math/ffma.h b/libc/src/math/ffma.h
new file mode 100644
index 0000000000000..98d89f2eef983
--- /dev/null
+++ b/libc/src/math/ffma.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for ffma --------------------------*- 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_FFMA_H
+#define LLVM_LIBC_SRC_MATH_FFMA_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float ffma(double x, double y, double z);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FFMA_H
diff --git a/libc/src/math/ffmaf128.h b/libc/src/math/ffmaf128.h
new file mode 100644
index 0000000000000..741099780b8d5
--- /dev/null
+++ b/libc/src/math/ffmaf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for ffmaf128 ----------------------*- 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_FFMAF128_H
+#define LLVM_LIBC_SRC_MATH_FFMAF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float ffmaf128(float128 x, float128 y, float128 z);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FFMAF128_H
diff --git a/libc/src/math/ffmal.h b/libc/src/math/ffmal.h
new file mode 100644
index 0000000000000..75fd40a0a92a2
--- /dev/null
+++ b/libc/src/math/ffmal.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for ffmal -------------------------*- 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_FFMAL_H
+#define LLVM_LIBC_SRC_MATH_FFMAL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float ffmal(long double x, long double y, long double z);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FFMAL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 7574f6c22bc17..445c070243999 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3145,6 +3145,80 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
)
+add_entrypoint_object(
+ fdiv
+ SRCS
+ fdiv.cpp
+ HDRS
+ ../fdiv.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.FPUtil.generic.div
+)
+
+add_entrypoint_object(
+ fdivl
+ SRCS
+ fdivl.cpp
+ HDRS
+ ../fdivl.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.FPUtil.generic.div
+)
+
+add_entrypoint_object(
+ fdivf128
+ SRCS
+ fdivf128.cpp
+ HDRS
+ ../fdivf128.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.generic.div
+)
+
+add_entrypoint_object(
+ ffma
+ SRCS
+ ffma.cpp
+ HDRS
+ ../ffma.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+)
+
+add_entrypoint_object(
+ ffmal
+ SRCS
+ ffmal.cpp
+ HDRS
+ ../ffmal.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.FPUtil.fma
+)
+
+add_entrypoint_object(
+ ffmaf128
+ SRCS
+ ffmaf128.cpp
+ HDRS
+ ../ffmaf128.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.fma
+)
+
add_entrypoint_object(
hypot
SRCS
diff --git a/libc/src/math/generic/fdiv.cpp b/libc/src/math/generic/fdiv.cpp
new file mode 100644
index 0000000000000..1d97fade22a37
--- /dev/null
+++ b/libc/src/math/generic/fdiv.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of fdiv 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/fdiv.h"
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, fdiv, (double x, double y)) {
+ return fputil::generic::div<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fdivf128.cpp b/libc/src/math/generic/fdivf128.cpp
new file mode 100644
index 0000000000000..192f13f5de10e
--- /dev/null
+++ b/libc/src/math/generic/fdivf128.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of fdivf128 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/fdivf128.h"
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, fdivf128, (float128 x, float128 y)) {
+ return fputil::generic::div<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fdivl.cpp b/libc/src/math/generic/fdivl.cpp
new file mode 100644
index 0000000000000..dcd5debc2acd9
--- /dev/null
+++ b/libc/src/math/generic/fdivl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of fdivl 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/fdivl.h"
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, fdivl, (long double x, long double y)) {
+ return fputil::generic::div<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ffma.cpp b/libc/src/math/generic/ffma.cpp
new file mode 100644
index 0000000000000..a4c834ddd7986
--- /dev/null
+++ b/libc/src/math/generic/ffma.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of ffma 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/ffma.h"
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, ffma, (double x, double y, double z)) {
+ return fputil::fma<float>(x, y, z);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ffmaf128.cpp b/libc/src/math/generic/ffmaf128.cpp
new file mode 100644
index 0000000000000..55da93020faf3
--- /dev/null
+++ b/libc/src/math/generic/ffmaf128.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of ffmaf128 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/ffmaf128.h"
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, ffmaf128, (float128 x, float128 y, float128 z)) {
+ return fputil::fma<float>(x, y, z);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ffmal.cpp b/libc/src/math/generic/ffmal.cpp
new file mode 100644
index 0000000000000..d5cd4f763cbe5
--- /dev/null
+++ b/libc/src/math/generic/ffmal.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of ffmal 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/ffmal.h"
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, ffmal,
+ (long double x, long double y, long double z)) {
+ return fputil::fma<float>(x, y, z);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 7cb24f85170bc..5578e83e84845 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2455,6 +2455,63 @@ add_fp_unittest(
libc.src.math.dsubl
)
+add_fp_unittest(
+ fdiv_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ fdiv_test.cpp
+ HDRS
+ DivTest.h
+ DEPENDS
+ libc.src.math.fdiv
+)
+
+add_fp_unittest(
+ fdivl_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ fdivl_test.cpp
+ HDRS
+ DivTest.h
+ DEPENDS
+ libc.src.math.fdivl
+)
+
+
+add_fp_unittest(
+ ffma_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ ffma_test.cpp
+ HDRS
+ FmaTest.h
+ DEPENDS
+ libc.src.math.ffma
+ libc.src.stdlib.rand
+ libc.src.stdlib.srand
+)
+
+add_fp_unittest(
+ ffmal_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ ffmal_test.cpp
+ HDRS
+ FmaTest.h
+ DEPENDS
+ libc.src.math.ffmal
+ libc.src.stdlib.rand
+ libc.src.stdlib.srand
+)
+
add_subdirectory(generic)
add_subdirectory(smoke)
diff --git a/libc/test/src/math/fdiv_test.cpp b/libc/test/src/math/fdiv_test.cpp
new file mode 100644
index 0000000000000..f0bd602003b28
--- /dev/null
+++ b/libc/test/src/math/fdiv_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fdiv ------------------------------------------------===//
+//
+// 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 "DivTest.h"
+
+#include "src/math/fdiv.h"
+
+LIST_DIV_TESTS(float, double, LIBC_NAMESPACE::fdiv)
diff --git a/libc/test/src/math/fdivl_test.cpp b/libc/test/src/math/fdivl_test.cpp
new file mode 100644
index 0000000000000..bc2b0e4d9f060
--- /dev/null
+++ b/libc/test/src/math/fdivl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fdivl -----------------------------------------------===//
+//
+// 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 "DivTest.h"
+
+#include "src/math/fdivl.h"
+
+LIST_DIV_TESTS(float, long double, LIBC_NAMESPACE::fdivl)
diff --git a/libc/test/src/math/ffma_test.cpp b/libc/test/src/math/ffma_test.cpp
new file mode 100644
index 0000000000000..4b6a25c50d15c
--- /dev/null
+++ b/libc/test/src/math/ffma_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ffma ------------------------------------------------===//
+//
+// 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 "FmaTest.h"
+
+#include "src/math/ffma.h"
+
+LIST_NARROWING_FMA_TESTS(float, double, LIBC_NAMESPACE::ffma)
diff --git a/libc/test/src/math/ffmal_test.cpp b/libc/test/src/math/ffmal_test.cpp
new file mode 100644
index 0000000000000..200d9e16839d0
--- /dev/null
+++ b/libc/test/src/math/ffmal_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ffmal -----------------------------------------------===//
+//
+// 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 "FmaTest.h"
+
+#include "src/math/ffmal.h"
+
+LIST_NARROWING_FMA_TESTS(float, long double, LIBC_NAMESPACE::ffmal)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 07d5d78d57996..e1c95b6196a8d 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4070,8 +4070,8 @@ add_fp_unittest(
HDRS
DivTest.h
DEPENDS
+ libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.__support.FPUtil.basic_operations
libc.src.math.f16div
)
@@ -4084,8 +4084,8 @@ add_fp_unittest(
HDRS
DivTest.h
DEPENDS
+ libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.__support.FPUtil.basic_operations
libc.src.math.f16divf
)
@@ -4098,8 +4098,8 @@ add_fp_unittest(
HDRS
DivTest.h
DEPENDS
+ libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.__support.FPUtil.basic_operations
libc.src.math.f16divl
)
@@ -4112,8 +4112,8 @@ add_fp_unittest(
HDRS
DivTest.h
DEPENDS
+ libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.__support.FPUtil.basic_operations
libc.src.math.f16divf128
)
@@ -4213,6 +4213,84 @@ add_fp_unittest(
libc.src.math.f16sqrtf128
)
+add_fp_unittest(
+ fdiv_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fdiv_test.cpp
+ HDRS
+ DivTest.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.fdiv
+)
+
+add_fp_unittest(
+ fdivl_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fdivl_test.cpp
+ HDRS
+ DivTest.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.fdivl
+)
+
+add_fp_unittest(
+ fdivf128_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fdivf128_test.cpp
+ HDRS
+ DivTest.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.fdivf128
+)
+
+add_fp_unittest(
+ ffma_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ ffma_test.cpp
+ HDRS
+ FmaTest.h
+ DEPENDS
+ libc.src.math.ffma
+)
+
+add_fp_unittest(
+ ffmal_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ ffmal_test.cpp
+ HDRS
+ FmaTest.h
+ DEPENDS
+ libc.src.math.ffmal
+)
+
+add_fp_unittest(
+ ffmaf128_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ ffmaf128_test.cpp
+ HDRS
+ FmaTest.h
+ DEPENDS
+ libc.src.math.ffmaf128
+)
+
add_fp_unittest(
fsqrt_test
SUITE
diff --git a/libc/test/src/math/smoke/DivTest.h b/libc/test/src/math/smoke/DivTest.h
index b30fc17aac1d5..666179628c55f 100644
--- a/libc/test/src/math/smoke/DivTest.h
+++ b/libc/test/src/math/smoke/DivTest.h
@@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_DIVTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_DIVTEST_H
+#include "hdr/errno_macros.h"
#include "hdr/fenv_macros.h"
-#include "src/__support/FPUtil/BasicOperations.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/RoundingModeUtils.h"
diff --git a/libc/test/src/math/smoke/fdiv_test.cpp b/libc/test/src/math/smoke/fdiv_test.cpp
new file mode 100644
index 0000000000000..f0bd602003b28
--- /dev/null
+++ b/libc/test/src/math/smoke/fdiv_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fdiv ------------------------------------------------===//
+//
+// 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 "DivTest.h"
+
+#include "src/math/fdiv.h"
+
+LIST_DIV_TESTS(float, double, LIBC_NAMESPACE::fdiv)
diff --git a/libc/test/src/math/smoke/fdivf128_test.cpp b/libc/test/src/math/smoke/fdivf128_test.cpp
new file mode 100644
index 0000000000000..a687e079b597e
--- /dev/null
+++ b/libc/test/src/math/smoke/fdivf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fdivf128 --------------------------------------------===//
+//
+// 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 "DivTest.h"
+
+#include "src/math/fdivf128.h"
+
+LIST_DIV_TESTS(float, float128, LIBC_NAMESPACE::fdivf128)
diff --git a/libc/test/src/math/smoke/fdivl_test.cpp b/libc/test/src/math/smoke/fdivl_test.cpp
new file mode 100644
index 0000000000000..bc2b0e4d9f060
--- /dev/null
+++ b/libc/test/src/math/smoke/fdivl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fdivl -----------------------------------------------===//
+//
+// 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 "DivTest.h"
+
+#include "src/math/fdivl.h"
+
+LIST_DIV_TESTS(float, long double, LIBC_NAMESPACE::fdivl)
diff --git a/libc/test/src/math/smoke/ffma_test.cpp b/libc/test/src/math/smoke/ffma_test.cpp
new file mode 100644
index 0000000000000..4b6a25c50d15c
--- /dev/null
+++ b/libc/test/src/math/smoke/ffma_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ffma ------------------------------------------------===//
+//
+// 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 "FmaTest.h"
+
+#include "src/math/ffma.h"
+
+LIST_NARROWING_FMA_TESTS(float, double, LIBC_NAMESPACE::ffma)
diff --git a/libc/test/src/math/smoke/ffmaf128_test.cpp b/libc/test/src/math/smoke/ffmaf128_test.cpp
new file mode 100644
index 0000000000000..a8f81e253df2f
--- /dev/null
+++ b/libc/test/src/math/smoke/ffmaf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ffmaf128 --------------------------------------------===//
+//
+// 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 "FmaTest.h"
+
+#include "src/math/ffmaf128.h"
+
+LIST_NARROWING_FMA_TESTS(float, float128, LIBC_NAMESPACE::ffmaf128)
diff --git a/libc/test/src/math/smoke/ffmal_test.cpp b/libc/test/src/math/smoke/ffmal_test.cpp
new file mode 100644
index 0000000000000..200d9e16839d0
--- /dev/null
+++ b/libc/test/src/math/smoke/ffmal_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ffmal -----------------------------------------------===//
+//
+// 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 "FmaTest.h"
+
+#include "src/math/ffmal.h"
+
+LIST_NARROWING_FMA_TESTS(float, long double, LIBC_NAMESPACE::ffmal)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 4263c9dccb6a5..7ce6a70d09316 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -1080,15 +1080,19 @@ void explain_ternary_operation_one_output_error(
template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<float> &, float, double, RoundingMode);
+template void explain_ternary_operation_one_output_error(
+ Operation, const TernaryInput<double> &, float, double, RoundingMode);
template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<double> &, double, double, RoundingMode);
+template void explain_ternary_operation_one_output_error(
+ Operation, const TernaryInput<long double> &, float, double, RoundingMode);
+template void explain_ternary_operation_one_output_error(
+ Operation, const TernaryInput<long double> &, double, double, RoundingMode);
template void
explain_ternary_operation_one_output_error(Operation,
const TernaryInput<long double> &,
long double, double, RoundingMode);
-template void explain_ternary_operation_one_output_error(
- Operation, const TernaryInput<long double> &, double, double, RoundingMode);
#ifdef LIBC_TYPES_HAS_FLOAT16
template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<float> &, float16, double, RoundingMode);
@@ -1266,17 +1270,22 @@ bool compare_ternary_operation_one_output(Operation op,
template bool compare_ternary_operation_one_output(Operation,
const TernaryInput<float> &,
float, double, RoundingMode);
+template bool compare_ternary_operation_one_output(Operation,
+ const TernaryInput<double> &,
+ float, double, RoundingMode);
template bool compare_ternary_operation_one_output(Operation,
const TernaryInput<double> &,
double, double,
RoundingMode);
+template bool compare_ternary_operation_one_output(
+ Operation, const TernaryInput<long double> &, float, double, RoundingMode);
+template bool compare_ternary_operation_one_output(
+ Operation, const TernaryInput<long double> &, double, double, RoundingMode);
template bool
compare_ternary_operation_one_output(Operation,
const TernaryInput<long double> &,
long double, double, RoundingMode);
-template bool compare_ternary_operation_one_output(
- Operation, const TernaryInput<long double> &, double, double, RoundingMode);
#ifdef LIBC_TYPES_HAS_FLOAT16
template bool compare_ternary_operation_one_output(Operation,
const TernaryInput<float> &,
More information about the libc-commits
mailing list