@@ -182,7 +182,7 @@ compile_op_ibinopt_const(JitCompContext *cc, JitReg left, JitReg right,
182182
183183 if (jit_reg_is_const (left ) || jit_reg_is_const (right )) {
184184 res = handle_one_const (cc , left , right , is_i32 );
185- if (! res )
185+ if (res )
186186 goto shortcut ;
187187 }
188188
@@ -787,25 +787,44 @@ jit_compile_op_i64_bitwise(JitCompContext *cc, IntBitwise bitwise_op)
787787
788788DEF_UNI_INT_CONST_OPS (shl )
789789{
790- if (IS_CONST_ZERO (right )) {
790+ if (IS_CONST_ZERO (right ) || IS_CONST_ZERO ( left ) ) {
791791 return left ;
792792 }
793+
794+ if (jit_reg_is_const (right )) {
795+ JitReg res = is_i32 ? jit_cc_new_reg_I32 (cc ) : jit_cc_new_reg_I64 (cc );
796+ GEN_INSN (SHL , res , left , right );
797+ return res ;
798+ }
793799 return 0 ;
794800}
795801
796802DEF_UNI_INT_CONST_OPS (shrs )
797803{
798- if (IS_CONST_ZERO (right )) {
804+ if (IS_CONST_ZERO (right ) || IS_CONST_ZERO (left )
805+ || IS_CONST_ALL_ONE (left , is_i32 )) {
799806 return left ;
800807 }
808+
809+ if (jit_reg_is_const (right )) {
810+ JitReg res = is_i32 ? jit_cc_new_reg_I32 (cc ) : jit_cc_new_reg_I64 (cc );
811+ GEN_INSN (SHRS , res , left , right );
812+ return res ;
813+ }
801814 return 0 ;
802815}
803816
804817DEF_UNI_INT_CONST_OPS (shru )
805818{
806- if (IS_CONST_ZERO (right )) {
819+ if (IS_CONST_ZERO (right ) || IS_CONST_ZERO ( left ) ) {
807820 return left ;
808821 }
822+
823+ if (jit_reg_is_const (right )) {
824+ JitReg res = is_i32 ? jit_cc_new_reg_I32 (cc ) : jit_cc_new_reg_I64 (cc );
825+ GEN_INSN (SHRU , res , left , right );
826+ return res ;
827+ }
809828 return 0 ;
810829}
811830
@@ -958,11 +977,15 @@ compile_int_shru(JitCompContext *cc, JitReg left, JitReg right, bool is_i32)
958977
959978DEF_UNI_INT_CONST_OPS (rotl )
960979{
961- if (IS_CONST_ZERO (right ))
980+ if (IS_CONST_ZERO (right ) || IS_CONST_ZERO (left )
981+ || IS_CONST_ALL_ONE (left , is_i32 ))
962982 return left ;
963983
964- if (IS_CONST_ZERO (left ))
965- return right ;
984+ if (jit_reg_is_const (right )) {
985+ JitReg res = is_i32 ? jit_cc_new_reg_I32 (cc ) : jit_cc_new_reg_I64 (cc );
986+ GEN_INSN (ROTL , res , left , right );
987+ return res ;
988+ }
966989
967990 return 0 ;
968991}
@@ -986,7 +1009,7 @@ do_i64_const_rotl(int64 lhs, int64 rhs)
9861009static JitReg
9871010compile_int_rotl (JitCompContext * cc , JitReg left , JitReg right , bool is_i32 )
9881011{
989- JitReg res , tmp , shl_res , shr_res ;
1012+ JitReg res ;
9901013#if defined(BUILD_TARGET_X86_64 ) || defined(BUILD_TARGET_AMD_64 )
9911014 JitReg ecx_hreg = jit_codegen_get_hreg_by_name ("ecx" );
9921015 JitReg rcx_hreg = jit_codegen_get_hreg_by_name ("rcx" );
@@ -1000,34 +1023,13 @@ compile_int_rotl(JitCompContext *cc, JitReg left, JitReg right, bool is_i32)
10001023
10011024 left = mov_left_to_reg (cc , is_i32 , left );
10021025
1003- if (is_i32 ) {
1004- tmp = jit_cc_new_reg_I32 (cc );
1005- shl_res = jit_cc_new_reg_I32 (cc );
1006- shr_res = jit_cc_new_reg_I32 (cc );
1007- res = jit_cc_new_reg_I32 (cc );
1008- }
1009- else {
1010- tmp = jit_cc_new_reg_I64 (cc );
1011- shl_res = jit_cc_new_reg_I64 (cc );
1012- shr_res = jit_cc_new_reg_I64 (cc );
1013- res = jit_cc_new_reg_I64 (cc );
1014- }
1015-
1016- /* 32/64 - rhs */
1017- GEN_INSN (SUB , tmp , is_i32 ? NEW_CONST (I32 , 32 ) : NEW_CONST (I64 , 64 ), right );
1026+ res = is_i32 ? jit_cc_new_reg_I32 (cc ) : jit_cc_new_reg_I64 (cc );
10181027#if defined(BUILD_TARGET_X86_64 ) || defined(BUILD_TARGET_AMD_64 )
10191028 GEN_INSN (MOV , is_i32 ? ecx_hreg : rcx_hreg , right );
1020- GEN_INSN (SHL , shl_res , left , is_i32 ? ecx_hreg : rcx_hreg );
1021-
1022- GEN_INSN (MOV , is_i32 ? ecx_hreg : rcx_hreg , tmp );
1023- GEN_INSN (SHRU , shr_res , left , is_i32 ? ecx_hreg : rcx_hreg );
1024-
1025- GEN_INSN (OR , res , shl_res , shr_res );
1029+ GEN_INSN (ROTL , res , left , is_i32 ? ecx_hreg : rcx_hreg );
10261030 GEN_INSN (MOV , ecx_hreg , ecx_hreg );
10271031#else
1028- GEN_INSN (SHL , shl_res , left , right );
1029- GEN_INSN (SHRU , shr_res , left , tmp );
1030- GEN_INSN (OR , res , shl_res , shr_res );
1032+ GEN_INSN (ROTL , res , left , right );
10311033#endif
10321034
10331035shortcut :
@@ -1036,11 +1038,15 @@ compile_int_rotl(JitCompContext *cc, JitReg left, JitReg right, bool is_i32)
10361038
10371039DEF_UNI_INT_CONST_OPS (rotr )
10381040{
1039- if (IS_CONST_ZERO (right ))
1041+ if (IS_CONST_ZERO (right ) || IS_CONST_ZERO (left )
1042+ || IS_CONST_ALL_ONE (left , is_i32 ))
10401043 return left ;
10411044
1042- if (IS_CONST_ZERO (left ))
1043- return right ;
1045+ if (jit_reg_is_const (right )) {
1046+ JitReg res = is_i32 ? jit_cc_new_reg_I32 (cc ) : jit_cc_new_reg_I64 (cc );
1047+ GEN_INSN (ROTR , res , left , right );
1048+ return res ;
1049+ }
10441050
10451051 return 0 ;
10461052}
@@ -1064,7 +1070,7 @@ do_i64_const_rotr(int64 lhs, int64 rhs)
10641070static JitReg
10651071compile_int_rotr (JitCompContext * cc , JitReg left , JitReg right , bool is_i32 )
10661072{
1067- JitReg res , tmp , shr_res , shl_res ;
1073+ JitReg res ;
10681074#if defined(BUILD_TARGET_X86_64 ) || defined(BUILD_TARGET_AMD_64 )
10691075 JitReg ecx_hreg = jit_codegen_get_hreg_by_name ("ecx" );
10701076 JitReg rcx_hreg = jit_codegen_get_hreg_by_name ("rcx" );
@@ -1078,34 +1084,13 @@ compile_int_rotr(JitCompContext *cc, JitReg left, JitReg right, bool is_i32)
10781084
10791085 left = mov_left_to_reg (cc , is_i32 , left );
10801086
1081- if (is_i32 ) {
1082- tmp = jit_cc_new_reg_I32 (cc );
1083- shr_res = jit_cc_new_reg_I32 (cc );
1084- shl_res = jit_cc_new_reg_I32 (cc );
1085- res = jit_cc_new_reg_I32 (cc );
1086- }
1087- else {
1088- tmp = jit_cc_new_reg_I64 (cc );
1089- shr_res = jit_cc_new_reg_I64 (cc );
1090- shl_res = jit_cc_new_reg_I64 (cc );
1091- res = jit_cc_new_reg_I64 (cc );
1092- }
1093-
1094- /* 32/64 - rhs */
1095- GEN_INSN (SUB , tmp , is_i32 ? NEW_CONST (I32 , 32 ) : NEW_CONST (I64 , 64 ), right );
1087+ res = is_i32 ? jit_cc_new_reg_I32 (cc ) : jit_cc_new_reg_I64 (cc );
10961088#if defined(BUILD_TARGET_X86_64 ) || defined(BUILD_TARGET_AMD_64 )
10971089 GEN_INSN (MOV , is_i32 ? ecx_hreg : rcx_hreg , right );
1098- GEN_INSN (SHRU , shl_res , left , is_i32 ? ecx_hreg : rcx_hreg );
1099-
1100- GEN_INSN (MOV , is_i32 ? ecx_hreg : rcx_hreg , tmp );
1101- GEN_INSN (SHL , shr_res , left , is_i32 ? ecx_hreg : rcx_hreg );
1102-
1103- GEN_INSN (OR , res , shl_res , shr_res );
1090+ GEN_INSN (ROTR , res , left , is_i32 ? ecx_hreg : rcx_hreg );
11041091 GEN_INSN (MOV , ecx_hreg , ecx_hreg );
11051092#else
1106- GEN_INSN (SHRU , shr_res , left , right );
1107- GEN_INSN (SHL , shl_res , left , tmp );
1108- GEN_INSN (OR , res , shr_res , shl_res );
1093+ GEN_INSN (ROTR , res , left , right );
11091094#endif
11101095
11111096shortcut :
0 commit comments