[PATCH] D14931: [Support] Add optional argument to SaturatingAdd() and SaturatingMultiply() to indicate that overflow occurred
David Li via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 23 12:52:30 PST 2015
davidxl added a comment.
Looks good with minor fix (suggested in comments).
================
Comment at: include/llvm/Support/MathExtras.h:687
@@ -672,3 +686,3 @@
typename std::enable_if<std::is_unsigned<T>::value, T>::type
-SaturatingMultiply(T X, T Y) {
+SaturatingMultiply(T X, T Y, bool &ResultOverflowed) {
// Hacker's Delight, p. 30 has a different algorithm, but we don't use that
----------------
I think it is better to initialize ResultOverlowed to false and only update when overflow happens.
http://reviews.llvm.org/D14931
More information about the llvm-commits
mailing list