From patchwork Thu Sep 17 17:15:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1366297 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yjGWKae1; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BskBY0QJKz9sTQ for ; Fri, 18 Sep 2020 03:15:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1BDCF3A4781F; Thu, 17 Sep 2020 17:15:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1BDCF3A4781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600362944; bh=EXFS/7sGepT/qgP469IWCghyZ+2W1C1UT8ng3iF0qsU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yjGWKae178K567xismQuogdoM9vSaaaug/Q1pcpDscY0113woiEXWdOn7STLUNem6 RmJct6x31IxvaGbjWxolDkGbzgY+r/wBgOZ0Nk53w9rXXO+GUijHgzLSyj0LAnRCmU JFceO6hNk9/aVrS+yZlw+SQWeyanhjucftU0PW6o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by sourceware.org (Postfix) with ESMTPS id 5FBFE398BC1B for ; Thu, 17 Sep 2020 17:15:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5FBFE398BC1B Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08HHEQD7034655 for ; Thu, 17 Sep 2020 17:15:40 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 33j91dvagb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 17 Sep 2020 17:15:40 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08HHA5LR020194 for ; Thu, 17 Sep 2020 17:15:39 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 33khpnchh5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 17 Sep 2020 17:15:39 +0000 Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 08HHFbdA011545 for ; Thu, 17 Sep 2020 17:15:38 GMT Received: from sequence.us.oracle.com (/10.159.157.136) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Sep 2020 17:15:36 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH] bpf: use xBPF signed div, mod insns when available Date: Thu, 17 Sep 2020 10:15:30 -0700 Message-Id: <20200917171530.37619-1-david.faust@oracle.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9747 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=1 mlxlogscore=999 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009170128 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9747 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 suspectscore=1 mlxlogscore=999 clxscore=1015 adultscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009170128 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Faust via Gcc-patches From: David Faust Reply-To: David Faust Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The 'mod' and 'div' operators in eBPF are unsigned, with no signed counterpart. xBPF adds two new ALU operations, sdiv and smod, for signed division and modulus, respectively. Update bpf.md with 'define_insn' blocks for signed div and mod to use them when targetting xBPF, and add new tests to ensure they are used appropriately. 2020-09-17 David Faust gcc/ * config/bpf/bpf.md: Add defines for signed div and mod operators. gcc/testsuite/ * gcc.target/bpf/diag-sdiv.c: New test. * gcc.target/bpf/diag-smod.c: New test. * gcc.target/bpf/xbpf-sdiv-1.c: New test. * gcc.target/bpf/xbpf-smod-1.c: New test. --- gcc/config/bpf/bpf.md | 20 ++++++++++++++++++++ gcc/testsuite/gcc.target/bpf/diag-sdiv.c | 12 ++++++++++++ gcc/testsuite/gcc.target/bpf/diag-smod.c | 12 ++++++++++++ gcc/testsuite/gcc.target/bpf/xbpf-sdiv-1.c | 14 ++++++++++++++ gcc/testsuite/gcc.target/bpf/xbpf-smod-1.c | 14 ++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 gcc/testsuite/gcc.target/bpf/diag-sdiv.c create mode 100644 gcc/testsuite/gcc.target/bpf/diag-smod.c create mode 100644 gcc/testsuite/gcc.target/bpf/xbpf-sdiv-1.c create mode 100644 gcc/testsuite/gcc.target/bpf/xbpf-smod-1.c diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md index 41bb4fcd9a7..ac87e3d9c53 100644 --- a/gcc/config/bpf/bpf.md +++ b/gcc/config/bpf/bpf.md @@ -160,6 +160,16 @@ (define_insn "udiv3" "div\t%0,%2" [(set_attr "type" "")]) +;; However, xBPF does provide a signed division operator, sdiv. + +(define_insn "div3" + [(set (match_operand:AM 0 "register_operand" "=r,r") + (div:AM (match_operand:AM 1 "register_operand" " 0,0") + (match_operand:AM 2 "reg_or_imm_operand" "r,I")))] + "TARGET_XBPF" + "sdiv\t%0,%2" + [(set_attr "type" "")]) + ;;; Modulus ;; Note that eBPF doesn't provide instructions for signed integer @@ -173,6 +183,16 @@ (define_insn "umod3" "mod\t%0,%2" [(set_attr "type" "")]) +;; Again, xBPF provides a signed version, smod. + +(define_insn "mod3" + [(set (match_operand:AM 0 "register_operand" "=r,r") + (mod:AM (match_operand:AM 1 "register_operand" " 0,0") + (match_operand:AM 2 "reg_or_imm_operand" "r,I")))] + "TARGET_XBPF" + "smod\t%0,%2" + [(set_attr "type" "")]) + ;;; Logical AND (define_insn "and3" [(set (match_operand:AM 0 "register_operand" "=r,r") diff --git a/gcc/testsuite/gcc.target/bpf/diag-sdiv.c b/gcc/testsuite/gcc.target/bpf/diag-sdiv.c new file mode 100644 index 00000000000..db0c494a789 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/diag-sdiv.c @@ -0,0 +1,12 @@ +/* Verify signed division does not produce 'sdiv' insn in eBPF. */ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +void +foo () +{ + signed int x = 5; + signed int y = 2; + signed int z = x / y; +} +/* { dg-final { scan-assembler-not "sdiv(32)?\t%r" } } */ diff --git a/gcc/testsuite/gcc.target/bpf/diag-smod.c b/gcc/testsuite/gcc.target/bpf/diag-smod.c new file mode 100644 index 00000000000..20234ee39cc --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/diag-smod.c @@ -0,0 +1,12 @@ +/* Verify signed modulo does not produce 'smod' insn in eBPF. */ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +void +foo () +{ + signed int x = 5; + signed int y = 2; + signed int z = x % y; +} +/* { dg-final { scan-assembler-not "smod(32)?\t%r" } } */ diff --git a/gcc/testsuite/gcc.target/bpf/xbpf-sdiv-1.c b/gcc/testsuite/gcc.target/bpf/xbpf-sdiv-1.c new file mode 100644 index 00000000000..f6c5c9e9f1c --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/xbpf-sdiv-1.c @@ -0,0 +1,14 @@ +/* Verify that sdiv instruction is used for xBPF. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -mxbpf" } */ + +void +foo () +{ + signed int x = 5; + signed int y = 2; + signed int z = x / y; + signed int w = x / 3; +} + +/* { dg-final { scan-assembler "sdiv(32)?\t%r" } } */ diff --git a/gcc/testsuite/gcc.target/bpf/xbpf-smod-1.c b/gcc/testsuite/gcc.target/bpf/xbpf-smod-1.c new file mode 100644 index 00000000000..b3e5816b5cf --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/xbpf-smod-1.c @@ -0,0 +1,14 @@ +/* Verify that smod instruction is used for xBPF. */ +/* { dg-do compile } */ +/* { dg-options "-O0 -mxbpf" } */ + +void +foo () +{ + signed int x = 5; + signed int y = 2; + signed int z = x % y; + signed int w = x % 3; +} + +/* { dg-final { scan-assembler "smod(32)?\t%r" } } */