Auto merge of #47080 - varkor:contrib-12, r=rkruppe

Optimise min/max

Swapping the conditions generates more efficient x86 assembly. See
https://github.com/rust-lang/rust/pull/46926#issuecomment-354567412.

r? @rkruppe
This commit is contained in:
bors 2017-12-31 00:09:18 +00:00
commit 54d7285a34
2 changed files with 4 additions and 4 deletions

View file

@ -263,7 +263,7 @@ impl Float for f32 {
// Since we do not support sNaN in Rust yet, we do not need to handle them.
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
(if self < other || self.is_nan() { other } else { self }) * 1.0
(if self.is_nan() || self < other { other } else { self }) * 1.0
}
/// Returns the minimum of the two numbers.
@ -277,6 +277,6 @@ impl Float for f32 {
// Since we do not support sNaN in Rust yet, we do not need to handle them.
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
(if self < other || other.is_nan() { self } else { other }) * 1.0
(if other.is_nan() || self < other { self } else { other }) * 1.0
}
}

View file

@ -261,7 +261,7 @@ impl Float for f64 {
// Since we do not support sNaN in Rust yet, we do not need to handle them.
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
(if self < other || self.is_nan() { other } else { self }) * 1.0
(if self.is_nan() || self < other { other } else { self }) * 1.0
}
/// Returns the minimum of the two numbers.
@ -275,6 +275,6 @@ impl Float for f64 {
// Since we do not support sNaN in Rust yet, we do not need to handle them.
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
(if self < other || other.is_nan() { self } else { other }) * 1.0
(if other.is_nan() || self < other { self } else { other }) * 1.0
}
}