Skip to content

[libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. #150968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

bassiounix
Copy link
Contributor

Copy link
Contributor Author

bassiounix commented Jul 28, 2025

@llvmbot
Copy link
Member

llvmbot commented Jul 28, 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


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

9 Files Affected:

  • (modified) libc/shared/math.h (+1)
  • (added) libc/shared/math/atan2.h (+23)
  • (modified) libc/src/__support/math/CMakeLists.txt (+17-3)
  • (added) libc/src/__support/math/atan2.h (+209)
  • (modified) libc/src/math/generic/CMakeLists.txt (+1-7)
  • (modified) libc/src/math/generic/atan2.cpp (+2-185)
  • (modified) libc/test/shared/CMakeLists.txt (+1)
  • (modified) libc/test/shared/shared_math_test.cpp (+1)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+11-3)
diff --git a/libc/shared/math.h b/libc/shared/math.h
index bcbe0de56170a..0605d918eb2af 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atan2.h"
 #include "math/atanf.h"
 #include "math/atanf16.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/atan2.h b/libc/shared/math/atan2.h
new file mode 100644
index 0000000000000..894110838817c
--- /dev/null
+++ b/libc/shared/math/atan2.h
@@ -0,0 +1,23 @@
+//===-- Shared atan2 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_ATAN2_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 04cbd3fd1cc01..bbb07b62552f6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -158,7 +158,7 @@ add_header_library(
   asinhf16
   HDRS
     asinhf16.h
