]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf, arm64: Factor out emit_a64_add_i()
authorPeilin Ye <yepeilin@google.com>
Fri, 3 Jan 2025 02:03:42 +0000 (02:03 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 6 Jan 2025 14:07:26 +0000 (15:07 +0100)
As suggested by Xu, factor out emit_a64_add_i() for later use. No
functional change.

Suggested-by: Xu Kuohai <xukuohai@huaweicloud.com>
Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Xu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/bpf/fedbaca80e6d8bd5bcba1ac5320dfbbdab14472e.1735868489.git.yepeilin@google.com
arch/arm64/net/bpf_jit_comp.c

index 9040033eb1eab57a7e10d39f007c38ab93436611..8ee9528d87955c6334b5e8c2afe5b1ad94441edf 100644 (file)
@@ -267,6 +267,19 @@ static bool is_addsub_imm(u32 imm)
        return !(imm & ~0xfff) || !(imm & ~0xfff000);
 }
 
+static inline void emit_a64_add_i(const bool is64, const int dst, const int src,
+                                 const int tmp, const s32 imm, struct jit_ctx *ctx)
+{
+       if (is_addsub_imm(imm)) {
+               emit(A64_ADD_I(is64, dst, src, imm), ctx);
+       } else if (is_addsub_imm(-imm)) {
+               emit(A64_SUB_I(is64, dst, src, -imm), ctx);
+       } else {
+               emit_a64_mov_i(is64, tmp, imm, ctx);
+               emit(A64_ADD(is64, dst, src, tmp), ctx);
+       }
+}
+
 /*
  * There are 3 types of AArch64 LDR/STR (immediate) instruction:
  * Post-index, Pre-index, Unsigned offset.
@@ -1144,14 +1157,7 @@ emit_bswap_uxt:
        /* dst = dst OP imm */
        case BPF_ALU | BPF_ADD | BPF_K:
        case BPF_ALU64 | BPF_ADD | BPF_K:
-               if (is_addsub_imm(imm)) {
-                       emit(A64_ADD_I(is64, dst, dst, imm), ctx);
-               } else if (is_addsub_imm(-imm)) {
-                       emit(A64_SUB_I(is64, dst, dst, -imm), ctx);
-               } else {
-                       emit_a64_mov_i(is64, tmp, imm, ctx);
-                       emit(A64_ADD(is64, dst, dst, tmp), ctx);
-               }
+               emit_a64_add_i(is64, dst, dst, tmp, imm, ctx);
                break;
        case BPF_ALU | BPF_SUB | BPF_K:
        case BPF_ALU64 | BPF_SUB | BPF_K: