Skip to content

[libc][math][c23] Add dfma{l,f128} and dsub{l,f128} C23 math functions #101089

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 16 commits into from
Jul 31, 2024

Conversation

aaryanshukla
Copy link
Contributor

@aaryanshukla aaryanshukla commented Jul 29, 2024

No description provided.

@llvmbot llvmbot added the libc label Jul 29, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2024

@llvm/pr-subscribers-libc

Author: None (aaryanshukla)

Changes
  • [libc][math]: implemented dfma and dsub
  • functions
  • fixed entrypoints
  • adding
  • everything but index.rst
  • [libc][math][c23]

Patch is 26.55 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/101089.diff

32 Files Affected:

  • (modified) libc/config/baremetal/arm/entrypoints.txt (+2)
  • (modified) libc/config/baremetal/riscv/entrypoints.txt (+2)
  • (modified) libc/config/darwin/arm/entrypoints.txt (+2)
  • (modified) libc/config/darwin/x86_64/entrypoints.txt (+2)
  • (modified) libc/config/linux/aarch64/entrypoints.txt (+4)
  • (modified) libc/config/linux/arm/entrypoints.txt (+2)
  • (modified) libc/config/linux/riscv/entrypoints.txt (+2)
  • (modified) libc/config/linux/x86_64/entrypoints.txt (+5)
  • (modified) libc/config/windows/entrypoints.txt (+2)
  • (modified) libc/docs/math/index.rst (+2-2)
  • (modified) libc/spec/llvm_libc_ext.td (+3)
  • (modified) libc/spec/stdc.td (+7)
  • (modified) libc/src/math/CMakeLists.txt (+4-1)
  • (added) libc/src/math/dfmaf128.h (+21)
  • (added) libc/src/math/dfmal.h (+21)
  • (added) libc/src/math/dsubf128.h (+21)
  • (added) libc/src/math/dsubl.h (+19)
  • (modified) libc/src/math/generic/CMakeLists.txt (+51)
  • (added) libc/src/math/generic/dfmaf128.cpp (+26)
  • (added) libc/src/math/generic/dfmal.cpp (+21)
  • (added) libc/src/math/generic/dsubf128.cpp (+20)
  • (added) libc/src/math/generic/dsubl.cpp (+20)
  • (modified) libc/test/src/math/CMakeLists.txt (+52)
  • (added) libc/test/src/math/dfmaf128_test.cpp (+13)
  • (added) libc/test/src/math/dfmal_test.cpp (+13)
  • (added) libc/test/src/math/dsubf128_test.cpp (+13)
  • (added) libc/test/src/math/dsubl_test.cpp (+13)
  • (modified) libc/test/src/math/smoke/CMakeLists.txt (+48)
  • (added) libc/test/src/math/smoke/dfmaf128_test.cpp (+13)
  • (added) libc/test/src/math/smoke/dfmal_test.cpp (+13)
  • (added) libc/test/src/math/smoke/dsubf128_test.cpp (+13)
  • (added) libc/test/src/math/smoke/dsubl_test.cpp (+13)
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 8025ac09b9f82..cd43e2ba19e45 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -247,6 +247,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.cos
     libc.src.math.cosf
     libc.src.math.coshf
+    libc.src.math.dfmal
+    libc.src.math.dsubl
     libc.src.math.erff
     libc.src.math.exp
     libc.src.math.exp10
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index fb0308c953746..e8452d273556a 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -243,6 +243,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.cos
     libc.src.math.cosf
     libc.src.math.coshf
+    libc.src.math.dfmal
+    libc.src.math.dsubl
     libc.src.math.erff
     libc.src.math.exp
     libc.src.math.exp10
diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/arm/entrypoints.txt
index ea5c7b537bbec..6d524da677409 100644
--- a/libc/config/darwin/arm/entrypoints.txt
+++ b/libc/config/darwin/arm/entrypoints.txt
@@ -135,6 +135,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.cos
     libc.src.math.cosf
     libc.src.math.cospif
+    libc.src.math.dfmal
+    libc.src.math.dsubl
     libc.src.math.dsqrtl
     libc.src.math.erff
     libc.src.math.exp
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 1a7353172d464..ff3abb233ba8a 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -119,7 +119,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.ceill
     #libc.src.math.coshf
     #libc.src.math.cosf
