Use ?SHL and ?SHR for 'bsl' and 'bsr' #504

Merged
zxq9 merged 1 commits from PT-163388694-add_native_bit_shift into master 2019-01-23 21:15:15 +09:00
5 changed files with 10 additions and 10 deletions

View File

@ -2,7 +2,7 @@
%% NOTE: When possible deps are referenced by Git ref to ensure consistency between builds.
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git",
{ref,"6aec14e"}}}
{ref,"720510a"}}}
]}.

View File

@ -1,4 +1,4 @@
[{<<"aebytecode">>,
{git,"https://github.com/aeternity/aebytecode.git",
{ref,"6aec14e64d9ad4dedad98c64b2c16e30af1ea9ea"}},
{ref,"720510a24de32c9bad6486f34ca7babde124bf1e"}},
0}].

View File

@ -526,12 +526,9 @@ ast_binop(Op, Ann, {typed, _, A, Type}, B, Icode)
ast_binop('++', _, A, B, Icode) ->
#funcall{ function = #var_ref{ name = {builtin, list_concat} },
args = [ast_body(A, Icode), ast_body(B, Icode)] };
ast_binop('bsl', _, A, B, Icode) ->
#binop{op = '*', left = ast_body(A, Icode),
right = #binop{op = '^', left = {integer, 2}, right = ast_body(B, Icode)}};
ast_binop('bsr', _, A, B, Icode) ->
#binop{op = 'div', left = ast_body(A, Icode),
right = #binop{op = '^', left = {integer, 2}, right = ast_body(B, Icode)}};
%% Bit shift operations takes their arguments backwards!?
ast_binop(Op, _, A, B, Icode) when Op =:= 'bsl'; Op =:= 'bsr' ->
#binop{op = Op, right = ast_body(A, Icode), left = ast_body(B, Icode)};
ast_binop(Op, _, A, B, Icode) ->
#binop{op = Op, left = ast_body(A, Icode), right = ast_body(B, Icode)}.

View File

@ -81,8 +81,9 @@ option_some(X) -> {tuple, [{integer, 1}, X]}.
-define(EXP(A, B), op('^', A, B)).
-define(AND(A, B), op('&&', A, B)).
-define(BSL(X, B), ?MUL(X, ?EXP(2, ?MUL(B, 8)))).
-define(BSR(X, B), ?DIV(X, ?EXP(2, ?MUL(B, 8)))).
%% Bit shift operations takes their arguments backwards!?
-define(BSL(X, B), op('bsl', ?MUL(B, 8), X)).
-define(BSR(X, B), op('bsr', ?MUL(B, 8), X)).
op(Op, A, B) -> {binop, Op, operand(A), operand(B)}.

View File

@ -562,6 +562,8 @@ assemble_infix('^') -> i(?EXP);
assemble_infix('bor') -> i(?OR);
assemble_infix('band') -> i(?AND);
assemble_infix('bxor') -> i(?XOR);
assemble_infix('bsl') -> i(?SHL);
assemble_infix('bsr') -> i(?SHR);
assemble_infix('<') -> i(?SLT); %% comparisons are SIGNED
assemble_infix('>') -> i(?SGT);
assemble_infix('==') -> i(?EQ);