Skip to content

Commit

Permalink
improve performance of signed saturating_mul
Browse files Browse the repository at this point in the history
Reciprocal throughput is improved from 2.3 to 1.7.
https://godbolt.org/z/ROMiX6
  • Loading branch information
tspiteri committed Oct 11, 2019
1 parent 000d90b commit 57aae75
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ $EndFeature, "
#[inline]
pub fn saturating_mul(self, rhs: Self) -> Self {
self.checked_mul(rhs).unwrap_or_else(|| {
if (self < 0 && rhs < 0) || (self > 0 && rhs > 0) {
if (self < 0) == (rhs < 0) {
Self::max_value()
} else {
Self::min_value()
Expand Down

0 comments on commit 57aae75

Please sign in to comment.