Skip to content

Commit 88328bc

Browse files
committed
experimental builtin_fma support
Signed-off-by: Ian <[email protected]>
1 parent ce5d4b8 commit 88328bc

File tree

1 file changed

+29
-0
lines changed
  • include/ccmath/internal/builtins

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <type_traits>
4+
5+
namespace ccm::internal::builtin
6+
{
7+
template <typename T>
8+
inline constexpr bool has_constexpr_fma =
9+
#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__)
10+
(std::is_same_v<T, float> || std::is_same_v<T, double> || std::is_same_v<T, long double>);
11+
#else
12+
false;
13+
#endif
14+
15+
template <typename T>
16+
constexpr auto fma(T x, T y, T z)
17+
-> std::enable_if_t<has_constexpr_fma<T>, T>
18+
{
19+
if constexpr (std::is_same_v<T, float>) {
20+
return __builtin_fmaf(x, y, z);
21+
}
22+
if constexpr (std::is_same_v<T, double>) {
23+
return __builtin_fma(x, y, z);
24+
}
25+
if constexpr (std::is_same_v<T, long double>) {
26+
return __builtin_fmal(x, y, z);
27+
}
28+
}
29+
} // namespace ccm::internal::builtin

0 commit comments

Comments
 (0)