* [PATCH] LoongArch: BPF: Optimize doubleword loads with ld.d and ldptr.d
@ 2026-11-18 8:12 Tiezhu Yang
2026-12-04 7:11 ` George Guo
0 siblings, 1 reply; 2+ messages in thread
From: Tiezhu Yang @ 2026-11-18 8:12 UTC (permalink / raw)
To: Huacai Chen, Hengqi Chen; +Cc: loongarch, bpf, linux-kernel
Currently, 64-bit doubleword loads (BPF_DW) unconditionally load the
offset into a temporary register with move_imm() and emit ldx.d.
Optimize these loads by emitting ld.d for signed 12-bit offsets and
ldptr.d for 4-byte aligned signed 16-bit offsets, or falling back to
move_imm() + ldx.d when necessary.
With this patch, only a single load instruction is emitted in most
cases.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
This is based on the patch:
LoongArch: BPF: Fix the offset of stptr.w and stptr.d stores
https://lore.kernel.org/loongarch/20261118071444.10258-1-dongtai.guo@linux.dev/T/#u
Note that BPF_W is left unchanged because LoongArch provides ldptr.w
(which sign-extends to 64 bits) but lacks an unsigned zero-extending
ldptr.wu instruction required by standard 32-bit BPF loads.
arch/loongarch/net/bpf_jit.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
index 906f34f420f1..d36891db1179 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -1352,8 +1352,14 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
}
break;
case BPF_DW:
- move_imm(ctx, t1, off);
- emit_insn(ctx, ldxd, dst, src, t1);
+ if (is_signed_imm12(off)) {
+ emit_insn(ctx, ldd, dst, src, off);
+ } else if (is_aligned_signed_imm16(off)) {
+ emit_insn(ctx, ldptrd, dst, src, off >> 2);
+ } else {
+ move_imm(ctx, t1, off);
+ emit_insn(ctx, ldxd, dst, src, t1);
+ }
break;
}
--
2.42.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] LoongArch: BPF: Optimize doubleword loads with ld.d and ldptr.d
2026-11-18 8:12 [PATCH] LoongArch: BPF: Optimize doubleword loads with ld.d and ldptr.d Tiezhu Yang
@ 2026-12-04 7:11 ` George Guo
0 siblings, 0 replies; 2+ messages in thread
From: George Guo @ 2026-12-04 7:11 UTC (permalink / raw)
To: yangtiezhu
Cc: chenhuacai, hengqi.chen, loongarch, bpf, linux-kernel, George Guo
On 2026/11/18 16:12, Tiezhu Yang wrote:
> Optimize these loads by emitting ld.d for signed 12-bit offsets and
> ldptr.d for 4-byte aligned signed 16-bit offsets, or falling back to
> move_imm() + ldx.d when necessary.
Tested on Loongson-3C6000, together with "LoongArch: BPF: Fix the offset
of stptr.w and stptr.d stores". The jit_insns tests passed, including
the ldst_offsets subtests:
$ sudo ./test_progs -t jit_insns,jit_insns_blinded
...
#196/26 jit_insns/ldst_offsets:OK
...
#196 jit_insns:OK
...
#197/11 jit_insns_blinded/ldst_offsets:OK
...
#197 jit_insns_blinded:OK
Summary: 2/47 PASSED, 0 SKIPPED, 0/0 FAILED
Reviewed-by: George Guo <guodongtai@kylinos.cn>
Tested-by: George Guo <guodongtai@kylinos.cn>
Thanks,
George
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 7:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 8:12 [PATCH] LoongArch: BPF: Optimize doubleword loads with ld.d and ldptr.d Tiezhu Yang
2026-12-04 7:11 ` George Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®