aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_asm.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-04-29 12:27:16 +0200
committerBjörn Gustavsson <[email protected]>2015-04-29 12:27:16 +0200
commit688e88924ee453d4a617980ec38b12e30568bda9 (patch)
tree8fd0680c817cf6ea05ebaa729ed012e962db3ddd /lib/compiler/src/beam_asm.erl
parent3ce2fe4c0e88da5ff8f50624f133e1fee9726473 (diff)
parentf4adfc60acb46a86f49627397913b6841b744ed2 (diff)
downloadotp-688e88924ee453d4a617980ec38b12e30568bda9.tar.gz
otp-688e88924ee453d4a617980ec38b12e30568bda9.tar.bz2
otp-688e88924ee453d4a617980ec38b12e30568bda9.zip
Merge branch 'bjorn/compiler/misc'
* bjorn/compiler/misc: test_lib: Simplify uniq/0 beam_dict: Correct comparison in opcode/2 beam_utils: Re-use the local helper function drop_labels/1 beam_asm: Speed up encoding of large numbers compilation_SUITE: Speed up the self_compile test cases beam_listing: Optimize writing of .S files v3_core, v3_codegen: Eliminate old-style catches cerl_inline: Replace old-style 'catch' with 'try'...'catch' sys_core_fold: Suppress warnings better beam_utils: Teach check_liveness/3 to understand get_map_elements Teach beam_trim to handle map instructions beam_utils: Be less conservative about liveness for exit instructions beam_validator: Stop validating the 'aligned' flag for binaries beam_validator: Clean up updating of types for y register beam_validator: Remove support for removed BIF fault/1,2 beam_validator: Correct merging of states beam_validator: Correct merging of y registers sys_pre_expand: Remove unused fields in #expand{} record
Diffstat (limited to 'lib/compiler/src/beam_asm.erl')
-rw-r--r--lib/compiler/src/beam_asm.erl44
1 files changed, 17 insertions, 27 deletions
diff --git a/lib/compiler/src/beam_asm.erl b/lib/compiler/src/beam_asm.erl
index 084686def7..73694b96ce 100644
--- a/lib/compiler/src/beam_asm.erl
+++ b/lib/compiler/src/beam_asm.erl
@@ -431,45 +431,35 @@ encode_alloc_list_1([], Dict, Acc) ->
{iolist_to_binary(Acc),Dict}.
encode(Tag, N) when N < 0 ->
- encode1(Tag, negative_to_bytes(N, []));
+ encode1(Tag, negative_to_bytes(N));
encode(Tag, N) when N < 16 ->
(N bsl 4) bor Tag;
encode(Tag, N) when N < 16#800 ->
[((N bsr 3) band 2#11100000) bor Tag bor 2#00001000, N band 16#ff];
encode(Tag, N) ->
- encode1(Tag, to_bytes(N, [])).
+ encode1(Tag, to_bytes(N)).
encode1(Tag, Bytes) ->
- case length(Bytes) of
+ case iolist_size(Bytes) of
Num when 2 =< Num, Num =< 8 ->
[((Num-2) bsl 5) bor 2#00011000 bor Tag| Bytes];
Num when 8 < Num ->
[2#11111000 bor Tag, encode(?tag_u, Num-9)| Bytes]
end.
-
-to_bytes(N0, Acc) ->
- Bits = 3*128,
- case N0 bsr Bits of
- 0 ->
- to_bytes_1(N0, Acc);
- N ->
- to_bytes(N, binary_to_list(<<N0:Bits>>) ++ Acc)
- end.
-
-to_bytes_1(0, [B|_]=Done) when B < 128 -> Done;
-to_bytes_1(N, Acc) -> to_bytes(N bsr 8, [N band 16#ff|Acc]).
-
-negative_to_bytes(N0, Acc) ->
- Bits = 3*128,
- case N0 bsr Bits of
- -1 ->
- negative_to_bytes_1(N0, Acc);
- N ->
- negative_to_bytes_1(N, binary_to_list(<<N0:Bits>>) ++ Acc)
+to_bytes(N) ->
+ Bin = binary:encode_unsigned(N),
+ case Bin of
+ <<0:1,_/bits>> -> Bin;
+ <<1:1,_/bits>> -> [0,Bin]
end.
-negative_to_bytes_1(-1, [B1,_B2|_]=Done) when B1 > 127 ->
- Done;
-negative_to_bytes_1(N, Acc) ->
- negative_to_bytes_1(N bsr 8, [N band 16#ff|Acc]).
+negative_to_bytes(N) when N >= -16#8000 ->
+ <<N:16>>;
+negative_to_bytes(N) ->
+ Bytes = byte_size(binary:encode_unsigned(-N)),
+ Bin = <<N:Bytes/unit:8>>,
+ case Bin of
+ <<0:1,_/bits>> -> [16#ff,Bin];
+ <<1:1,_/bits>> -> Bin
+ end.