Skip to content

Commit 66bb58a

Browse files
peilin-yeborkmann
authored andcommitted
bpf, arm64: Factor out emit_a64_add_i()
As suggested by Xu, factor out emit_a64_add_i() for later use. No functional change. Suggested-by: Xu Kuohai <[email protected]> Signed-off-by: Peilin Ye <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Xu Kuohai <[email protected]> Link: https://lore.kernel.org/bpf/fedbaca80e6d8bd5bcba1ac5320dfbbdab14472e.1735868489.git.yepeilin@google.com
1 parent 0a58072 commit 66bb58a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ static bool is_addsub_imm(u32 imm)
267267
return !(imm & ~0xfff) || !(imm & ~0xfff000);
268268
}
269269

270+
static inline void emit_a64_add_i(const bool is64, const int dst, const int src,
271+
const int tmp, const s32 imm, struct jit_ctx *ctx)
272+
{
273+
if (is_addsub_imm(imm)) {
274+
emit(A64_ADD_I(is64, dst, src, imm), ctx);
275+
} else if (is_addsub_imm(-imm)) {
276+
emit(A64_SUB_I(is64, dst, src, -imm), ctx);
277+
} else {
278+
emit_a64_mov_i(is64, tmp, imm, ctx);
279+
emit(A64_ADD(is64, dst, src, tmp), ctx);
280+
}
281+
}
282+
270283
/*
271284
* There are 3 types of AArch64 LDR/STR (immediate) instruction:
272285
* Post-index, Pre-index, Unsigned offset.
@@ -1144,14 +1157,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
11441157
/* dst = dst OP imm */
11451158
case BPF_ALU | BPF_ADD | BPF_K:
11461159
case BPF_ALU64 | BPF_ADD | BPF_K:
1147-
if (is_addsub_imm(imm)) {
1148-
emit(A64_ADD_I(is64, dst, dst, imm), ctx);
1149-
} else if (is_addsub_imm(-imm)) {
1150-
emit(A64_SUB_I(is64, dst, dst, -imm), ctx);
1151-
} else {
1152-
emit_a64_mov_i(is64, tmp, imm, ctx);
1153-
emit(A64_ADD(is64, dst, dst, tmp), ctx);
1154-
}
1160+
emit_a64_add_i(is64, dst, dst, tmp, imm, ctx);
11551161
break;
11561162
case BPF_ALU | BPF_SUB | BPF_K:
11571163
case BPF_ALU64 | BPF_SUB | BPF_K:

0 commit comments

Comments
 (0)