mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 15:59:20 +03:00
wasm_interp: 'reinterpret' instructions
This commit is contained in:
parent
46737b4a41
commit
94ca352ed7
@ -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 {
|
||||
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user