about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2022-04-22 18:39:25 -0700
committerJubilee Young <workingjubilee@gmail.com>2022-04-22 19:34:33 -0700
commit4da8682523ed8527046790f288ee55dd394be52a (patch)
tree63859fe4fa07ff3ce6d0923163a76d704ca4be0e
parentbb555b828ca93cef1f01d4c7b74015e8fe87dbae (diff)
downloadrust-4da8682523ed8527046790f288ee55dd394be52a.tar.gz
rust-4da8682523ed8527046790f288ee55dd394be52a.zip
Remove unnecessary const-time x87-related checks
-rw-r--r--library/core/src/num/f32.rs24
-rw-r--r--library/core/src/num/f64.rs24
2 files changed, 16 insertions, 32 deletions
diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs
index 5359f02851b..e1a46086af0 100644
--- a/library/core/src/num/f32.rs
+++ b/library/core/src/num/f32.rs
@@ -928,19 +928,9 @@ impl f32 {
                 FpCategory::Subnormal => {
                     panic!("const-eval error: cannot use f32::to_bits on a subnormal number")
                 }
-                FpCategory::Infinite =>
-                // SAFETY: Infinity per se is fine
-                unsafe { mem::transmute::<f32, u32>(ct) },
-                FpCategory::Zero | FpCategory::Normal => {
+                FpCategory::Infinite | FpCategory::Normal | FpCategory::Zero => {
                     // SAFETY: We have a normal floating point number. Now we transmute, i.e. do a bitcopy.
-                    let bits: u32 = unsafe { mem::transmute::<f32, u32>(ct) };
-                    // Let's doublecheck to make sure it wasn't a weird float by truncating it.
-                    if bits >> 23 & 0xFF == 0xFF {
-                        panic!(
-                            "const-eval error: an unusually large x87 floating point value should not leak into const eval"
-                        )
-                    };
-                    bits
+                    unsafe { mem::transmute::<f32, u32>(ct) }
                 }
             }
         }
@@ -1021,13 +1011,15 @@ impl f32 {
         const fn ct_u32_to_f32(ct: u32) -> f32 {
             match f32::classify_bits(ct) {
                 FpCategory::Subnormal => {
-                    panic!("const-eval error: cannot use f32::from_bits on a subnormal number");
+                    panic!("const-eval error: cannot use f32::from_bits on a subnormal number")
                 }
                 FpCategory::Nan => {
-                    panic!("const-eval error: cannot use f32::from_bits on NaN");
+                    panic!("const-eval error: cannot use f32::from_bits on NaN")
+                }
+                FpCategory::Infinite | FpCategory::Normal | FpCategory::Zero => {
+                    // SAFETY: It's not a frumious number
+                    unsafe { mem::transmute::<u32, f32>(ct) }
                 }
-                // SAFETY: It's not a frumious number
-                _ => unsafe { mem::transmute::<u32, f32>(ct) },
             }
         }
         // SAFETY: `u32` is a plain old datatype so we can always... uh...
diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs
index 61b040cf0fe..b07f201ca4a 100644
--- a/library/core/src/num/f64.rs
+++ b/library/core/src/num/f64.rs
@@ -921,19 +921,9 @@ impl f64 {
                 FpCategory::Subnormal => {
                     panic!("const-eval error: cannot use f64::to_bits on a subnormal number")
                 }
-                FpCategory::Infinite =>
-                // SAFETY: Infinity per se is fine
-                unsafe { mem::transmute::<f64, u64>(ct) },
-                FpCategory::Zero | FpCategory::Normal => {
+                FpCategory::Infinite | FpCategory::Normal | FpCategory::Zero => {
                     // SAFETY: We have a normal floating point number. Now we transmute, i.e. do a bitcopy.
-                    let bits: u64 = unsafe { mem::transmute::<f64, u64>(ct) };
-                    // Let's doublecheck to make sure it wasn't a weird float by truncating it.
-                    if (bits >> 52) & 0x7FF == 0x7FF {
-                        panic!(
-                            "const-eval error: an unusually large x87 floating point value should not leak into const eval"
-                        )
-                    };
-                    bits
+                    unsafe { mem::transmute::<f64, u64>(ct) }
                 }
             }
         }
@@ -1019,13 +1009,15 @@ impl f64 {
         const fn ct_u64_to_f64(ct: u64) -> f64 {
             match f64::classify_bits(ct) {
                 FpCategory::Subnormal => {
-                    panic!("const-eval error: cannot use f64::from_bits on a subnormal number");
+                    panic!("const-eval error: cannot use f64::from_bits on a subnormal number")
                 }
                 FpCategory::Nan => {
-                    panic!("const-eval error: cannot use f64::from_bits on NaN");
+                    panic!("const-eval error: cannot use f64::from_bits on NaN")
+                }
+                FpCategory::Infinite | FpCategory::Normal | FpCategory::Zero => {
+                    // SAFETY: It's not a frumious number
+                    unsafe { mem::transmute::<u64, f64>(ct) }
                 }
-                // SAFETY: It's not a frumious number
-                _ => unsafe { mem::transmute::<u64, f64>(ct) },
             }
         }
         // SAFETY: `u64` is a plain old datatype so we can always... uh...