@@ -824,24 +824,16 @@ if_block_cond(
824824) when ? IS_GPR (Reg ) ->
825825 % AND with mask
826826 OffsetBefore = StreamModule :offset (Stream0 ),
827- Stream1 =
828- try
829- I = jit_aarch64_asm :and_ (Temp , Reg , Mask ),
830- StreamModule :append (Stream0 , I )
831- catch
832- error :{unencodable_immediate , Val } ->
833- MoveI = jit_aarch64_asm :mov (Temp , Mask ),
834- AndI = jit_aarch64_asm :and_ (Temp , Reg , Temp ),
835- StreamModule :append (Stream0 , <<MoveI /binary , AndI /binary >>)
836- end ,
827+ State1 = op_imm (State0 , and_ , Temp , Reg , Mask ),
828+ Stream1 = State1 # state .stream ,
837829 % Compare with value
838830 I2 = jit_aarch64_asm :cmp (Temp , Val ),
839831 Stream2 = StreamModule :append (Stream1 , I2 ),
840832 OffsetAfter = StreamModule :offset (Stream2 ),
841833 I3 = jit_aarch64_asm :bcc (eq , 0 ),
842834 Stream3 = StreamModule :append (Stream2 , I3 ),
843- State1 = State0 # state {stream = Stream3 },
844- {State1 , eq , OffsetAfter - OffsetBefore };
835+ State2 = State1 # state {stream = Stream3 },
836+ {State2 , eq , OffsetAfter - OffsetBefore };
845837if_block_cond (
846838 # state {
847839 stream_module = StreamModule ,
@@ -1728,47 +1720,40 @@ get_module_index(
17281720 Reg
17291721 }.
17301722
1731- and_ (# state {stream_module = StreamModule , stream = Stream0 } = State , Reg , Val ) ->
1723+ op_imm (# state {stream_module = StreamModule , stream = Stream0 } = State , Op , Reg , Reg , Val ) ->
17321724 Stream1 =
17331725 try
1734- I = jit_aarch64_asm :and_ (Reg , Reg , Val ),
1726+ I = jit_aarch64_asm :Op (Reg , Reg , Val ),
17351727 StreamModule :append (Stream0 , I )
17361728 catch
17371729 error :{unencodable_immediate , Val } ->
17381730 [Temp | _ ] = State # state .available_regs ,
17391731 I1 = jit_aarch64_asm :mov (Temp , Val ),
1740- I2 = jit_aarch64_asm :and_ (Reg , Reg , Temp ),
1732+ I2 = jit_aarch64_asm :Op (Reg , Reg , Temp ),
17411733 StreamModule :append (Stream0 , <<I1 /binary , I2 /binary >>)
17421734 end ,
1743- State # state {stream = Stream1 }.
1744-
1745- or_ (# state {stream_module = StreamModule , stream = Stream0 } = State , Reg , Val ) ->
1735+ State # state {stream = Stream1 };
1736+ op_imm (# state {stream_module = StreamModule , stream = Stream0 } = State , Op , RegA , RegB , Val ) ->
17461737 Stream1 =
17471738 try
1748- I = jit_aarch64_asm :orr ( Reg , Reg , Val ),
1739+ I = jit_aarch64_asm :Op ( RegA , RegB , Val ),
17491740 StreamModule :append (Stream0 , I )
17501741 catch
17511742 error :{unencodable_immediate , Val } ->
1752- [Temp | _ ] = State # state .available_regs ,
1753- I1 = jit_aarch64_asm :mov (Temp , Val ),
1754- I2 = jit_aarch64_asm :orr (Reg , Reg , Temp ),
1755- StreamModule :append (Stream0 , <<I1 /binary , I2 /binary >>)
1743+ MoveI = jit_aarch64_asm :mov (RegA , Val ),
1744+ AndI = jit_aarch64_asm :Op (RegA , RegB , RegA ),
1745+ StreamModule :append (Stream0 , <<MoveI /binary , AndI /binary >>)
17561746 end ,
17571747 State # state {stream = Stream1 }.
17581748
1759- add (# state {stream_module = StreamModule , stream = Stream0 } = State , Reg , Val ) ->
1760- Stream1 =
1761- try
1762- I = jit_aarch64_asm :add (Reg , Reg , Val ),
1763- StreamModule :append (Stream0 , I )
1764- catch
1765- error :{unencodable_immediate , Val } ->
1766- [Temp | _ ] = State # state .available_regs ,
1767- I1 = jit_aarch64_asm :mov (Temp , Val ),
1768- I2 = jit_aarch64_asm :add (Reg , Reg , Temp ),
1769- StreamModule :append (Stream0 , <<I1 /binary , I2 /binary >>)
1770- end ,
1771- State # state {stream = Stream1 }.
1749+ and_ (State , Reg , Val ) ->
1750+ op_imm (State , and_ , Reg , Reg , Val ).
1751+
1752+ or_ (State , Reg , Val ) ->
1753+ op_imm (State , orr , Reg , Reg , Val ).
1754+
1755+ add (State , Reg , Val ) ->
1756+ op_imm (State , add , Reg , Reg , Val ).
17721757
17731758sub (# state {stream_module = StreamModule , stream = Stream0 } = State , Reg , Val ) ->
17741759 I1 = jit_aarch64_asm :sub (Reg , Reg , Val ),
0 commit comments