wasm_interp: 'reinterpret' instructions

This commit is contained in:
Brian Carroll 2022-11-28 21:43:37 +00:00
parent 46737b4a41
commit 94ca352ed7
No known key found for this signature in database
GPG Key ID: 5C7B2EC4101703C0
2 changed files with 53 additions and 12 deletions

View File

@ -1139,10 +1139,26 @@ impl<'a> Instance<'a> {
F64CONVERTUI64 => todo!("{:?} @ {:#x}", op_code, file_offset),
F64PROMOTEF32 => todo!("{:?} @ {:#x}", op_code, file_offset),
I32REINTERPRETF32 => todo!("{:?} @ {:#x}", op_code, file_offset),
I64REINTERPRETF64 => todo!("{:?} @ {:#x}", op_code, file_offset),
F32REINTERPRETI32 => todo!("{:?} @ {:#x}", op_code, file_offset),
F64REINTERPRETI64 => todo!("{:?} @ {:#x}", op_code, file_offset),
I32REINTERPRETF32 => {
let x = self.value_stack.pop_f32();
self.value_stack
.push(Value::I32(i32::from_ne_bytes(x.to_ne_bytes())));
}
I64REINTERPRETF64 => {
let x = self.value_stack.pop_f64();
self.value_stack
.push(Value::I64(i64::from_ne_bytes(x.to_ne_bytes())));
}
F32REINTERPRETI32 => {
let x = self.value_stack.pop_i32();
self.value_stack
.push(Value::F32(f32::from_ne_bytes(x.to_ne_bytes())));
}
F64REINTERPRETI64 => {
let x = self.value_stack.pop_i64();
self.value_stack
.push(Value::F64(f64::from_ne_bytes(x.to_ne_bytes())));
}
}
if let Some(debug_string) = &self.debug_string {

View File

@ -1,6 +1,7 @@
#![cfg(test)]
use roc_wasm_interp::test_utils::test_op_example;
use roc_wasm_module::{opcodes::OpCode::*, Value};
// #[test]
// fn test_i32wrapi64() {}
@ -65,14 +66,38 @@ use roc_wasm_interp::test_utils::test_op_example;
// #[test]
// fn test_f64promotef32() {}
// #[test]
// fn test_i32reinterpretf32() {}
#[test]
fn test_i32reinterpretf32() {
test_op_example(
I32REINTERPRETF32,
[Value::F32(12.375)],
Value::I32(0x4146_0000),
);
}
// #[test]
// fn test_i64reinterpretf64() {}
#[test]
fn test_i64reinterpretf64() {
test_op_example(
I64REINTERPRETF64,
[Value::F64(0.01171875)],
Value::from(0x3F88_0000_0000_0000u64),
);
}
// #[test]
// fn test_f32reinterpreti32() {}
#[test]
fn test_f32reinterpreti32() {
test_op_example(
F32REINTERPRETI32,
[Value::I32(0x4146_0000)],
Value::F32(12.375),
);
}
// #[test]
// fn test_f64reinterpreti64() {}
#[test]
fn test_f64reinterpreti64() {
test_op_example(
F64REINTERPRETI64,
[Value::from(0x3F88_0000_0000_0000u64)],
Value::F64(0.01171875),
);
}