-
Notifications
You must be signed in to change notification settings - Fork 15k
[libc] Use __builtin_elementwise_fma instead of __builtin_fma #126288
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
__builtin_elementwise_fma doesn't consider errno and is thus more suitable for libc fma implementation. Fixes llvm#126025
@llvm/pr-subscribers-libc Author: Petr Hosek (petrhosek) Changes__builtin_elementwise_fma doesn't consider errno and is thus more suitable for libc fma implementation. Fixes #126025 Full diff: https://github.com/llvm/llvm-project/pull/126288.diff 2 Files Affected:
diff --git a/libc/src/__support/FPUtil/FMA.h b/libc/src/__support/FPUtil/FMA.h
index 807d685239732e5..7b505d22c06b6ac 100644
--- a/libc/src/__support/FPUtil/FMA.h
+++ b/libc/src/__support/FPUtil/FMA.h
@@ -25,11 +25,11 @@ LIBC_INLINE OutType fma(InType x, InType y, InType z) {
#ifdef LIBC_TARGET_CPU_HAS_FMA
template <> LIBC_INLINE float fma(float x, float y, float z) {
- return __builtin_fmaf(x, y, z);
+ return __builtin_elementwise_fma(x, y, z);
}
template <> LIBC_INLINE double fma(double x, double y, double z) {
- return __builtin_fma(x, y, z);
+ return __builtin_elementwise_fma(x, y, z);
}
#endif // LIBC_TARGET_CPU_HAS_FMA
diff --git a/libc/src/__support/FPUtil/multiply_add.h b/libc/src/__support/FPUtil/multiply_add.h
index a86067c401873ba..763799f1f29d72b 100644
--- a/libc/src/__support/FPUtil/multiply_add.h
+++ b/libc/src/__support/FPUtil/multiply_add.h
@@ -47,11 +47,11 @@ namespace LIBC_NAMESPACE_DECL {
namespace fputil {
LIBC_INLINE float multiply_add(float x, float y, float z) {
- return __builtin_fmaf(x, y, z);
+ return __builtin_elementwise_fma(x, y, z);
}
LIBC_INLINE double multiply_add(double x, double y, double z) {
- return __builtin_fma(x, y, z);
+ return __builtin_elementwise_fma(x, y, z);
}
} // namespace fputil
|
Using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are borrowed from OpenCL I believe and aren't available in gcc
, so you'd need a has_builtin
guard. https://godbolt.org/z/s63hK9Y4T.
They're supposed to support LLVM's vector type AFAIK. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me but I'll wait for @arsenm to chime in since he knows this stuff better than I do.
I wonder if we should use the inline assembly version in the case where |
I'm fine with that; at least for 32b ARM (wasn't that the only arch that was problematic?). |
…26288) __builtin_elementwise_fma doesn't consider errno and is thus more suitable for libc fma implementation.
…26288) __builtin_elementwise_fma doesn't consider errno and is thus more suitable for libc fma implementation.
__builtin_elementwise_fma doesn't consider errno and is thus more suitable for libc fma implementation.