[PATCH] D15385: [Support] Add saturating multiply-add support function

David Li via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 10 10:23:36 PST 2015


davidxl added inline comments.

================
Comment at: include/llvm/Support/MathExtras.h:727
@@ +726,3 @@
+typename std::enable_if<std::is_unsigned<T>::value, T>::type
+SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed = nullptr) {
+  bool Dummy;
----------------
slingn wrote:
> davidxl wrote:
> > Do we want types of X and Y to be same ? For instance, the weight can be less than 1.
> > 
> > Also we may want to have an overloaded function that is used for common cases where one of the X or Y is constant:
> > 
> > template <typename T, uint64_t Multiplier>
> > 	​typename std::enable_if<std::is_unsigned<T>::value, T>::type   		​       SaturatingMultiplyAdd(T X, T A, bool *ResultOverflowed = nullptr) {
> >  ...
> > }
> > 
> > it is probably just slightly more efficient so probably not in this patch.
> X and Y are the multiplicands. Why would they need to be different types for just the unsigned arithmetic case? I guess the addend (A) could usefully be a negative number but that's inconsistent with SaturatingAdd() as it is currently defined.
> 
> The pending weighted profile change (D15306) doesn't support weight < 1.
Ok -- sounds reasonable.


http://reviews.llvm.org/D15385





More information about the llvm-commits mailing list