Skip to content

Commit

Permalink
Add pow_f32 opcode to VM
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Sep 30, 2023
1 parent dbad0de commit 4c52f51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions vm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ impl Assembler
"asin_f32" => self.code.push_op(Op::asin_f32),
"acos_f32" => self.code.push_op(Op::acos_f32),
"atan_f32" => self.code.push_op(Op::atan_f32),
"pow_f32" => self.code.push_op(Op::pow_f32),
"sqrt_f32" => self.code.push_op(Op::sqrt_f32),

"eq_f32" => self.code.push_op(Op::eq_f32),
Expand Down
8 changes: 8 additions & 0 deletions vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub enum Op
asin_f32,
acos_f32,
atan_f32,
pow_f32,
sqrt_f32,

// 32-bit floating-point comparison instructions
Expand Down Expand Up @@ -1211,6 +1212,13 @@ impl VM
self.push(v0.atan());
}

// Should return NaN for invalid inputs
Op::pow_f32 => {
let v1 = self.pop().as_f32();
let v0 = self.pop().as_f32();
self.push(v0.powf(v1));
}

// Should return NaN for invalid inputs
Op::sqrt_f32 => {
let v0 = self.pop().as_f32();
Expand Down

0 comments on commit 4c52f51

Please sign in to comment.