mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
wasm_interp: last few instructions!
This commit is contained in:
parent
17810d5134
commit
d29ea7fedf
3 changed files with 91 additions and 7 deletions
|
@ -1107,9 +1107,28 @@ impl<'a> Instance<'a> {
|
|||
let arg1 = self.value_stack.pop_f32();
|
||||
self.value_stack.push(Value::F32(arg1 / arg2));
|
||||
}
|
||||
F32MIN => todo!("{:?} @ {:#x}", op_code, file_offset),
|
||||
F32MAX => todo!("{:?} @ {:#x}", op_code, file_offset),
|
||||
F32COPYSIGN => todo!("{:?} @ {:#x}", op_code, file_offset),
|
||||
F32MIN => {
|
||||
let arg2 = self.value_stack.pop_f32();
|
||||
let arg1 = self.value_stack.pop_f32();
|
||||
let result = if arg1 < arg2 { arg1 } else { arg2 };
|
||||
self.value_stack.push(Value::F32(result));
|
||||
}
|
||||
F32MAX => {
|
||||
let arg2 = self.value_stack.pop_f32();
|
||||
let arg1 = self.value_stack.pop_f32();
|
||||
let result = if arg1 > arg2 { arg1 } else { arg2 };
|
||||
self.value_stack.push(Value::F32(result));
|
||||
}
|
||||
F32COPYSIGN => {
|
||||
let arg2 = self.value_stack.pop_f32();
|
||||
let arg1 = self.value_stack.pop_f32();
|
||||
let result = if arg1.is_sign_negative() == arg2.is_sign_negative() {
|
||||
arg1
|
||||
} else {
|
||||
arg2
|
||||
};
|
||||
self.value_stack.push(Value::F32(result));
|
||||
}
|
||||
|
||||
F64ABS => {
|
||||
let arg = self.value_stack.pop_f64();
|
||||
|
@ -1175,9 +1194,28 @@ impl<'a> Instance<'a> {
|
|||
let arg1 = self.value_stack.pop_f64();
|
||||
self.value_stack.push(Value::F64(arg1 / arg2));
|
||||
}
|
||||
F64MIN => todo!("{:?} @ {:#x}", op_code, file_offset),
|
||||
F64MAX => todo!("{:?} @ {:#x}", op_code, file_offset),
|
||||
F64COPYSIGN => todo!("{:?} @ {:#x}", op_code, file_offset),
|
||||
F64MIN => {
|
||||
let arg2 = self.value_stack.pop_f64();
|
||||
let arg1 = self.value_stack.pop_f64();
|
||||
let result = if arg1 < arg2 { arg1 } else { arg2 };
|
||||
self.value_stack.push(Value::F64(result));
|
||||
}
|
||||
F64MAX => {
|
||||
let arg2 = self.value_stack.pop_f64();
|
||||
let arg1 = self.value_stack.pop_f64();
|
||||
let result = if arg1 > arg2 { arg1 } else { arg2 };
|
||||
self.value_stack.push(Value::F64(result));
|
||||
}
|
||||
F64COPYSIGN => {
|
||||
let arg2 = self.value_stack.pop_f64();
|
||||
let arg1 = self.value_stack.pop_f64();
|
||||
let result = if arg1.is_sign_negative() == arg2.is_sign_negative() {
|
||||
arg1
|
||||
} else {
|
||||
arg2
|
||||
};
|
||||
self.value_stack.push(Value::F64(result));
|
||||
}
|
||||
|
||||
I32WRAPI64 => {
|
||||
let arg = self.value_stack.pop_u64();
|
||||
|
|
|
@ -160,3 +160,26 @@ fn test_f32div() {
|
|||
test_f32_binop(op, -1.0, 0.0, f32::NEG_INFINITY);
|
||||
// test_f32_binop(op, 0.0, 0.0, f32::NAN); // can't check NaN for equality! LOL
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_f32min() {
|
||||
let op = F32MIN;
|
||||
test_f32_binop(op, 1.1, 2.2, 1.1);
|
||||
test_f32_binop(op, -1.1, -2.2, -2.2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_f32max() {
|
||||
let op = F32MAX;
|
||||
test_f32_binop(op, 1.1, 2.2, 2.2);
|
||||
test_f32_binop(op, -1.1, -2.2, -1.1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_f32copysign() {
|
||||
let op = F32COPYSIGN;
|
||||
test_f32_binop(op, 1.1, 2.2, 1.1);
|
||||
test_f32_binop(op, -1.1, -2.2, -1.1);
|
||||
test_f32_binop(op, -1.1, 1.1, 1.1);
|
||||
test_f32_binop(op, 1.1, -1.1, -1.1);
|
||||
}
|
||||
|
|
|
@ -158,5 +158,28 @@ fn test_f64div() {
|
|||
|
||||
test_f64_binop(op, 1.0, 0.0, f64::INFINITY);
|
||||
test_f64_binop(op, -1.0, 0.0, f64::NEG_INFINITY);
|
||||
// test_f64_binop(op, 0.0, 0.0, f64::NAN); // can't check NaN for equality! LOL
|
||||
// to-probably-never-do: check NaN. It needs its own special test setup.
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_f64min() {
|
||||
let op = F64MIN;
|
||||
test_f64_binop(op, 1.1, 2.2, 1.1);
|
||||
test_f64_binop(op, -1.1, -2.2, -2.2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_f64max() {
|
||||
let op = F64MAX;
|
||||
test_f64_binop(op, 1.1, 2.2, 2.2);
|
||||
test_f64_binop(op, -1.1, -2.2, -1.1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_f64copysign() {
|
||||
let op = F64COPYSIGN;
|
||||
test_f64_binop(op, 1.1, 2.2, 1.1);
|
||||
test_f64_binop(op, -1.1, -2.2, -1.1);
|
||||
test_f64_binop(op, -1.1, 1.1, 1.1);
|
||||
test_f64_binop(op, 1.1, -1.1, -1.1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue