aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/beam_load.c
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2010-12-08 15:27:37 +0100
committerBjörn Gustavsson <[email protected]>2011-01-17 15:23:46 +0100
commit74d7bd100b742a803c8de82c9c997308cf871038 (patch)
tree8230b273d29b0c2f60950c9c7a0db747d217d18d /erts/emulator/beam/beam_load.c
parentb166f8975387d7ef07409e841d45c2cd74c2282e (diff)
downloadotp-74d7bd100b742a803c8de82c9c997308cf871038.tar.gz
otp-74d7bd100b742a803c8de82c9c997308cf871038.tar.bz2
otp-74d7bd100b742a803c8de82c9c997308cf871038.zip
Optimize addition of a small integer to a variable
Introduce a new i_increment/4 to optimize the addition of a register and a small integer. This instruction saves two instruction words compared to the standard instructions (an i_fetch/2 instruction followed by a i_plus/3 instruction) and will also be slightly faster.
Diffstat (limited to 'erts/emulator/beam/beam_load.c')
-rw-r--r--erts/emulator/beam/beam_load.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/erts/emulator/beam/beam_load.c b/erts/emulator/beam/beam_load.c
index 2d57c8a218..e6448931eb 100644
--- a/erts/emulator/beam/beam_load.c
+++ b/erts/emulator/beam/beam_load.c
@@ -2787,6 +2787,52 @@ gen_skip_bits2(LoaderState* stp, GenOpArg Fail, GenOpArg Ms,
return op;
}
+static GenOp*
+gen_increment(LoaderState* stp, GenOpArg Reg, GenOpArg Integer,
+ GenOpArg Live, GenOpArg Dst)
+{
+ GenOp* op;
+
+ NEW_GENOP(stp, op);
+ op->op = genop_i_increment_4;
+ op->arity = 4;
+ op->next = NULL;
+ op->a[0] = Reg;
+ op->a[1].type = TAG_u;
+ op->a[1].val = Integer.val;
+ op->a[2] = Live;
+ op->a[3] = Dst;
+ return op;
+}
+
+static GenOp*
+gen_increment_from_minus(LoaderState* stp, GenOpArg Reg, GenOpArg Integer,
+ GenOpArg Live, GenOpArg Dst)
+{
+ GenOp* op;
+
+ NEW_GENOP(stp, op);
+ op->op = genop_i_increment_4;
+ op->arity = 4;
+ op->next = NULL;
+ op->a[0] = Reg;
+ op->a[1].type = TAG_u;
+ op->a[1].val = -Integer.val;
+ op->a[2] = Live;
+ op->a[3] = Dst;
+ return op;
+}
+
+/*
+ * Test whether the negation of the given number is small.
+ */
+static int
+negation_is_small(LoaderState* stp, GenOpArg Int)
+{
+ return Int.type == TAG_i && IS_SSMALL(-Int.val);
+}
+
+
static int
smp(LoaderState* stp)
{