[libc-commits] [PATCH] D158746: [libc] Fix fputil::multiply_add and fputil::polyeval template signatures.

Tue Ly via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Aug 24 08:52:31 PDT 2023


lntue created this revision.
lntue added reviewers: michaelrj, sivachandra, gchatelet.
Herald added projects: libc-project, All.
lntue requested review of this revision.

Fix fputil::multiply_add and fputil::polyeval template function
signatures


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158746

Files:
  libc/src/__support/FPUtil/PolyEval.h
  libc/src/__support/FPUtil/multiply_add.h


Index: libc/src/__support/FPUtil/multiply_add.h
===================================================================
--- libc/src/__support/FPUtil/multiply_add.h
+++ 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 <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;
 }
 
Index: libc/src/__support/FPUtil/PolyEval.h
===================================================================
--- libc/src/__support/FPUtil/PolyEval.h
+++ 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);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158746.553148.patch
Type: text/x-patch
Size: 2148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230824/9537b0ba/attachment.bin>


More information about the libc-commits mailing list