@@ -670,6 +670,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
670
670
unsigned int target ;
671
671
u64 t64 ;
672
672
s64 t64s ;
673
+ int bpf_op = BPF_OP (insn -> code );
673
674
674
675
switch (insn -> code ) {
675
676
case BPF_ALU64 | BPF_ADD | BPF_K : /* ALU64_IMM */
@@ -758,13 +759,13 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
758
759
emit_instr (ctx , sll , dst , dst , 0 );
759
760
if (insn -> imm == 1 ) {
760
761
/* div by 1 is a nop, mod by 1 is zero */
761
- if (BPF_OP ( insn -> code ) == BPF_MOD )
762
+ if (bpf_op == BPF_MOD )
762
763
emit_instr (ctx , addu , dst , MIPS_R_ZERO , MIPS_R_ZERO );
763
764
break ;
764
765
}
765
766
gen_imm_to_reg (insn , MIPS_R_AT , ctx );
766
767
emit_instr (ctx , divu , dst , MIPS_R_AT );
767
- if (BPF_OP ( insn -> code ) == BPF_DIV )
768
+ if (bpf_op == BPF_DIV )
768
769
emit_instr (ctx , mflo , dst );
769
770
else
770
771
emit_instr (ctx , mfhi , dst );
@@ -786,13 +787,13 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
786
787
787
788
if (insn -> imm == 1 ) {
788
789
/* div by 1 is a nop, mod by 1 is zero */
789
- if (BPF_OP ( insn -> code ) == BPF_MOD )
790
+ if (bpf_op == BPF_MOD )
790
791
emit_instr (ctx , addu , dst , MIPS_R_ZERO , MIPS_R_ZERO );
791
792
break ;
792
793
}
793
794
gen_imm_to_reg (insn , MIPS_R_AT , ctx );
794
795
emit_instr (ctx , ddivu , dst , MIPS_R_AT );
795
- if (BPF_OP ( insn -> code ) == BPF_DIV )
796
+ if (bpf_op == BPF_DIV )
796
797
emit_instr (ctx , mflo , dst );
797
798
else
798
799
emit_instr (ctx , mfhi , dst );
@@ -817,7 +818,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
817
818
emit_instr (ctx , dinsu , dst , MIPS_R_ZERO , 32 , 32 );
818
819
did_move = false;
819
820
if (insn -> src_reg == BPF_REG_10 ) {
820
- if (BPF_OP ( insn -> code ) == BPF_MOV ) {
821
+ if (bpf_op == BPF_MOV ) {
821
822
emit_instr (ctx , daddiu , dst , MIPS_R_SP , MAX_BPF_STACK );
822
823
did_move = true;
823
824
} else {
@@ -827,15 +828,15 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
827
828
} else if (get_reg_val_type (ctx , this_idx , insn -> src_reg ) == REG_32BIT ) {
828
829
int tmp_reg = MIPS_R_AT ;
829
830
830
- if (BPF_OP ( insn -> code ) == BPF_MOV ) {
831
+ if (bpf_op == BPF_MOV ) {
831
832
tmp_reg = dst ;
832
833
did_move = true;
833
834
}
834
835
emit_instr (ctx , daddu , tmp_reg , src , MIPS_R_ZERO );
835
836
emit_instr (ctx , dinsu , tmp_reg , MIPS_R_ZERO , 32 , 32 );
836
837
src = MIPS_R_AT ;
837
838
}
838
- switch (BPF_OP ( insn -> code ) ) {
839
+ switch (bpf_op ) {
839
840
case BPF_MOV :
840
841
if (!did_move )
841
842
emit_instr (ctx , daddu , dst , src , MIPS_R_ZERO );
@@ -867,7 +868,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
867
868
emit_instr (ctx , beq , src , MIPS_R_ZERO , b_off );
868
869
emit_instr (ctx , movz , MIPS_R_V0 , MIPS_R_ZERO , src );
869
870
emit_instr (ctx , ddivu , dst , src );
870
- if (BPF_OP ( insn -> code ) == BPF_DIV )
871
+ if (bpf_op == BPF_DIV )
871
872
emit_instr (ctx , mflo , dst );
872
873
else
873
874
emit_instr (ctx , mfhi , dst );
@@ -911,15 +912,15 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
911
912
if (ts == REG_64BIT || ts == REG_32BIT_ZERO_EX ) {
912
913
int tmp_reg = MIPS_R_AT ;
913
914
914
- if (BPF_OP ( insn -> code ) == BPF_MOV ) {
915
+ if (bpf_op == BPF_MOV ) {
915
916
tmp_reg = dst ;
916
917
did_move = true;
917
918
}
918
919
/* sign extend */
919
920
emit_instr (ctx , sll , tmp_reg , src , 0 );
920
921
src = MIPS_R_AT ;
921
922
}
922
- switch (BPF_OP ( insn -> code ) ) {
923
+ switch (bpf_op ) {
923
924
case BPF_MOV :
924
925
if (!did_move )
925
926
emit_instr (ctx , addu , dst , src , MIPS_R_ZERO );
@@ -950,7 +951,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
950
951
emit_instr (ctx , beq , src , MIPS_R_ZERO , b_off );
951
952
emit_instr (ctx , movz , MIPS_R_V0 , MIPS_R_ZERO , src );
952
953
emit_instr (ctx , divu , dst , src );
953
- if (BPF_OP ( insn -> code ) == BPF_DIV )
954
+ if (bpf_op == BPF_DIV )
954
955
emit_instr (ctx , mflo , dst );
955
956
else
956
957
emit_instr (ctx , mfhi , dst );
@@ -977,7 +978,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
977
978
break ;
978
979
case BPF_JMP | BPF_JEQ | BPF_K : /* JMP_IMM */
979
980
case BPF_JMP | BPF_JNE | BPF_K : /* JMP_IMM */
980
- cmp_eq = (BPF_OP ( insn -> code ) == BPF_JEQ );
981
+ cmp_eq = (bpf_op == BPF_JEQ );
981
982
dst = ebpf_to_mips_reg (ctx , insn , dst_reg_fp_ok );
982
983
if (dst < 0 )
983
984
return dst ;
@@ -1012,18 +1013,18 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
1012
1013
emit_instr (ctx , sll , MIPS_R_AT , dst , 0 );
1013
1014
dst = MIPS_R_AT ;
1014
1015
}
1015
- if (BPF_OP ( insn -> code ) == BPF_JSET ) {
1016
+ if (bpf_op == BPF_JSET ) {
1016
1017
emit_instr (ctx , and , MIPS_R_AT , dst , src );
1017
1018
cmp_eq = false;
1018
1019
dst = MIPS_R_AT ;
1019
1020
src = MIPS_R_ZERO ;
1020
- } else if (BPF_OP ( insn -> code ) == BPF_JSGT || BPF_OP ( insn -> code ) == BPF_JSLE ) {
1021
+ } else if (bpf_op == BPF_JSGT || bpf_op == BPF_JSLE ) {
1021
1022
emit_instr (ctx , dsubu , MIPS_R_AT , dst , src );
1022
1023
if ((insn + 1 )-> code == (BPF_JMP | BPF_EXIT ) && insn -> off == 1 ) {
1023
1024
b_off = b_imm (exit_idx , ctx );
1024
1025
if (is_bad_offset (b_off ))
1025
1026
return - E2BIG ;
1026
- if (BPF_OP ( insn -> code ) == BPF_JSGT )
1027
+ if (bpf_op == BPF_JSGT )
1027
1028
emit_instr (ctx , blez , MIPS_R_AT , b_off );
1028
1029
else
1029
1030
emit_instr (ctx , bgtz , MIPS_R_AT , b_off );
@@ -1033,35 +1034,35 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
1033
1034
b_off = b_imm (this_idx + insn -> off + 1 , ctx );
1034
1035
if (is_bad_offset (b_off ))
1035
1036
return - E2BIG ;
1036
- if (BPF_OP ( insn -> code ) == BPF_JSGT )
1037
+ if (bpf_op == BPF_JSGT )
1037
1038
emit_instr (ctx , bgtz , MIPS_R_AT , b_off );
1038
1039
else
1039
1040
emit_instr (ctx , blez , MIPS_R_AT , b_off );
1040
1041
emit_instr (ctx , nop );
1041
1042
break ;
1042
- } else if (BPF_OP ( insn -> code ) == BPF_JSGE || BPF_OP ( insn -> code ) == BPF_JSLT ) {
1043
+ } else if (bpf_op == BPF_JSGE || bpf_op == BPF_JSLT ) {
1043
1044
emit_instr (ctx , slt , MIPS_R_AT , dst , src );
1044
- cmp_eq = BPF_OP ( insn -> code ) == BPF_JSGE ;
1045
+ cmp_eq = bpf_op == BPF_JSGE ;
1045
1046
dst = MIPS_R_AT ;
1046
1047
src = MIPS_R_ZERO ;
1047
- } else if (BPF_OP ( insn -> code ) == BPF_JGT || BPF_OP ( insn -> code ) == BPF_JLE ) {
1048
+ } else if (bpf_op == BPF_JGT || bpf_op == BPF_JLE ) {
1048
1049
/* dst or src could be AT */
1049
1050
emit_instr (ctx , dsubu , MIPS_R_T8 , dst , src );
1050
1051
emit_instr (ctx , sltu , MIPS_R_AT , dst , src );
1051
1052
/* SP known to be non-zero, movz becomes boolean not */
1052
1053
emit_instr (ctx , movz , MIPS_R_T9 , MIPS_R_SP , MIPS_R_T8 );
1053
1054
emit_instr (ctx , movn , MIPS_R_T9 , MIPS_R_ZERO , MIPS_R_T8 );
1054
1055
emit_instr (ctx , or , MIPS_R_AT , MIPS_R_T9 , MIPS_R_AT );
1055
- cmp_eq = BPF_OP ( insn -> code ) == BPF_JGT ;
1056
+ cmp_eq = bpf_op == BPF_JGT ;
1056
1057
dst = MIPS_R_AT ;
1057
1058
src = MIPS_R_ZERO ;
1058
- } else if (BPF_OP ( insn -> code ) == BPF_JGE || BPF_OP ( insn -> code ) == BPF_JLT ) {
1059
+ } else if (bpf_op == BPF_JGE || bpf_op == BPF_JLT ) {
1059
1060
emit_instr (ctx , sltu , MIPS_R_AT , dst , src );
1060
- cmp_eq = BPF_OP ( insn -> code ) == BPF_JGE ;
1061
+ cmp_eq = bpf_op == BPF_JGE ;
1061
1062
dst = MIPS_R_AT ;
1062
1063
src = MIPS_R_ZERO ;
1063
1064
} else { /* JNE/JEQ case */
1064
- cmp_eq = (BPF_OP ( insn -> code ) == BPF_JEQ );
1065
+ cmp_eq = (bpf_op == BPF_JEQ );
1065
1066
}
1066
1067
jeq_common :
1067
1068
/*
@@ -1122,7 +1123,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
1122
1123
case BPF_JMP | BPF_JSGE | BPF_K : /* JMP_IMM */
1123
1124
case BPF_JMP | BPF_JSLT | BPF_K : /* JMP_IMM */
1124
1125
case BPF_JMP | BPF_JSLE | BPF_K : /* JMP_IMM */
1125
- cmp_eq = (BPF_OP ( insn -> code ) == BPF_JSGE );
1126
+ cmp_eq = (bpf_op == BPF_JSGE );
1126
1127
dst = ebpf_to_mips_reg (ctx , insn , dst_reg_fp_ok );
1127
1128
if (dst < 0 )
1128
1129
return dst ;
@@ -1132,7 +1133,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
1132
1133
b_off = b_imm (exit_idx , ctx );
1133
1134
if (is_bad_offset (b_off ))
1134
1135
return - E2BIG ;
1135
- switch (BPF_OP ( insn -> code ) ) {
1136
+ switch (bpf_op ) {
1136
1137
case BPF_JSGT :
1137
1138
emit_instr (ctx , blez , dst , b_off );
1138
1139
break ;
@@ -1152,7 +1153,7 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
1152
1153
b_off = b_imm (this_idx + insn -> off + 1 , ctx );
1153
1154
if (is_bad_offset (b_off ))
1154
1155
return - E2BIG ;
1155
- switch (BPF_OP ( insn -> code ) ) {
1156
+ switch (bpf_op ) {
1156
1157
case BPF_JSGT :
1157
1158
emit_instr (ctx , bgtz , dst , b_off );
1158
1159
break ;
@@ -1173,14 +1174,14 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
1173
1174
* only "LT" compare available, so we must use imm + 1
1174
1175
* to generate "GT" and imm -1 to generate LE
1175
1176
*/
1176
- if (BPF_OP ( insn -> code ) == BPF_JSGT )
1177
+ if (bpf_op == BPF_JSGT )
1177
1178
t64s = insn -> imm + 1 ;
1178
- else if (BPF_OP ( insn -> code ) == BPF_JSLE )
1179
+ else if (bpf_op == BPF_JSLE )
1179
1180
t64s = insn -> imm + 1 ;
1180
1181
else
1181
1182
t64s = insn -> imm ;
1182
1183
1183
- cmp_eq = BPF_OP ( insn -> code ) == BPF_JSGT || BPF_OP ( insn -> code ) == BPF_JSGE ;
1184
+ cmp_eq = bpf_op == BPF_JSGT || bpf_op == BPF_JSGE ;
1184
1185
if (t64s >= S16_MIN && t64s <= S16_MAX ) {
1185
1186
emit_instr (ctx , slti , MIPS_R_AT , dst , (int )t64s );
1186
1187
src = MIPS_R_AT ;
@@ -1197,22 +1198,22 @@ static int build_one_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
1197
1198
case BPF_JMP | BPF_JGE | BPF_K :
1198
1199
case BPF_JMP | BPF_JLT | BPF_K :
1199
1200
case BPF_JMP | BPF_JLE | BPF_K :
1200
- cmp_eq = (BPF_OP ( insn -> code ) == BPF_JGE );
1201
+ cmp_eq = (bpf_op == BPF_JGE );
1201
1202
dst = ebpf_to_mips_reg (ctx , insn , dst_reg_fp_ok );
1202
1203
if (dst < 0 )
1203
1204
return dst ;
1204
1205
/*
1205
1206
* only "LT" compare available, so we must use imm + 1
1206
1207
* to generate "GT" and imm -1 to generate LE
1207
1208
*/
1208
- if (BPF_OP ( insn -> code ) == BPF_JGT )
1209
+ if (bpf_op == BPF_JGT )
1209
1210
t64s = (u64 )(u32 )(insn -> imm ) + 1 ;
1210
- else if (BPF_OP ( insn -> code ) == BPF_JLE )
1211
+ else if (bpf_op == BPF_JLE )
1211
1212
t64s = (u64 )(u32 )(insn -> imm ) + 1 ;
1212
1213
else
1213
1214
t64s = (u64 )(u32 )(insn -> imm );
1214
1215
1215
- cmp_eq = BPF_OP ( insn -> code ) == BPF_JGT || BPF_OP ( insn -> code ) == BPF_JGE ;
1216
+ cmp_eq = bpf_op == BPF_JGT || bpf_op == BPF_JGE ;
1216
1217
1217
1218
emit_const_to_reg (ctx , MIPS_R_AT , (u64 )t64s );
1218
1219
emit_instr (ctx , sltu , MIPS_R_AT , dst , MIPS_R_AT );
0 commit comments