+    #libc.src.math.dfmal
     #libc.src.math.dsqrtl
+    #libc.src.math.dsubl
     #libc.src.math.expf
     #libc.src.math.exp2f
     #libc.src.math.expm1f
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 0be6f884f0368..d055943f9642d 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -358,8 +358,10 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.cosf
     libc.src.math.coshf
     libc.src.math.cospif
+    libc.src.math.dfmal
     libc.src.math.dmull
     libc.src.math.dsqrtl
+    libc.src.math.dsubl
     libc.src.math.erff
     libc.src.math.exp
     libc.src.math.exp10
@@ -599,7 +601,9 @@ if(LIBC_TYPES_HAS_FLOAT128)
     # math.h C23 _Float128 entrypoints
     libc.src.math.ceilf128
     libc.src.math.copysignf128
+    libc.src.math.dfmaf128
     libc.src.math.dsqrtf128
+    libc.src.math.dsubf128
     libc.src.math.fabsf128
     libc.src.math.fdimf128
     libc.src.math.floorf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 55f118395c22e..0f9097d0859cc 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -227,7 +227,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.cos
     libc.src.math.cosf
     libc.src.math.coshf
+    libc.src.math.dfmal
     libc.src.math.dsqrtl
+    libc.src.math.dsubl
     libc.src.math.erff
     libc.src.math.exp
     libc.src.math.exp10
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 597aeb361afe4..8293b7b2e3828 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -383,8 +383,10 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.cosf
     libc.src.math.coshf
     libc.src.math.cospif
+    libc.src.math.dfmal
     libc.src.math.dmull
     libc.src.math.dsqrtl
+    libc.src.math.dsubl
     libc.src.math.erff
     libc.src.math.exp
     libc.src.math.exp10
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index f7813fc16ff7c..0d91ae5310d26 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -383,8 +383,10 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.cosf
     libc.src.math.coshf
     libc.src.math.cospif
+    libc.src.math.dfmal
     libc.src.math.dmull
     libc.src.math.dsqrtl
+    libc.src.math.dsubl
     libc.src.math.erff
     libc.src.math.exp
     libc.src.math.exp10
@@ -559,6 +561,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.canonicalizef16
     libc.src.math.ceilf16
     libc.src.math.copysignf16
+    
     libc.src.math.f16add
     libc.src.math.f16addf
     libc.src.math.f16addl
@@ -645,8 +648,10 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.canonicalizef128
     libc.src.math.ceilf128
     libc.src.math.copysignf128
+    libc.src.math.dfmaf128
     libc.src.math.dmulf128
     libc.src.math.dsqrtf128
+    libc.src.math.dsubf128
     libc.src.math.fabsf128
     libc.src.math.fdimf128
     libc.src.math.floorf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index b6aced83c5815..b72cc09fa28f5 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -132,6 +132,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.cos
     libc.src.math.cosf
     libc.src.math.coshf
