[libc-commits] [libc] [llvm] [libc][math] Refactor fmul-fsub-frexp family to header-only (PR #195431)

via libc-commits libc-commits at lists.llvm.org
Sat May 2 01:31:51 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Anonmiraj (AnonMiraj)

<details>
<summary>Changes</summary>

Refactors the fmul-fsub-frexp math family to be header-only.

part of: #<!-- -->147386

Target Functions:
  - fmul
  - fmulf128
  - fmull
  - fsub
  - fsubf128
  - fsubl
  - frexp
  - frexpbf16
  - frexpl

---

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


35 Files Affected:

- (modified) libc/shared/math.h (+9) 
- (added) libc/shared/math/fmul.h (+23) 
- (added) libc/shared/math/fmulf128.h (+29) 
- (added) libc/shared/math/fmull.h (+23) 
- (added) libc/shared/math/frexp.h (+23) 
- (added) libc/shared/math/frexpbf16.h (+23) 
- (added) libc/shared/math/frexpl.h (+23) 
- (added) libc/shared/math/fsub.h (+23) 
- (added) libc/shared/math/fsubf128.h (+29) 
- (added) libc/shared/math/fsubl.h (+23) 
- (modified) libc/src/__support/FPUtil/double_double.h (+3-2) 
- (modified) libc/src/__support/math/CMakeLists.txt (+87) 
- (added) libc/src/__support/math/fmul.h (+126) 
- (added) libc/src/__support/math/fmulf128.h (+31) 
- (added) libc/src/__support/math/fmull.h (+25) 
- (added) libc/src/__support/math/frexp.h (+25) 
- (added) libc/src/__support/math/frexpbf16.h (+26) 
- (added) libc/src/__support/math/frexpl.h (+25) 
- (added) libc/src/__support/math/fsub.h (+25) 
- (added) libc/src/__support/math/fsubf128.h (+31) 
- (added) libc/src/__support/math/fsubl.h (+25) 
- (modified) libc/src/math/generic/CMakeLists.txt (+9-17) 
- (modified) libc/src/math/generic/fmul.cpp (+4-105) 
- (modified) libc/src/math/generic/fmulf128.cpp (+2-4) 
- (modified) libc/src/math/generic/fmull.cpp (+2-4) 
- (modified) libc/src/math/generic/frexp.cpp (+2-4) 
- (modified) libc/src/math/generic/frexpbf16.cpp (+2-5) 
- (modified) libc/src/math/generic/frexpl.cpp (+2-4) 
- (modified) libc/src/math/generic/fsub.cpp (+2-4) 
- (modified) libc/src/math/generic/fsubf128.cpp (+2-4) 
- (modified) libc/src/math/generic/fsubl.cpp (+2-4) 
- (modified) libc/test/shared/CMakeLists.txt (+18) 
- (modified) libc/test/shared/shared_math_constexpr_test.cpp (+20) 
- (modified) libc/test/shared/shared_math_test.cpp (+18) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+128-8) 


``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 2641e0e71676f..4cd943a2435f2 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -238,9 +238,15 @@
 #include "math/fmodf128.h"
 #include "math/fmodf16.h"
 #include "math/fmodl.h"
+#include "math/fmul.h"
+#include "math/fmulf128.h"
+#include "math/fmull.h"
+#include "math/frexp.h"
+#include "math/frexpbf16.h"
 #include "math/frexpf.h"
 #include "math/frexpf128.h"
 #include "math/frexpf16.h"
+#include "math/frexpl.h"
 #include "math/fromfp.h"
 #include "math/fromfpbf16.h"
 #include "math/fromfpf.h"
@@ -256,6 +262,9 @@
 #include "math/fsqrt.h"
 #include "math/fsqrtf128.h"
 #include "math/fsqrtl.h"
+#include "math/fsub.h"
+#include "math/fsubf128.h"
+#include "math/fsubl.h"
 #include "math/getpayload.h"
 #include "math/getpayloadbf16.h"
 #include "math/getpayloadf.h"
