[libcxx-commits] [libcxx] [libc++][modules] Remove dependency on __algorithm/max from hypot.h (PR #107150)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 3 13:31:15 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

<details>
<summary>Changes</summary>

That dependency was added recently when we made improvements to std::hypot, but that resulted in `__math` depending on `__algorithm`, which is a very heavyweight module. This patch uses `__builtin_fmax` to avoid depending on `std::max` as a simple solution.

---
Full diff: https://github.com/llvm/llvm-project/pull/107150.diff


1 Files Affected:

- (modified) libcxx/include/__math/hypot.h (+1-2) 


``````````diff
diff --git a/libcxx/include/__math/hypot.h b/libcxx/include/__math/hypot.h
index b992163711010a..94c43e7d0f9d1f 100644
--- a/libcxx/include/__math/hypot.h
+++ b/libcxx/include/__math/hypot.h
@@ -9,7 +9,6 @@
 #ifndef _LIBCPP___MATH_HYPOT_H
 #define _LIBCPP___MATH_HYPOT_H
 
-#include <__algorithm/max.h>
 #include <__config>
 #include <__math/abs.h>
 #include <__math/exponential_functions.h>
@@ -63,7 +62,7 @@ _LIBCPP_HIDE_FROM_ABI _Real __hypot(_Real __x, _Real __y, _Real __z) {
   const _Real __overflow_scale     = __math::ldexp(_Real(1), -(__exp + 20));
 
   // Scale arguments depending on their size
-  const _Real __max_abs = std::max(__math::fabs(__x), std::max(__math::fabs(__y), __math::fabs(__z)));
+  const _Real __max_abs = __builtin_fmax(__math::fabs(__x), __builtin_fmax(__math::fabs(__y), __math::fabs(__z)));
   _Real __scale;
   if (__max_abs > __overflow_threshold) { // x*x + y*y + z*z might overflow
     __scale = __overflow_scale;

``````````

</details>


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


More information about the libcxx-commits mailing list