Skip to content

Commit 4987eac

Browse files
Jakub Kicinskiborkmann
authored andcommitted
nfp: bpf: optimize codegen for JSET with a constant
The top word of the constant can only have bits set if sign extension set it to all-1, therefore we don't really have to mask the top half of the register. We can just OR it into the result as is. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 6e77484 commit 4987eac

File tree

1 file changed

+10
-12
lines changed
  • drivers/net/ethernet/netronome/nfp/bpf

1 file changed

+10
-12
lines changed

drivers/net/ethernet/netronome/nfp/bpf/jit.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,21 +3052,19 @@ static int jset_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
30523052
{
30533053
const struct bpf_insn *insn = &meta->insn;
30543054
u64 imm = insn->imm; /* sign extend */
3055+
u8 dst_gpr = insn->dst_reg * 2;
30553056
swreg tmp_reg;
30563057

3057-
if (imm & ~0U) {
3058-
tmp_reg = ur_load_imm_any(nfp_prog, imm & ~0U, imm_b(nfp_prog));
3059-
emit_alu(nfp_prog, reg_none(),
3060-
reg_a(insn->dst_reg * 2), ALU_OP_AND, tmp_reg);
3061-
emit_br(nfp_prog, BR_BNE, insn->off, 0);
3062-
}
3063-
3064-
if (imm >> 32) {
3065-
tmp_reg = ur_load_imm_any(nfp_prog, imm >> 32, imm_b(nfp_prog));
3058+
tmp_reg = ur_load_imm_any(nfp_prog, imm & ~0U, imm_b(nfp_prog));
3059+
emit_alu(nfp_prog, imm_b(nfp_prog),
3060+
reg_a(dst_gpr), ALU_OP_AND, tmp_reg);
3061+
/* Upper word of the mask can only be 0 or ~0 from sign extension,
3062+
* so either ignore it or OR the whole thing in.
3063+
*/
3064+
if (imm >> 32)
30663065
emit_alu(nfp_prog, reg_none(),
3067-
reg_a(insn->dst_reg * 2 + 1), ALU_OP_AND, tmp_reg);
3068-
emit_br(nfp_prog, BR_BNE, insn->off, 0);
3069-
}
3066+
reg_a(dst_gpr + 1), ALU_OP_OR, imm_b(nfp_prog));
3067+
emit_br(nfp_prog, BR_BNE, insn->off, 0);
30703068

30713069
return 0;
30723070
}

0 commit comments

Comments
 (0)