diff --git a/libc/shared/math/fmul.h b/libc/shared/math/fmul.h
new file mode 100644
index 0000000000000..c5d759feaedb0
--- /dev/null
+++ b/libc/shared/math/fmul.h
@@ -0,0 +1,23 @@
+//===-- Shared fmul function ------------------------------------*- 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_SHARED_MATH_FMUL_H
+#define LLVM_LIBC_SHARED_MATH_FMUL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmul.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmul;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMUL_H
diff --git a/libc/shared/math/fmulf128.h b/libc/shared/math/fmulf128.h
new file mode 100644
index 0000000000000..279d9a84d12a6
--- /dev/null
+++ b/libc/shared/math/fmulf128.h
@@ -0,0 +1,29 @@
+//===-- Shared fmulf128 function --------------------------------*- 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_SHARED_MATH_FMULF128_H
+#define LLVM_LIBC_SHARED_MATH_FMULF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmulf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmulf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FMULF128_H
diff --git a/libc/shared/math/fmull.h b/libc/shared/math/fmull.h
new file mode 100644
index 0000000000000..6e88f5df1c97f
--- /dev/null
+++ b/libc/shared/math/fmull.h
@@ -0,0 +1,23 @@
+//===-- Shared fmull function -----------------------------------*- 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_SHARED_MATH_FMULL_H
+#define LLVM_LIBC_SHARED_MATH_FMULL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmull.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmull;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMULL_H
diff --git a/libc/shared/math/frexp.h b/libc/shared/math/frexp.h
new file mode 100644
index 0000000000000..7dcf87eea85fc
--- /dev/null
+++ b/libc/shared/math/frexp.h
@@ -0,0 +1,23 @@
+//===-- Shared frexp function -----------------------------------*- 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_SHARED_MATH_FREXP_H
+#define LLVM_LIBC_SHARED_MATH_FREXP_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/frexp.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::frexp;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FREXP_H
diff --git a/libc/shared/math/frexpbf16.h b/libc/shared/math/frexpbf16.h
new file mode 100644
index 0000000000000..33ddb25c3cf67
--- /dev/null
+++ b/libc/shared/math/frexpbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared frexpbf16 function -------------------------------*- 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_SHARED_MATH_FREXPBF16_H
+#define LLVM_LIBC_SHARED_MATH_FREXPBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/frexpbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::frexpbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FREXPBF16_H
diff --git a/libc/shared/math/frexpl.h b/libc/shared/math/frexpl.h
new file mode 100644
index 0000000000000..68f0fd3a342d5
--- /dev/null
+++ b/libc/shared/math/frexpl.h
@@ -0,0 +1,23 @@
+//===-- Shared frexpl function ----------------------------------*- 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_SHARED_MATH_FREXPL_H
+#define LLVM_LIBC_SHARED_MATH_FREXPL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/frexpl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::frexpl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FREXPL_H
diff --git a/libc/shared/math/fsub.h b/libc/shared/math/fsub.h
new file mode 100644
index 0000000000000..38396a26b1c72
--- /dev/null
+++ b/libc/shared/math/fsub.h
@@ -0,0 +1,23 @@
+//===-- Shared fsub function ------------------------------------*- 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_SHARED_MATH_FSUB_H
+#define LLVM_LIBC_SHARED_MATH_FSUB_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fsub.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fsub;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FSUB_H
diff --git a/libc/shared/math/fsubf128.h b/libc/shared/math/fsubf128.h
new file mode 100644
index 0000000000000..b8cf101704dc0
--- /dev/null
+++ b/libc/shared/math/fsubf128.h
@@ -0,0 +1,29 @@
+//===-- Shared fsubf128 function --------------------------------*- 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_SHARED_MATH_FSUBF128_H
+#define LLVM_LIBC_SHARED_MATH_FSUBF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fsubf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fsubf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FSUBF128_H
diff --git a/libc/shared/math/fsubl.h b/libc/shared/math/fsubl.h
new file mode 100644
index 0000000000000..658de2fdc98cc
--- /dev/null
+++ b/libc/shared/math/fsubl.h
@@ -0,0 +1,23 @@
+//===-- Shared fsubl function -----------------------------------*- 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_SHARED_MATH_FSUBL_H
+#define LLVM_LIBC_SHARED_MATH_FSUBL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fsubl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fsubl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FSUBL_H
diff --git a/libc/src/__support/FPUtil/double_double.h b/libc/src/__support/FPUtil/double_double.h
index 3913f7acb7f8c..31049ced5a934 100644
--- a/libc/src/__support/FPUtil/double_double.h
+++ b/libc/src/__support/FPUtil/double_double.h
@@ -87,7 +87,8 @@ LIBC_INLINE constexpr NumberPair<T> split(T a) {
 
 // Helper for non-fma exact mult where the first number is already split.
 template <typename T = double, size_t SPLIT_B = DefaultSplit<T>::VALUE>
-LIBC_INLINE NumberPair<T> exact_mult(const NumberPair<T> &as, T a, T b) {
+LIBC_INLINE constexpr NumberPair<T> exact_mult(const NumberPair<T> &as, T a,
+                                               T b) {
   NumberPair<T> bs = split<T, SPLIT_B>(b);
   NumberPair<T> r{0.0, 0.0};
 
@@ -128,7 +129,7 @@ template <> struct TargetHasFmaInstruction<double> {
 // the generated constants to precision <= 51, and splitting it by 2^28 + 1,
 // then a * b = r.hi + r.lo is exact for all rounding modes.
 template <typename T = double, size_t SPLIT_B = DefaultSplit<T>::VALUE>
-LIBC_INLINE NumberPair<T> exact_mult(T a, T b) {
+LIBC_INLINE LIBC_CONSTEXPR NumberPair<T> exact_mult(T a, T b) {
   NumberPair<T> r{0.0, 0.0};
 
   if constexpr (TargetHasFmaInstruction<T>::VALUE) {
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 3100dca01d68e..db689026d404f 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1420,6 +1420,64 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  fmul
+  HDRS
+    fmul.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.double_double
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmulf128
+  HDRS
+    fmulf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmull
+  HDRS
+    fmull.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  frexp
+  HDRS
+    frexp.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  frexpbf16
+  HDRS
+    frexpbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  frexpl
+  HDRS
+    frexpl.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   fromfp
   HDRS
@@ -1534,6 +1592,35 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  fsub
+  HDRS
+    fsub.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fsubf128
+  HDRS
+    fsubf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fsubl
+  HDRS
+    fsubl.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
+
+
 add_header_library(
   ldexp
   HDRS
diff --git a/libc/src/__support/math/fmul.h b/libc/src/__support/math/fmul.h
new file mode 100644
index 0000000000000..52c6c80232ba4
--- /dev/null
+++ b/libc/src/__support/math/fmul.h
@@ -0,0 +1,126 @@
+//===-- Implementation header for fmul --------------------------*- 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___SUPPORT_MATH_FMUL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMUL_H
+
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float fmul(double x, double y) {
+
+  // Without FMA instructions, fputil::exact_mult is not
+  // correctly rounded for all rounding modes, so we fall
+  // back to the generic `fmul` implementation
+
+#ifndef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+  return fputil::generic::mul<float>(x, y);
+#else
+  fputil::DoubleDouble prod = fputil::exact_mult(x, y);
+  using DoubleBits = fputil::FPBits<double>;
+  using DoubleStorageType = typename DoubleBits::StorageType;
+  using FloatBits = fputil::FPBits<float>;
+  using FloatStorageType = typename FloatBits::StorageType;
+  DoubleBits x_bits(x);
+  DoubleBits y_bits(y);
+
+  Sign result_sign = x_bits.sign() == y_bits.sign() ? Sign::POS : Sign::NEG;
+  double result = prod.hi;
+  DoubleBits hi_bits(prod.hi), lo_bits(prod.lo);
+  // Check for cases where we need to propagate the sticky bits:
+  constexpr uint64_t STICKY_MASK = 0xFFF'FFF; // Lower (52 - 23 - 1 = 28 bits)
+  uint64_t sticky_bits = (hi_bits.uintval() & STICKY_MASK);
+  if (LIBC_UNLIKELY(sticky_bits == 0)) {
+    // Might need to propagate sticky bits:
+    if (!(lo_bits.is_inf_or_nan() || lo_bits.is_zero())) {
+      // Now prod.lo is nonzero and finite, we need to propagate sticky bits.
+      if (lo_bits.sign() != hi_bits.sign())
+        result = DoubleBits(hi_bits.uintval() - 1).get_val();
+      else
+        result = DoubleBits(hi_bits.uintval() | 1).get_val();
+    }
+  }
+
+  float result_f = static_cast<float>(result);
+  FloatBits rf_bits(result_f);
+  uint32_t rf_exp = rf_bits.get_biased_exponent();
+  if (LIBC_LIKELY(rf_exp > 0 && rf_exp < 2 * FloatBits::EXP_BIAS + 1)) {
+    return result_f;
+  }
+
+  // Now result_f is either inf/nan/zero/denormal.
+  if (x_bits.is_nan() || y_bits.is_nan()) {
+    if (x_bits.is_signaling_nan() || y_bits.is_signaling_nan())
+      fputil::raise_except_if_required(FE_INVALID);
+
+    if (x_bits.is_quiet_nan()) {
+      DoubleStorageType x_payload = x_bits.get_mantissa();
+      x_payload >>= DoubleBits::FRACTION_LEN - FloatBits::FRACTION_LEN;
+      return FloatBits::quiet_nan(x_bits.sign(),
+                                  static_cast<FloatStorageType>(x_payload))
+          .get_val();
+    }
+
+    if (y_bits.is_quiet_nan()) {
+      DoubleStorageType y_payload = y_bits.get_mantissa();
+      y_payload >>= DoubleBits::FRACTION_LEN - FloatBits::FRACTION_LEN;
+      return FloatBits::quiet_nan(y_bits.sign(),
+                                  static_cast<FloatStorageType>(y_payload))
+          .get_val();
+    }
+
+    return FloatBits::quiet_nan().get_val();
+  }
+
+  if (x_bits.is_inf()) {
+    if (y_bits.is_zero()) {
+      fputil::set_errno_if_required(EDOM);
+      fputil::raise_except_if_required(FE_INVALID);
+
+      return FloatBits::quiet_nan().get_val();
+    }
+
+    return FloatBits::inf(result_sign).get_val();
+  }
+
+  if (y_bits.is_inf()) {
+    if (x_bits.is_zero()) {
+      fputil::set_errno_if_required(EDOM);
+      fputil::raise_except_if_required(FE_INVALID);
+      return FloatBits::quiet_nan().get_val();
+    }
+
+    return FloatBits::inf(result_sign).get_val();
+  }
+
+  // Now either x or y is zero, and the other one is finite.
+  if (rf_bits.is_inf()) {
+    fputil::set_errno_if_required(ERANGE);
+    return FloatBits::inf(result_sign).get_val();
+  }
+
+  if (x_bits.is_zero() || y_bits.is_zero())
+    return FloatBits::zero(result_sign).get_val();
+
+  fputil::set_errno_if_required(ERANGE);
+  fputil::raise_except_if_required(FE_UNDERFLOW);
+  return result_f;
+
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMUL_H
diff --git a/libc/src/__support/math/fmulf128.h b/libc/src/__support/math/fmulf128.h
new file mode 100644
index 0000000000000..858befc0b54b4
--- /dev/null
+++ b/libc/src/__support/math/fmulf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for fmulf128 ----------------------*- 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___SUPPORT_MATH_FMULF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMULF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float fmulf128(float128 x, float128 y) {
+  return fputil::generic::mul<float>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMULF128_H
diff --git a/libc/src/__support/math/fmull.h b/libc/src/__support/math/fmull.h
new file mode 100644
index 0000000000000..68893b579a427
--- /dev/null
+++ b/libc/src/__support/math/fmull.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmull -------------------------*- 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___SUPPORT_MATH_FMULL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMULL_H
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float fmull(long double x, long double y) {
+  return fputil::generic::mul<float>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMULL_H
diff --git a/libc/src/__support/math/frexp.h b/libc/src/__support/math/frexp.h
new file mode 100644
index 0000000000000..f143111c16c4b
--- /dev/null
+++ b/libc/src/__support/math/frexp.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for frexp -------------------------*- 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___SUPPORT_MATH_FREXP_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FREXP_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double frexp(double x, int *exp) {
+  return fputil::frexp(x, *exp);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FREXP_H
diff --git a/libc/src/__support/math/frexpbf16.h b/libc/src/__support/math/frexpbf16.h
new file mode 100644
index 0000000000000..cb31ba47560a8
--- /dev/null
+++ b/libc/src/__supp...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/195431


More information about the libc-commits mailing list