File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
include/ccmath/internal/builtins Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments