[RFC bpf-next 1/2] bpf, mips: Factor narrow loads out of emit_ldx()
Nicholas Dudar <[email protected]>
| Newsgroups | org.kernel.vger.linux-mips,org.kernel.vger.bpf,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Factor the byte, half-word, and word load selection out of emit_ldx() in both MIPS JIT backends. The existing unsigned LDX paths remain the only callers and retain the same native instructions, upper-half handling, and clobber accounting. The double-word paths remain unchanged. This gives narrow loads one width dispatcher that can be extended without duplicating the BPF size switch. No functional change intended. Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Nicholas Dudar <[email protected]> --- arch/mips/net/bpf_jit_comp32.c | 28 ++++++++++++++++++++-------- arch/mips/net/bpf_jit_comp64.c | 18 ++++++++++++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c index b3f6b92ac34ed..48a3c834453f2 100644 --- a/arch/mips/net/bpf_jit_comp32.c +++ b/arch/mips/net/bpf_jit_comp32.c @@ -707,24 +707,36 @@ static void emit_trunc_r64(struct jit_context *ctx, const u8 dst[], u32 width) } } -/* Load operation: dst = *(size*)(src + off) */ -static void emit_ldx(struct jit_context *ctx, - const u8 dst[], u8 src, s16 off, u8 size) +/* Narrow load operation: dst = *(size *)(src + off) */ +static void emit_ldx_narrow(struct jit_context *ctx, + u8 dst, u8 src, s16 off, u8 size) { switch (size) { /* Load a byte */ case BPF_B: - emit(ctx, lbu, lo(dst), off, src); - emit(ctx, move, hi(dst), MIPS_R_ZERO); + emit(ctx, lbu, dst, off, src); break; /* Load a half word */ case BPF_H: - emit(ctx, lhu, lo(dst), off, src); - emit(ctx, move, hi(dst), MIPS_R_ZERO); + emit(ctx, lhu, dst, off, src); break; /* Load a word */ case BPF_W: - emit(ctx, lw, lo(dst), off, src); + emit(ctx, lw, dst, off, src); + break; + } +} + +/* Load operation: dst = *(size *)(src + off) */ +static void emit_ldx(struct jit_context *ctx, + const u8 dst[], u8 src, s16 off, u8 size) +{ + switch (size) { + /* Load a byte, half word or word */ + case BPF_B: + case BPF_H: + case BPF_W: + emit_ldx_narrow(ctx, lo(dst), src, off, size); emit(ctx, move, hi(dst), MIPS_R_ZERO); break; /* Load a double word */ diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c index ee99f46828c86..22fb58f970223 100644 --- a/arch/mips/net/bpf_jit_comp64.c +++ b/arch/mips/net/bpf_jit_comp64.c @@ -398,8 +398,9 @@ static void emit_trunc_r64(struct jit_context *ctx, u8 dst, u32 width) clobber_reg(ctx, dst); } -/* Load operation: dst = *(size*)(src + off) */ -static void emit_ldx(struct jit_context *ctx, u8 dst, u8 src, s16 off, u8 size) +/* Narrow load operation: dst = *(size *)(src + off) */ +static void emit_ldx_narrow(struct jit_context *ctx, + u8 dst, u8 src, s16 off, u8 size) { switch (size) { /* Load a byte */ @@ -414,6 +415,19 @@ static void emit_ldx(struct jit_context *ctx, u8 dst, u8 src, s16 off, u8 size) case BPF_W: emit(ctx, lwu, dst, off, src); break; + } +} + +/* Load operation: dst = *(size *)(src + off) */ +static void emit_ldx(struct jit_context *ctx, u8 dst, u8 src, s16 off, u8 size) +{ + switch (size) { + /* Load a byte, half word or word */ + case BPF_B: + case BPF_H: + case BPF_W: + emit_ldx_narrow(ctx, dst, src, off, size); + break; /* Load a double word */ case BPF_DW: emit(ctx, ld, dst, off, src);