Skip to content

Commit

Permalink
issue #163 improve codegen for adding two integers when one is a cons…
Browse files Browse the repository at this point in the history
…tant
  • Loading branch information
dibyendumajumdar committed Apr 5, 2020
1 parent 22c467e commit eae8eb9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/ravi_jitshared.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,21 @@ static void emit_if_op(struct function *fn, int A, int B, int C, int pc, const c
static void emit_ii_op(struct function *fn, int A, int B, int C, int pc, const char *op) {
(void)pc;
emit_reg(fn, "ra", A);
emit_reg_or_k(fn, "rb", B);
emit_reg_or_k(fn, "rc", C);
membuff_add_fstring(&fn->body, "setivalue(ra, ivalue(rb) %s ivalue(rc));\n", op);
if (ISK(B)) {
TValue *Konst1 = &fn->p->k[INDEXK(B)];
emit_reg_or_k(fn, "rc", C);
membuff_add_fstring(&fn->body, "setivalue(ra, %lld %s ivalue(rc));\n", Konst1->value_.i, op);
}
else if (ISK(C)) {
TValue *Konst1 = &fn->p->k[INDEXK(C)];
emit_reg_or_k(fn, "rb", B);
membuff_add_fstring(&fn->body, "setivalue(ra, ivalue(rb) %s %lld);\n", op, Konst1->value_.i);
}
else {
emit_reg_or_k(fn, "rb", B);
emit_reg_or_k(fn, "rc", C);
membuff_add_fstring(&fn->body, "setivalue(ra, ivalue(rb) %s ivalue(rc));\n", op);
}
}

static void emit_op_divii(struct function *fn, int A, int B, int C, int pc) {
Expand Down

0 comments on commit eae8eb9

Please sign in to comment.