[libc-commits] [libc] 6baee7f - [libc] Fix fputil::multiply_add and fputil::polyeval template signatures.
Tue Ly via libc-commits
libc-commits at lists.llvm.org
Thu Aug 24 09:01:09 PDT 2023
Author: Tue Ly
Date: 2023-08-24T12:00:55-04:00
New Revision: 6baee7f2b349db99a1843c741e159efae6089504
URL: https://github.com/llvm/llvm-project/commit/6baee7f2b349db99a1843c741e159efae6089504
DIFF: https://github.com/llvm/llvm-project/commit/6baee7f2b349db99a1843c741e159efae6089504.diff
LOG: [libc] Fix fputil::multiply_add and fputil::polyeval template signatures.
Fix fputil::multiply_add and fputil::polyeval template function
signatures.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D158746
Added:
Modified:
libc/src/__support/FPUtil/PolyEval.h
libc/src/__support/FPUtil/multiply_add.h
Removed:
################################################################################
diff --git a/libc/src/__support/FPUtil/PolyEval.h b/libc/src/__support/FPUtil/PolyEval.h
index 4b4d0a80222bd7..7f4af5c3406c2b 100644
--- a/libc/src/__support/FPUtil/PolyEval.h
+++ b/libc/src/__support/FPUtil/PolyEval.h
@@ -23,12 +23,27 @@
namespace __llvm_libc {
namespace fputil {
-template <typename T> LIBC_INLINE T polyeval(const T &, const T &a0) {
+template <typename T>
+LIBC_INLINE cpp::enable_if_t<(sizeof(T) > sizeof(void *)), T>
+polyeval(const T &, const T &a0) {
return a0;
}
+template <typename T>
+LIBC_INLINE cpp::enable_if_t<(sizeof(T) <= sizeof(void *)), T> polyeval(T,
+ T a0) {
+ return a0;
+}
+
+template <typename T, typename... Ts>
+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 <typename T, typename... Ts>
-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
index 39e53a36451e6a..b45293d976a865 100644
--- 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 @@ namespace fputil {
// which uses FMA instructions to speed up if available.
template <typename T>
-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 <typename T>
+LIBC_INLINE cpp::enable_if_t<(sizeof(T) <= sizeof(void *)), T>
+multiply_add(T x, T y, T z) {
return x * y + z;
}
More information about the libc-commits
mailing list