diff --git a/libc/src/__support/FPUtil/PolyEval.h b/libc/src/__support/FPUtil/PolyEval.h --- a/libc/src/__support/FPUtil/PolyEval.h +++ b/libc/src/__support/FPUtil/PolyEval.h @@ -23,12 +23,27 @@ namespace __llvm_libc { namespace fputil { -template LIBC_INLINE T polyeval(const T &, const T &a0) { +template +LIBC_INLINE cpp::enable_if_t<(sizeof(T) > sizeof(void *)), T> +polyeval(const T &, const T &a0) { return a0; } +template +LIBC_INLINE cpp::enable_if_t<(sizeof(T) <= sizeof(void *)), T> polyeval(T, + T a0) { + return a0; +} + +template +LIBC_INLINE cpp::enable_if_t<(sizeof(T) > sizeof(void *)), T> +polyeval(const T &x, const T &a0, const Ts &...a) { + return multiply_add(x, polyeval(x, a...), a0); +} + template -LIBC_INLINE T polyeval(const T &x, const T &a0, const Ts &...a) { +LIBC_INLINE cpp::enable_if_t<(sizeof(T) <= sizeof(void *)), T> +polyeval(T x, T a0, Ts... a) { return multiply_add(x, polyeval(x, a...), a0); } diff --git a/libc/src/__support/FPUtil/multiply_add.h b/libc/src/__support/FPUtil/multiply_add.h --- a/libc/src/__support/FPUtil/multiply_add.h +++ b/libc/src/__support/FPUtil/multiply_add.h @@ -9,6 +9,7 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_MULTIPLY_ADD_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_MULTIPLY_ADD_H +#include "src/__support/CPP/type_traits.h" #include "src/__support/common.h" #include "src/__support/macros/properties/architectures.h" #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA @@ -21,7 +22,14 @@ // which uses FMA instructions to speed up if available. template -LIBC_INLINE T multiply_add(const T &x, const T &y, const T &z) { +LIBC_INLINE cpp::enable_if_t<(sizeof(T) > sizeof(void *)), T> +multiply_add(const T &x, const T &y, const T &z) { + return x * y + z; +} + +template +LIBC_INLINE cpp::enable_if_t<(sizeof(T) <= sizeof(void *)), T> +multiply_add(T x, T y, T z) { return x * y + z; }