Skip to content

Commit 151182c

Browse files
committed
Merge pull request atomvm#1849 from pguyot/w39/fix-binary-matching-with-large-integers-on-32bits
JIT: Fix binary matching with large integers on 32bits These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 6a39f8a + a457077 commit 151182c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

libs/jit/src/jit.erl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,11 +2962,25 @@ first_pass_bs_match_equal_colon_equal(
29622962
]),
29632963
MSt2 = handle_error_if({Result, '==', 0}, MMod, MSt1),
29642964
MSt3 = cond_jump_to_label({Result, '==', ?FALSE_ATOM}, Fail, MMod, MSt2),
2965-
MSt4 = MMod:shift_right(MSt3, Result, 4),
2966-
MSt5 = cond_jump_to_label({Result, '!=', PatternValue}, Fail, MMod, MSt4),
2967-
MSt6 = MMod:add(MSt5, BSOffsetReg, Size),
2968-
MSt7 = MMod:free_native_registers(MSt6, [Result]),
2969-
{J0 - 3, Rest3, MatchState, BSOffsetReg, MSt7}.
2965+
MSt6 =
2966+
case MMod:word_size() of
2967+
4 when PatternValue bsr 28 > 0 ->
2968+
% PatternValue doesn't match on immediate integer, so unbox Result for comparison
2969+
MMod:if_block(
2970+
MSt3, {Result, '&', ?TERM_PRIMARY_MASK, '!=', ?TERM_PRIMARY_BOXED}, fun(BSt0) ->
2971+
MMod:jump_to_label(BSt0, Fail)
2972+
end
2973+
),
2974+
MSt4 = MMod:and_(MSt3, Result, ?TERM_PRIMARY_CLEAR_MASK),
2975+
{MSt5, IntValue} = MMod:get_array_element(MSt4, {free, Result}, 1),
2976+
cond_jump_to_label({IntValue, '!=', PatternValue}, Fail, MMod, MSt5);
2977+
_ ->
2978+
MSt4 = MMod:shift_right(MSt3, Result, 4),
2979+
cond_jump_to_label({Result, '!=', PatternValue}, Fail, MMod, MSt4)
2980+
end,
2981+
MSt7 = MMod:add(MSt6, BSOffsetReg, Size),
2982+
MSt8 = MMod:free_native_registers(MSt7, [Result]),
2983+
{J0 - 3, Rest3, MatchState, BSOffsetReg, MSt8}.
29702984

29712985
first_pass_bs_match_skip(MatchState, BSOffsetReg, J0, Rest0, MMod, MSt0) ->
29722986
{Stride, Rest1} = decode_literal(Rest0),

0 commit comments

Comments
 (0)