Skip to content

Commit

Permalink
fix(jit): Implemented % operator for float
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed May 18, 2024
1 parent 28876cf commit 9aa961b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Jit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2702,8 +2702,24 @@ fn generateBinary(self: *Self, node: Ast.Node.Index) Error!?m.MIR_op_t {
},
.Percent => {
if (left_type_def == .Float or right_type_def == .Float) {
// FIXME: mir doesn't seem to have a mod/rem for floats?
unreachable;
const f_res = m.MIR_new_reg_op(
self.ctx,
try self.REG("f_res", m.MIR_T_D),
);

const pdt = m.MIR_new_reg_op(
self.ctx,
try self.REG("p", m.MIR_T_D),
);

// quotient
self.DDIV(f_res, left, right);
// product
self.DMUL(pdt, f_res, right);
// remainder
self.DSUB(f_res, f_res, pdt);

self.wrap(.Float, f_res, res);
} else {
self.MODS(res, left, right);

Expand Down

0 comments on commit 9aa961b

Please sign in to comment.