From patchwork Tue Aug 27 22:49:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Murzin X-Patchwork-Id: 270266 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 471D32C019E for ; Wed, 28 Aug 2013 08:02:55 +1000 (EST) Received: from mail-la0-x22d.google.com (mail-la0-x22d.google.com [IPv6:2a00:1450:4010:c03::22d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 688DD2C007C for ; Wed, 28 Aug 2013 04:50:32 +1000 (EST) Received: by mail-la0-f45.google.com with SMTP id eh20so3926626lab.32 for ; Tue, 27 Aug 2013 11:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=QQZoQw4pJ0gRtxdJHtKpOTNnZFwxTkh4mxnNvSboG5c=; b=VQ+6l5YBCBfEeZX0qW1QxEOzEDTyWlbkQ1JyUYK6LremThP0We83Zz95PF4HsJxkb5 RmUzphEZFj5csBDC1oTa8+shqHf3+oxVPhRUlS6F0SQzzxaED9oaMi1DYrn8wdQuTYYK 5225hg8jbV7ZC+/ksRAsZaaN4yuvKEoai7vqSzASONl0vPDqb8qfpPCtKQbq/G5Lpeen WdlQC+zgG7n5hY4EhmHBelbiIPvUBydBzRouBxHVjK5+feZmHndMMWG13wtE39QSA2OO zVYA79jFRq5Tq/VlOQkViVEZBtuZMGfOJxQtrxdnXi04xSobmaxRPsOxC/IP5l47luID d4jw== X-Received: by 10.112.128.166 with SMTP id np6mr18743264lbb.7.1377629426123; Tue, 27 Aug 2013 11:50:26 -0700 (PDT) Received: from localhost.localdomain ([83.220.236.96]) by mx.google.com with ESMTPSA id m13sm7722008lbo.11.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 27 Aug 2013 11:50:25 -0700 (PDT) From: Vladimir Murzin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] ppc: bpf_jit: support MOD operation Date: Wed, 28 Aug 2013 02:49:52 +0400 Message-Id: <1377643792-10327-1-git-send-email-murzin.v@gmail.com> X-Mailer: git-send-email 1.8.1.5 X-Mailman-Approved-At: Wed, 28 Aug 2013 08:02:29 +1000 Cc: dborkman@redhat.com, paulus@samba.org, davem@davemloft.net, Vladimir Murzin X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16rc2 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" commit b6069a9570 (filter: add MOD operation) added generic support for modulus operation in BPF. This patch brings JIT support for PPC64 Signed-off-by: Vladimir Murzin Acked-by: Matt Evans --- arch/powerpc/net/bpf_jit_comp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index bf56e33..96f24dc 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -193,6 +193,28 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image, PPC_MUL(r_A, r_A, r_scratch1); } break; + case BPF_S_ALU_MOD_X: /* A %= X; */ + ctx->seen |= SEEN_XREG; + PPC_CMPWI(r_X, 0); + if (ctx->pc_ret0 != -1) { + PPC_BCC(COND_EQ, addrs[ctx->pc_ret0]); + } else { + PPC_BCC_SHORT(COND_NE, (ctx->idx*4)+12); + PPC_LI(r_ret, 0); + PPC_JMP(exit_addr); + } + PPC_DIVWU(r_scratch1, r_A, r_X); + PPC_MUL(r_scratch1, r_X, r_scratch1); + PPC_SUB(r_A, r_A, r_scratch1); + break; + case BPF_S_ALU_MOD_K: /* A %= K; */ +#define r_scratch2 (r_scratch1 + 1) + PPC_LI32(r_scratch2, K); + PPC_DIVWU(r_scratch1, r_A, r_scratch2); + PPC_MUL(r_scratch1, r_scratch2, r_scratch1); + PPC_SUB(r_A, r_A, r_scratch1); +#undef r_scratch2 + break; case BPF_S_ALU_DIV_X: /* A /= X; */ ctx->seen |= SEEN_XREG; PPC_CMPWI(r_X, 0);