diff options
author | Björn Gustavsson <[email protected]> | 2010-12-07 16:04:05 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-01-17 15:23:46 +0100 |
commit | b166f8975387d7ef07409e841d45c2cd74c2282e (patch) | |
tree | 71d131ef1b7b3578db18ef22844b9909143fb001 /erts/emulator/beam | |
parent | bc0a998391ce2720f2c6099c809a45094d099fbd (diff) | |
download | otp-b166f8975387d7ef07409e841d45c2cd74c2282e.tar.gz otp-b166f8975387d7ef07409e841d45c2cd74c2282e.tar.bz2 otp-b166f8975387d7ef07409e841d45c2cd74c2282e.zip |
Introduce a special instruction for select_val with two values
The new instruction will save one word (because no size operand
is needed), and is slightly faster.
Handle select_tuple_arity in the same way.
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r-- | erts/emulator/beam/beam_emu.c | 47 | ||||
-rw-r--r-- | erts/emulator/beam/beam_load.c | 27 | ||||
-rw-r--r-- | erts/emulator/beam/ops.tab | 9 |
3 files changed, 83 insertions, 0 deletions
diff --git a/erts/emulator/beam/beam_emu.c b/erts/emulator/beam/beam_emu.c index ea813ef09f..afba17f7bd 100644 --- a/erts/emulator/beam/beam_emu.c +++ b/erts/emulator/beam/beam_emu.c @@ -1882,6 +1882,53 @@ void process_main(void) NextPF(0, next); } + + { + Eterm select_val2; + + OpCase(i_select_tuple_arity2_yfAfAf): + select_val2 = yb(Arg(0)); + goto do_select_tuple_arity2; + + OpCase(i_select_tuple_arity2_xfAfAf): + select_val2 = xb(Arg(0)); + goto do_select_tuple_arity2; + + OpCase(i_select_tuple_arity2_rfAfAf): + select_val2 = r(0); + I--; + + do_select_tuple_arity2: + if (is_not_tuple(select_val2)) { + goto select_val2_fail; + } + select_val2 = *tuple_val(select_val2); + goto do_select_val2; + + OpCase(i_select_val2_yfcfcf): + select_val2 = yb(Arg(0)); + goto do_select_val2; + + OpCase(i_select_val2_xfcfcf): + select_val2 = xb(Arg(0)); + goto do_select_val2; + + OpCase(i_select_val2_rfcfcf): + select_val2 = r(0); + I--; + + do_select_val2: + if (select_val2 == Arg(2)) { + I += 2; + } else if (select_val2 == Arg(4)) { + I += 4; + } + + select_val2_fail: + SET_I((BeamInstr *) Arg(1)); + Goto(*I); + } + { Eterm select_val; diff --git a/erts/emulator/beam/beam_load.c b/erts/emulator/beam/beam_load.c index 02aef95a52..2d57c8a218 100644 --- a/erts/emulator/beam/beam_load.c +++ b/erts/emulator/beam/beam_load.c @@ -2978,6 +2978,21 @@ gen_select_tuple_arity(LoaderState* stp, GenOpArg S, GenOpArg Fail, ASSERT(op->a[i].val < op->a[i+2].val); } #endif + + /* + * Use a special-cased instruction if there are only two values. + */ + if (size == 2) { + op->op = genop_i_select_tuple_arity2_6; + op->arity--; + op->a[2].type = TAG_u; + op->a[2].val = arityval(op->a[3].val); + op->a[3] = op->a[4]; + op->a[4].type = TAG_u; + op->a[4].val = arityval(op->a[5].val); + op->a[5] = op->a[6]; + } + return op; } @@ -3228,6 +3243,18 @@ gen_select_val(LoaderState* stp, GenOpArg S, GenOpArg Fail, } #endif + /* + * Use a special-cased instruction if there are only two values. + */ + if (size == 2) { + op->op = genop_i_select_val2_6; + op->arity--; + op->a[2] = op->a[3]; + op->a[3] = op->a[4]; + op->a[4] = op->a[5]; + op->a[5] = op->a[6]; + } + return op; } diff --git a/erts/emulator/beam/ops.tab b/erts/emulator/beam/ops.tab index 04e2e72b0d..6db55e1402 100644 --- a/erts/emulator/beam/ops.tab +++ b/erts/emulator/beam/ops.tab @@ -160,6 +160,15 @@ select_tuple_arity S=d Fail=f Size=u Rest=* => \ i_select_val r f I i_select_val x f I i_select_val y f I + +i_select_val2 r f c f c f +i_select_val2 x f c f c f +i_select_val2 y f c f c f + +i_select_tuple_arity2 r f A f A f +i_select_tuple_arity2 x f A f A f +i_select_tuple_arity2 y f A f A f + i_select_tuple_arity r f I i_select_tuple_arity x f I i_select_tuple_arity y f I |