Remove unnecessary const-time x87-related checks

This commit is contained in:
Jubilee Young 2022-04-22 18:39:25 -07:00
parent bb555b828c
commit 4da8682523
2 changed files with 16 additions and 32 deletions

View File

@ -928,19 +928,9 @@ const fn ct_f32_to_u32(ct: f32) -> u32 {
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 @@ pub const fn from_bits(v: u32) -> Self {
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...

View File

@ -921,19 +921,9 @@ const fn ct_f64_to_u64(ct: f64) -> u64 {
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 @@ pub const fn from_bits(v: u64) -> Self {
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...