wasm_interp: use wrapping arithmetic

This commit is contained in:
Brian Carroll 2022-11-27 22:07:31 +00:00
parent 8e15d49720
commit e3df393a22
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0

View file

@ -753,37 +753,37 @@ impl<'a> ExecutionState<'a> {
I32ADD => { I32ADD => {
let arg2 = self.value_stack.pop_i32(); let arg2 = self.value_stack.pop_i32();
let arg1 = self.value_stack.pop_i32(); let arg1 = self.value_stack.pop_i32();
self.value_stack.push(Value::from(arg1 + arg2)); self.value_stack.push(Value::from(arg1.wrapping_add(arg2)));
} }
I32SUB => { I32SUB => {
let arg2 = self.value_stack.pop_i32(); let arg2 = self.value_stack.pop_i32();
let arg1 = self.value_stack.pop_i32(); let arg1 = self.value_stack.pop_i32();
self.value_stack.push(Value::from(arg1 - arg2)); self.value_stack.push(Value::from(arg1.wrapping_sub(arg2)));
} }
I32MUL => { I32MUL => {
let arg2 = self.value_stack.pop_i32(); let arg2 = self.value_stack.pop_i32();
let arg1 = self.value_stack.pop_i32(); let arg1 = self.value_stack.pop_i32();
self.value_stack.push(Value::from(arg1 * arg2)); self.value_stack.push(Value::from(arg1.wrapping_mul(arg2)));
} }
I32DIVS => { I32DIVS => {
let arg2 = self.value_stack.pop_i32(); let arg2 = self.value_stack.pop_i32();
let arg1 = self.value_stack.pop_i32(); let arg1 = self.value_stack.pop_i32();
self.value_stack.push(Value::from(arg1 / arg2)); self.value_stack.push(Value::from(arg1.wrapping_div(arg2)));
} }
I32DIVU => { I32DIVU => {
let arg2 = self.value_stack.pop_u32(); let arg2 = self.value_stack.pop_u32();
let arg1 = self.value_stack.pop_u32(); let arg1 = self.value_stack.pop_u32();
self.value_stack.push(Value::from(arg1 / arg2)); self.value_stack.push(Value::from(arg1.wrapping_div(arg2)));
} }
I32REMS => { I32REMS => {
let arg2 = self.value_stack.pop_i32(); let arg2 = self.value_stack.pop_i32();
let arg1 = self.value_stack.pop_i32(); let arg1 = self.value_stack.pop_i32();
self.value_stack.push(Value::from(arg1 % arg2)); self.value_stack.push(Value::from(arg1.wrapping_rem(arg2)));
} }
I32REMU => { I32REMU => {
let arg2 = self.value_stack.pop_u32(); let arg2 = self.value_stack.pop_u32();
let arg1 = self.value_stack.pop_u32(); let arg1 = self.value_stack.pop_u32();
self.value_stack.push(Value::from(arg1 % arg2)); self.value_stack.push(Value::from(arg1.wrapping_rem(arg2)));
} }
I32AND => { I32AND => {
let arg2 = self.value_stack.pop_u32(); let arg2 = self.value_stack.pop_u32();