Skip to content

Conversation

@bassiounix
Copy link
Contributor

@bassiounix bassiounix commented Jul 11, 2025

@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Jul 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2025

@llvm/pr-subscribers-libc

Author: Muhammad Bassiouni (bassiounix)

Changes

Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450

@lntue


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

12 Files Affected:

  • (modified) libc/shared/math.h (+1)
  • (added) libc/shared/math/exp.h (+23)
  • (modified) libc/src/__support/math/CMakeLists.txt (+39)
  • (added) libc/src/__support/math/exp.h (+449)
  • (added) libc/src/__support/math/exp_constants.h (+174)
  • (added) libc/src/__support/math/exp_utils.h (+73)
  • (modified) libc/src/math/generic/CMakeLists.txt (+3-19)
  • (modified) libc/src/math/generic/common_constants.cpp (-157)
  • (modified) libc/src/math/generic/common_constants.h (+2-6)
  • (modified) libc/src/math/generic/exp.cpp (+2-425)
  • (modified) libc/src/math/generic/explogxf.h (+2-55)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+44-13)
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 4ddc29c7ae834..69783aecc7864 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -12,5 +12,6 @@
 #include "libc_common.h"
 
 #include "math/expf.h"
+#include "math/exp.h"
 
 #endif // LLVM_LIBC_SHARED_MATH_H
diff --git a/libc/shared/math/exp.h b/libc/shared/math/exp.h
new file mode 100644
index 0000000000000..7cdd6331e613a
--- /dev/null
+++ b/libc/shared/math/exp.h
@@ -0,0 +1,23 @@
+//===-- Shared exp 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_EXP_H
+#define LLVM_LIBC_SHARED_MATH_EXP_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/exp.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::exp;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_EXP_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 66c1d19a1cab0..92af75b4d946d 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -22,3 +22,42 @@ add_header_library(
     libc.src.__support.macros.config
     libc.src.__support.macros.optimization
 )