-DEPENDS
+  DEPENDS
     .acoshf_utils
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -176,7 +176,7 @@ add_header_library(
   atan_utils
   HDRS
     atan_utils.h
-DEPENDS
+  DEPENDS
     libc.src.__support.integer_literals
     libc.src.__support.FPUtil.double_double
     libc.src.__support.FPUtil.dyadic_float
@@ -189,7 +189,21 @@ add_header_library(
   atan
   HDRS
     atan.h
-DEPENDS
+  DEPENDS
+    .atan_utils
+    libc.src.__support.FPUtil.double_double
+    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.macros.optimization
+)
+
+add_header_library(
+  atan2
+  HDRS
+    atan2.h
+  DEPENDS
     .atan_utils
     libc.src.__support.FPUtil.double_double
     libc.src.__support.FPUtil.fenv_impl
diff --git a/libc/src/__support/math/atan2.h b/libc/src/__support/math/atan2.h
new file mode 100644
index 0000000000000..90ed926c8d75f
--- /dev/null
+++ b/libc/src/__support/math/atan2.h
@@ -0,0 +1,209 @@
+//===-- Implementation header for atan2 -------------------------*- 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_ATAN2_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// There are several range reduction steps we can take for atan2(y, x) as
+// follow:
+
+// * Range reduction 1: signness
+// atan2(y, x) will return a number between -PI and PI representing the angle
+// forming by the 0x axis and the vector (x, y) on the 0xy-plane.
+// In particular, we have that:
+//   atan2(y, x) = atan( y/x )         if x >= 0 and y >= 0 (I-quadrant)
+//               = pi + atan( y/x )    if x < 0 and y >= 0  (II-quadrant)
+//               = -pi + atan( y/x )   if x < 0 and y < 0   (III-quadrant)
+//               = atan( y/x )         if x >= 0 and y < 0  (IV-quadrant)
+// Since atan function is odd, we can use the formula:
+//   atan(-u) = -atan(u)
+// to adjust the above conditions a bit further:
+//   atan2(y, x) = atan( |y|/|x| )         if x >= 0 and y >= 0 (I-quadrant)
+//               = pi - atan( |y|/|x| )    if x < 0 and y >= 0  (II-quadrant)
+//               = -pi + atan( |y|/|x| )   if x < 0 and y < 0   (III-quadrant)
+//               = -atan( |y|/|x| )        if x >= 0 and y < 0  (IV-quadrant)
+// Which can be simplified to:
+//   atan2(y, x) = sign(y) * atan( |y|/|x| )             if x >= 0
+//               = sign(y) * (pi - atan( |y|/|x| ))      if x < 0
+
+// * Range reduction 2: reciprocal
+// Now that the argument inside atan is positive, we can use the formula:
+//   atan(1/x) = pi/2 - atan(x)
+// to make the argument inside atan <= 1 as follow:
+//   atan2(y, x) = sign(y) * atan( |y|/|x|)            if 0 <= |y| <= x
+//               = sign(y) * (pi/2 - atan( |x|/|y| )   if 0 <= x < |y|
+//               = sign(y) * (pi - atan( |y|/|x| ))    if 0 <= |y| <= -x
+//               = sign(y) * (pi/2 + atan( |x|/|y| ))  if 0 <= -x < |y|
+
+// * Range reduction 3: look up table.
+// After the previous two range reduction steps, we reduce the problem to
+// compute atan(u) with 0 <= u <= 1, or to be precise:
+//   atan( n / d ) where n = min(|x|, |y|) and d = max(|x|, |y|).
+// An accurate polynomial approximation for the whole [0, 1] input range will
+// require a very large degree.  To make it more efficient, we reduce the input
+// range further by finding an integer idx such that:
+//   | n/d - idx/64 | <= 1/128.
+// In particular,
+//   idx := round(2^6 * n/d)
+// Then for the fast pass, we find a polynomial approximation for:
+//   atan( n/d ) ~ atan( idx/64 ) + (n/d - idx/64) * Q(n/d - idx/64)
+// For the accurate pass, we use the addition formula:
+//   atan( n/d ) - atan( idx/64 ) = atan( (n/d - idx/64)/(1 + (n*idx)/(64*d)) )
+//                                = atan( (n - d*(idx/64))/(d + n*(idx/64)) )
+// And for the fast pass, we use degree-9 Taylor polynomial to compute the RHS:
+//   atan(u) ~ P(u) = u - u^3/3 + u^5/5 - u^7/7 + u^9/9
+// with absolute errors bounded by:
+//   |atan(u) - P(u)| < |u|^11 / 11 < 2^-80
+// and relative errors bounded by:
+//   |(atan(u) - P(u)) / P(u)| < u^10 / 11 < 2^-73.
+
+LIBC_INLINE static constexpr double atan2(double y, double x) {
+  using namespace atan_internal;
+  using FPBits = fputil::FPBits<double>;
+
+  constexpr double IS_NEG[2] = {1.0, -1.0};
+  constexpr DoubleDouble ZERO = {0.0, 0.0};
+  constexpr DoubleDouble MZERO = {-0.0, -0.0};
+  constexpr DoubleDouble PI = {0x1.1a62633145c07p-53, 0x1.921fb54442d18p+1};
+  constexpr DoubleDouble MPI = {-0x1.1a62633145c07p-53, -0x1.921fb54442d18p+1};
+  constexpr DoubleDouble PI_OVER_2 = {0x1.1a62633145c07p-54,
+                                      0x1.921fb54442d18p0};
+  constexpr DoubleDouble MPI_OVER_2 = {-0x1.1a62633145c07p-54,
+                                       -0x1.921fb54442d18p0};
+  constexpr DoubleDouble PI_OVER_4 = {0x1.1a62633145c07p-55,
+                                      0x1.921fb54442d18p-1};
+  constexpr DoubleDouble THREE_PI_OVER_4 = {0x1.a79394c9e8a0ap-54,
+                                            0x1.2d97c7f3321d2p+1};
+  // Adjustment for constant term:
+  //   CONST_ADJ[x_sign][y_sign][recip]
+  constexpr DoubleDouble CONST_ADJ[2][2][2] = {
+      {{ZERO, MPI_OVER_2}, {MZERO, MPI_OVER_2}},
+      {{MPI, PI_OVER_2}, {MPI, PI_OVER_2}}};
+
+  FPBits x_bits(x), y_bits(y);
+  bool x_sign = x_bits.sign().is_neg();
+  bool y_sign = y_bits.sign().is_neg();
+  x_bits = x_bits.abs();
+  y_bits = y_bits.abs();
+  uint64_t x_abs = x_bits.uintval();
+  uint64_t y_abs = y_bits.uintval();
+  bool recip = x_abs < y_abs;
+  uint64_t min_abs = recip ? x_abs : y_abs;
+  uint64_t max_abs = !recip ? x_abs : y_abs;
+  unsigned min_exp = static_cast<unsigned>(min_abs >> FPBits::FRACTION_LEN);
+  unsigned max_exp = static_cast<unsigned>(max_abs >> FPBits::FRACTION_LEN);
+
+  double num = FPBits(min_abs).get_val();
+  double den = FPBits(max_abs).get_val();
+
+  // Check for exceptional cases, whether inputs are 0, inf, nan, or close to
+  // overflow, or close to underflow.
+  if (LIBC_UNLIKELY(max_exp > 0x7ffU - 128U || min_exp < 128U)) {
+    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);
+      return FPBits::quiet_nan().get_val();
+    }
+    unsigned x_except = x == 0.0 ? 0 : (FPBits(x_abs).is_inf() ? 2 : 1);
+    unsigned y_except = y == 0.0 ? 0 : (FPBits(y_abs).is_inf() ? 2 : 1);
+
+    // Exceptional cases:
+    //   EXCEPT[y_except][x_except][x_is_neg]
+    // with x_except & y_except:
+    //   0: zero
+    //   1: finite, non-zero
+    //   2: infinity
+    constexpr DoubleDouble EXCEPTS[3][3][2] = {
+        {{ZERO, PI}, {ZERO, PI}, {ZERO, PI}},
+        {{PI_OVER_2, PI_OVER_2}, {ZERO, ZERO}, {ZERO, PI}},
+        {{PI_OVER_2, PI_OVER_2},
+         {PI_OVER_2, PI_OVER_2},
+         {PI_OVER_4, THREE_PI_OVER_4}},
+    };
+
+    if ((x_except != 1) || (y_except != 1)) {
+      DoubleDouble r = EXCEPTS[y_except][x_except][x_sign];
+      return fputil::multiply_add(IS_NEG[y_sign], r.hi, IS_NEG[y_sign] * r.lo);
+    }
+    bool scale_up = min_exp < 128U;
+    bool scale_down = max_exp > 0x7ffU - 128U;
+    // At least one input is denormal, multiply both numerator and denominator
+    // by some large enough power of 2 to normalize denormal inputs.
+    if (scale_up) {
+      num *= 0x1.0p64;
+      if (!scale_down)
+        den *= 0x1.0p64;
+    } else if (scale_down) {
+      den *= 0x1.0p-64;
+      if (!scale_up)
+        num *= 0x1.0p-64;
+    }
+
+    min_abs = FPBits(num).uintval();
+    max_abs = FPBits(den).uintval();
+    min_exp = static_cast<unsigned>(min_abs >> FPBits::FRACTION_LEN);
+    max_exp = static_cast<unsigned>(max_abs >> FPBits::FRACTION_LEN);
+  }
+
+  double final_sign = IS_NEG[(x_sign != y_sign) != recip];
+  DoubleDouble const_term = CONST_ADJ[x_sign][y_sign][recip];
+  unsigned exp_diff = max_exp - min_exp;
+  // We have the following bound for normalized n and d:
+  //   2^(-exp_diff - 1) < n/d < 2^(-exp_diff + 1).
+  if (LIBC_UNLIKELY(exp_diff > 54)) {
+    return fputil::multiply_add(final_sign, const_term.hi,
+                                final_sign * (const_term.lo + num / den));
+  }
+
+  double k = fputil::nearest_integer(64.0 * num / den);
+  unsigned idx = static_cast<unsigned>(k);
+  // k = idx / 64
+  k *= 0x1.0p-6;
+
+  // Range reduction:
+  // atan(n/d) - atan(k/64) = atan((n/d - k/64) / (1 + (n/d) * (k/64)))
+  //                        = atan((n - d * k/64)) / (d + n * k/64))
+  DoubleDouble num_k = fputil::exact_mult(num, k);
+  DoubleDouble den_k = fputil::exact_mult(den, k);
+
+  // num_dd = n - d * k
+  DoubleDouble num_dd = fputil::exact_add(num - den_k.hi, -den_k.lo);
+  // den_dd = d + n * k
+  DoubleDouble den_dd = fputil::exact_add(den, num_k.hi);
+  den_dd.lo += num_k.lo;
+
+  // q = (n - d * k) / (d + n * k)
+  DoubleDouble q = fputil::div(num_dd, den_dd);
+  // p ~ atan(q)
+  DoubleDouble p = atan_eval(q);
+
+  DoubleDouble r = fputil::add(const_term, fputil::add(ATAN_I[idx], p));
+  r.hi *= final_sign;
+  r.lo *= final_sign;
+
+  return r.hi + r.lo;
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 007e5701b7538..8071a0b013748 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4066,13 +4066,7 @@ add_entrypoint_object(
   HDRS
     ../atan2.h
   DEPENDS
-    libc.src.__support.math.atan_utils
-    libc.src.__support.FPUtil.double_double
-    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.macros.optimization
+    
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/atan2.cpp b/libc/src/math/generic/atan2.cpp
index 58042d3bcf721..4aaa63d077d4c 100644
--- a/libc/src/math/generic/atan2.cpp
+++ b/libc/src/math/generic/atan2.cpp
@@ -7,195 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/atan2.h"
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/double_double.h"
-#include "src/__support/FPUtil/multiply_add.h"
-#include "src/__support/FPUtil/nearest_integer.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-#include "src/__support/math/atan_utils.h"
+#include "src/__support/math/atan2.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-// There are several range reduction steps we can take for atan2(y, x) as
-// follow:
-
-// * Range reduction 1: signness
-// atan2(y, x) will return a number between -PI and PI representing the angle
-// forming by the 0x axis and the vector (x, y) on the 0xy-plane.
-// In particular, we have that:
-//   atan2(y, x) = atan( y/x )         if x >= 0 and y >= 0 (I-quadrant)
-//               = pi + atan( y/x )    if x < 0 and y >= 0  (II-quadrant)
-//               = -pi + atan( y/x )   if x < 0 and y < 0   (III-quadrant)
-//               = atan( y/x )         if x >= 0 and y < 0  (IV-quadrant)
-// Since atan function is odd, we can use the formula:
-//   atan(-u) = -atan(u)
-// to adjust the above conditions a bit further:
-//   atan2(y, x) = atan( |y|/|x| )         if x >= 0 and y >= 0 (I-quadrant)
-//               = pi - atan( |y|/|x| )    if x < 0 and y >= 0  (II-quadrant)
-//               = -pi + atan( |y|/|x| )   if x < 0 and y < 0   (III-quadrant)
-//               = -atan( |y|/|x| )        if x >= 0 and y < 0  (IV-quadrant)
-// Which can be simplified to:
-//   atan2(y, x) = sign(y) * atan( |y|/|x| )             if x >= 0
-//               = sign(y) * (pi - atan( |y|/|x| ))      if x < 0
-
-// * Range reduction 2: reciprocal
-// Now that the argument inside atan is positive, we can use the formula:
-//   atan(1/x) = pi/2 - atan(x)
-// to make the argument inside atan <= 1 as follow:
-//   atan2(y, x) = sign(y) * atan( |y|/|x|)            if 0 <= |y| <= x
-//               = sign(y) * (pi/2 - atan( |x|/|y| )   if 0 <= x < |y|
-//               = sign(y) * (pi - atan( |y|/|x| ))    if 0 <= |y| <= -x
-//               = sign(y) * (pi/2 + atan( |x|/|y| ))  if 0 <= -x < |y|
-
-// * Range reduction 3: look up table.
-// After the previous two range reduction steps, we reduce the problem to
-// compute atan(u) with 0 <= u <= 1, or to be precise:
-//   atan( n / d ) where n = min(|x|, |y|) and d = max(|x|, |y|).
-// An accurate polynomial approximation for the whole [0, 1] input range will
-// require a very large degree.  To make it more efficient, we reduce the input
-// range further by finding an integer idx such that:
-//   | n/d - idx/64 | <= 1/128.
-// In particular,
-//   idx := round(2^6 * n/d)
-// Then for the fast pass, we find a polynomial approximation for:
-//   atan( n/d ) ~ atan( idx/64 ) + (n/d - idx/64) * Q(n/d - idx/64)
-// For the accurate pass, we use the addition formula:
-//   atan( n/d ) - atan( idx/64 ) = atan( (n/d - idx/64)/(1 + (n*idx)/(64*d)) )
-//                                = atan( (n - d*(idx/64))/(d + n*(idx/64)) )
-// And for the fast pass, we use degree-9 Taylor polynomial to compute the RHS:
-//   atan(u) ~ P(u) = u - u^3/3 + u^5/5 - u^7/7 + u^9/9
-// with absolute errors bounded by:
-//   |atan(u) - P(u)| < |u|^11 / 11 < 2^-80
-// and relative errors bounded by:
-//   |(atan(u) - P(u)) / P(u)| < u^10 / 11 < 2^-73.
-
 LLVM_LIBC_FUNCTION(double, atan2, (double y, double x)) {
-  using namespace atan_internal;
-  using FPBits = fputil::FPBits<double>;
-
-  constexpr double IS_NEG[2] = {1.0, -1.0};
-  constexpr DoubleDouble ZERO = {0.0, 0.0};
-  constexpr DoubleDouble MZERO = {-0.0, -0.0};
-  constexpr DoubleDouble PI = {0x1.1a62633145c07p-53, 0x1.921fb54442d18p+1};
-  constexpr DoubleDouble MPI = {-0x1.1a62633145c07p-53, -0x1.921fb54442d18p+1};
-  constexpr DoubleDouble PI_OVER_2 = {0x1.1a62633145c07p-54,
-                                      0x1.921fb54442d18p0};
-  constexpr DoubleDouble MPI_OVER_2 = {-0x1.1a62633145c07p-54,
-                                       -0x1.921fb54442d18p0};
-  constexpr DoubleDouble PI_OVER_4 = {0x1.1a62633145c07p-55,
-                                      0x1.921fb54442d18p-1};
-  constexpr DoubleDouble THREE_PI_OVER_4 = {0x1.a79394c9e8a0ap-54,
-                                            0x1.2d97c7f3321d2p+1};
-  // Adjustment for constant term:
-  //   CONST_ADJ[x_sign][y_sign][recip]
-  constexpr DoubleDouble CONST_ADJ[2][2][2] = {
-      {{ZERO, MPI_OVER_2}, {MZERO, MPI_OVER_2}},
-      {{MPI, PI_OVER_2}, {MPI, PI_OVER_2}}};
-
-  FPBits x_bits(x), y_bits(y);
-  bool x_sign = x_bits.sign().is_neg();
-  bool y_sign = y_bits.sign().is_neg();
-  x_bits = x_bits.abs();
-  y_bits = y_bits.abs();
-  uint64_t x_abs = x_bits.uintval();
-  uint64_t y_abs = y_bits.uintval();
-  bool recip = x_abs < y_abs;
-  uint64_t min_abs = recip ? x_abs : y_abs;
-  uint64_t max_abs = !recip ? x_abs : y_abs;
-  unsigned min_exp = static_cast<unsigned>(min_abs >> FPBits::FRACTION_LEN);
-  unsigned max_exp = static_cast<unsigned>(max_abs >> FPBits::FRACTION_LEN);
-
-  double num = FPBits(min_abs).get_val();
-  double den = FPBits(max_abs).get_val();
-
-  // Check for exceptional cases, whether inputs are 0, inf, nan, or close to
-  // overflow, or close to underflow.
-  if (LIBC_UNLIKELY(max_exp > 0x7ffU - 128U || min_exp < 128U)) {
-    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);
-      return FPBits::quiet_nan().get_val();
-    }
-    unsigned x_except = x == 0.0 ? 0 : (FPBits(x_abs).is_inf() ? 2 : 1);
-    unsigned y_except = y == 0.0 ? 0 : (FPBits(y_abs).is_inf() ? 2 : 1);
-
-    // Exceptional cases:
-    //   EXCEPT[y_except][x_except][x_is_neg]
-    // with x_except & y_except:
-    //   0: zero
-    //   1: finite, non-zero
-    //   2: infinity
-    constexpr DoubleDouble EXCEPTS[3][3][2] = {
-        {{ZERO, PI}, {ZERO, PI}, {ZERO, PI}},
-        {{PI_OVER_2, PI_OVER_2}, {ZERO, ZERO}, {ZERO, PI}},
-        {{PI_OVER_2, PI_OVER_2},
-         {PI_OVER_2, PI_OVER_2},
-         {PI_OVER_4, THREE_PI_OVER_4}},
-    };
-
-    if ((x_except != 1) || (y_except != 1)) {
-      DoubleDouble r = EXCEPTS[y_except][x_except][x_sign];
-      return fputil::multiply_add(IS_NEG[y_sign], r.hi, IS_NEG[y_sign] * r.lo);
-    }
-    bool scale_up = min_exp < 128U;
-    bool scale_down = max_exp > 0x7ffU - 128U;
-    // At least one input is denormal, multiply both numerator and denominator
-    // by some large enough power of 2 to normalize denormal inputs.
-    if (scale_up) {
-      num *= 0x1.0p64;
-      if (!scale_down)
-        den *= 0x1.0p64;
-    } else if (scale_down) {
-      den *= 0x1.0p-64;
-      if (!scale_up)
-        num *= 0x1.0p-64;
-    }
-
-    min_abs = FPBits(num).uintval();
-    max_abs = FPBits(den).uintval();
-    min_exp = static_cast<unsigned>(min_abs >> FPBits::FRACTION_LEN);
-    max_exp = static_cast<unsigned>(max_abs >> FPBits::FRACTION_LEN);
-  }
-
-  double final_sign = IS_NEG[(x_sign != y_sign) != recip];
-  DoubleDouble const_term = CONST_ADJ[x_sign][y_sign][recip];
-  unsigned exp_diff = max_exp - min_exp;
-  // We have the following bound for normalized n and d:
-  //   2^(-exp_diff - 1) < n/d < 2^(-exp_diff + 1).
-  if (LIBC_UNLIKELY(exp_diff > 54)) {
-    return fputil::multiply_add(final_sign, const_term.hi,
-                                final_sign * (const_term.lo + num / den));
-  }
-
-  double k = fputil::nearest_integer(64.0 * num / den);
-  unsigned idx = static_cast<unsigned>(k);
-  // k = idx / 64
-  k *= 0x1.0p-6;
-
-  // Range reduction:
-  // atan(n/d) - atan(k/64) = atan((n/d - k/64) / (1 + (n/d) * (k/64)))
-  //                        = atan((n - d * k/64)) / (d + n * k/64))
-  DoubleDouble num_k = fputil::exact_mult(num, k);
-  DoubleDouble den_k = fputil::exact_mult(den, k);
-
-  // num_dd = n - d * k
-  DoubleDouble num_dd = fputil::e...
[truncated]

@bassiounix bassiounix requested review from lntue and removed request for keith, rupprecht and aaronmondal July 28, 2025 15:09
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder branch from 65ffa96 to e361d72 Compare July 28, 2025 15:18
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from e622554 to d0488b8 Compare July 28, 2025 15:19
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder branch from e361d72 to 5077f3f Compare July 28, 2025 16:45
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from d0488b8 to 079c38e Compare July 28, 2025 16:46
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder branch from 5077f3f to bd94b9d Compare July 28, 2025 17:33
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from 079c38e to fd8651a Compare July 28, 2025 17:33
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder branch from bd94b9d to f4dade3 Compare July 28, 2025 18:21
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from fd8651a to 29c47d3 Compare July 28, 2025 18:21
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder branch from f4dade3 to 72b3b89 Compare July 29, 2025 17:22
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from 29c47d3 to bc90bfa Compare July 29, 2025 17:22
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder branch from 72b3b89 to a491096 Compare July 29, 2025 17:51
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch 2 times, most recently from d411e78 to d2d3ef1 Compare July 29, 2025 17:57
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder branch from a491096 to 0f24379 Compare July 29, 2025 17:57
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from d2d3ef1 to c4fe44e Compare July 29, 2025 18:18
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder branch 2 times, most recently from 4cc63c7 to 8ca5b0c Compare July 30, 2025 04:26
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from c4fe44e to 6ea5207 Compare July 30, 2025 04:27
Base automatically changed from users/bassiounix/spr/07-28-_libc_math_refactor_atanf16_implementation_to_header-only_in_src___support_math_folder to main July 30, 2025 20:31
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch 3 times, most recently from 28d927f to 3d0a9b5 Compare July 30, 2025 20:49
Copy link
Contributor Author

bassiounix commented Jul 30, 2025

Merge activity

  • Jul 30, 9:53 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 30, 9:55 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 30, 9:59 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 30, 10:07 PM UTC: @bassiounix merged this pull request with Graphite.

@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from 3d0a9b5 to 54f80ed Compare July 30, 2025 21:54
@bassiounix bassiounix force-pushed the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch from 54f80ed to 45b9f4e Compare July 30, 2025 21:58
@bassiounix bassiounix merged commit c8b6ddf into main Jul 30, 2025
19 checks passed
@bassiounix bassiounix deleted the users/bassiounix/spr/07-28-_libc_math_refactor_atan2_implementation_to_header-only_in_src___support_math_folder branch July 30, 2025 22:07
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 30, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building libc,utils at step 5 "compile-openmp".

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

Here is the relevant piece of the build log for the reference
Step 5 (compile-openmp) failure: build (failure)
...
1.219 [4/32/667] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fsqrt.dir/fsqrt.cpp.o
1.220 [4/31/668] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16addf.dir/f16addf.cpp.o
1.224 [4/30/669] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16divl.dir/f16divl.cpp.o
1.224 [4/29/670] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.fmaf16.dir/fmaf16.cpp.o
1.227 [4/28/671] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2.dir/atan2.cpp.o
1.227 [4/27/672] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16sqrt.dir/f16sqrt.cpp.o
1.241 [4/26/673] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16sqrtl.dir/f16sqrtl.cpp.o
1.249 [4/25/674] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16div.dir/f16div.cpp.o
1.255 [4/24/675] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16sqrtf.dir/f16sqrtf.cpp.o
1.257 [4/23/676] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.o
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang++ --target=amdgcn-amd-amdhsa -DLIBC_NAMESPACE=__llvm_libc_22_0_0_git -D__LIBC_USE_FLOAT16_CONVERSION -I/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc -isystem /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa -O3 -DNDEBUG --target=amdgcn-amd-amdhsa -D__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC -D__LIBC_USE_BUILTIN_ROUND -D__LIBC_USE_BUILTIN_ROUNDEVEN -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)" -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_SHARED -fpie -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -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 -nogpulib -fvisibility=hidden -fconvergent-functions -flto -Wno-multi-gpu -Xclang -mcode-object-version=none -DLIBC_COPT_PUBLIC_PACKAGING -UNDEBUG -MD -MT libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.o -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.o.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.o -c /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/math/generic/atan2l.cpp
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/math/generic/atan2l.cpp:20:7: error: use of undeclared identifier 'atan2'; did you mean 'atan2l'?
   20 |       atan2(static_cast<double>(y), static_cast<double>(x)));
      |       ^~~~~
      |       atan2l
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/math/generic/atan2l.cpp:17:33: note: 'atan2l' declared here
   17 | LLVM_LIBC_FUNCTION(long double, atan2l, (long double y, long double x)) {
      |                                 ^
1 error generated.
1.271 [4/22/677] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.dmull.dir/dmull.cpp.o
1.287 [4/21/678] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16sub.dir/f16sub.cpp.o
1.291 [4/20/679] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16fmaf.dir/f16fmaf.cpp.o
1.292 [4/19/680] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16mul.dir/f16mul.cpp.o
1.293 [4/18/681] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan.dir/atan.cpp.o
1.294 [4/17/682] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16addl.dir/f16addl.cpp.o
1.299 [4/16/683] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16divf.dir/f16divf.cpp.o
1.300 [4/15/684] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16mulf.dir/f16mulf.cpp.o
1.302 [4/14/685] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16mull.dir/f16mull.cpp.o
1.309 [4/13/686] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16add.dir/f16add.cpp.o
1.309 [4/12/687] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16fmal.dir/f16fmal.cpp.o
1.325 [4/11/688] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16subf.dir/f16subf.cpp.o
1.333 [4/10/689] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16subl.dir/f16subl.cpp.o
1.343 [4/9/690] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.f16fma.dir/f16fma.cpp.o
1.442 [4/8/691] Building CXX object libc/src/time/CMakeFiles/libc.src.time.strftime_l.dir/strftime_l.cpp.o
1.465 [4/7/692] Building CXX object libc/src/time/CMakeFiles/libc.src.time.strftime.dir/strftime.cpp.o
1.794 [4/6/693] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.vsnprintf.dir/vsnprintf.cpp.o
1.828 [4/5/694] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.snprintf.dir/snprintf.cpp.o
1.830 [4/4/695] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.sprintf.dir/sprintf.cpp.o
1.877 [4/3/696] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.vsprintf.dir/vsprintf.cpp.o
1.941 [4/2/697] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.vasprintf.dir/vasprintf.cpp.o
1.965 [4/1/698] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.asprintf.dir/asprintf.cpp.o
ninja: build stopped: subcommand failed.
42.429 [6/2/4683] No patch step for 'runtimes'
FAILED: runtimes/runtimes-amdgcn-amd-amdhsa-stamps/runtimes-amdgcn-amd-amdhsa-build /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-amdgcn-amd-amdhsa-stamps/runtimes-amdgcn-amd-amdhsa-build 
cd /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-amdgcn-amd-amdhsa-bins && /usr/bin/cmake --build .
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 30, 2025

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

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

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)
...
[914/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.asinf.dir/asinf.cpp.obj
[915/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.ffs.dir/ffs.cpp.obj
[916/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.index.dir/index.cpp.obj
[917/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.strcasecmp.dir/strcasecmp.cpp.obj
[918/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memset_explicit.dir/memset_explicit.cpp.obj
[919/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.rindex.dir/rindex.cpp.obj
[920/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ffmal.dir/ffmal.cpp.obj
[921/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ffma.dir/ffma.cpp.obj
[922/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.setpayloadsig.dir/setpayloadsig.cpp.obj
[923/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.obj
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-7bp2xusl/./bin/clang++ --target=armv7em-none-eabi -DLIBC_NAMESPACE=__llvm_libc_22_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-7bp2xusl/include/armv7em-unknown-none-eabi --target=armv7em-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" "-Dfputs(string, stream)=puts(string)" -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-7bp2xusl/runtimes/runtimes-armv7em-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG --target=armv7em-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.atan2l.dir/atan2l.cpp.obj -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.obj.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/atan2l.cpp
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/atan2l.cpp:20:7: error: use of undeclared identifier 'atan2'; did you mean 'atan2l'?
   20 |       atan2(static_cast<double>(y), static_cast<double>(x)));
      |       ^~~~~
      |       atan2l
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/atan2l.cpp:17:33: note: 'atan2l' declared here
   17 | LLVM_LIBC_FUNCTION(long double, atan2l, (long double y, long double x)) {
      |                                 ^
1 error generated.
[924/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.ffsl.dir/ffsl.cpp.obj
[925/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.strcasecmp_l.dir/strcasecmp_l.cpp.obj
[926/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.setpayloadsigf.dir/setpayloadsigf.cpp.obj
[927/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strndup.dir/strndup.cpp.obj
[928/2524] Building CXX object libc/src/stdio/baremetal/CMakeFiles/libc.src.stdio.baremetal.vscanf.dir/vscanf.cpp.obj
[929/2524] Building CXX object libc/src/time/CMakeFiles/libc.src.time.difftime.dir/difftime.cpp.obj
[930/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.cbrtf.dir/cbrtf.cpp.obj
[931/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.bcmp.dir/bcmp.cpp.obj
[932/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.strncasecmp.dir/strncasecmp.cpp.obj
[933/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strxfrm_l.dir/strxfrm_l.cpp.obj
[934/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.ffsll.dir/ffsll.cpp.obj
[935/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan.dir/atan.cpp.obj
[936/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strxfrm.dir/strxfrm.cpp.obj
[937/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.scalbn.dir/scalbn.cpp.obj
[938/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.acosf.dir/acosf.cpp.obj
[939/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.setpayloadsigl.dir/setpayloadsigl.cpp.obj
[940/2524] Building CXX object libc/src/time/baremetal/CMakeFiles/libc.src.time.baremetal.timespec_get.dir/timespec_get.cpp.obj
[941/2524] Building CXX object libc/src/locale/CMakeFiles/libc.src.locale.locale.dir/locale.cpp.obj
[942/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memcpy.dir/memcpy.cpp.obj
[943/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.bcopy.dir/bcopy.cpp.obj
[944/2524] Building CXX object libc/src/locale/CMakeFiles/libc.src.locale.freelocale.dir/freelocale.cpp.obj
[945/2524] Building CXX object libc/src/locale/CMakeFiles/libc.src.locale.uselocale.dir/uselocale.cpp.obj
[946/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.strncasecmp_l.dir/strncasecmp_l.cpp.obj
[947/2524] Building CXX object libc/src/locale/CMakeFiles/libc.src.locale.duplocale.dir/duplocale.cpp.obj
[948/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2.dir/atan2.cpp.obj
[949/2524] Building CXX object libc/src/wchar/CMakeFiles/libc.src.wchar.wcslen.dir/wcslen.cpp.obj
[950/2524] Building CXX object libc/src/time/baremetal/CMakeFiles/libc.src.time.baremetal.clock.dir/clock.cpp.obj
[951/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.bzero.dir/bzero.cpp.obj
[952/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memmove.dir/memmove.cpp.obj
Step 6 (build) failure: build (failure)
...
[914/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.asinf.dir/asinf.cpp.obj
[915/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.ffs.dir/ffs.cpp.obj
[916/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.index.dir/index.cpp.obj
[917/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.strcasecmp.dir/strcasecmp.cpp.obj
[918/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memset_explicit.dir/memset_explicit.cpp.obj
[919/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.rindex.dir/rindex.cpp.obj
[920/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ffmal.dir/ffmal.cpp.obj
[921/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.ffma.dir/ffma.cpp.obj
[922/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.setpayloadsig.dir/setpayloadsig.cpp.obj
[923/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.obj
FAILED: libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-7bp2xusl/./bin/clang++ --target=armv7em-none-eabi -DLIBC_NAMESPACE=__llvm_libc_22_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-7bp2xusl/include/armv7em-unknown-none-eabi --target=armv7em-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" "-Dfputs(string, stream)=puts(string)" -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-7bp2xusl/runtimes/runtimes-armv7em-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG --target=armv7em-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.atan2l.dir/atan2l.cpp.obj -MF libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.obj.d -o libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2l.dir/atan2l.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/atan2l.cpp
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/atan2l.cpp:20:7: error: use of undeclared identifier 'atan2'; did you mean 'atan2l'?
   20 |       atan2(static_cast<double>(y), static_cast<double>(x)));
      |       ^~~~~
      |       atan2l
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/math/generic/atan2l.cpp:17:33: note: 'atan2l' declared here
   17 | LLVM_LIBC_FUNCTION(long double, atan2l, (long double y, long double x)) {
      |                                 ^
1 error generated.
[924/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.ffsl.dir/ffsl.cpp.obj
[925/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.strcasecmp_l.dir/strcasecmp_l.cpp.obj
[926/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.setpayloadsigf.dir/setpayloadsigf.cpp.obj
[927/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strndup.dir/strndup.cpp.obj
[928/2524] Building CXX object libc/src/stdio/baremetal/CMakeFiles/libc.src.stdio.baremetal.vscanf.dir/vscanf.cpp.obj
[929/2524] Building CXX object libc/src/time/CMakeFiles/libc.src.time.difftime.dir/difftime.cpp.obj
[930/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.cbrtf.dir/cbrtf.cpp.obj
[931/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.bcmp.dir/bcmp.cpp.obj
[932/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.strncasecmp.dir/strncasecmp.cpp.obj
[933/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strxfrm_l.dir/strxfrm_l.cpp.obj
[934/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.ffsll.dir/ffsll.cpp.obj
[935/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan.dir/atan.cpp.obj
[936/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strxfrm.dir/strxfrm.cpp.obj
[937/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.scalbn.dir/scalbn.cpp.obj
[938/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.acosf.dir/acosf.cpp.obj
[939/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.setpayloadsigl.dir/setpayloadsigl.cpp.obj
[940/2524] Building CXX object libc/src/time/baremetal/CMakeFiles/libc.src.time.baremetal.timespec_get.dir/timespec_get.cpp.obj
[941/2524] Building CXX object libc/src/locale/CMakeFiles/libc.src.locale.locale.dir/locale.cpp.obj
[942/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memcpy.dir/memcpy.cpp.obj
[943/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.bcopy.dir/bcopy.cpp.obj
[944/2524] Building CXX object libc/src/locale/CMakeFiles/libc.src.locale.freelocale.dir/freelocale.cpp.obj
[945/2524] Building CXX object libc/src/locale/CMakeFiles/libc.src.locale.uselocale.dir/uselocale.cpp.obj
[946/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.strncasecmp_l.dir/strncasecmp_l.cpp.obj
[947/2524] Building CXX object libc/src/locale/CMakeFiles/libc.src.locale.duplocale.dir/duplocale.cpp.obj
[948/2524] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.atan2.dir/atan2.cpp.obj
[949/2524] Building CXX object libc/src/wchar/CMakeFiles/libc.src.wchar.wcslen.dir/wcslen.cpp.obj
[950/2524] Building CXX object libc/src/time/baremetal/CMakeFiles/libc.src.time.baremetal.clock.dir/clock.cpp.obj
[951/2524] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.bzero.dir/bzero.cpp.obj
[952/2524] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memmove.dir/memmove.cpp.obj

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