aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-09-13 11:48:27 +0200
committerBjörn Gustavsson <[email protected]>2017-09-13 11:48:27 +0200
commitb36f0b6d381746a16c8d8c2bb3767d9ffb44c3f8 (patch)
treefb2b46887f842e06a87ce98169b81f62ff7fd8fe /erts/emulator
parent89c5a525ea9dc47677ef7b68bd5e80fad1cb546e (diff)
parenta58daf5c38b4921c82008c811cd5dd178deef49f (diff)
downloadotp-b36f0b6d381746a16c8d8c2bb3767d9ffb44c3f8.tar.gz
otp-b36f0b6d381746a16c8d8c2bb3767d9ffb44c3f8.tar.bz2
otp-b36f0b6d381746a16c8d8c2bb3767d9ffb44c3f8.zip
Merge branch 'bjorn/erts/improve-beam-ops'
* bjorn/erts/improve-beam-ops: Add built-in macros $ARG_POSITION() and $IS_PACKED() Use 't' instead of 'I' bit syntax operands Optimize operand type for match context in i_bs_get_integer Change operand type from 's' to 'S' for a few instructions Use the correct name of the parameter
Diffstat (limited to 'erts/emulator')
-rw-r--r--erts/emulator/beam/macros.tab2
-rw-r--r--erts/emulator/beam/ops.tab34
-rwxr-xr-xerts/emulator/utils/beam_makeops55
3 files changed, 63 insertions, 28 deletions
diff --git a/erts/emulator/beam/macros.tab b/erts/emulator/beam/macros.tab
index bac96be7d3..35bbc92fea 100644
--- a/erts/emulator/beam/macros.tab
+++ b/erts/emulator/beam/macros.tab
@@ -65,7 +65,7 @@ GC_TEST_PRESERVE(NeedHeap, Live, PreserveTerm) {
$PreserveTerm = reg[$Live];
SWAPIN;
}
- HEAP_SPACE_VERIFIED($Nh);
+ HEAP_SPACE_VERIFIED($NeedHeap);
}
diff --git a/erts/emulator/beam/ops.tab b/erts/emulator/beam/ops.tab
index 992857b099..3c9f5a4073 100644
--- a/erts/emulator/beam/ops.tab
+++ b/erts/emulator/beam/ops.tab
@@ -707,7 +707,7 @@ is_boolean f xy
is_function2 Fail=f acq Arity => jump Fail
is_function2 Fail=f Fun a => jump Fail
-is_function2 f s s
+is_function2 f S s
# Allocating & initializing.
allocate Need Regs | init Y => allocate_init Need Regs Y
@@ -1073,13 +1073,13 @@ func_info M F A => i_func_info u M F A
%warm
bs_start_match2 Fail=f ica X Y D => jump Fail
bs_start_match2 Fail Bin X Y D => i_bs_start_match2 Bin Fail X Y D
-i_bs_start_match2 xy f I I x
+i_bs_start_match2 xy f t t x
bs_save2 Reg Index => gen_bs_save(Reg, Index)
-i_bs_save2 x I
+i_bs_save2 x t
bs_restore2 Reg Index => gen_bs_restore(Reg, Index)
-i_bs_restore2 x I
+i_bs_restore2 x t
# Matching integers
bs_match_string Fail Ms Bits Val => i_bs_match_string Ms Fail Bits Val
@@ -1092,7 +1092,7 @@ bs_get_integer2 Fail=f Ms=x Live=u Sz=sq Unit=u Flags=u Dst=d => \
i_bs_get_integer_small_imm x W f t x
i_bs_get_integer_imm x W t f t x
-i_bs_get_integer f I I s s x
+i_bs_get_integer f t t x s x
i_bs_get_integer_8 x f x
i_bs_get_integer_16 x f x
@@ -1105,9 +1105,9 @@ bs_get_binary2 Fail=f Ms=x Live=u Sz=sq Unit=u Flags=u Dst=d => \
gen_get_binary2(Fail, Ms, Live, Sz, Unit, Flags, Dst)
i_bs_get_binary_imm2 f x t W t x
-i_bs_get_binary2 f x I s I x
-i_bs_get_binary_all2 f x I I x
-i_bs_get_binary_all_reuse x f I
+i_bs_get_binary2 f x t s t x
+i_bs_get_binary_all2 f x t t x
+i_bs_get_binary_all_reuse x f t
# Fetching float from binaries.
bs_get_float2 Fail=f Ms=x Live=u Sz=s Unit=u Flags=u Dst=d => \
@@ -1115,7 +1115,7 @@ bs_get_float2 Fail=f Ms=x Live=u Sz=s Unit=u Flags=u Dst=d => \
bs_get_float2 Fail=f Ms=x Live=u Sz=q Unit=u Flags=u Dst=d => jump Fail
-i_bs_get_float2 f x I s I x
+i_bs_get_float2 f x t s t x
# Miscellanous
@@ -1123,8 +1123,8 @@ bs_skip_bits2 Fail=f Ms=x Sz=sq Unit=u Flags=u => \
gen_skip_bits2(Fail, Ms, Sz, Unit, Flags)
i_bs_skip_bits_imm2 f x W
-i_bs_skip_bits2 f x xy I
-i_bs_skip_bits_all2 f x I
+i_bs_skip_bits2 f x xy t
+i_bs_skip_bits_all2 f x t
bs_test_tail2 Fail=f Ms=x Bits=u==0 => bs_test_zero_tail2 Fail Ms
bs_test_tail2 Fail=f Ms=x Bits=u => bs_test_tail_imm2 Fail Ms Bits
@@ -1132,7 +1132,7 @@ bs_test_zero_tail2 f x
bs_test_tail_imm2 f x W
bs_test_unit F Ms Unit=u==8 => bs_test_unit8 F Ms
-bs_test_unit f x I
+bs_test_unit f x t
bs_test_unit8 f x
# An y register operand for bs_context_to_binary is rare,
@@ -1153,7 +1153,7 @@ bs_skip_utf8 Fail=f Ms=x u u => i_bs_get_utf8 Ms Fail x
bs_get_utf16 Fail=f Ms=x u Flags=u Dst=d => i_bs_get_utf16 Ms Fail Flags Dst
bs_skip_utf16 Fail=f Ms=x u Flags=u => i_bs_get_utf16 Ms Fail Flags x
-i_bs_get_utf16 x f I x
+i_bs_get_utf16 x f t x
bs_get_utf32 Fail=f Ms=x Live=u Flags=u Dst=d => \
bs_get_integer2 Fail Ms Live i=32 u=1 Flags Dst | \
@@ -1162,7 +1162,7 @@ bs_skip_utf32 Fail=f Ms=x Live=u Flags=u => \
bs_get_integer2 Fail Ms Live i=32 u=1 Flags x | \
i_bs_validate_unicode_retract Fail x Ms
-i_bs_validate_unicode_retract j s s
+i_bs_validate_unicode_retract j s S
%hot
#
@@ -1221,7 +1221,7 @@ bs_private_append Fail Size Unit Bin Flags Dst => \
bs_init_writable
i_bs_append j I t t s x
-i_bs_private_append j t s s x
+i_bs_private_append j t s S x
#
# Storing integers into binaries.
@@ -1507,7 +1507,9 @@ i_band s s j t d
i_bor j I s s d
i_bxor j I s s d
-i_int_bnot j s t d
+i_int_bnot Fail Src=c Live Dst => move Src x | i_int_bnot Fail x Live Dst
+
+i_int_bnot j S t d
#
# Old guard BIFs that creates heap fragments are no longer allowed.
diff --git a/erts/emulator/utils/beam_makeops b/erts/emulator/utils/beam_makeops
index e55d3eadb5..8e34e07035 100755
--- a/erts/emulator/utils/beam_makeops
+++ b/erts/emulator/utils/beam_makeops
@@ -268,6 +268,16 @@ if ($wordsize == 64) {
}
#
+# Add placeholders for built-in macros.
+#
+
+$c_code{'IS_PACKED'} = ['$Expr',"built-in macro",('Expr')];
+$c_code{'ARG_POSITION'} = ['$Expr',"built-in macro",('Expr')];
+foreach my $name (keys %c_code) {
+ $c_code_used{$name} = 1;
+}
+
+#
# Parse the input files.
#
@@ -1382,14 +1392,8 @@ sub expand_all {
my $keep = substr($code, 0, $-[0]);
my $after = substr($code, $+[0]);
- # Keep the special, pre-defined bindings.
- my %new_bindings;
- foreach my $key (qw(NEXT_INSTRUCTION)) {
- $new_bindings{$key} = $bindings{$key};
- }
-
my $body;
- ($body,$code) = expand_macro($macro_name, $after, \%new_bindings);
+ ($body,$code) = expand_macro($macro_name, $after, \%bindings);
$res .= "$keep$body";
}
@@ -1436,21 +1440,49 @@ sub expand_macro {
$arg =~ s/^\s*//;
}
- # Now combine bindings from the parameter names and arguments.
- my %bindings = %{$bindings_ref};
+ # Make sure that the number of arguments are correct.
if (@vars != @args) {
error("calling $name with ", scalar(@args),
" arguments instead of expected ", scalar(@vars), " arguments...");
}
+
+ # Now combine bindings from the parameter names and arguments.
+ my %bindings = %{$bindings_ref};
+ my %new_bindings;
+
+ # Keep the special, pre-defined bindings.
+ foreach my $key (qw(NEXT_INSTRUCTION)) {
+ $new_bindings{$key} = $bindings{$key};
+ }
+
for (my $i = 0; $i < @vars; $i++) {
- $bindings{$vars[$i]} = $args[$i];
+ my $arg = $args[$i];
+ $arg = eval { expand_all($arg, \%bindings) };
+ unless (defined $arg) {
+ warn $@;
+ die "... from the body of $name at $where\n";
+ }
+ $new_bindings{$vars[$i]} = $arg;
}
- $body = eval { expand_all($body, \%bindings) };
+ $body = eval { expand_all($body, \%new_bindings) };
unless (defined $body) {
warn $@;
die "... from the body of $name at $where\n";
}
+
+ # Handle built-in macros.
+ if ($name eq 'ARG_POSITION') {
+ if ($body =~ /^I\[(\d+)\]$/) {
+ $body = $1;
+ } else {
+ $body = 0;
+ }
+ } elsif ($name eq 'IS_PACKED') {
+ $body = ($body =~ /^I\[\d+\]$/) ? 0 : 1;
+ }
+
+ # Wrap body if needed and return resul.t
$body = "do {\n$body\n} while (0)"
if needs_do_wrapper($body);
($body,$rest);
@@ -1476,6 +1508,7 @@ sub needs_do_wrapper {
return 0 if /^[A-Z_]*SWAPOUT/;
return 0 if /^if\s*[(]/;
return 0 if /^goto\b/;
+ return 0 if /^\d+/;
return 1; # Not sure, say that it is needed.
}