@@ -2124,12 +2124,11 @@ first_pass(<<?OP_BS_GET_POSITION, Rest0/binary>>, MMod, MSt0, State0) ->
21242124 {MSt3 , Reg } = MMod :move_to_native_register (MSt2 , Src ),
21252125 {MSt4 , Reg } = MMod :and_ (MSt3 , {free , Reg }, ? TERM_PRIMARY_CLEAR_MASK ),
21262126 MSt5 = MMod :move_array_element (MSt4 , Reg , 2 , Reg ),
2127- MSt6 = MMod :shift_left (MSt5 , Reg , 4 ),
2128- MSt7 = MMod :or_ (MSt6 , Reg , ? TERM_INTEGER_TAG ),
2129- MSt8 = MMod :move_to_vm_register (MSt7 , Reg , Dest ),
2130- MSt9 = MMod :free_native_registers (MSt8 , [Reg , Dest ]),
2131- ? ASSERT_ALL_NATIVE_FREE (MSt9 ),
2132- first_pass (Rest3 , MMod , MSt9 , State0 );
2127+ {MSt6 , Reg } = term_from_int (Reg , MMod , MSt5 ),
2128+ MSt7 = MMod :move_to_vm_register (MSt6 , Reg , Dest ),
2129+ MSt8 = MMod :free_native_registers (MSt7 , [Reg , Dest ]),
2130+ ? ASSERT_ALL_NATIVE_FREE (MSt8 ),
2131+ first_pass (Rest3 , MMod , MSt8 , State0 );
21332132% 168
21342133first_pass (<<? OP_BS_SET_POSITION , Rest0 /binary >>, MMod , MSt0 , State0 ) ->
21352134 ? ASSERT_ALL_NATIVE_FREE (MSt0 ),
@@ -2769,20 +2768,38 @@ first_pass_bs_create_bin_insert_value(
27692768 ),
27702769 {MSt5 , NewOffset , CreatedBin };
27712770first_pass_bs_create_bin_insert_value (
2772- AtomType , _Flags , Src , Size , _SegmentUnit , _Fail , CreatedBin , Offset , MMod , MSt0
2771+ AtomType , _Flags , Src , Size , SegmentUnit , Fail , CreatedBin , Offset , MMod , MSt0
27732772) when AtomType =:= binary orelse AtomType =:= append orelse AtomType =:= private_append ->
2774- {MSt1 , SizeValue } = MMod :call_primitive (MSt0 , ? PRIM_BITSTRING_COPY_BINARY , [
2775- ctx , jit_state , CreatedBin , Offset , Src , Size
2773+ {MSt4 , SizeInBits } =
2774+ if
2775+ is_integer (Size ) andalso Size band 16#F =:= ? TERM_INTEGER_TAG ->
2776+ {MSt0 , term_from_int (SegmentUnit * (Size bsr 4 ))};
2777+ Size =:= ? ALL_ATOM ->
2778+ {MSt0 , Size };
2779+ SegmentUnit =:= 1 ->
2780+ {MSt1 , SizeReg } = MMod :move_to_native_register (MSt0 , Size ),
2781+ MSt2 = cond_raise_badarg_or_jump_to_fail_label (
2782+ {SizeReg , '&' , ? TERM_IMMED_TAG_MASK , '!=' , ? TERM_INTEGER_TAG }, Fail , MMod , MSt1
2783+ ),
2784+ {MSt2 , {free , SizeReg }};
2785+ true ->
2786+ {MSt1 , SizeReg } = term_to_int (Size , Fail , MMod , MSt0 ),
2787+ MSt2 = MMod :mul (MSt1 , SizeReg , SegmentUnit ),
2788+ {MSt3 , SizeReg } = term_from_int (SizeReg , MMod , MSt2 ),
2789+ {MSt3 , {free , SizeReg }}
2790+ end ,
2791+ {MSt5 , SizeValue } = MMod :call_primitive (MSt4 , ? PRIM_BITSTRING_COPY_BINARY , [
2792+ ctx , jit_state , CreatedBin , Offset , Src , SizeInBits
27762793 ]),
2777- MSt2 = MMod :if_block (MSt1 , {SizeValue , '<' , 0 }, fun (BlockSt ) ->
2794+ MSt6 = MMod :if_block (MSt5 , {SizeValue , '<' , 0 }, fun (BlockSt ) ->
27782795 MMod :call_primitive_last (BlockSt , ? PRIM_HANDLE_ERROR , [
27792796 ctx , jit_state , offset
27802797 ])
27812798 end ),
2782- {MSt3 , NewOffset } = first_pass_bs_create_bin_insert_value_increment_offset (
2783- MMod , MSt2 , Offset , SizeValue , 1
2799+ {MSt7 , NewOffset } = first_pass_bs_create_bin_insert_value_increment_offset (
2800+ MMod , MSt6 , Offset , SizeValue , 1
27842801 ),
2785- {MSt3 , NewOffset , CreatedBin };
2802+ {MSt7 , NewOffset , CreatedBin };
27862803first_pass_bs_create_bin_insert_value (
27872804 _OtherType , _Flag , _Src , _Size , _SegmentUnit , _Fail , CreatedBin , Offset , _MMod , MSt0
27882805) ->
@@ -3786,6 +3803,13 @@ decode_allocator_list0(MMod, AccNeed, Remaining, Rest0) ->
37863803term_from_int (Int ) when is_integer (Int ) ->
37873804 (Int bsl 4 ) bor ? TERM_INTEGER_TAG .
37883805
3806+ term_from_int (Int , _MMod , MSt0 ) when is_integer (Int ) ->
3807+ {MSt0 , term_from_int (Int )};
3808+ term_from_int (Reg , MMod , MSt0 ) when is_atom (Reg ) ->
3809+ MSt1 = MMod :shift_left (MSt0 , Reg , 4 ),
3810+ MSt2 = MMod :or_ (MSt1 , Reg , ? TERM_INTEGER_TAG ),
3811+ {MSt2 , Reg }.
3812+
37893813term_get_tuple_arity (Tuple , MMod , MSt0 ) ->
37903814 {MSt1 , Reg } =
37913815 case Tuple of
0 commit comments