about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-12-31 00:09:18 +0000
committerbors <bors@rust-lang.org>2017-12-31 00:09:18 +0000
commit54d7285a349a3558755a31bba5682d7618b66967 (patch)
tree0d8f4a7b0e07606bac90731b3483a7d578cb6b88
parent3f916bd3029262e2270dfbafb9ab045927499abd (diff)
parentfba16d3f0bcf697775d91e91064f8584b9697042 (diff)
downloadrust-54d7285a349a3558755a31bba5682d7618b66967.tar.gz
rust-54d7285a349a3558755a31bba5682d7618b66967.zip
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
-rw-r--r--src/libcore/num/f32.rs4
-rw-r--r--src/libcore/num/f64.rs4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs
index 7f758f2a23b..0dc58d61e49 100644
--- a/src/libcore/num/f32.rs
+++ b/src/libcore/num/f32.rs
@@ -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
     }
 }
diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs
index b9db4990a7e..0e76000efe9 100644
--- a/src/libcore/num/f64.rs
+++ b/src/libcore/num/f64.rs
@@ -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
     }
 }