implement signed integer extension operations

This commit is contained in:
Folkert 2023-07-25 19:22:03 +02:00
parent 26ef2bd46b
commit 0e71e0d1b1
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 90 additions and 9 deletions

View file

@ -1728,6 +1728,26 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
self.value_store
.push(Value::F64(f64::from_ne_bytes(x.to_ne_bytes())));
}
I32EXTEND8S => {
let x = self.value_store.pop_i32()?;
self.value_store.push(Value::I32(x as i8 as i32));
}
I32EXTEND16S => {
let x = self.value_store.pop_i32()?;
self.value_store.push(Value::I32(x as i16 as i32));
}
I64EXTEND8S => {
let x = self.value_store.pop_i64()?;
self.value_store.push(Value::I64(x as i8 as i64));
}
I64EXTEND16S => {
let x = self.value_store.pop_i64()?;
self.value_store.push(Value::I64(x as i16 as i64));
}
I64EXTEND32S => {
let x = self.value_store.pop_i64()?;
self.value_store.push(Value::I64(x as i32 as i64));
}
}
if let Some(debug_string) = &self.debug_string {

View file

@ -247,3 +247,48 @@ fn test_f64reinterpreti64() {
Value::F64(0.01171875),
);
}
#[test]
fn test_i32extend8s() {
test_op_example(
I32EXTEND8S,
[Value::from(0xFFu32 as i32)],
Value::I32(0xFFFFFFFFu32 as i32),
)
}
#[test]
fn test_i32extend16s() {
test_op_example(
I32EXTEND16S,
[Value::from(0xFFFFu32)],
Value::I32(0xFFFFFFFFu32 as i32),
)
}
#[test]
fn test_i64extend8s() {
test_op_example(
I64EXTEND8S,
[Value::from(0xFFu64 as i64)],
Value::I64(u64::MAX as i64),
)
}
#[test]
fn test_i64extend16s() {
test_op_example(
I64EXTEND16S,
[Value::from(0xFFFFu64 as i64)],
Value::I64(u64::MAX as i64),
)
}
#[test]
fn test_i64extend32s() {
test_op_example(
I64EXTEND32S,
[Value::from(0xFFFFFFFFu64 as i64)],
Value::I64(u64::MAX as i64),
)
}