From 7ef20ac6395e0befd9adb2d25ddb65673cb0e9f4 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Fri, 21 Jun 2024 16:34:26 +0100 Subject: [PATCH 01/10] FoR array holds encoded values as unsinged --- encodings/fastlanes/src/for/compress.rs | 16 +++++++++----- encodings/fastlanes/src/for/compute.rs | 2 +- encodings/fastlanes/src/for/mod.rs | 28 +++++++++++++++++++----- vortex-scalar/src/primitive.rs | 29 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 12 deletions(-) diff --git a/encodings/fastlanes/src/for/compress.rs b/encodings/fastlanes/src/for/compress.rs index 1372d56c9..ff6d0eae7 100644 --- a/encodings/fastlanes/src/for/compress.rs +++ b/encodings/fastlanes/src/for/compress.rs @@ -60,9 +60,13 @@ impl EncodingCompression for FoREncoding { let child = match_each_integer_ptype!(parray.ptype(), |$T| { if shift == <$T>::PTYPE.bit_width() as u8 { - ConstantArray::new(Scalar::zero::<$T>(parray.dtype().nullability()), parray.len()).into_array() + let unsigned_dtype = + DType::Primitive(parray.ptype().to_unsigned(), parray.dtype().nullability()); + ConstantArray::new(Scalar::zero::<$T>(parray.dtype().nullability()).cast(&unsigned_dtype).unwrap(), parray.len()).into_array() } else { - compress_primitive::<$T>(parray, shift, $T::try_from(&min)?).into_array() + compress_primitive::<$T>(&parray, shift, $T::try_from(&min)?) + .reinterpret_cast(parray.ptype().to_unsigned()) + .into_array() } }); let for_like = like.map(|like_arr| FoRArray::try_from(like_arr).unwrap()); @@ -76,7 +80,7 @@ impl EncodingCompression for FoREncoding { } fn compress_primitive( - parray: PrimitiveArray, + parray: &PrimitiveArray, shift: u8, min: T, ) -> PrimitiveArray { @@ -103,7 +107,7 @@ fn compress_primitive( pub fn decompress(array: FoRArray) -> VortexResult { let shift = array.shift(); let ptype: PType = array.dtype().try_into()?; - let encoded = array.encoded().into_primitive()?; + let encoded = array.encoded().into_primitive()?.reinterpret_cast(ptype); Ok(match_each_integer_ptype!(ptype, |$T| { let reference: $T = array.reference().try_into()?; PrimitiveArray::from_vec( @@ -202,9 +206,9 @@ mod test { assert_eq!(i8::MIN, i8::try_from(compressed.reference()).unwrap()); let encoded = compressed.encoded().into_primitive().unwrap(); - let bitcast: &[u8] = unsafe { std::mem::transmute(encoded.maybe_null_slice::()) }; + let encoded_bytes: &[u8] = encoded.maybe_null_slice::(); let unsigned: Vec = (0..u8::MAX).collect_vec(); - assert_eq!(bitcast, unsigned.as_slice()); + assert_eq!(encoded_bytes, unsigned.as_slice()); let decompressed = compressed.array().clone().into_primitive().unwrap(); assert_eq!( diff --git a/encodings/fastlanes/src/for/compute.rs b/encodings/fastlanes/src/for/compute.rs index 8c12a2b63..d9d5d280a 100644 --- a/encodings/fastlanes/src/for/compute.rs +++ b/encodings/fastlanes/src/for/compute.rs @@ -36,7 +36,7 @@ impl TakeFn for FoRArray { impl ScalarAtFn for FoRArray { fn scalar_at(&self, index: usize) -> VortexResult { - let encoded_scalar = scalar_at(&self.encoded(), index)?; + let encoded_scalar = scalar_at(&self.encoded(), index)?.reinterpret_cast(self.ptype()); let encoded = PrimitiveScalar::try_from(&encoded_scalar)?; let reference = PrimitiveScalar::try_from(self.reference())?; diff --git a/encodings/fastlanes/src/for/mod.rs b/encodings/fastlanes/src/for/mod.rs index c1732ff2b..5095d4bb5 100644 --- a/encodings/fastlanes/src/for/mod.rs +++ b/encodings/fastlanes/src/for/mod.rs @@ -3,6 +3,7 @@ use vortex::stats::ArrayStatisticsCompute; use vortex::validity::{ArrayValidity, LogicalValidity}; use vortex::visitor::{AcceptArrayVisitor, ArrayVisitor}; use vortex::{impl_encoding, ArrayDType, Canonical, IntoCanonical}; +use vortex_dtype::PType; use vortex_error::vortex_bail; use vortex_scalar::Scalar; @@ -24,9 +25,13 @@ impl FoRArray { if reference.is_null() { vortex_bail!("Reference value cannot be null",); } - let reference = reference.cast(child.dtype())?; + let reference = reference.cast( + &reference + .dtype() + .with_nullability(child.dtype().nullability()), + )?; Self::try_from_parts( - child.dtype().clone(), + reference.dtype().clone(), FoRMetadata { reference, shift }, [child].into(), StatsSet::new(), @@ -35,9 +40,17 @@ impl FoRArray { #[inline] pub fn encoded(&self) -> Array { - self.array() - .child(0, self.dtype()) - .expect("Missing FoR child") + let dtype = if self.reference().dtype().is_signed_int() { + &DType::Primitive( + PType::try_from(self.reference().dtype()) + .unwrap() + .to_unsigned(), + self.reference().dtype().nullability(), + ) + } else { + self.dtype() + }; + self.array().child(0, dtype).expect("Missing FoR child") } #[inline] @@ -49,6 +62,11 @@ impl FoRArray { pub fn shift(&self) -> u8 { self.metadata().shift } + + #[inline] + pub fn ptype(&self) -> PType { + self.dtype().try_into().unwrap() + } } impl ArrayValidity for FoRArray { diff --git a/vortex-scalar/src/primitive.rs b/vortex-scalar/src/primitive.rs index f1e25f395..d8f51b358 100644 --- a/vortex-scalar/src/primitive.rs +++ b/vortex-scalar/src/primitive.rs @@ -84,6 +84,27 @@ impl Scalar { } } + pub fn reinterpret_cast(&self, ptype: PType) -> Self { + let primitive = PrimitiveScalar::try_from(self).unwrap(); + if primitive.ptype() == ptype { + return self.clone(); + } + + assert_eq!( + primitive.ptype().byte_width(), + ptype.byte_width(), + "can't reinterpret cast between integers of two different widths" + ); + + Self { + dtype: DType::Primitive(ptype, self.dtype.nullability()), + value: primitive + .pvalue + .map(ScalarValue::Primitive) + .unwrap_or_else(|| ScalarValue::Null), + } + } + pub fn zero>(nullability: Nullability) -> Self { Self { dtype: DType::Primitive(T::PTYPE, nullability), @@ -165,3 +186,11 @@ impl TryFrom<&Scalar> for usize { .map(|v| v as Self) } } + +impl TryFrom for usize { + type Error = VortexError; + + fn try_from(value: Scalar) -> Result { + usize::try_from(&value) + } +} From b73dbf49901d5087a6f0f3e3bb44deee1838dc70 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Fri, 21 Jun 2024 17:07:45 +0100 Subject: [PATCH 02/10] fixes --- vortex-scalar/src/primitive.rs | 17 ++++++++++------- vortex-scalar/src/pvalue.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/vortex-scalar/src/primitive.rs b/vortex-scalar/src/primitive.rs index d8f51b358..261e3a8ef 100644 --- a/vortex-scalar/src/primitive.rs +++ b/vortex-scalar/src/primitive.rs @@ -96,13 +96,16 @@ impl Scalar { "can't reinterpret cast between integers of two different widths" ); - Self { - dtype: DType::Primitive(ptype, self.dtype.nullability()), - value: primitive - .pvalue - .map(ScalarValue::Primitive) - .unwrap_or_else(|| ScalarValue::Null), - } + match_each_native_ptype!(ptype, |$P| { + Self { + dtype: DType::Primitive(ptype, self.dtype.nullability()), + value: primitive + .pvalue + .map(|p| p.reinterpret_cast::<$P>()) + .map(ScalarValue::Primitive) + .unwrap_or_else(|| ScalarValue::Null), + } + }) } pub fn zero>(nullability: Nullability) -> Self { diff --git a/vortex-scalar/src/pvalue.rs b/vortex-scalar/src/pvalue.rs index 1cc3702a8..f7777e506 100644 --- a/vortex-scalar/src/pvalue.rs +++ b/vortex-scalar/src/pvalue.rs @@ -1,6 +1,8 @@ +use std::mem; + use num_traits::NumCast; use vortex_dtype::half::f16; -use vortex_dtype::PType; +use vortex_dtype::{NativePType, PType}; use vortex_error::vortex_err; use vortex_error::VortexError; @@ -35,6 +37,31 @@ impl PValue { Self::F64(_) => PType::F64, } } + + pub fn reinterpret_cast>(&self) -> Self { + if T::PTYPE == self.ptype() { + return *self; + } + + assert!(T::PTYPE.is_int(), "Can only reinterpret cast integers"); + + assert_eq!( + T::PTYPE.byte_width(), + self.ptype().byte_width(), + "Cannot reinterpret cast between types of different widths" + ); + match self { + PValue::U8(v) => unsafe { mem::transmute::(*v) }.into(), + PValue::U16(v) => unsafe { mem::transmute::(*v) }.into(), + PValue::U32(v) => unsafe { mem::transmute::(*v) }.into(), + PValue::U64(v) => unsafe { mem::transmute::(*v) }.into(), + PValue::I8(v) => unsafe { mem::transmute::(*v) }.into(), + PValue::I16(v) => unsafe { mem::transmute::(*v) }.into(), + PValue::I32(v) => unsafe { mem::transmute::(*v) }.into(), + PValue::I64(v) => unsafe { mem::transmute::(*v) }.into(), + _ => unreachable!("Can't reinterpret cast floats"), + } + } } macro_rules! int_pvalue { From eff321d635785ffe0f3b55ef99c3184894503417 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Mon, 24 Jun 2024 14:04:18 +0100 Subject: [PATCH 03/10] less --- encodings/fastlanes/src/for/compress.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/encodings/fastlanes/src/for/compress.rs b/encodings/fastlanes/src/for/compress.rs index ff6d0eae7..79f7d27d6 100644 --- a/encodings/fastlanes/src/for/compress.rs +++ b/encodings/fastlanes/src/for/compress.rs @@ -60,9 +60,12 @@ impl EncodingCompression for FoREncoding { let child = match_each_integer_ptype!(parray.ptype(), |$T| { if shift == <$T>::PTYPE.bit_width() as u8 { - let unsigned_dtype = - DType::Primitive(parray.ptype().to_unsigned(), parray.dtype().nullability()); - ConstantArray::new(Scalar::zero::<$T>(parray.dtype().nullability()).cast(&unsigned_dtype).unwrap(), parray.len()).into_array() + ConstantArray::new( + Scalar::zero::<$T>(parray.dtype().nullability()) + .reinterpret_cast(parray.ptype().to_unsigned()), + parray.len(), + ) + .into_array() } else { compress_primitive::<$T>(&parray, shift, $T::try_from(&min)?) .reinterpret_cast(parray.ptype().to_unsigned()) From f3165fbe275bb05a3e23d1d7c1ab2c2c775607a4 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Mon, 24 Jun 2024 14:06:11 +0100 Subject: [PATCH 04/10] less --- encodings/fastlanes/src/for/compress.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/encodings/fastlanes/src/for/compress.rs b/encodings/fastlanes/src/for/compress.rs index 79f7d27d6..615e34ee4 100644 --- a/encodings/fastlanes/src/for/compress.rs +++ b/encodings/fastlanes/src/for/compress.rs @@ -6,7 +6,7 @@ use vortex::compress::{CompressConfig, Compressor, EncodingCompression}; use vortex::stats::{ArrayStatistics, Stat}; use vortex::validity::ArrayValidity; use vortex::{Array, ArrayDType, ArrayTrait, IntoArray, IntoArrayVariant}; -use vortex_dtype::{match_each_integer_ptype, NativePType, PType}; +use vortex_dtype::{match_each_integer_ptype, NativePType}; use vortex_error::{vortex_err, VortexResult}; use vortex_scalar::Scalar; @@ -109,7 +109,7 @@ fn compress_primitive( pub fn decompress(array: FoRArray) -> VortexResult { let shift = array.shift(); - let ptype: PType = array.dtype().try_into()?; + let ptype = array.ptype(); let encoded = array.encoded().into_primitive()?.reinterpret_cast(ptype); Ok(match_each_integer_ptype!(ptype, |$T| { let reference: $T = array.reference().try_into()?; From 8a123423d42f1f7a0f4d51be236a924aece2ee7f Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Mon, 24 Jun 2024 14:08:38 +0100 Subject: [PATCH 05/10] less --- encodings/fastlanes/src/for/mod.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/encodings/fastlanes/src/for/mod.rs b/encodings/fastlanes/src/for/mod.rs index 5095d4bb5..a1e4d6755 100644 --- a/encodings/fastlanes/src/for/mod.rs +++ b/encodings/fastlanes/src/for/mod.rs @@ -40,13 +40,8 @@ impl FoRArray { #[inline] pub fn encoded(&self) -> Array { - let dtype = if self.reference().dtype().is_signed_int() { - &DType::Primitive( - PType::try_from(self.reference().dtype()) - .unwrap() - .to_unsigned(), - self.reference().dtype().nullability(), - ) + let dtype = if self.ptype().is_signed_int() { + &DType::Primitive(self.ptype().to_unsigned(), self.dtype().nullability()) } else { self.dtype() }; From 8f00d3e5c3fa3635b7a8a3f6d152c79f97e81bf3 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Mon, 24 Jun 2024 16:39:17 +0100 Subject: [PATCH 06/10] less --- vortex-scalar/src/primitive.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/vortex-scalar/src/primitive.rs b/vortex-scalar/src/primitive.rs index 261e3a8ef..63144da7b 100644 --- a/vortex-scalar/src/primitive.rs +++ b/vortex-scalar/src/primitive.rs @@ -189,11 +189,3 @@ impl TryFrom<&Scalar> for usize { .map(|v| v as Self) } } - -impl TryFrom for usize { - type Error = VortexError; - - fn try_from(value: Scalar) -> Result { - usize::try_from(&value) - } -} From d678c8aab89be437210d1c41004cb0c7d1686526 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Mon, 24 Jun 2024 16:40:17 +0100 Subject: [PATCH 07/10] spaces --- vortex-scalar/src/pvalue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vortex-scalar/src/pvalue.rs b/vortex-scalar/src/pvalue.rs index f7777e506..61da81572 100644 --- a/vortex-scalar/src/pvalue.rs +++ b/vortex-scalar/src/pvalue.rs @@ -44,12 +44,12 @@ impl PValue { } assert!(T::PTYPE.is_int(), "Can only reinterpret cast integers"); - assert_eq!( T::PTYPE.byte_width(), self.ptype().byte_width(), "Cannot reinterpret cast between types of different widths" ); + match self { PValue::U8(v) => unsafe { mem::transmute::(*v) }.into(), PValue::U16(v) => unsafe { mem::transmute::(*v) }.into(), From 8e182536378045bea0a8c7e4192730d770a4d7aa Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Mon, 24 Jun 2024 16:51:25 +0100 Subject: [PATCH 08/10] fully implement reinterpret_cast --- vortex-scalar/src/primitive.rs | 18 +++++----- vortex-scalar/src/pvalue.rs | 61 +++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/vortex-scalar/src/primitive.rs b/vortex-scalar/src/primitive.rs index 63144da7b..58ec75a60 100644 --- a/vortex-scalar/src/primitive.rs +++ b/vortex-scalar/src/primitive.rs @@ -96,16 +96,14 @@ impl Scalar { "can't reinterpret cast between integers of two different widths" ); - match_each_native_ptype!(ptype, |$P| { - Self { - dtype: DType::Primitive(ptype, self.dtype.nullability()), - value: primitive - .pvalue - .map(|p| p.reinterpret_cast::<$P>()) - .map(ScalarValue::Primitive) - .unwrap_or_else(|| ScalarValue::Null), - } - }) + Self { + dtype: DType::Primitive(ptype, self.dtype.nullability()), + value: primitive + .pvalue + .map(|p| p.reinterpret_cast(ptype)) + .map(ScalarValue::Primitive) + .unwrap_or_else(|| ScalarValue::Null), + } } pub fn zero>(nullability: Nullability) -> Self { diff --git a/vortex-scalar/src/pvalue.rs b/vortex-scalar/src/pvalue.rs index 61da81572..a44b535ca 100644 --- a/vortex-scalar/src/pvalue.rs +++ b/vortex-scalar/src/pvalue.rs @@ -2,7 +2,7 @@ use std::mem; use num_traits::NumCast; use vortex_dtype::half::f16; -use vortex_dtype::{NativePType, PType}; +use vortex_dtype::PType; use vortex_error::vortex_err; use vortex_error::VortexError; @@ -38,28 +38,65 @@ impl PValue { } } - pub fn reinterpret_cast>(&self) -> Self { - if T::PTYPE == self.ptype() { + pub fn reinterpret_cast(&self, ptype: PType) -> Self { + if ptype == self.ptype() { return *self; } - assert!(T::PTYPE.is_int(), "Can only reinterpret cast integers"); assert_eq!( - T::PTYPE.byte_width(), + ptype.byte_width(), self.ptype().byte_width(), "Cannot reinterpret cast between types of different widths" ); match self { PValue::U8(v) => unsafe { mem::transmute::(*v) }.into(), - PValue::U16(v) => unsafe { mem::transmute::(*v) }.into(), - PValue::U32(v) => unsafe { mem::transmute::(*v) }.into(), - PValue::U64(v) => unsafe { mem::transmute::(*v) }.into(), + PValue::U16(v) => match ptype { + PType::I16 => unsafe { mem::transmute::(*v) }.into(), + PType::F16 => f16::from_bits(*v).into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, + PValue::U32(v) => match ptype { + PType::I32 => unsafe { mem::transmute::(*v) }.into(), + PType::F32 => f32::from_bits(*v).into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, + PValue::U64(v) => match ptype { + PType::I64 => unsafe { mem::transmute::(*v) }.into(), + PType::F64 => f64::from_bits(*v).into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, PValue::I8(v) => unsafe { mem::transmute::(*v) }.into(), - PValue::I16(v) => unsafe { mem::transmute::(*v) }.into(), - PValue::I32(v) => unsafe { mem::transmute::(*v) }.into(), - PValue::I64(v) => unsafe { mem::transmute::(*v) }.into(), - _ => unreachable!("Can't reinterpret cast floats"), + PValue::I16(v) => match ptype { + PType::U16 => unsafe { mem::transmute::(*v) }.into(), + PType::F16 => f16::from_bits(unsafe { mem::transmute::(*v) }).into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, + PValue::I32(v) => match ptype { + PType::U32 => unsafe { mem::transmute::(*v) }.into(), + PType::F32 => f32::from_bits(unsafe { mem::transmute::(*v) }).into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, + PValue::I64(v) => match ptype { + PType::U64 => unsafe { mem::transmute::(*v) }.into(), + PType::F64 => f64::from_bits(unsafe { mem::transmute::(*v) }).into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, + PValue::F16(v) => match ptype { + PType::U16 => v.to_bits().into(), + PType::I16 => unsafe { mem::transmute::(v.to_bits()) }.into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, + PValue::F32(v) => match ptype { + PType::U32 => v.to_bits().into(), + PType::I32 => unsafe { mem::transmute::(v.to_bits()) }.into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, + PValue::F64(v) => match ptype { + PType::U64 => v.to_bits().into(), + PType::I64 => unsafe { mem::transmute::(v.to_bits()) }.into(), + _ => unreachable!("Only same width type are allowed to be reinterpreted"), + }, } } } From f21a1c6e9611f7f99c5c5b82f8d595b495411849 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Mon, 24 Jun 2024 16:53:14 +0100 Subject: [PATCH 09/10] use --- vortex-scalar/src/primitive.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vortex-scalar/src/primitive.rs b/vortex-scalar/src/primitive.rs index 58ec75a60..9b9496e3e 100644 --- a/vortex-scalar/src/primitive.rs +++ b/vortex-scalar/src/primitive.rs @@ -96,14 +96,14 @@ impl Scalar { "can't reinterpret cast between integers of two different widths" ); - Self { - dtype: DType::Primitive(ptype, self.dtype.nullability()), - value: primitive + Scalar::new( + DType::Primitive(ptype, self.dtype.nullability()), + primitive .pvalue .map(|p| p.reinterpret_cast(ptype)) .map(ScalarValue::Primitive) .unwrap_or_else(|| ScalarValue::Null), - } + ) } pub fn zero>(nullability: Nullability) -> Self { From c8e9fb7e1354183b4e787341c54678ce2f16d597 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Mon, 24 Jun 2024 17:13:22 +0100 Subject: [PATCH 10/10] transmute --- vortex-scalar/src/pvalue.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/vortex-scalar/src/pvalue.rs b/vortex-scalar/src/pvalue.rs index a44b535ca..c077294f3 100644 --- a/vortex-scalar/src/pvalue.rs +++ b/vortex-scalar/src/pvalue.rs @@ -38,6 +38,7 @@ impl PValue { } } + #[allow(clippy::transmute_int_to_float, clippy::transmute_float_to_int)] pub fn reinterpret_cast(&self, ptype: PType) -> Self { if ptype == self.ptype() { return *self; @@ -53,48 +54,48 @@ impl PValue { PValue::U8(v) => unsafe { mem::transmute::(*v) }.into(), PValue::U16(v) => match ptype { PType::I16 => unsafe { mem::transmute::(*v) }.into(), - PType::F16 => f16::from_bits(*v).into(), + PType::F16 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, PValue::U32(v) => match ptype { PType::I32 => unsafe { mem::transmute::(*v) }.into(), - PType::F32 => f32::from_bits(*v).into(), + PType::F32 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, PValue::U64(v) => match ptype { PType::I64 => unsafe { mem::transmute::(*v) }.into(), - PType::F64 => f64::from_bits(*v).into(), + PType::F64 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, PValue::I8(v) => unsafe { mem::transmute::(*v) }.into(), PValue::I16(v) => match ptype { PType::U16 => unsafe { mem::transmute::(*v) }.into(), - PType::F16 => f16::from_bits(unsafe { mem::transmute::(*v) }).into(), + PType::F16 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, PValue::I32(v) => match ptype { PType::U32 => unsafe { mem::transmute::(*v) }.into(), - PType::F32 => f32::from_bits(unsafe { mem::transmute::(*v) }).into(), + PType::F32 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, PValue::I64(v) => match ptype { PType::U64 => unsafe { mem::transmute::(*v) }.into(), - PType::F64 => f64::from_bits(unsafe { mem::transmute::(*v) }).into(), + PType::F64 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, PValue::F16(v) => match ptype { - PType::U16 => v.to_bits().into(), - PType::I16 => unsafe { mem::transmute::(v.to_bits()) }.into(), + PType::U16 => unsafe { mem::transmute::(*v) }.into(), + PType::I16 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, PValue::F32(v) => match ptype { - PType::U32 => v.to_bits().into(), - PType::I32 => unsafe { mem::transmute::(v.to_bits()) }.into(), + PType::U32 => unsafe { mem::transmute::(*v) }.into(), + PType::I32 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, PValue::F64(v) => match ptype { - PType::U64 => v.to_bits().into(), - PType::I64 => unsafe { mem::transmute::(v.to_bits()) }.into(), + PType::U64 => unsafe { mem::transmute::(*v) }.into(), + PType::I64 => unsafe { mem::transmute::(*v) }.into(), _ => unreachable!("Only same width type are allowed to be reinterpreted"), }, }