+    libc.src.math.dfmal
+    libc.src.math.dsubl
     libc.src.math.erff
     libc.src.math.exp
     libc.src.math.expf
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index f287c16fd01e2..07ce817bb7e64 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -118,11 +118,11 @@ Basic Operations
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | ddiv             | N/A              | N/A             |                        | N/A                  |                        | 7.12.14.4              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| dfma             | N/A              | N/A             |                        | N/A                  |                        | 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                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| dsub             | N/A              | N/A             |                        | N/A                  |                        | 7.12.14.2              | F.10.11                    |
+| dsub             | N/A              | N/A             | |check|                | N/A                  | |check|\*              | 7.12.14.2              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | f16add           | |check|\*        | |check|\*       | |check|\*              | N/A                  | |check|                | 7.12.14.1              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td
index f3a8862574ac5..8503f66f34b54 100644
--- a/libc/spec/llvm_libc_ext.td
+++ b/libc/spec/llvm_libc_ext.td
@@ -57,7 +57,10 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
       [], // Types
       [], // Enumerations
       [
+          GuardedFunctionSpec<"dfmaf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
           GuardedFunctionSpec<"dsqrtf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+          GuardedFunctionSpec<"dsubf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+
 	  
           GuardedFunctionSpec<"f16add", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
           GuardedFunctionSpec<"f16addf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 0aae65308d33a..880046d6fb344 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -397,6 +397,13 @@ def StdC : StandardSpec<"stdc"> {
           GuardedFunctionSpec<"ceilf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
           GuardedFunctionSpec<"ceilf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
 
+          FunctionSpec<"dfmal", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
+          FunctionSpec<"dfmaf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<Float128Type]>,
+          FunctionSpec<"dsubl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
+          
+
+
+
           FunctionSpec<"fabs", RetValSpec<DoubleType>, [ArgSpec<DoubleType>], [ConstAttr]>,
           FunctionSpec<"fabsf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
           FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 25aef3f72e3cd..a816076d3919f 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -88,9 +88,12 @@ add_math_entrypoint_object(cospif)
 
 add_math_entrypoint_object(dmull)
 add_math_entrypoint_object(dmulf128)
-
+add_math_entrypoint_object(dfmal)
+add_math_entrypoint_object(dfmaf128)
 add_math_entrypoint_object(dsqrtl)
 add_math_entrypoint_object(dsqrtf128)
+add_math_entrypoint_object(dsubl)
+add_math_entrypoint_object(dsubf128)
 
 add_math_entrypoint_object(erf)
 add_math_entrypoint_object(erff)
diff --git a/libc/src/math/dfmaf128.h b/libc/src/math/dfmaf128.h
new file mode 100644
index 0000000000000..1b2e72851c806
--- /dev/null
+++ b/libc/src/math/dfmaf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for dfmaf128 ----------------------*- 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_DFMAF128_H
+#define LLVM_LIBC_SRC_MATH_DFMAF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+double dfmaf128(float128 x, float128 y, float128 z);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_DFMAF128_H
diff --git a/libc/src/math/dfmal.h b/libc/src/math/dfmal.h
new file mode 100644
index 0000000000000..a31fa5b5838fe
--- /dev/null
+++ b/libc/src/math/dfmal.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for dfmal --------------------*- 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_DFMAL_H
+#define LLVM_LIBC_SRC_MATH_DFMAL_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+double dfmal(long double x, long double y, long double z);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_DFMAL_H
diff --git a/libc/src/math/dsubf128.h b/libc/src/math/dsubf128.h
new file mode 100644
index 0000000000000..8ac58a916f0de
--- /dev/null
+++ b/libc/src/math/dsubf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for dsubf128 ----------------------*- 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_DSUBF128_H
+#define LLVM_LIBC_SRC_MATH_DSUBF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+double dsubf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_DSUBF128_H
diff --git a/libc/src/math/dsubl.h b/libc/src/math/dsubl.h
new file mode 100644
index 0000000000000..4dc396c2731a1
--- /dev/null
+++ b/libc/src/math/dsubl.h
@@ -0,0 +1,19 @@
+//===-- Implementation header for dsubl -------------------------*- 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_DSUBL_H
+#define LLVM_LIBC_SRC_MATH_DSUBL_H
+
+#include "src/__support/macros/config.h"
+namespace LIBC_NAMESPACE_DECL {
+
+double dsubl(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_DSUBL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index ef96d6c4c2f37..fea64e9a9c601 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -129,6 +129,31 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  dfmaf128
+  SRCS
+    dfmaf128.cpp
+  HDRS
+    ../dfmaf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.fma
+    libc.src.__support.macros.properties.types
+  COMPILE_OPTIONS
+    -O3
+)
+
+add_entrypoint_object(
+  dfmal
+  SRCS
+    dfmal.cpp
+  HDRS
+    ../dfmal.h
+  DEPENDS
+    libc.src.__support.FPUtil.fma
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_entrypoint_object(
   dsqrtl
   SRCS
@@ -154,6 +179,32 @@ add_entrypoint_object(
     -O3
 )
 
+
+add_entrypoint_object(
+  dsubf128
+  SRCS
+    dsubf128.cpp
+  HDRS
+    ../dsubf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.properties.types
+  COMPILE_OPTIONS
+    -O3
+)
+
+add_entrypoint_object(
+  dsubl
+  SRCS
+    dsubl.cpp
+  HDRS
+    ../dsubl.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_header_library(
   range_reduction
   HDRS
diff --git a/libc/src/math/generic/dfmaf128.cpp b/libc/src/math/generic/dfmaf128.cpp
new file mode 100644
index 0000000000000..5bc15df9051c3
--- /dev/null
+++ b/libc/src/math/generic/dfmaf128.cpp
@@ -0,0 +1,26 @@
+//===-- Implementation header for dfmaf128 ----------------------*- 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_DFMAf128_H
+#define LLVM_LIBC_SRC_MATH_DFMAf128_H
+
+#include "src/__support/macros/config.h"
+#include "src/math/dfmaf128.h"
+#include "src/__support/macros/properties/types.h"
+#include "src/__support/FPUtil/FMA.h"
+
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(double, dfmaf128, (float128 x, float128 y, float128 z)) {
+  return fputil::generic::fma<double>(x, y, z);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_DFMAf128_H
diff --git a/libc/src/math/generic/dfmal.cpp b/libc/src/math/generic/dfmal.cpp
new file mode 100644
index 0000000000000..02e0ce84ace83
--- /dev/null
+++ b/libc/src/math/generic/dfmal.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of dfmal 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/dfmal.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(double, dfmal,
+                   (long double x, long double y, long double z)) {
+  return fputil::fma<double>(x, y, z);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/dsubf128.cpp b/libc/src/math/generic/dsubf128.cpp
new file mode 100644
index 0000000000000..1b2f1214b3a6f
--- /dev/null
+++ b/libc/src/math/generic/dsubf128.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of dsubf128 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/dsubf128.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(double, dsubf128, (float128 x, float128 y)) {
+  return fputil::generic::sub<double>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/dsubl.cpp b/libc/src/math/generic/dsubl.cpp
new file mode 100644
index 0000000000000..8b567d0869d2a
--- /dev/null
+++ b/libc/src/math/generic/dsubl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of dsubl 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/dsubl.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(double, dsubl, (long double x, long double y)) {
+  return fputil::generic::sub<double>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 3ad5d98858165..a1d79d91c6a61 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2368,6 +2368,58 @@ add_fp_unittest(
     libc.src.stdlib.srand
 )
 
+add_fp_unittest(
+  dfmal_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    dfmal_test.cpp
+  HDRS
+    FmaTest.h
+  DEPENDS
+    libc.src.math.dfmal
+)
+
+add_fp_unittest(
+  dfmaf128_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    dfmaf128_test.cpp
+  HDRS
+    FmaTest.h
+  DEPENDS
+    libc.src.math.dfmaf128
+)
+
+add_fp_unittest(
+  dsubl_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    dsubl_test.cpp
+  HDRS
+    SubTest.h
+  DEPENDS
+    libc.src.math.dsubl
+)
+
+add_fp_unittest(
+  dsubf128_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    dsubf128_test.cpp
+  HDRS
+    SubTest.h
+  DEPENDS
+    libc.src.math.dsubf128
+)
+
 add_subdirectory(generic)
 add_subdirectory(smoke)
 
diff --git a/libc/test/src/math/dfmaf128_test.cpp b/libc/test/src/math/dfmaf128_test....
[truncated]

@aaryanshukla aaryanshukla changed the title d math functions [libc][math][c23] Add dfma{l,f128} and dsub{l,f128} C23 math functions Jul 29, 2024
Copy link

github-actions bot commented Jul 29, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@overmighty overmighty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest you use https://github.com/overmighty/llvm-dev-utils/blob/master/llvm_libc_add_math_function.py to save time. For example:

for type in 'l' 'f128'; do
  ~/projects/llvm-dev-utils/llvm_libc_add_math_function.py "${type}" 'double' 'dfma' 'TYPE x, TYPE y, TYPE z' 'FmaTest' 'LIST_NARROWING_FMA_TESTS'
  ~/projects/llvm-dev-utils/llvm_libc_add_math_function.py "${type}" 'double' 'dsub' 'TYPE x, TYPE y' 'SubTest' 'LIST_SUB_TESTS'
done

Right now it generates the header, implementation file boilerplate, and smoke test based on a test template header. It doesn't generate MPFR tests yet.

@overmighty
Copy link
Member

Since you're adding smoke tests that use SubTest.h, I pushed a commit that updates the SubTest.h dependencies, if you don't mind.

@overmighty
Copy link
Member

overmighty commented Jul 30, 2024

You should test locally with either:

cmake --build path/to/your/build/directory --target libc-math-unittests

or:

cmake --build path/to/your/build/directory --target check-libc

Part of the reason why the CI failed is that you need to add new explicit template instantiations in libc/utils/MPFRWrapper/MPFRUtils.cpp for functions that take long double inputs and output a double.

included long double inp and double output template
removed from riscv entrypoints
removed dfmaf128 and dsubf128 from MPFR
@aaryanshukla
Copy link
Contributor Author

@overmighty @lntue should I merge this now?

Comment on lines 397 to 413
DEPENDS
libc.src.errno.errno
libc.hdr.fenv_macros
libc.src.math.dsubl
)

add_fp_unittest(
dsubf128_test
SUITE
libc-math-smoke-tests
SRCS
dsubf128_test.cpp
HDRS
SubTest.h
DEPENDS
libc.src.errno.errno
libc.hdr.fenv_macros
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have been libc.hdr.errno_macros instead of libc.src.errno.errno here.

Copy link
Member

@overmighty overmighty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM besides a last issue: FMA smoke tests having unused dependencies. You should look at the dependencies of the respective f16* functions and copy them unless you find that the dependency list is wrong.

@aaryanshukla aaryanshukla merged commit 30b5d4a into llvm:main Jul 31, 2024
7 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 31, 2024

LLVM Buildbot has detected a new failure on builder libc-arm32-debian-dbg running on libc-arm32-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/182/builds/1731

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[       OK ] LlvmLibcCeilTest.RoundedNubmers (22 us)
[ RUN      ] LlvmLibcCeilTest.Fractions
[       OK ] LlvmLibcCeilTest.Fractions (43 us)
Ran 3 tests.  PASS: 3  FAIL: 0
[138/700] Running unit test libc.test.src.math.smoke.dfmal_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFmaTest.SpecialNumbers
[       OK ] LlvmLibcFmaTest.SpecialNumbers (101 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[139/700] Running unit test libc.test.src.math.smoke.dsubl_test.__unit__
FAILED: projects/libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.dsubl_test.__unit__ /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.dsubl_test.__unit__ 
cd /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/test/src/math/smoke && /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/test/src/math/smoke/libc.test.src.math.smoke.dsubl_test.__unit__.__build__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcSubTest.SpecialNumbers
[       OK ] LlvmLibcSubTest.SpecialNumbers (53 us)
[ RUN      ] LlvmLibcSubTest.InvalidOperations
[       OK ] LlvmLibcSubTest.InvalidOperations (19 us)
[ RUN      ] LlvmLibcSubTest.RangeErrors
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:67: FAILURE
Failed to match func(in.min_denormal, in.neg_min_denormal) against LIBC_NAMESPACE::testing::getMatcher< LIBC_NAMESPACE::testing::TestCond::EQ>(zero).
Expected floating point value: 0x0000000000000000 = (S: 0, E: 0x0000, M: 0x0000000000000000)
Actual floating point value: 0x0000000000000001 = (S: 0, E: 0x0000, M: 0x0000000000000001)
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:67: FAILURE
      Expected: __llvm_libc_19_0_0_git::fputil::test_except((1 | 2 | 4 | 8 | 16)) & ((8 | 16) ? (8 | 16) : (1 | 2 | 4 | 8 | 16))
      Which is: 0
To be equal to: (8 | 16)
      Which is: 24
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:68: FAILURE
      Expected: actual
      Which is: 0
To be equal to: 34
      Which is: 34
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:71: FAILURE
Failed to match func(in.neg_min_denormal, in.min_denormal) against LIBC_NAMESPACE::testing::getMatcher< LIBC_NAMESPACE::testing::TestCond::EQ>(neg_zero).
Expected floating point value: 0x8000000000000000 = (S: 1, E: 0x0000, M: 0x0000000000000000)
Actual floating point value: 0x8000000000000001 = (S: 1, E: 0x0000, M: 0x0000000000000001)
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:71: FAILURE
      Expected: __llvm_libc_19_0_0_git::fputil::test_except((1 | 2 | 4 | 8 | 16)) & ((8 | 16) ? (8 | 16) : (1 | 2 | 4 | 8 | 16))
      Which is: 0
To be equal to: (8 | 16)
      Which is: 24
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:72: FAILURE
      Expected: actual
      Which is: 0
To be equal to: 34
      Which is: 34
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:84: FAILURE
Failed to match func(in.min_denormal, in.neg_min_denormal) against LIBC_NAMESPACE::testing::getMatcher< LIBC_NAMESPACE::testing::TestCond::EQ>(zero).
Expected floating point value: 0x0000000000000000 = (S: 0, E: 0x0000, M: 0x0000000000000000)
Step 7 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[       OK ] LlvmLibcCeilTest.RoundedNubmers (22 us)
[ RUN      ] LlvmLibcCeilTest.Fractions
[       OK ] LlvmLibcCeilTest.Fractions (43 us)
Ran 3 tests.  PASS: 3  FAIL: 0
[138/700] Running unit test libc.test.src.math.smoke.dfmal_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFmaTest.SpecialNumbers
[       OK ] LlvmLibcFmaTest.SpecialNumbers (101 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[139/700] Running unit test libc.test.src.math.smoke.dsubl_test.__unit__
FAILED: projects/libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.dsubl_test.__unit__ /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/test/src/math/smoke/CMakeFiles/libc.test.src.math.smoke.dsubl_test.__unit__ 
cd /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/test/src/math/smoke && /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/test/src/math/smoke/libc.test.src.math.smoke.dsubl_test.__unit__.__build__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcSubTest.SpecialNumbers
[       OK ] LlvmLibcSubTest.SpecialNumbers (53 us)
[ RUN      ] LlvmLibcSubTest.InvalidOperations
[       OK ] LlvmLibcSubTest.InvalidOperations (19 us)
[ RUN      ] LlvmLibcSubTest.RangeErrors
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:67: FAILURE
Failed to match func(in.min_denormal, in.neg_min_denormal) against LIBC_NAMESPACE::testing::getMatcher< LIBC_NAMESPACE::testing::TestCond::EQ>(zero).
Expected floating point value: 0x0000000000000000 = (S: 0, E: 0x0000, M: 0x0000000000000000)
Actual floating point value: 0x0000000000000001 = (S: 0, E: 0x0000, M: 0x0000000000000001)
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:67: FAILURE
      Expected: __llvm_libc_19_0_0_git::fputil::test_except((1 | 2 | 4 | 8 | 16)) & ((8 | 16) ? (8 | 16) : (1 | 2 | 4 | 8 | 16))
      Which is: 0
To be equal to: (8 | 16)
      Which is: 24
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:68: FAILURE
      Expected: actual
      Which is: 0
To be equal to: 34
      Which is: 34
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:71: FAILURE
Failed to match func(in.neg_min_denormal, in.min_denormal) against LIBC_NAMESPACE::testing::getMatcher< LIBC_NAMESPACE::testing::TestCond::EQ>(neg_zero).
Expected floating point value: 0x8000000000000000 = (S: 1, E: 0x0000, M: 0x0000000000000000)
Actual floating point value: 0x8000000000000001 = (S: 1, E: 0x0000, M: 0x0000000000000001)
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:71: FAILURE
      Expected: __llvm_libc_19_0_0_git::fputil::test_except((1 | 2 | 4 | 8 | 16)) & ((8 | 16) ? (8 | 16) : (1 | 2 | 4 | 8 | 16))
      Which is: 0
To be equal to: (8 | 16)
      Which is: 24
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:72: FAILURE
      Expected: actual
      Which is: 0
To be equal to: 34
      Which is: 34
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/test/src/math/smoke/SubTest.h:84: FAILURE
Failed to match func(in.min_denormal, in.neg_min_denormal) against LIBC_NAMESPACE::testing::getMatcher< LIBC_NAMESPACE::testing::TestCond::EQ>(zero).
Expected floating point value: 0x0000000000000000 = (S: 0, E: 0x0000, M: 0x0000000000000000)

@aaryanshukla
Copy link
Contributor Author

@overmighty I am removing dsubl for now in another patch.

@mikhailramalho
Copy link
Member

@aaryanshukla this is causing an issue in the rv32 buildbot: https://lab.llvm.org/staging/#/builders/196/builds/136

aaryanshukla added a commit that referenced this pull request Aug 6, 2024
…ons #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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants