Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1702333pxb; Mon, 12 Apr 2021 04:52:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyXFGysMcUbrmHIfZadrG9iQBcjWRGJLSNhWZS1jE5clTu8RQCW2IlRPfqvs0jPGLtM/HP X-Received: by 2002:a50:9b18:: with SMTP id o24mr28936938edi.227.1618228348986; Mon, 12 Apr 2021 04:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618228348; cv=none; d=google.com; s=arc-20160816; b=ARHHkfZqeHqxpHrlCpcUS8UwKOJsMQDhtSHM3PLPNDs2onuQ6cvszQi3DzG3p+hmAa Py5ODKzJfWFov9ctt9AXNJYUDwmyOybNcTnTM5Pd/rtAeyTDA2qeVDVElfG97VubGvZL LM7AoKptJjpyu/oCjGIAqLr/0LOMJlBG4bPMkO3AjDPdkuwvoMSJiL/DpaLupULwTOWr 2HJWbxC7EneH2qZEnFo+XFQwOa18xl5arsD26vF3tQFuITy8QO0wJv9ptlvW92XGLVEh WDVHIk3t+bp+j3talaOKqT0r5jR3KkEPXHG8qSPqHLVsHhA9dHvC5O76meaKHbMSG11Y N47g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:cc:to:subject:from:references:in-reply-to :message-id; bh=hDLPXuXwP5A2CRPquus8aCH8rptkoT1H+ipXvOY69mA=; b=h7TCSd39Ca5FuzlG1qt1AdOGT8ZtxjA2zowRLsv8CyH8vW6Zf3ShzRlHtpOWFo0rUO K/Kl/5Snvy8gYBkijivouRHdmrbjM+uvksPA1ypfHEJs3Yf8wLrtkRPxNvIuWkzJv7k5 h5zNlJI/gKl+we2E0l7a+s/Sa0jlSjp2s4qpUL/5awgfR/0PzmQipFk4vCRbu8SauZ6j LyJb1SXLmfUFAXh3/ukBOw/a3mKQcW8s4aqI1OirTc31xVMtxSGek5GanATRvrKHfw6x QJBjpmZclvXwnKeDVzY90ls25b3YWw67UhVL4FRK7WcaRKziIjpkdf+rtpQZBOugMcK6 uzOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq21si5636573ejb.186.2021.04.12.04.52.05; Mon, 12 Apr 2021 04:52:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240670AbhDLLuo (ORCPT + 99 others); Mon, 12 Apr 2021 07:50:44 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:15361 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238482AbhDLLui (ORCPT ); Mon, 12 Apr 2021 07:50:38 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4FJn2N6PHjz9tyR3; Mon, 12 Apr 2021 13:44:12 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id hJ_xhjYiOndS; Mon, 12 Apr 2021 13:44:12 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4FJn2N5XR7z9tyQT; Mon, 12 Apr 2021 13:44:12 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C589F8B78E; Mon, 12 Apr 2021 13:44:17 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 8DnIkpbJZT5P; Mon, 12 Apr 2021 13:44:17 +0200 (CEST) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6AE118B78D; Mon, 12 Apr 2021 13:44:17 +0200 (CEST) Received: by po16121vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 3985267A06; Mon, 12 Apr 2021 11:44:17 +0000 (UTC) Message-Id: <03167350b05b2fe8b741e53363ee37709d0f878d.1618227846.git.christophe.leroy@csgroup.eu> In-Reply-To: <34d12a4f75cb8b53a925fada5e7ddddd3b145203.1618227846.git.christophe.leroy@csgroup.eu> References: <34d12a4f75cb8b53a925fada5e7ddddd3b145203.1618227846.git.christophe.leroy@csgroup.eu> From: Christophe Leroy Subject: [PATCH 2/3] powerpc/ebpf32: Rework 64 bits shifts to avoid tests and branches To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@chromium.org, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, bpf@vger.kernel.org Date: Mon, 12 Apr 2021 11:44:17 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Re-implement BPF_ALU64 | BPF_{LSH/RSH/ARSH} | BPF_X with branchless implementation copied from misc_32.S. Signed-off-by: Christophe Leroy --- arch/powerpc/net/bpf_jit_comp32.c | 39 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index ca6fe1583460..ef21b09df76e 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -548,16 +548,15 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * EMIT(PPC_RAW_SLW(dst_reg, dst_reg, src_reg)); break; case BPF_ALU64 | BPF_LSH | BPF_X: /* dst <<= src; */ - EMIT(PPC_RAW_ADDIC_DOT(__REG_R0, src_reg, -32)); - PPC_BCC_SHORT(COND_LT, (ctx->idx + 4) * 4); - EMIT(PPC_RAW_SLW(dst_reg_h, dst_reg, __REG_R0)); - EMIT(PPC_RAW_LI(dst_reg, 0)); - PPC_JMP((ctx->idx + 6) * 4); + bpf_set_seen_register(ctx, tmp_reg); EMIT(PPC_RAW_SUBFIC(__REG_R0, src_reg, 32)); EMIT(PPC_RAW_SLW(dst_reg_h, dst_reg_h, src_reg)); + EMIT(PPC_RAW_ADDI(tmp_reg, src_reg, 32)); EMIT(PPC_RAW_SRW(__REG_R0, dst_reg, __REG_R0)); - EMIT(PPC_RAW_SLW(dst_reg, dst_reg, src_reg)); + EMIT(PPC_RAW_SLW(tmp_reg, dst_reg, tmp_reg)); EMIT(PPC_RAW_OR(dst_reg_h, dst_reg_h, __REG_R0)); + EMIT(PPC_RAW_SLW(dst_reg, dst_reg, src_reg)); + EMIT(PPC_RAW_OR(dst_reg_h, dst_reg_h, tmp_reg)); break; case BPF_ALU | BPF_LSH | BPF_K: /* (u32) dst <<= (u32) imm */ if (!imm) @@ -585,16 +584,15 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * EMIT(PPC_RAW_SRW(dst_reg, dst_reg, src_reg)); break; case BPF_ALU64 | BPF_RSH | BPF_X: /* dst >>= src */ - EMIT(PPC_RAW_ADDIC_DOT(__REG_R0, src_reg, -32)); - PPC_BCC_SHORT(COND_LT, (ctx->idx + 4) * 4); - EMIT(PPC_RAW_SRW(dst_reg, dst_reg_h, __REG_R0)); - EMIT(PPC_RAW_LI(dst_reg_h, 0)); - PPC_JMP((ctx->idx + 6) * 4); - EMIT(PPC_RAW_SUBFIC(0, src_reg, 32)); + bpf_set_seen_register(ctx, tmp_reg); + EMIT(PPC_RAW_SUBFIC(__REG_R0, src_reg, 32)); EMIT(PPC_RAW_SRW(dst_reg, dst_reg, src_reg)); + EMIT(PPC_RAW_ADDI(tmp_reg, src_reg, 32)); EMIT(PPC_RAW_SLW(__REG_R0, dst_reg_h, __REG_R0)); - EMIT(PPC_RAW_SRW(dst_reg_h, dst_reg_h, src_reg)); + EMIT(PPC_RAW_SRW(tmp_reg, dst_reg_h, tmp_reg)); EMIT(PPC_RAW_OR(dst_reg, dst_reg, __REG_R0)); + EMIT(PPC_RAW_SRW(dst_reg_h, dst_reg_h, src_reg)); + EMIT(PPC_RAW_OR(dst_reg, dst_reg, tmp_reg)); break; case BPF_ALU | BPF_RSH | BPF_K: /* (u32) dst >>= (u32) imm */ if (!imm) @@ -622,16 +620,17 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * EMIT(PPC_RAW_SRAW(dst_reg_h, dst_reg, src_reg)); break; case BPF_ALU64 | BPF_ARSH | BPF_X: /* (s64) dst >>= src */ - EMIT(PPC_RAW_ADDIC_DOT(__REG_R0, src_reg, -32)); - PPC_BCC_SHORT(COND_LT, (ctx->idx + 4) * 4); - EMIT(PPC_RAW_SRAW(dst_reg, dst_reg_h, __REG_R0)); - EMIT(PPC_RAW_SRAWI(dst_reg_h, dst_reg_h, 31)); - PPC_JMP((ctx->idx + 6) * 4); - EMIT(PPC_RAW_SUBFIC(0, src_reg, 32)); + bpf_set_seen_register(ctx, tmp_reg); + EMIT(PPC_RAW_SUBFIC(__REG_R0, src_reg, 32)); EMIT(PPC_RAW_SRW(dst_reg, dst_reg, src_reg)); EMIT(PPC_RAW_SLW(__REG_R0, dst_reg_h, __REG_R0)); - EMIT(PPC_RAW_SRAW(dst_reg_h, dst_reg_h, src_reg)); + EMIT(PPC_RAW_ADDI(tmp_reg, src_reg, 32)); EMIT(PPC_RAW_OR(dst_reg, dst_reg, __REG_R0)); + EMIT(PPC_RAW_RLWINM(__REG_R0, tmp_reg, 0, 26, 26)); + EMIT(PPC_RAW_SRAW(tmp_reg, dst_reg_h, tmp_reg)); + EMIT(PPC_RAW_SRAW(dst_reg_h, dst_reg_h, src_reg)); + EMIT(PPC_RAW_SLW(tmp_reg, tmp_reg, __REG_R0)); + EMIT(PPC_RAW_OR(dst_reg, dst_reg, tmp_reg)); break; case BPF_ALU | BPF_ARSH | BPF_K: /* (s32) dst >>= imm */ if (!imm) -- 2.25.0