This is an archive of the discontinued LLVM Phabricator instance.

[Support] Add optional argument to SaturatingAdd() and SaturatingMultiply() to indicate that overflow occurred
ClosedPublic

Authored by slingn on Nov 23 2015, 11:24 AM.

Details

Summary

Adds the ability for callers to detect when saturation occurred on the result of saturating addition/multiplication.

Diff Detail

Event Timeline

slingn updated this revision to Diff 40955.Nov 23 2015, 11:24 AM
slingn retitled this revision from to [Support] Add optional argument to SaturatingAdd() and SaturatingMultiply() to indicate that overflow occurred.
slingn updated this object.
slingn added reviewers: davidxl, silvas, rsmith.
slingn added a subscriber: llvm-commits.
davidxl edited edge metadata.Nov 23 2015, 12:52 PM

Looks good with minor fix (suggested in comments).

include/llvm/Support/MathExtras.h
687

I think it is better to initialize ResultOverlowed to false and only update when overflow happens.

slingn updated this revision to Diff 40968.Nov 23 2015, 1:24 PM
slingn marked an inline comment as done.
slingn edited edge metadata.

Updated for davidxl's comments.

This revision was automatically updated to reflect the committed changes.