提交 54d7285a 编写于 作者: B bors

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
......@@ -263,7 +263,7 @@ fn max(self, other: f32) -> 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 @@ fn min(self, other: f32) -> 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
}
}
......@@ -261,7 +261,7 @@ fn max(self, other: f64) -> 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 @@ fn min(self, other: f64) -> 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
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册