nfp: bpf: encode all 64bit shifts
authorJakub Kicinski <jakub.kicinski@netronome.com>
Mon, 9 Oct 2017 04:04:07 +0000 (21:04 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 Oct 2017 16:51:02 +0000 (09:51 -0700)
Add encodings of all 64bit shift operations.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/bpf/jit.c

index 7bcff007075cffed5ad01d43ef2bc9a6cc9a5ed6..095cf50e845003983722af76a289daa6a60d3d73 100644 (file)
@@ -825,12 +825,24 @@ static int sub_imm64(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 static int shl_imm64(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 {
        const struct bpf_insn *insn = &meta->insn;
-
-       if (insn->imm != 32)
-               return 1; /* TODO */
-
-       wrp_reg_mov(nfp_prog, insn->dst_reg * 2 + 1, insn->dst_reg * 2);
-       wrp_immed(nfp_prog, reg_both(insn->dst_reg * 2), 0);
+       u8 dst = insn->dst_reg * 2;
+
+       if (insn->imm < 32) {
+               emit_shf(nfp_prog, reg_both(dst + 1),
+                        reg_a(dst + 1), SHF_OP_NONE, reg_b(dst),
+                        SHF_SC_R_DSHF, 32 - insn->imm);
+               emit_shf(nfp_prog, reg_both(dst),
+                        reg_none(), SHF_OP_NONE, reg_b(dst),
+                        SHF_SC_L_SHF, insn->imm);
+       } else if (insn->imm == 32) {
+               wrp_reg_mov(nfp_prog, dst + 1, dst);
+               wrp_immed(nfp_prog, reg_both(dst), 0);
+       } else if (insn->imm > 32) {
+               emit_shf(nfp_prog, reg_both(dst + 1),
+                        reg_none(), SHF_OP_NONE, reg_b(dst),
+                        SHF_SC_L_SHF, insn->imm - 32);
+               wrp_immed(nfp_prog, reg_both(dst), 0);
+       }
 
        return 0;
 }
@@ -838,12 +850,24 @@ static int shl_imm64(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 static int shr_imm64(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 {
        const struct bpf_insn *insn = &meta->insn;
-
-       if (insn->imm != 32)
-               return 1; /* TODO */
-
-       wrp_reg_mov(nfp_prog, insn->dst_reg * 2, insn->dst_reg * 2 + 1);
-       wrp_immed(nfp_prog, reg_both(insn->dst_reg * 2 + 1), 0);
+       u8 dst = insn->dst_reg * 2;
+
+       if (insn->imm < 32) {
+               emit_shf(nfp_prog, reg_both(dst),
+                        reg_a(dst + 1), SHF_OP_NONE, reg_b(dst),
+                        SHF_SC_R_DSHF, insn->imm);
+               emit_shf(nfp_prog, reg_both(dst + 1),
+                        reg_none(), SHF_OP_NONE, reg_b(dst + 1),
+                        SHF_SC_R_SHF, insn->imm);
+       } else if (insn->imm == 32) {
+               wrp_reg_mov(nfp_prog, dst, dst + 1);
+               wrp_immed(nfp_prog, reg_both(dst + 1), 0);
+       } else if (insn->imm > 32) {
+               emit_shf(nfp_prog, reg_both(dst),
+                        reg_none(), SHF_OP_NONE, reg_b(dst + 1),
+                        SHF_SC_R_SHF, insn->imm - 32);
+               wrp_immed(nfp_prog, reg_both(dst + 1), 0);
+       }
 
        return 0;
 }