All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hengqi Chen <hengqi.chen@gmail.com>
To: loongarch@lists.linux.dev, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	chenhuacai@kernel.org, kernel@xen0n.name, yangtiezhu@loongson.cn,
	hengqi.chen@gmail.com
Subject: [PATCH bpf-next 3/8] LoongArch: BPF: Support sign-extension mov instructions
Date: Thu, 26 Oct 2023 18:43:32 +0000	[thread overview]
Message-ID: <20231026184337.563801-4-hengqi.chen@gmail.com> (raw)
In-Reply-To: <20231026184337.563801-1-hengqi.chen@gmail.com>

Add support for sign-extension mov instructions.

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 arch/loongarch/net/bpf_jit.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
index 0c2bbca527ef..ac9edf02675c 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -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 */
-- 
2.34.1


  parent reply	other threads:[~2023-10-27  6:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-26 18:43 [PATCH bpf-next 0/8] bpf: Support cpu v4 instructions for LoongArch Hengqi Chen
2023-10-26 18:43 ` [PATCH bpf-next 1/8] LoongArch: Add more instruction opcodes and emit_* helpers Hengqi Chen
2023-10-26 18:43 ` [PATCH bpf-next 2/8] LoongArch: BPF: Support sign-extension load instructions Hengqi Chen
2023-10-26 18:43 ` Hengqi Chen [this message]
2023-10-26 18:43 ` [PATCH bpf-next 4/8] LoongArch: BPF: Support unconditional bswap instructions Hengqi Chen
2023-10-26 18:43 ` [PATCH bpf-next 5/8] LoongArch: BPF: Support 32-bit offset jmp instructions Hengqi Chen
2023-10-26 18:43 ` [PATCH bpf-next 6/8] LoongArch: BPF: Support signed div instructions Hengqi Chen
2023-10-26 18:43 ` [PATCH bpf-next 7/8] LoongArch: BPF: Support signed mod instructions Hengqi Chen
2023-10-26 18:43 ` [PATCH bpf-next 8/8] selftests/bpf: Enable cpu v4 tests for LoongArch Hengqi Chen
2023-10-27  7:05   ` Huacai Chen
2023-10-27  8:39     ` Hengqi Chen
2023-10-27  8:42       ` Huacai Chen
2023-10-27  9:41         ` Hengqi Chen
2023-10-27  9:46           ` Huacai Chen
2023-11-09 15:25   ` Huacai Chen
2023-11-11 14:50     ` Hengqi Chen
2023-11-11 16:19       ` Huacai Chen
2023-11-12  2:49         ` Huacai Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231026184337.563801-4-hengqi.chen@gmail.com \
    --to=hengqi.chen@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel@xen0n.name \
    --cc=loongarch@lists.linux.dev \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.