+
+add_header_library(
+  exp_constants
+  HDRS
+    exp_constants.h
+  DEPENDS
+    libc.src.__support.FPUtil.triple_double
+)
+
+add_header_library(
+  exp_utils
+  HDRS
+    exp_utils.h
+  DEPENDS
+    libc.src.__support.CPP.optional
+    libc.src.__support.CPP.bit
+    libc.src.__support.FPUtil.fp_bits
+)
+
+add_header_library(
+  exp
+  HDRS
+    exp.h
+  DEPENDS
+    .exp_constants
+    .exp_utils
+    libc.src.__support.CPP.bit
+    libc.src.__support.CPP.optional
+    libc.src.__support.FPUtil.dyadic_float
+    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.FPUtil.nearest_integer
+    libc.src.__support.FPUtil.polyeval
+    libc.src.__support.FPUtil.rounding_mode
+    libc.src.__support.FPUtil.triple_double
+    libc.src.__support.integer_literals
+    libc.src.__support.macros.optimization
+)
diff --git a/libc/src/__support/math/exp.h b/libc/src/__support/math/exp.h
new file mode 100644
index 0000000000000..6d9ac8d401e06
--- /dev/null
+++ b/libc/src/__support/math/exp.h
@@ -0,0 +1,449 @@
+//===-- Implementation header for exp ---------------------------*- 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_EXP_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP_H
+
+#include "exp_constants.h"
+#include "exp_utils.h"
+#include "src/__support/CPP/bit.h"
+#include "src/__support/CPP/optional.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/FPUtil/rounding_mode.h"
+#include "src/__support/FPUtil/triple_double.h"
+#include "src/__support/common.h"
+#include "src/__support/integer_literals.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+
+namespace LIBC_NAMESPACE_DECL {
+
+using fputil::DoubleDouble;
+using fputil::TripleDouble;
+using Float128 = typename fputil::DyadicFloat<128>;
+
+using LIBC_NAMESPACE::operator""_u128;
+
+// log2(e)
+static constexpr double LOG2_E = 0x1.71547652b82fep+0;
+
+// Error bounds:
+// Errors when using double precision.
+static constexpr double ERR_D = 0x1.8p-63;
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+// Errors when using double-double precision.
+static constexpr double ERR_DD = 0x1.0p-99;
+#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+// -2^-12 * log(2)
+// > a = -2^-12 * log(2);
+// > b = round(a, 30, RN);
+// > c = round(a - b, 30, RN);
+// > d = round(a - b - c, D, RN);
+// Errors < 1.5 * 2^-133
+static constexpr double MLOG_2_EXP2_M12_HI = -0x1.62e42ffp-13;
+static constexpr double MLOG_2_EXP2_M12_MID = 0x1.718432a1b0e26p-47;
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+static constexpr double MLOG_2_EXP2_M12_MID_30 = 0x1.718432ap-47;
+static constexpr double MLOG_2_EXP2_M12_LO = 0x1.b0e2633fe0685p-79;
+#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+namespace {
+
+// Polynomial approximations with double precision:
+// Return expm1(dx) / x ~ 1 + dx / 2 + dx^2 / 6 + dx^3 / 24.
+// For |dx| < 2^-13 + 2^-30:
+//   | output - expm1(dx) / dx | < 2^-51.
+static constexpr double poly_approx_d(double dx) {
+  // dx^2
+  double dx2 = dx * dx;
+  // c0 = 1 + dx / 2
+  double c0 = fputil::multiply_add(dx, 0.5, 1.0);
+  // c1 = 1/6 + dx / 24
+  double c1 =
+      fputil::multiply_add(dx, 0x1.5555555555555p-5, 0x1.5555555555555p-3);
+  // p = dx^2 * c1 + c0 = 1 + dx / 2 + dx^2 / 6 + dx^3 / 24
+  double p = fputil::multiply_add(dx2, c1, c0);
+  return p;
+}
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+// Polynomial approximation with double-double precision:
+// Return exp(dx) ~ 1 + dx + dx^2 / 2 + ... + dx^6 / 720
+// For |dx| < 2^-13 + 2^-30:
+//   | output - exp(dx) | < 2^-101
+static constexpr DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
+  // Taylor polynomial.
+  constexpr DoubleDouble COEFFS[] = {
+      {0, 0x1p0},                                      // 1
+      {0, 0x1p0},                                      // 1
+      {0, 0x1p-1},                                     // 1/2
+      {0x1.5555555555555p-57, 0x1.5555555555555p-3},   // 1/6
+      {0x1.5555555555555p-59, 0x1.5555555555555p-5},   // 1/24
+      {0x1.1111111111111p-63, 0x1.1111111111111p-7},   // 1/120
+      {-0x1.f49f49f49f49fp-65, 0x1.6c16c16c16c17p-10}, // 1/720
+  };
+
+  DoubleDouble p = fputil::polyeval(dx, COEFFS[0], COEFFS[1], COEFFS[2],
+                                    COEFFS[3], COEFFS[4], COEFFS[5], COEFFS[6]);
+  return p;
+}
+
+// Polynomial approximation with 128-bit precision:
+// Return exp(dx) ~ 1 + dx + dx^2 / 2 + ... + dx^7 / 5040
+// For |dx| < 2^-13 + 2^-30:
+//   | output - exp(dx) | < 2^-126.
+static constexpr Float128 poly_approx_f128(const Float128 &dx) {
+  constexpr Float128 COEFFS_128[]{
+      {Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
+      {Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
+      {Sign::POS, -128, 0x80000000'00000000'00000000'00000000_u128}, // 0.5
+      {Sign::POS, -130, 0xaaaaaaaa'aaaaaaaa'aaaaaaaa'aaaaaaab_u128}, // 1/6
+      {Sign::POS, -132, 0xaaaaaaaa'aaaaaaaa'aaaaaaaa'aaaaaaab_u128}, // 1/24
+      {Sign::POS, -134, 0x88888888'88888888'88888888'88888889_u128}, // 1/120
+      {Sign::POS, -137, 0xb60b60b6'0b60b60b'60b60b60'b60b60b6_u128}, // 1/720
+      {Sign::POS, -140, 0xd00d00d0'0d00d00d'00d00d00'd00d00d0_u128}, // 1/5040
+  };
+
+  Float128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1], COEFFS_128[2],
+                                COEFFS_128[3], COEFFS_128[4], COEFFS_128[5],
+                                COEFFS_128[6], COEFFS_128[7]);
+  return p;
+}
+
+// Compute exp(x) using 128-bit precision.
+// TODO(lntue): investigate triple-double precision implementation for this
+// step.
+static constexpr Float128 exp_f128(double x, double kd, int idx1, int idx2) {
+  // Recalculate dx:
+
+  double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
+  double t2 = kd * MLOG_2_EXP2_M12_MID_30;                     // exact
+  double t3 = kd * MLOG_2_EXP2_M12_LO;                         // Error < 2^-133
+
+  Float128 dx = fputil::quick_add(
+      Float128(t1), fputil::quick_add(Float128(t2), Float128(t3)));
+
+  // TODO: Skip recalculating exp_mid1 and exp_mid2.
+  Float128 exp_mid1 =
+      fputil::quick_add(Float128(EXP2_MID1[idx1].hi),
+                        fputil::quick_add(Float128(EXP2_MID1[idx1].mid),
+                                          Float128(EXP2_MID1[idx1].lo)));
+
+  Float128 exp_mid2 =
+      fputil::quick_add(Float128(EXP2_MID2[idx2].hi),
+                        fputil::quick_add(Float128(EXP2_MID2[idx2].mid),
+                                          Float128(EXP2_MID2[idx2].lo)));
+
+  Float128 exp_mid = fputil::quick_mul(exp_mid1, exp_mid2);
+
+  Float128 p = poly_approx_f128(dx);
+
+  Float128 r = fputil::quick_mul(exp_mid, p);
+
+  r.exponent += static_cast<int>(kd) >> 12;
+
+  return r;
+}
+
+// Compute exp(x) with double-double precision.
+static constexpr DoubleDouble exp_double_double(double x, double kd,
+                               const DoubleDouble &exp_mid) {
+  // Recalculate dx:
+  //   dx = x - k * 2^-12 * log(2)
+  double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
+  double t2 = kd * MLOG_2_EXP2_M12_MID_30;                     // exact
+  double t3 = kd * MLOG_2_EXP2_M12_LO;                         // Error < 2^-130
+
+  DoubleDouble dx = fputil::exact_add(t1, t2);
+  dx.lo += t3;
+
+  // Degree-6 Taylor polynomial approximation in double-double precision.
+  // | p - exp(x) | < 2^-100.
+  DoubleDouble p = poly_approx_dd(dx);
+
+  // Error bounds: 2^-99.
+  DoubleDouble r = fputil::quick_mult(exp_mid, p);
+
+  return r;
+}
+#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+// Check for exceptional cases when
+// |x| <= 2^-53 or x < log(2^-1075) or x >= 0x1.6232bdd7abcd3p+9
+static constexpr double set_exceptional(double x) {
+  using FPBits = typename fputil::FPBits<double>;
+  FPBits xbits(x);
+
+  uint64_t x_u = xbits.uintval();
+  uint64_t x_abs = xbits.abs().uintval();
+
+  // |x| <= 2^-53
+  if (x_abs <= 0x3ca0'0000'0000'0000ULL) {
+    // exp(x) ~ 1 + x
+    return 1 + x;
+  }
+
+  // x <= log(2^-1075) || x >= 0x1.6232bdd7abcd3p+9 or inf/nan.
+
+  // x <= log(2^-1075) or -inf/nan
+  if (x_u >= 0xc087'4910'd52d'3052ULL) {
+    // exp(-Inf) = 0
+    if (xbits.is_inf())
+      return 0.0;
+
+    // exp(nan) = nan
+    if (xbits.is_nan())
+      return x;
+
+    if (fputil::quick_get_round() == FE_UPWARD)
+      return FPBits::min_subnormal().get_val();
+    fputil::set_errno_if_required(ERANGE);
+    fputil::raise_except_if_required(FE_UNDERFLOW);
+    return 0.0;
+  }
+
+  // x >= round(log(MAX_NORMAL), D, RU) = 0x1.62e42fefa39fp+9 or +inf/nan
+  // x is finite
+  if (x_u < 0x7ff0'0000'0000'0000ULL) {
+    int rounding = fputil::quick_get_round();
+    if (rounding == FE_DOWNWARD || rounding == FE_TOWARDZERO)
+      return FPBits::max_normal().get_val();
+
+    fputil::set_errno_if_required(ERANGE);
+    fputil::raise_except_if_required(FE_OVERFLOW);
+  }
+  // x is +inf or nan
+  return x + FPBits::inf().get_val();
+}
+
+} // namespace
+
+namespace math {
+
+static constexpr double exp(double x) {
+  using FPBits = typename fputil::FPBits<double>;
+  FPBits xbits(x);
+
+  uint64_t x_u = xbits.uintval();
+
+  // Upper bound: max normal number = 2^1023 * (2 - 2^-52)
+  // > round(log (2^1023 ( 2 - 2^-52 )), D, RU) = 0x1.62e42fefa39fp+9
+  // > round(log (2^1023 ( 2 - 2^-52 )), D, RD) = 0x1.62e42fefa39efp+9
+  // > round(log (2^1023 ( 2 - 2^-52 )), D, RN) = 0x1.62e42fefa39efp+9
+  // > round(exp(0x1.62e42fefa39fp+9), D, RN) = infty
+
+  // Lower bound: min denormal number / 2 = 2^-1075
+  // > round(log(2^-1075), D, RN) = -0x1.74910d52d3052p9
+
+  // Another lower bound: min normal number = 2^-1022
+  // > round(log(2^-1022), D, RN) = -0x1.6232bdd7abcd2p9
+
+  // x < log(2^-1075) or x >= 0x1.6232bdd7abcd3p+9 or |x| < 2^-53.
+  if (LIBC_UNLIKELY(x_u >= 0xc0874910d52d3052 ||
+                    (x_u < 0xbca0000000000000 && x_u >= 0x40862e42fefa39f0) ||
+                    x_u < 0x3ca0000000000000)) {
+    return set_exceptional(x);
+  }
+
+  // Now log(2^-1075) <= x <= -2^-53 or 2^-53 <= x < log(2^1023 * (2 - 2^-52))
+
+  // Range reduction:
+  // Let x = log(2) * (hi + mid1 + mid2) + lo
+  // in which:
+  //   hi is an integer
+  //   mid1 * 2^6 is an integer
+  //   mid2 * 2^12 is an integer
+  // then:
+  //   exp(x) = 2^hi * 2^(mid1) * 2^(mid2) * exp(lo).
+  // With this formula:
+  //   - multiplying by 2^hi is exact and cheap, simply by adding the exponent
+  //     field.
+  //   - 2^(mid1) and 2^(mid2) are stored in 2 x 64-element tables.
+  //   - exp(lo) ~ 1 + lo + a0 * lo^2 + ...
+  //
+  // They can be defined by:
+  //   hi + mid1 + mid2 = 2^(-12) * round(2^12 * log_2(e) * x)
+  // If we store L2E = round(log2(e), D, RN), then:
+  //   log2(e) - L2E ~ 1.5 * 2^(-56)
+  // So the errors when computing in double precision is:
+  //   | x * 2^12 * log_2(e) - D(x * 2^12 * L2E) | <=
+  //  <= | x * 2^12 * log_2(e) - x * 2^12 * L2E | +
+  //     + | x * 2^12 * L2E - D(x * 2^12 * L2E) |
+  //  <= 2^12 * ( |x| * 1.5 * 2^-56 + eps(x))  for RN
+  //     2^12 * ( |x| * 1.5 * 2^-56 + 2*eps(x)) for other rounding modes.
+  // So if:
+  //   hi + mid1 + mid2 = 2^(-12) * round(x * 2^12 * L2E) is computed entirely
+  // in double precision, the reduced argument:
+  //   lo = x - log(2) * (hi + mid1 + mid2) is bounded by:
+  //   |lo| <= 2^-13 + (|x| * 1.5 * 2^-56 + 2*eps(x))
+  //         < 2^-13 + (1.5 * 2^9 * 1.5 * 2^-56 + 2*2^(9 - 52))
+  //         < 2^-13 + 2^-41
+  //
+
+  // The following trick computes the round(x * L2E) more efficiently
+  // than using the rounding instructions, with the tradeoff for less accuracy,
+  // and hence a slightly larger range for the reduced argument `lo`.
+  //
+  // To be precise, since |x| < |log(2^-1075)| < 1.5 * 2^9,
+  //   |x * 2^12 * L2E| < 1.5 * 2^9 * 1.5 < 2^23,
+  // So we can fit the rounded result round(x * 2^12 * L2E) in int32_t.
+  // Thus, the goal is to be able to use an additional addition and fixed width
+  // shift to get an int32_t representing round(x * 2^12 * L2E).
+  //
+  // Assuming int32_t using 2-complement representation, since the mantissa part
+  // of a double precision is unsigned with the leading bit hidden, if we add an
+  // extra constant C = 2^e1 + 2^e2 with e1 > e2 >= 2^25 to the product, the
+  // part that are < 2^e2 in resulted mantissa of (x*2^12*L2E + C) can be
+  // considered as a proper 2-complement representations of x*2^12*L2E.
+  //
+  // One small problem with this approach is that the sum (x*2^12*L2E + C) in
+  // double precision is rounded to the least significant bit of the dorminant
+  // factor C.  In order to minimize the rounding errors from this addition, we
+  // want to minimize e1.  Another constraint that we want is that after
+  // shifting the mantissa so that the least significant bit of int32_t
+  // corresponds to the unit bit of (x*2^12*L2E), the sign is correct without
+  // any adjustment.  So combining these 2 requirements, we can choose
+  //   C = 2^33 + 2^32, so that the sign bit corresponds to 2^31 bit, and hence
+  // after right shifting the mantissa, the resulting int32_t has correct sign.
+  // With this choice of C, the number of mantissa bits we need to shift to the
+  // right is: 52 - 33 = 19.
+  //
+  // Moreover, since the integer right shifts are equivalent to rounding down,
+  // we can add an extra 0.5 so that it will become round-to-nearest, tie-to-
+  // +infinity.  So in particular, we can compute:
+  //   hmm = x * 2^12 * L2E + C,
+  // where C = 2^33 + 2^32 + 2^-1, then if
+  //   k = int32_t(lower 51 bits of double(x * 2^12 * L2E + C) >> 19),
+  // the reduced argument:
+  //   lo = x - log(2) * 2^-12 * k is bounded by:
+  //   |lo| <= 2^-13 + 2^-41 + 2^-12*2^-19
+  //         = 2^-13 + 2^-31 + 2^-41.
+  //
+  // Finally, notice that k only uses the mantissa of x * 2^12 * L2E, so the
+  // exponent 2^12 is not needed.  So we can simply define
+  //   C = 2^(33 - 12) + 2^(32 - 12) + 2^(-13 - 12), and
+  //   k = int32_t(lower 51 bits of double(x * L2E + C) >> 19).
+
+  // Rounding errors <= 2^-31 + 2^-41.
+  double tmp = fputil::multiply_add(x, LOG2_E, 0x1.8000'0000'4p21);
+  int k = static_cast<int>(cpp::bit_cast<uint64_t>(tmp) >> 19);
+  double kd = static_cast<double>(k);
+
+  uint32_t idx1 = (k >> 6) & 0x3f;
+  uint32_t idx2 = k & 0x3f;
+  int hi = k >> 12;
+
+  bool denorm = (hi <= -1022);
+
+  DoubleDouble exp_mid1{EXP2_MID1[idx1].mid, EXP2_MID1[idx1].hi};
+  DoubleDouble exp_mid2{EXP2_MID2[idx2].mid, EXP2_MID2[idx2].hi};
+
+  DoubleDouble exp_mid = fputil::quick_mult(exp_mid1, exp_mid2);
+
+  // |x - (hi + mid1 + mid2) * log(2) - dx| < 2^11 * eps(M_LOG_2_EXP2_M12.lo)
+  //                                        = 2^11 * 2^-13 * 2^-52
+  //                                        = 2^-54.
+  // |dx| < 2^-13 + 2^-30.
+  double lo_h = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
+  double dx = fputil::multiply_add(kd, MLOG_2_EXP2_M12_MID, lo_h);
+
+  // We use the degree-4 Taylor polynomial to approximate exp(lo):
+  //   exp(lo) ~ 1 + lo + lo^2 / 2 + lo^3 / 6 + lo^4 / 24 = 1 + lo * P(lo)
+  // So that the errors are bounded by:
+  //   |P(lo) - expm1(lo)/lo| < |lo|^4 / 64 < 2^(-13 * 4) / 64 = 2^-58
+  // Let P_ be an evaluation of P where all intermediate computations are in
+  // double precision.  Using either Horner's or Estrin's schemes, the evaluated
+  // errors can be bounded by:
+  //      |P_(dx) - P(dx)| < 2^-51
+  //   => |dx * P_(dx) - expm1(lo) | < 1.5 * 2^-64
+  //   => 2^(mid1 + mid2) * |dx * P_(dx) - expm1(lo)| < 1.5 * 2^-63.
+  // Since we approximate
+  //   2^(mid1 + mid2) ~ exp_mid.hi + exp_mid.lo,
+  // We use the expression:
+  //    (exp_mid.hi + exp_mid.lo) * (1 + dx * P_(dx)) ~
+  //  ~ exp_mid.hi + (exp_mid.hi * dx * P_(dx) + exp_mid.lo)
+  // with errors bounded by 1.5 * 2^-63.
+
+  double mid_lo = dx * exp_mid.hi;
+
+  // Approximate expm1(dx)/dx ~ 1 + dx / 2 + dx^2 / 6 + dx^3 / 24.
+  double p = poly_approx_d(dx);
+
+  double lo = fputil::multiply_add(p, mid_lo, exp_mid.lo);
+
+#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  if (LIBC_UNLIKELY(denorm)) {
+    return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo, ERR_D)
+        .value();
+  } else {
+    // to multiply by 2^hi, a fast way is to simply add hi to the exponent
+    // field.
+    int64_t exp_hi = static_cast<int64_t>(hi) << FPBits::FRACTION_LEN;
+    double r =
+        cpp::bit_cast<double>(exp_hi + cpp::bit_cast<int64_t>(exp_mid.hi + lo));
+    return r;
+  }
+#else
+  if (LIBC_UNLIKELY(denorm)) {
+    if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, ERR_D);
+        LIBC_LIKELY(r.has_value()))
+      return r.value();
+  } else {
+    double upper = exp_mid.hi + (lo + ERR_D);
+    double lower = exp_mid.hi + (lo - ERR_D);
+
+    if (LIBC_LIKELY(upper == lower)) {
+      // to multiply by 2^hi, a fast way is to simply add hi to the exponent
+      // field.
+      int64_t exp_hi = static_cast<int64_t>(hi) << FPBits::FRACTION_LEN;
+      double r = cpp::bit_cast<double>(exp_hi + cpp::bit_cast<int64_t>(upper));
+      return r;
+    }
+  }
+
+  // Use double-double
+  DoubleDouble r_dd = exp_double_double(x, kd, exp_mid);
+
+  if (LIBC_UNLIKELY(denorm)) {
+    if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, ERR_DD);
+        LIBC_LIKELY(r.has_value()))
+      return r.value();
+  } else {
+    double upper_dd = r_dd.hi + (r_dd.lo + ERR_DD);
+    double lower_dd = r_dd.hi + (r_dd.lo - ERR_DD);
+
+    if (LIBC_LIKELY(upper_dd == lower_dd)) {
+      int64_t exp_hi = static_cast<int64_t>(hi) << FPBits::FRACTION_LEN;
+      double r =
+          cpp::bit_cast<double>(exp_hi + cpp::bit_cast<int64_t>(upper_dd));
+      return r;
+    }
+  }
+
+  // Use 128-bit precision
+  Float128 r_f128 = exp_f128(x, kd, idx1, idx2);
+
+  return static_cast<double>(r_f128);
+#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP_H
diff --git a/libc/src/__support/math/exp_constants.h b/libc/src/__support/math/exp_constants.h
new file mode 100644
index 0000000000000..32976a86a01ad
--- /dev/null
+++ b/libc/src/__support/math/exp_constants.h
@@ -0,0 +1,174 @@
+//===-- Constants for exp function ------------------------------*- C++ -*-===//
+//
+// Part o...
[truncated]

@github-actions
Copy link

github-actions bot commented Jul 11, 2025

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

@lntue lntue merged commit a76dfde into llvm:main Jul 14, 2025
19 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 14, 2025

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

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

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)
...
-- Build files have been written to: /home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/build
@@@BUILD_STEP build libc@@@
Running: ninja libc
[1/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.common_constants.dir/common_constants.cpp.o
[2/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.log2f.dir/log2f.cpp.o
[3/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.logf.dir/logf.cpp.o
[4/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10f.dir/exp10f.cpp.o
[5/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2f.dir/exp2f.cpp.o
[6/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.log1pf.dir/log1pf.cpp.o
[7/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g --target=arm-linux-gnueabihf -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/math/generic/exp.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/math/exp.h:70:25: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr double poly_approx_d(double dx) {
                        ^
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/math/exp.h:74:15: note: non-constexpr function 'multiply_add<double>' cannot be used in a constant expression
  double c0 = fputil::multiply_add(dx, 0.5, 1.0);
              ^
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/FPUtil/multiply_add.h:27:1: note: declared here
multiply_add(const T &x, const T &y, const T &z) {
^
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/math/exp.h:130:27: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr Float128 exp_f128(double x, double kd, int idx1, int idx2) {
                          ^
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/math/exp.h:133:15: note: non-constexpr function 'multiply_add<double>' cannot be used in a constant expression
  double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
              ^
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/FPUtil/multiply_add.h:27:1: note: declared here
multiply_add(const T &x, const T &y, const T &z) {
^
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/math/exp.h:163:31: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr DoubleDouble exp_double_double(double x, double kd,
                              ^
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/math/exp.h:167:15: note: non-constexpr function 'multiply_add<double>' cannot be used in a constant expression
  double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
              ^
/home/llvm-libc-buildbot/buildbot-worker/libc-arm32-qemu-debian/libc-arm32-qemu-debian-dbg/llvm-project/libc/src/__support/FPUtil/multiply_add.h:27:1: note: declared here
multiply_add(const T &x, const T &y, const T &z) {
^
3 errors generated.
[8/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.powf.dir/powf.cpp.o
[9/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.log10f.dir/log10f.cpp.o
[10/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expm1f.dir/expm1f.cpp.o
[11/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.pow.dir/pow.cpp.o
[12/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.explogxf.dir/explogxf.cpp.o
[13/26] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10.dir/exp10.cpp.o

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 14, 2025

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-dbg running on libc-aarch64-ubuntu while building libc,utils at step 4 "annotate".

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

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)
...
[2/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.sinhf.dir/sinhf.cpp.o
[3/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atanhf.dir/atanhf.cpp.o
[4/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.tanhf.dir/tanhf.cpp.o
[5/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.explogxf.dir/explogxf.cpp.o
[6/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10f.dir/exp10f.cpp.o
[7/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expm1f.dir/expm1f.cpp.o
[8/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2m1f.dir/exp2m1f.cpp.o
[9/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.pow.dir/pow.cpp.o
[10/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2f.dir/exp2f.cpp.o
[11/27] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -D__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC -D__LIBC_USE_BUILTIN_ROUND -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/math/generic/exp.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/exp.h:70:25: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr double poly_approx_d(double dx) {
                        ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/exp.h:74:15: note: non-constexpr function 'multiply_add' cannot be used in a constant expression
  double c0 = fputil::multiply_add(dx, 0.5, 1.0);
              ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/FPUtil/multiply_add.h:60:20: note: declared here
LIBC_INLINE double multiply_add(double x, double y, double z) {
                   ^
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/exp.h:88:31: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
                              ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/exp.h:100:20: note: non-constexpr function 'polyeval<__llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>>' cannot be used in a constant expression
  DoubleDouble p = fputil::polyeval(dx, COEFFS[0], COEFFS[1], COEFFS[2],
                   ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/FPUtil/PolyEval.h:41:1: note: declared here
polyeval(const T &x, const T &a0, const Ts &...a) {
^
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/exp.h:109:27: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr Float128 poly_approx_f128(const Float128 &dx) {
                          ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/exp.h:121:16: note: non-constexpr function 'polyeval<__llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>>' cannot be used in a constant expression
  Float128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1], COEFFS_128[2],
               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/FPUtil/PolyEval.h:41:1: note: declared here
polyeval(const T &x, const T &a0, const Ts &...a) {
^
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/exp.h:130:27: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr Float128 exp_f128(double x, double kd, int idx1, int idx2) {
                          ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/exp.h:133:15: note: non-constexpr function 'multiply_add' cannot be used in a constant expression
  double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
              ^

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 14, 2025

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-fullbuild-dbg running on libc-aarch64-ubuntu while building libc,utils at step 4 "annotate".

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

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)
...
[19/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.pow.__internal__.dir/pow.cpp.o
[20/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.pow.dir/pow.cpp.o
[21/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.acoshf.__NO_ROUND_OPT.dir/acoshf.cpp.o
[22/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expm1f.dir/expm1f.cpp.o
[23/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2f.__NO_ROUND_OPT.__internal__.dir/exp2f.cpp.o
[24/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.acoshf.dir/acoshf.cpp.o
[25/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2m1f.__internal__.dir/exp2m1f.cpp.o
[26/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10.__NO_ROUND_OPT.dir/exp10.cpp.o
[27/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.coshf.__NO_ROUND_OPT.__internal__.dir/coshf.cpp.o
[28/1036] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__internal__.dir/exp.cpp.o
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__internal__.dir/exp.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -D__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC -D__LIBC_USE_BUILTIN_ROUND -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -std=gnu++17 -MD -MT libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__internal__.dir/exp.cpp.o -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__internal__.dir/exp.cpp.o.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__internal__.dir/exp.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/math/generic/exp.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:70:25: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr double poly_approx_d(double dx) {
                        ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:74:15: note: non-constexpr function 'multiply_add' cannot be used in a constant expression
  double c0 = fputil::multiply_add(dx, 0.5, 1.0);
              ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/multiply_add.h:60:20: note: declared here
LIBC_INLINE double multiply_add(double x, double y, double z) {
                   ^
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:88:31: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
                              ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:100:20: note: non-constexpr function 'polyeval<__llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>>' cannot be used in a constant expression
  DoubleDouble p = fputil::polyeval(dx, COEFFS[0], COEFFS[1], COEFFS[2],
                   ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/PolyEval.h:41:1: note: declared here
polyeval(const T &x, const T &a0, const Ts &...a) {
^
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:109:27: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr Float128 poly_approx_f128(const Float128 &dx) {
                          ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:121:16: note: non-constexpr function 'polyeval<__llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>, __llvm_libc_20_0_0_git::fputil::DyadicFloat<128>>' cannot be used in a constant expression
  Float128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1], COEFFS_128[2],
               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/PolyEval.h:41:1: note: declared here
polyeval(const T &x, const T &a0, const Ts &...a) {
^
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:130:27: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
static constexpr Float128 exp_f128(double x, double kd, int idx1, int idx2) {
                          ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:133:15: note: non-constexpr function 'multiply_add' cannot be used in a constant expression
  double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
              ^

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 14, 2025

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-gcc-fullbuild-dbg running on libc-x86_64-debian-fullbuild while building libc,utils at step 4 "annotate".

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

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)
...
-- Build files have been written to: /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build
@@@BUILD_STEP build libc@@@
Running: ninja libc
ninja: no work to do.
@@@BUILD_STEP build libc-startup@@@
Running: ninja libc-startup
ninja: no work to do.
@@@BUILD_STEP libc-unit-tests@@@
Running: ninja libc-unit-tests
[1/1445] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__NO_FMA_OPT.__NO_ROUND_OPT.dir/exp.cpp.o
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__NO_FMA_OPT.__NO_ROUND_OPT.dir/exp.cpp.o 
/usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -fpie -ffreestanding -DLIBC_FULL_BUILD -isystem/usr/lib/gcc/x86_64-linux-gnu/12//include -nostdinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -fext-numeric-literals -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__NO_FMA_OPT.__NO_ROUND_OPT.dir/exp.cpp.o -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__NO_FMA_OPT.__NO_ROUND_OPT.dir/exp.cpp.o.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.__NO_FMA_OPT.__NO_ROUND_OPT.dir/exp.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/math/generic/exp.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/math/generic/exp.cpp:10:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h: In function ‘constexpr double __llvm_libc_20_0_0_git::{anonymous}::poly_approx_d(double)’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:74:35: error: call to non-‘constexpr’ function ‘__llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) <= sizeof (void*)), T> __llvm_libc_20_0_0_git::fputil::multiply_add(T, T, T) [with T = double; __llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) <= sizeof (void*)), T> = double]’
   74 |   double c0 = fputil::multiply_add(dx, 0.5, 1.0);
      |               ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/PolyEval.h:12,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:18:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/multiply_add.h:33:1: note: ‘__llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) <= sizeof (void*)), T> __llvm_libc_20_0_0_git::fputil::multiply_add(T, T, T) [with T = double; __llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) <= sizeof (void*)), T> = double]’ declared here
   33 | multiply_add(T x, T y, T z) {
      | ^~~~~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h: In function ‘constexpr __llvm_libc_20_0_0_git::fputil::DoubleDouble __llvm_libc_20_0_0_git::{anonymous}::poly_approx_dd(const __llvm_libc_20_0_0_git::fputil::DoubleDouble&)’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:100:36: error: call to non-‘constexpr’ function ‘__llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) > sizeof (void*)), T> __llvm_libc_20_0_0_git::fputil::polyeval(const T&, const T&, const Ts& ...) [with T = __llvm_libc_20_0_0_git::NumberPair<double>; Ts = {__llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>}; __llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) > sizeof (void*)), T> = __llvm_libc_20_0_0_git::NumberPair<double>]’
  100 |   DoubleDouble p = fputil::polyeval(dx, COEFFS[0], COEFFS[1], COEFFS[2],
      |                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101 |                                     COEFFS[3], COEFFS[4], COEFFS[5], COEFFS[6]);
      |                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/PolyEval.h:41:1: note: ‘__llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) > sizeof (void*)), T> __llvm_libc_20_0_0_git::fputil::polyeval(const T&, const T&, const Ts& ...) [with T = __llvm_libc_20_0_0_git::NumberPair<double>; Ts = {__llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>, __llvm_libc_20_0_0_git::NumberPair<double>}; __llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) > sizeof (void*)), T> = __llvm_libc_20_0_0_git::NumberPair<double>]’ declared here
   41 | polyeval(const T &x, const T &a0, const Ts &...a) {
      | ^~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h: In function ‘constexpr __llvm_libc_20_0_0_git::Float128 __llvm_libc_20_0_0_git::{anonymous}::poly_approx_f128(const __llvm_libc_20_0_0_git::Float128&)’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:121:32: error: call to non-‘constexpr’ function ‘__llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) > sizeof (void*)), T> __llvm_libc_20_0_0_git::fputil::polyeval(const T&, const T&, const Ts& ...) [with T = DyadicFloat<128>; Ts = {DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>}; __llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) > sizeof (void*)), T> = DyadicFloat<128>]’
  121 |   Float128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1], COEFFS_128[2],
      |                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122 |                                 COEFFS_128[3], COEFFS_128[4], COEFFS_128[5],
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  123 |                                 COEFFS_128[6], COEFFS_128[7]);
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/PolyEval.h:41:1: note: ‘__llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) > sizeof (void*)), T> __llvm_libc_20_0_0_git::fputil::polyeval(const T&, const T&, const Ts& ...) [with T = DyadicFloat<128>; Ts = {DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>, DyadicFloat<128>}; __llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) > sizeof (void*)), T> = DyadicFloat<128>]’ declared here
   41 | polyeval(const T &x, const T &a0, const Ts &...a) {
      | ^~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h: In function ‘constexpr __llvm_libc_20_0_0_git::Float128 __llvm_libc_20_0_0_git::{anonymous}::exp_f128(double, double, int, int)’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/math/exp.h:133:35: error: call to non-‘constexpr’ function ‘__llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) <= sizeof (void*)), T> __llvm_libc_20_0_0_git::fputil::multiply_add(T, T, T) [with T = double; __llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) <= sizeof (void*)), T> = double]’
  133 |   double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
      |               ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/multiply_add.h:33:1: note: ‘__llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) <= sizeof (void*)), T> __llvm_libc_20_0_0_git::fputil::multiply_add(T, T, T) [with T = double; __llvm_libc_20_0_0_git::cpp::enable_if_t<(sizeof (T) <= sizeof (void*)), T> = double]’ declared here
   33 | multiply_add(T x, T y, T z) {
      | ^~~~~~~~~~~~

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 14, 2025

LLVM Buildbot has detected a new failure on builder fuchsia-x86_64-linux running on fuchsia-debian-64-us-central1-a-1 while building libc,utils at step 4 "annotate".

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

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
[604/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.lrintl.dir/lrintl.cpp.obj
[605/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.nearbyintf.dir/nearbyintf.cpp.obj
[606/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.erff.dir/erff.cpp.obj
[607/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.llrintl.dir/llrintl.cpp.obj
[608/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.nearbyintl.dir/nearbyintl.cpp.obj
[609/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.copysign.dir/copysign.cpp.obj
[610/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.copysignf.dir/copysignf.cpp.obj
[611/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.atof.dir/atof.cpp.obj
[612/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expf.dir/expf.cpp.obj
[613/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-x_d6ortc/./bin/clang++ --target=armv6m-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-x_d6ortc/include/armv6m-unknown-none-eabi --target=armv6m-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-x_d6ortc/runtimes/runtimes-armv6m-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG --target=armv6m-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_EXTERNAL -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/exp.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/exp.cpp:10:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/math/exp.h:70:25: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
   70 | static constexpr double poly_approx_d(double dx) {
      |                         ^~~~~~~~~~~~~
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/math/exp.h:74:15: note: non-constexpr function 'multiply_add<double>' cannot be used in a constant expression
   74 |   double c0 = fputil::multiply_add(dx, 0.5, 1.0);
      |               ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/FPUtil/multiply_add.h:27:1: note: declared here
   27 | multiply_add(const T &x, const T &y, const T &z) {
      | ^
1 error generated.
[614/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2f.dir/exp2f.cpp.obj
[615/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expm1f.dir/expm1f.cpp.obj
[616/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.copysignl.dir/copysignl.cpp.obj
[617/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtof.dir/strtof.cpp.obj
[618/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtod.dir/strtod.cpp.obj
[619/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtof_l.dir/strtof_l.cpp.obj
[620/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2m1f.dir/exp2m1f.cpp.obj
[621/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10m1f.dir/exp10m1f.cpp.obj
[622/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtold.dir/strtold.cpp.obj
[623/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtod_l.dir/strtod_l.cpp.obj
[624/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.frexp.dir/frexp.cpp.obj
[625/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10f.dir/exp10f.cpp.obj
[626/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.frexpf.dir/frexpf.cpp.obj
[627/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtold_l.dir/strtold_l.cpp.obj
[628/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.llogb.dir/llogb.cpp.obj
[629/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ilogb.dir/ilogb.cpp.obj
[630/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2.dir/exp2.cpp.obj
[631/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.frexpl.dir/frexpl.cpp.obj
[632/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ilogbf.dir/ilogbf.cpp.obj
[633/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ilogbl.dir/ilogbl.cpp.obj
[634/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10.dir/exp10.cpp.obj
[635/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expm1.dir/expm1.cpp.obj
[636/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.modff.dir/modff.cpp.obj
[637/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.log2f.dir/log2f.cpp.obj
[638/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fminl.dir/fminl.cpp.obj
[639/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.llogbl.dir/llogbl.cpp.obj
Step 6 (build) failure: build (failure)
...
[604/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.lrintl.dir/lrintl.cpp.obj
[605/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.nearbyintf.dir/nearbyintf.cpp.obj
[606/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.erff.dir/erff.cpp.obj
[607/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.llrintl.dir/llrintl.cpp.obj
[608/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.nearbyintl.dir/nearbyintl.cpp.obj
[609/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.copysign.dir/copysign.cpp.obj
[610/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.copysignf.dir/copysignf.cpp.obj
[611/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.atof.dir/atof.cpp.obj
[612/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expf.dir/expf.cpp.obj
[613/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-x_d6ortc/./bin/clang++ --target=armv6m-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-x_d6ortc/include/armv6m-unknown-none-eabi --target=armv6m-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-x_d6ortc/runtimes/runtimes-armv6m-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG --target=armv6m-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_EXTERNAL -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp.dir/exp.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/exp.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/exp.cpp:10:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/math/exp.h:70:25: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
   70 | static constexpr double poly_approx_d(double dx) {
      |                         ^~~~~~~~~~~~~
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/math/exp.h:74:15: note: non-constexpr function 'multiply_add<double>' cannot be used in a constant expression
   74 |   double c0 = fputil::multiply_add(dx, 0.5, 1.0);
      |               ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/FPUtil/multiply_add.h:27:1: note: declared here
   27 | multiply_add(const T &x, const T &y, const T &z) {
      | ^
1 error generated.
[614/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2f.dir/exp2f.cpp.obj
[615/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expm1f.dir/expm1f.cpp.obj
[616/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.copysignl.dir/copysignl.cpp.obj
[617/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtof.dir/strtof.cpp.obj
[618/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtod.dir/strtod.cpp.obj
[619/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtof_l.dir/strtof_l.cpp.obj
[620/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2m1f.dir/exp2m1f.cpp.obj
[621/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10m1f.dir/exp10m1f.cpp.obj
[622/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtold.dir/strtold.cpp.obj
[623/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtod_l.dir/strtod_l.cpp.obj
[624/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.frexp.dir/frexp.cpp.obj
[625/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10f.dir/exp10f.cpp.obj
[626/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.frexpf.dir/frexpf.cpp.obj
[627/2518] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtold_l.dir/strtold_l.cpp.obj
[628/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.llogb.dir/llogb.cpp.obj
[629/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ilogb.dir/ilogb.cpp.obj
[630/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2.dir/exp2.cpp.obj
[631/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.frexpl.dir/frexpl.cpp.obj
[632/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ilogbf.dir/ilogbf.cpp.obj
[633/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ilogbl.dir/ilogbl.cpp.obj
[634/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp10.dir/exp10.cpp.obj
[635/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.expm1.dir/expm1.cpp.obj
[636/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.modff.dir/modff.cpp.obj
[637/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.log2f.dir/log2f.cpp.obj
[638/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fminl.dir/fminl.cpp.obj
[639/2518] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.llogbl.dir/llogbl.cpp.obj

lntue added a commit that referenced this pull request Jul 14, 2025
…c/__support/math folder." (#148668)

Reverts #148091
Full build bots are failing.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 14, 2025
…-only in src/__support/math folder." (#148668)

Reverts llvm/llvm-project#148091
Full build bots are failing.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 14, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building libc,utils at step 7 "test-build-unified-tree-check-all".

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

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
...
PASS: lld :: COFF/base.test (98506 of 101553)
PASS: lld :: COFF/cfguard-off-instrumented.s (98507 of 101553)
PASS: lld :: COFF/cgprofile-err.s (98508 of 101553)
PASS: cfi-standalone-lld-x86_64 :: base-derived-destructor.cpp (98509 of 101553)
PASS: lld :: COFF/arm64ec.test (98510 of 101553)
PASS: lld :: COFF/cl-gl.test (98511 of 101553)
PASS: lld :: COFF/common.test (98512 of 101553)
PASS: lld :: COFF/comdat-weak.test (98513 of 101553)
PASS: lld :: COFF/autoimport-lto.ll (98514 of 101553)
TIMEOUT: MLIR :: Examples/standalone/test.toy (98515 of 101553)
******************** TEST 'MLIR :: Examples/standalone/test.toy' FAILED ********************
Exit Code: 1
Timeout: Reached timeout of 60 seconds

Command Output (stdout):
--
# RUN: at line 1
"/etc/cmake/bin/cmake" "/build/buildbot/premerge-monolithic-linux/llvm-project/mlir/examples/standalone" -G "Ninja"  -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang  -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir  -DLLVM_USE_LINKER=lld  -DPython3_EXECUTABLE="/usr/bin/python3.10"
# executed command: /etc/cmake/bin/cmake /build/buildbot/premerge-monolithic-linux/llvm-project/mlir/examples/standalone -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir -DLLVM_USE_LINKER=lld -DPython3_EXECUTABLE=/usr/bin/python3.10
# .---command stdout------------
# | -- The CXX compiler identification is Clang 16.0.6
# | -- The C compiler identification is Clang 16.0.6
# | -- Detecting CXX compiler ABI info
# | -- Detecting CXX compiler ABI info - done
# | -- Check for working CXX compiler: /usr/bin/clang++ - skipped
# | -- Detecting CXX compile features
# | -- Detecting CXX compile features - done
# | -- Detecting C compiler ABI info
# | -- Detecting C compiler ABI info - done
# | -- Check for working C compiler: /usr/bin/clang - skipped
# | -- Detecting C compile features
# | -- Detecting C compile features - done
# | -- Looking for histedit.h
# | -- Looking for histedit.h - found
# | -- Found LibEdit: /usr/include (found version "2.11") 
# | -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
# | -- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.13") 
# | -- Using MLIRConfig.cmake in: /build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir
# | -- Using LLVMConfig.cmake in: /build/buildbot/premerge-monolithic-linux/build/lib/cmake/llvm
# | -- Linker detection: unknown
# | -- Performing Test LLVM_LIBSTDCXX_MIN
# | -- Performing Test LLVM_LIBSTDCXX_MIN - Success
# | -- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR
# | -- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR - Success
# | -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER
# | -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER - Success
# | -- Performing Test C_SUPPORTS_FPIC
# | -- Performing Test C_SUPPORTS_FPIC - Success
# | -- Performing Test CXX_SUPPORTS_FPIC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bazel "Peripheral" support tier build system: utils/bazel libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants