Remove unsigned variants of DataValue (#6218)

* remove unsigned variants of DataValue

* make value operation names more in-line with cranelift IR
This commit is contained in:
T0b1-iOS
2023-04-18 16:08:29 +02:00
committed by GitHub
parent d4b771e5a3
commit 387db16d28
5 changed files with 271 additions and 364 deletions

View File

@@ -17,11 +17,6 @@ pub enum DataValue {
I32(i32),
I64(i64),
I128(i128),
U8(u8),
U16(u16),
U32(u32),
U64(u64),
U128(u128),
F32(Ieee32),
F64(Ieee64),
V128([u8; 16]),
@@ -42,16 +37,6 @@ impl PartialEq for DataValue {
(I64(_), _) => false,
(I128(l), I128(r)) => l == r,
(I128(_), _) => false,
(U8(l), U8(r)) => l == r,
(U8(_), _) => false,
(U16(l), U16(r)) => l == r,
(U16(_), _) => false,
(U32(l), U32(r)) => l == r,
(U32(_), _) => false,
(U64(l), U64(r)) => l == r,
(U64(_), _) => false,
(U128(l), U128(r)) => l == r,
(U128(_), _) => false,
(F32(l), F32(r)) => l.as_f32() == r.as_f32(),
(F32(_), _) => false,
(F64(l), F64(r)) => l.as_f64() == r.as_f64(),
@@ -81,11 +66,11 @@ impl DataValue {
/// Return the Cranelift IR [Type] for this [DataValue].
pub fn ty(&self) -> Type {
match self {
DataValue::I8(_) | DataValue::U8(_) => types::I8,
DataValue::I16(_) | DataValue::U16(_) => types::I16,
DataValue::I32(_) | DataValue::U32(_) => types::I32,
DataValue::I64(_) | DataValue::U64(_) => types::I64,
DataValue::I128(_) | DataValue::U128(_) => types::I128,
DataValue::I8(_) => types::I8,
DataValue::I16(_) => types::I16,
DataValue::I32(_) => types::I32,
DataValue::I64(_) => types::I64,
DataValue::I128(_) => types::I128,
DataValue::F32(_) => types::F32,
DataValue::F64(_) => types::F64,
DataValue::V128(_) => types::I8X16, // A default type.
@@ -108,11 +93,6 @@ impl DataValue {
DataValue::I32(i) => DataValue::I32(i.swap_bytes()),
DataValue::I64(i) => DataValue::I64(i.swap_bytes()),
DataValue::I128(i) => DataValue::I128(i.swap_bytes()),
DataValue::U8(i) => DataValue::U8(i.swap_bytes()),
DataValue::U16(i) => DataValue::U16(i.swap_bytes()),
DataValue::U32(i) => DataValue::U32(i.swap_bytes()),
DataValue::U64(i) => DataValue::U64(i.swap_bytes()),
DataValue::U128(i) => DataValue::U128(i.swap_bytes()),
DataValue::F32(f) => DataValue::F32(Ieee32::with_bits(f.bits().swap_bytes())),
DataValue::F64(f) => DataValue::F64(Ieee64::with_bits(f.bits().swap_bytes())),
DataValue::V128(mut v) => {
@@ -160,7 +140,6 @@ impl DataValue {
DataValue::F64(f) => dst[..8].copy_from_slice(&f.bits().to_ne_bytes()[..]),
DataValue::V128(v) => dst[..16].copy_from_slice(&v[..]),
DataValue::V64(v) => dst[..8].copy_from_slice(&v[..]),
_ => unimplemented!(),
};
}
@@ -258,18 +237,6 @@ impl DataValue {
(DataValue::F32(a), DataValue::F32(b)) => a.bits() == b.bits(),
(DataValue::F64(a), DataValue::F64(b)) => a.bits() == b.bits(),
// when testing for bitwise equality, the sign information does not matter
(DataValue::I8(a), DataValue::U8(b)) => *a as u8 == *b,
(DataValue::U8(a), DataValue::I8(b)) => *a == *b as u8,
(DataValue::I16(a), DataValue::U16(b)) => *a as u16 == *b,
(DataValue::U16(a), DataValue::I16(b)) => *a == *b as u16,
(DataValue::I32(a), DataValue::U32(b)) => *a as u32 == *b,
(DataValue::U32(a), DataValue::I32(b)) => *a == *b as u32,
(DataValue::I64(a), DataValue::U64(b)) => *a as u64 == *b,
(DataValue::U64(a), DataValue::I64(b)) => *a == *b as u64,
(DataValue::I128(a), DataValue::U128(b)) => *a as u128 == *b,
(DataValue::U128(a), DataValue::I128(b)) => *a == *b as u128,
// We don't need to worry about F32x4 / F64x2 Since we compare V128 which is already the
// raw bytes anyway
(a, b) => a == b,
@@ -339,11 +306,6 @@ build_conversion_impl!(i16, I16, I16);
build_conversion_impl!(i32, I32, I32);
build_conversion_impl!(i64, I64, I64);
build_conversion_impl!(i128, I128, I128);
build_conversion_impl!(u8, U8, I8);
build_conversion_impl!(u16, U16, I16);
build_conversion_impl!(u32, U32, I32);
build_conversion_impl!(u64, U64, I64);
build_conversion_impl!(u128, U128, I128);
build_conversion_impl!(Ieee32, F32, F32);
build_conversion_impl!(Ieee64, F64, F64);
build_conversion_impl!([u8; 16], V128, I8X16);
@@ -362,11 +324,6 @@ impl Display for DataValue {
DataValue::I32(dv) => write!(f, "{}", dv),
DataValue::I64(dv) => write!(f, "{}", dv),
DataValue::I128(dv) => write!(f, "{}", dv),
DataValue::U8(dv) => write!(f, "{}", dv),
DataValue::U16(dv) => write!(f, "{}", dv),
DataValue::U32(dv) => write!(f, "{}", dv),
DataValue::U64(dv) => write!(f, "{}", dv),
DataValue::U128(dv) => write!(f, "{}", dv),
// The Ieee* wrappers here print the expected syntax.
DataValue::F32(dv) => write!(f, "{}", dv),
DataValue::F64(dv) => write!(f, "{}", dv),