[libcxx-commits] [libcxx] [libc++][modules] Remove dependency on __algorithm/max from hypot.h (PR #107150)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 3 13:30:39 PDT 2024
https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/107150
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.
>From 59d8246e2fc82a78c916f39c92d5d88125537038 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 30 Aug 2024 16:09:06 -0400
Subject: [PATCH] [libc++][modules] Remove dependency on __algorithm/max from
hypot.h
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.
---
libcxx/include/__math/hypot.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
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;
More information about the libcxx-commits
mailing list