LoongArch: BPF: Support sign-extension mov instructions
authorHengqi Chen <hengqi.chen@gmail.com>
Wed, 8 Nov 2023 06:12:16 +0000 (14:12 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Wed, 8 Nov 2023 06:12:16 +0000 (14:12 +0800)
Add support for sign-extension mov instructions.

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/net/bpf_jit.c

index 0c2bbca527efa800cea3b245ec2d400a72e020b7..ac9edf02675cbfd27236fdba96a107e572a75d7b 100644 (file)
@@ -472,8 +472,23 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
        /* dst = src */
        case BPF_ALU | BPF_MOV | BPF_X:
        case BPF_ALU64 | BPF_MOV | BPF_X:
-               move_reg(ctx, dst, src);
-               emit_zext_32(ctx, dst, is32);
+               switch (off) {
+               case 0:
+                       move_reg(ctx, dst, src);
+                       emit_zext_32(ctx, dst, is32);
+                       break;
+               case 8:
+                       move_reg(ctx, t1, src);
+                       emit_insn(ctx, extwb, dst, t1);
+                       break;
+               case 16:
+                       move_reg(ctx, t1, src);
+                       emit_insn(ctx, extwh, dst, t1);
+                       break;
+               case 32:
+                       emit_insn(ctx, addw, dst, src, LOONGARCH_GPR_ZERO);
+                       break;
+               }
                break;
 
        /* dst = imm */