diff options
author | Björn Gustavsson <[email protected]> | 2018-01-26 10:46:23 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-01-26 10:46:23 +0100 |
commit | 26e3ec83c54d42d73c42ef7c4e79ae629866faa2 (patch) | |
tree | 85b4d8e6d245d2b6def5fc21d789dca6166775ab /lib/compiler | |
parent | 5b58d9e2d3262160b7f10d8b6798f89f0618c5f6 (diff) | |
download | otp-26e3ec83c54d42d73c42ef7c4e79ae629866faa2.tar.gz otp-26e3ec83c54d42d73c42ef7c4e79ae629866faa2.tar.bz2 otp-26e3ec83c54d42d73c42ef7c4e79ae629866faa2.zip |
beam_asm: Encode big numbers as literals
Numbers that clearly are not smalls can be encoded as
literals. Conservatively, we assume that integers whose
absolute value is greater than 1 bsl 128 are bignums and
that they can be encoded as literals.
Literals are slightly easier for the loader to handle than
huge integers.
Diffstat (limited to 'lib/compiler')
-rw-r--r-- | lib/compiler/src/beam_asm.erl | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/compiler/src/beam_asm.erl b/lib/compiler/src/beam_asm.erl index 453e00fce3..fa919ca862 100644 --- a/lib/compiler/src/beam_asm.erl +++ b/lib/compiler/src/beam_asm.erl @@ -407,7 +407,17 @@ encode_arg({atom, Atom}, Dict0) when is_atom(Atom) -> {Index, Dict} = beam_dict:atom(Atom, Dict0), {encode(?tag_a, Index), Dict}; encode_arg({integer, N}, Dict) -> - {encode(?tag_i, N), Dict}; + %% Conservatily assume that all integers whose absolute + %% value is greater than 1 bsl 128 will be bignums in + %% the runtime system. + if + N >= 1 bsl 128 -> + encode_arg({literal, N}, Dict); + N =< -(1 bsl 128) -> + encode_arg({literal, N}, Dict); + true -> + {encode(?tag_i, N), Dict} + end; encode_arg(nil, Dict) -> {encode(?tag_a, 0), Dict}; encode_arg({f, W}, Dict) -> |