Skip to content

Commit 2bdeeaa

Browse files
authored
[libc] Use __builtin_elementwise_fma instead of __builtin_fma (#126288)
__builtin_elementwise_fma doesn't consider errno and is thus more suitable for libc fma implementation.
1 parent 63c1be7 commit 2bdeeaa

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

libc/src/__support/FPUtil/FMA.h

+8
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ LIBC_INLINE OutType fma(InType x, InType y, InType z) {
2525

2626
#ifdef LIBC_TARGET_CPU_HAS_FMA
2727
template <> LIBC_INLINE float fma(float x, float y, float z) {
28+
#if __has_builtin(__builtin_elementwise_fma)
29+
return __builtin_elementwise_fma(x, y, z);
30+
#else
2831
return __builtin_fmaf(x, y, z);
32+
#endif
2933
}
3034

3135
template <> LIBC_INLINE double fma(double x, double y, double z) {
36+
#if __has_builtin(__builtin_elementwise_fma)
37+
return __builtin_elementwise_fma(x, y, z);
38+
#else
3239
return __builtin_fma(x, y, z);
40+
#endif
3341
}
3442
#endif // LIBC_TARGET_CPU_HAS_FMA
3543

libc/src/__support/FPUtil/multiply_add.h

+8
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,19 @@ namespace LIBC_NAMESPACE_DECL {
4747
namespace fputil {
4848

4949
LIBC_INLINE float multiply_add(float x, float y, float z) {
50+
#if __has_builtin(__builtin_elementwise_fma)
51+
return __builtin_elementwise_fma(x, y, z);
52+
#else
5053
return __builtin_fmaf(x, y, z);
54+
#endif
5155
}
5256

5357
LIBC_INLINE double multiply_add(double x, double y, double z) {
58+
#if __has_builtin(__builtin_elementwise_fma)
59+
return __builtin_elementwise_fma(x, y, z);
60+
#else
5461
return __builtin_fma(x, y, z);
62+
#endif
5563
}
5664

5765
} // namespace fputil

0 commit comments

Comments
 (0)