@@ -502,16 +502,26 @@ first_pass(<<?OP_IS_EQ_EXACT, Rest0/binary>>, MMod, MSt0, State0) ->
502502 {MSt1 , Arg1 , Rest2 } = decode_compact_term (Rest1 , MMod , MSt0 , State0 ),
503503 {MSt2 , Arg2 , Rest3 } = decode_compact_term (Rest2 , MMod , MSt1 , State0 ),
504504 ? TRACE (" OP_IS_EQ_EXACT ~p , ~p , ~p \n " , [Label , Arg1 , Arg2 ]),
505- {MSt3 , ResultReg } = MMod :call_primitive (MSt2 , ? PRIM_TERM_COMPARE , [
506- ctx , jit_state , {free , Arg1 }, {free , Arg2 }, ? TERM_COMPARE_EXACT
507- ]),
508- MSt4 = handle_error_if ({'(int)' , ResultReg , '==' , ? TERM_COMPARE_MEMORY_ALLOC_FAIL }, MMod , MSt3 ),
509- MSt5 = cond_jump_to_label (
510- {{free , ResultReg }, '&' , ? TERM_LESS_THAN + ? TERM_GREATER_THAN , '!=' , 0 },
511- Label ,
512- MMod ,
513- MSt4
514- ),
505+ % If Arg2 is an immediate, we don't need to call term_compare
506+ MSt5 =
507+ if
508+ is_integer (Arg2 ) ->
509+ {MSt3 , Arg1Reg } = MMod :move_to_native_register (MSt2 , Arg1 ),
510+ cond_jump_to_label ({{free , Arg1Reg }, '!=' , Arg2 }, Label , MMod , MSt3 );
511+ true ->
512+ {MSt3 , ResultReg } = MMod :call_primitive (MSt2 , ? PRIM_TERM_COMPARE , [
513+ ctx , jit_state , {free , Arg1 }, {free , Arg2 }, ? TERM_COMPARE_EXACT
514+ ]),
515+ MSt4 = handle_error_if (
516+ {'(int)' , ResultReg , '==' , ? TERM_COMPARE_MEMORY_ALLOC_FAIL }, MMod , MSt3
517+ ),
518+ cond_jump_to_label (
519+ {{free , ResultReg }, '&' , ? TERM_LESS_THAN + ? TERM_GREATER_THAN , '!=' , 0 },
520+ Label ,
521+ MMod ,
522+ MSt4
523+ )
524+ end ,
515525 first_pass (Rest3 , MMod , MSt5 , State0 );
516526% 44
517527first_pass (<<? OP_IS_NOT_EQ_EXACT , Rest0 /binary >>, MMod , MSt0 , State0 ) ->
@@ -520,11 +530,22 @@ first_pass(<<?OP_IS_NOT_EQ_EXACT, Rest0/binary>>, MMod, MSt0, State0) ->
520530 {MSt1 , Arg1 , Rest2 } = decode_compact_term (Rest1 , MMod , MSt0 , State0 ),
521531 {MSt2 , Arg2 , Rest3 } = decode_compact_term (Rest2 , MMod , MSt1 , State0 ),
522532 ? TRACE (" OP_IS_NOT_EQ_EXACT ~p , ~p , ~p \n " , [Label , Arg1 , Arg2 ]),
523- {MSt3 , ResultReg } = MMod :call_primitive (MSt2 , ? PRIM_TERM_COMPARE , [
524- ctx , jit_state , {free , Arg1 }, {free , Arg2 }, ? TERM_COMPARE_EXACT
525- ]),
526- MSt4 = handle_error_if ({'(int)' , ResultReg , '==' , ? TERM_COMPARE_MEMORY_ALLOC_FAIL }, MMod , MSt3 ),
527- MSt5 = cond_jump_to_label ({'(int)' , {free , ResultReg }, '==' , ? TERM_EQUALS }, Label , MMod , MSt4 ),
533+ MSt5 =
534+ if
535+ is_integer (Arg2 ) ->
536+ {MSt3 , Arg1Reg } = MMod :move_to_native_register (MSt2 , Arg1 ),
537+ cond_jump_to_label ({{free , Arg1Reg }, '==' , Arg2 }, Label , MMod , MSt3 );
538+ true ->
539+ {MSt3 , ResultReg } = MMod :call_primitive (MSt2 , ? PRIM_TERM_COMPARE , [
540+ ctx , jit_state , {free , Arg1 }, {free , Arg2 }, ? TERM_COMPARE_EXACT
541+ ]),
542+ MSt4 = handle_error_if (
543+ {'(int)' , ResultReg , '==' , ? TERM_COMPARE_MEMORY_ALLOC_FAIL }, MMod , MSt3
544+ ),
545+ cond_jump_to_label (
546+ {'(int)' , {free , ResultReg }, '==' , ? TERM_EQUALS }, Label , MMod , MSt4
547+ )
548+ end ,
528549 first_pass (Rest3 , MMod , MSt5 , State0 );
529550% 45
530551first_pass (<<? OP_IS_INTEGER , Rest0 /binary >>, MMod , MSt0 , State0 ) ->
0 commit comments