aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test/beam_literals_SUITE.erl
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/test/beam_literals_SUITE.erl
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/test/beam_literals_SUITE.erl')
-rw-r--r--erts/emulator/test/beam_literals_SUITE.erl37
1 files changed, 35 insertions, 2 deletions
diff --git a/erts/emulator/test/beam_literals_SUITE.erl b/erts/emulator/test/beam_literals_SUITE.erl
index f56d7ac1c5..1eda939cf8 100644
--- a/erts/emulator/test/beam_literals_SUITE.erl
+++ b/erts/emulator/test/beam_literals_SUITE.erl
@@ -23,7 +23,8 @@
matching_bigs/1, matching_more_bigs/1,
matching_bigs_and_smalls/1, badmatch/1, case_clause/1,
receiving/1, literal_type_tests/1,
- put_list/1, fconv/1, literal_case_expression/1]).
+ put_list/1, fconv/1, literal_case_expression/1,
+ increment/1]).
-include("test_server.hrl").
@@ -32,7 +33,7 @@ all(suite) ->
matching_bigs, matching_more_bigs,
matching_bigs_and_smalls, badmatch, case_clause,
receiving, literal_type_tests,
- put_list, fconv, literal_case_expression].
+ put_list, fconv, literal_case_expression, increment].
putting(doc) -> "Test creating lists and tuples containing big number literals.";
putting(Config) when is_list(Config) ->
@@ -419,6 +420,38 @@ literal_case_expression(Config) when is_list(Config) ->
?line code:purge(Mod),
ok.
+%% Test the i_increment instruction.
+increment(Config) when is_list(Config) ->
+ %% In the 32-bit emulator, Neg32 can be represented as a small,
+ %% but -Neg32 cannot. Therefore the i_increment instruction must
+ %% not be used in the subtraction that follows (since i_increment
+ %% cannot handle a bignum literal).
+ Neg32 = -(1 bsl 27),
+ Big32 = id(1 bsl 32),
+ Result32 = (1 bsl 32) + (1 bsl 27),
+ ?line Result32 = Big32 + (1 bsl 27),
+ ?line Result32 = Big32 - Neg32,
+
+ %% Same thing, but for the 64-bit emulator.
+ Neg64 = -(1 bsl 59),
+ Big64 = id(1 bsl 64),
+ Result64 = (1 bsl 64) + (1 bsl 59),
+ ?line Result64 = Big64 + (1 bsl 59),
+ ?line Result64 = Big64 - Neg64,
+
+ %% Test error handling for the i_increment instruction.
+ Bad = id(bad),
+ ?line {'EXIT',{badarith,_}} = (catch Bad + 42),
+
+ %% Small operands, but a big result.
+ Res32 = 1 bsl 27,
+ Small32 = id(Res32-1),
+ ?line Res32 = Small32 + 1,
+ Res64 = 1 bsl 59,
+ Small64 = id(Res64-1),
+ ?line Res64 = Small64 + 1,
+ ok.
+
%% Help functions.
chksum(Term) ->