diff options
| author | Masaki Muranaka <[email protected]> | 2013-03-18 17:29:43 +0900 |
|---|---|---|
| committer | Masaki Muranaka <[email protected]> | 2013-03-18 23:29:11 +0900 |
| commit | b8982c442f4af853583868aea8343b7831e68fbb (patch) | |
| tree | d531d809fcdc17022213b2d072621954a9560f4c | |
| parent | 7a78ecb14ce2d28f3f99c19eacbbdff5b385e3a8 (diff) | |
| download | mruby-b8982c442f4af853583868aea8343b7831e68fbb.tar.gz mruby-b8982c442f4af853583868aea8343b7831e68fbb.zip | |
Optimize OP_SUBI.
| -rw-r--r-- | src/vm.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -1600,28 +1600,30 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) CASE(OP_SUBI) { /* A B C R(A) := R(A)-C (Syms[B]=:+)*/ int a = GETARG_A(i); + mrb_value *regs_a = regs + a; /* need to check if + is overridden */ - switch (mrb_type(regs[a])) { + switch (mrb_type(regs_a[0])) { case MRB_TT_FIXNUM: { - mrb_int x = regs[a].attr_i; + mrb_int x = regs_a[0].attr_i; mrb_int y = GETARG_C(i); mrb_int z = x - y; - if (((x < 0) ^ (y < 0)) != 0 && (x < 0) != (z < 0)) { + if ((x < 0) != (z < 0) && ((x < 0) ^ (y < 0)) != 0) { /* integer overflow */ - SET_FLT_VALUE(regs[a], (mrb_float)x - (mrb_float)y); - break; + SET_FLT_VALUE(regs_a[0], (mrb_float)x - (mrb_float)y); + } + else { + regs_a[0].attr_i = z; } - regs[a].attr_i = z; } break; case MRB_TT_FLOAT: - regs[a].attr_f -= GETARG_C(i); + regs_a[0].attr_f -= GETARG_C(i); break; default: - SET_INT_VALUE(regs[a+1], GETARG_C(i)); + SET_INT_VALUE(regs_a[1], GETARG_C(i)); i = MKOP_ABC(OP_SEND, a, GETARG_B(i), 1); goto L_SEND; } |
