From patchwork Tue Jul 25 22:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 125906 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp52998vqo; Tue, 25 Jul 2023 15:50:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlEnNkT/SS/qthApTXcmN6P+x1BrmTpTJCBAMYzX1V9nuwywvKoV3GHbjJZroEbxcITO30/z X-Received: by 2002:a17:907:9445:b0:98e:738c:6d39 with SMTP id dl5-20020a170907944500b0098e738c6d39mr3433092ejc.36.1690325426021; Tue, 25 Jul 2023 15:50:26 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k20-20020a05640212d400b0051de186a810si8955952edx.551.2023.07.25.15.50.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 15:50:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sPAFb2u5; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 930F9385C420 for ; Tue, 25 Jul 2023 22:50:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 930F9385C420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690325424; bh=SV44XJp45iyKbEu4f8ghb+HOQwioTsUKASnq44WJeDw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=sPAFb2u5OdHIH4TQ6xPZmOHm1fWEIzLYjc/CPlX7++2OSLCB2CDxG09l9spV+z4eW inaTAxT4qnwcOjFRrvPRa3vlY/4FeszzVQDvBQG863eQbW02pb9QBUUiJX2X3ElY3F TdOeGjqxl5kQ6gOtjAZS9S6bRj12T00Mhh2j9svs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 231883858C52 for ; Tue, 25 Jul 2023 22:49:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 231883858C52 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36PJIX2p010691 for ; Tue, 25 Jul 2023 22:49:34 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3s07nup71w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 25 Jul 2023 22:49:33 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 36PLkObv029502 for ; Tue, 25 Jul 2023 22:49:33 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2174.outbound.protection.outlook.com [104.47.55.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3s05j5e6uu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 25 Jul 2023 22:49:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bUQFg7Sf0il7U2sImQnW8xBZyY1er/IexE2Sc7D0JKpghEP/oyx6RepkBOqZCZqm5Xz5v2Bpl6PxDt9opmK/mawbcy8P/S06HluxY2esnk8urGRTgXcljFw2zOJg+jDb6JPpRzKMI1PIQN6WGAg3NxAqxCS9FcCeYoQnoIFTD3xalchJCHJ8jDpaZoiXYKMX/I4qmQT22B1Yucfm4padJDCgbsMl4DeMkei80j4JSuBXlTafPMQmI/V+YdiAdPTb5COhr636M/U8D7IFfhSsRqw4NXlm25tTso+WGLzjU0mqLsmKOREQkiBIIGYlGi80e5+ib0NRN3huNUKoojXYtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SV44XJp45iyKbEu4f8ghb+HOQwioTsUKASnq44WJeDw=; b=M3j3g8sU4rTX9wVtAWSHDGhR1RNrez9fntBZxK4HaZYde9yHd05M+ZqHgtOzNIDbEyxQ6PvBZsu9VxbSN9scKiCMHIwEekkNZSt9chodB149H6r8zodZoX3cPUcF7LjHO2ijdpUwFpFbZshVCL/VM5pYx49OyHO4x6Okmv9sUthVhgxsy/zFdzIrg4Ltp2j1r09xM3QTXVwlLXGKv+2BD3PCGOTCI4mC8k1onqxedVuQeNpm8//qaTgCRca6FldYWyxN1JnAsv8fNIfqH5bo9g5AWCHEoeD48qmYGAlc7aw2qo2u0z2iAcFSgYUkvqO5XOARvD1P6x+t1BhHL7zAEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) by SN4PR10MB5800.namprd10.prod.outlook.com (2603:10b6:806:20f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 22:49:30 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::827f:8665:2052:16c5]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::827f:8665:2052:16c5%4]) with mapi id 15.20.6609.032; Tue, 25 Jul 2023 22:49:30 +0000 To: jose.marchesi@oracle.com Cc: gcc-patches@gcc.gnu.org Subject: [COMMITTED v2 1/2] bpf: don't print () in bpf_print_operand_address Date: Tue, 25 Jul 2023 15:49:20 -0700 Message-Id: <20230725224920.12392-1-david.faust@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <2e869548-5613-5f84-7210-490b23a789d9@oracle.com> References: <2e869548-5613-5f84-7210-490b23a789d9@oracle.com> X-ClientProxiedBy: BY5PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:180::31) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3213:EE_|SN4PR10MB5800:EE_ X-MS-Office365-Filtering-Correlation-Id: b0dc3c6d-7d30-4277-8c86-08db8d616815 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zFWzrdhSKjaieb8agZ0ipUVyFYH8fESVOYEnvtnWp/bj4wscmfzML/3HM4d4F3UMtVKHjP4FA37NYrzAZPiaLO8n+c71m6yuhX8ZR0Hv2zy3e3EIcQCn5MWa2xXjgvyg/gNYcY1knVPySDnq0tKG5YWr4aauoCkTT/Qta7cScBK+59TkkRgz/MLrYD9ajeoIvAMcsF2naEA59GyT5JTXaqBcmE9xpghiMm1yoNZKq3EWHXDT5C/VLVZ5Z9TI38dgoYrYm+5AwotZuJ7ZXuh3BixGxvVU2hLhjbf55yndoJqtP/xn5agxmLzdxpDT5/klgRh+aIv4i72r7SRbPhR91yv4Hb6KkS5Fic5fxvSZRB8ZWvLB7KRxjzIp2pvWqFsAXsdfmqHeJHXgzji5UIswSzHV5FSEOz57MpCGJnM1lUO94gHq6bSXCnVS27k4E6gSyObmYNzobHLM8QK4rQ45HX1D2QdwKn2ukpUWU7F+RfYvWu/ENutb5dKkurSykAhbhLIR881M9jcFWXnki98Xftm2W0iYPoQvGZ+K2MERROAWSqWbTwWH8jRTKGxDqZj/ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB3213.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(366004)(136003)(39860400002)(346002)(376002)(396003)(451199021)(6512007)(186003)(2616005)(1076003)(26005)(6506007)(316002)(66946007)(66556008)(6486002)(36756003)(41300700001)(44832011)(5660300002)(34206002)(38100700002)(2906002)(4326008)(6636002)(66476007)(8936002)(8676002)(83380400001)(478600001)(37006003)(6666004)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uy7ZrhI0Zm/3uyd3gK8uV0iWH/v5yK5D+2v5PGaj1fNhCyuLbXsbVnu/tzwj0n9SYT1M1NFq1plHatzCwC8Ngp80Xjdh0J3qcmQChV4+Lr3ou8djsVT6L9rzozWv4w7VGim/yO8txjlLAH7wZxKIoN1SvS8J1n+KddnuXS/yMYWoINSShRUnkSD/+WFxQPLC2JEQD3OXRiDm1klUFyczvOQnXi2WKV4H+jdUgDiwDXtAiD9yuAdBA8icD/qojQXHdJSV1ztnSDS6xUClM+c/Co3jE40ZV1y+emzHL6Gf6WgoyzHLKZNB8VN0YiXTNSs8I+litKUKY+S3DtXJMlgEhYVU5wzX1wqUzvK5I9y+fg+Et48NmbBluCjplepm/pKyBFOwK38N6lBrj0SYfbrQuJUbuQNclb/CFunktx821vu620Rp9KvP333PZGhxy+dS3AaUZn3mDZrhuuQL46KjnkR9DYTzp8FanESlX5zGDGTntCmha2bdynrsQbwx+TbfhJ6vtpX1LrBnmuDUDKaVke3Z8vDM3A3tBbju8lfZFKqZ6Jg+WGAMB3zXi+SqGv/mDlZOLiXWDIZ0uYAgi8Yml7HupxliyACKXWk1Fn56qMqRpc7EDM31XN3naOlA4ICjFcCpUvPeKxH2K6eV50wUBQ7qMRFRBJZGW55deA4XSOQmypUsO5lEp3bKHapFjdoHJkNTVivTRHC8TsU+gDQwYNJGNWFe7wSSxKaCeEb2TcoL/bXYRy85DOIucb6LN8mQGlfqxN/bQQO1nyXJi3+UkqymZOgijWHOQSZlGit89dVi2xt/I1MTITzl7qx+YWX5eLwfwUtuHf64vQszpbuKorOCsoof4I0kgpEhlqKN8jpG/TkQzPzER+UqOYtC4Q3cOHncUYiNOIav6mo6roWvMJkg8ttINPffhKSK8es+WfEJddUAyAYRQU1s3B3kSHMEBh10JdhEXF1DyuWGV5QrTR8ollKHsmaU6REAk8iUs1PBkGj4q5xzRsJC7mgXzj6tjDxmywGVFuLDGcFxbReBzXNxSvKyhTMNiPFleD5VuNPQhbr/XHRVWGBZC/0rAdnspIHU+AzNp3E0wNFZo5awlPs+hqz65YWsa+EBxAiJ6pBTRS79YR9NZuMIlxSTHNpEFe7HOaFsMlqObTsskmjcppH3dvVaqX2eH0E3kQ8Xb2ZAFLIV3ZSg7NbqugsipeArQDEcb8Lkdrk/+n4q8g1skoG47bPJ7vKj5H5ly5DbofXaXsEP2pEWtBN955wZ6sE+BGePvkM5gVlgEHOsxRksucqvHsxP6GTDOUpGMHsdLgqx1dvbGSqVhhywMNuJYMQh6fwyyjAlyTCPZoj3IvjHLwRKqJZAna0DeEdJmc8bMakmrkbbxyi/5boqsr5Q8gsu+G6jnbtq7MXoBNBEA8ZhWZ3GyPS9fW6NdCxrhs0xpzrnGlkAsZGOYkJpD2dGNNLCMPd+gDMBqEszWhl+Jp9VpFu+XkD6yy8cWJ8FP04fH10G6H+0tCk4L2HHqsMkwM1AxEGZL5w3wDh1DkCNS69EG958ybj3/no71j7BWOAD18TLml+3l2O1KutdPW6/nhsh X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: FPyhP0NVKRMv6Aj9YsptSAKM1v07ibCP1kkCRhVJMR1k6hbcNowOL3TtpvkLo9WGAgOgX1M/4Tf4cbpNHhWq3awKaW2lI//VYG3wHC7bcyMHb99V4WQ7uSvL8bQegV1S1gtmE8ccqm7qXfFnw4rGqx8zuaDMyshagFBs4UwdD2JogPgtm+rjhZ73smUjCggkSJMRqjJzxVqeHXuPd3aAyvwUuupS7lIaWYh+5khjGmnixdCw+iYjQxdGPMpFD7cs3rlW0ZuxW7w/0kvkescGyTgq29aC5VpcPZWsbStdiJHgYbWpS1ORU8s3cSrBFQ8RrRsAowF9R4PRjU4qARQIr3wGStqJOZJAF12OlNojiL5v1F3jLnEzduU6Yukemy908fBZHYHTPbXDKXUl2vLAl9QE2rI8hPjIhY76/XlQq3XXkR0EbuDIlMksT5vBzHzRuYoynRh1giUoAFkiAN8UhHucXbJAxvd4HWJnS+FYnsnNYCVC+uEeba0h+OBJdQ4V8erAZtSPzZUMs7GdNbT0/opscVyIfeBVFZR43tZW4zG+MB/cb9t/Rwn5vnPdwZxyWLUQfLJfGCPAfBOV4alCwkAYbYsmCn9V6qKmTKVeEkYdlVhJRcck43Pv7iyoyHbOfJdHqkkGpRcfX0QhIr/S2SQlgOA5wZVFFyI9bbMfdJU0uGfzMu8+R+KLzDxMJTct5w7jEFR2xTVUxhoFyo0OZZn6kiR3FSa2pybHY/W95lQUu6Sf8fLVrpAdjfgFN2MP X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0dc3c6d-7d30-4277-8c86-08db8d616815 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 22:49:30.2197 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: x2FI4iXaChOMnWEvwjPgJhHenOIAEoLemgoC33NUE7qK75g3+E8C3FUtVZP8AevwVusLJR0xIG97vAIeiHluCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR10MB5800 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-25_12,2023-07-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307250194 X-Proofpoint-ORIG-GUID: PVAfGG0F6LimJuWL8vqM7KLnbu4-Glik X-Proofpoint-GUID: PVAfGG0F6LimJuWL8vqM7KLnbu4-Glik X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772432154892742261 X-GMAIL-MSGID: 1772434673736573456 [Changes from v1: save calls to fprintf] Unfortunately, the pseudo-C dialect syntax used for some of the v3 atomic instructions clashes with unconditionally printing the surrounding parentheses in bpf_print_operand_address. Instead, place the parentheses in the output templates where needed. gcc/ * config/bpf/bpf.cc (bpf_print_operand_address): Don't print enclosing parentheses for pseudo-C dialect. * config/bpf/bpf.md (zero_exdendhidi2): Add parentheses around operands of pseudo-C dialect output templates where needed. (zero_extendqidi2): Likewise. (zero_extendsidi2): Likewise. (*mov): Likewise. --- gcc/config/bpf/bpf.cc | 11 +++++++---- gcc/config/bpf/bpf.md | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 55b6927a62f..2e1e3e3abcf 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -933,9 +933,10 @@ bpf_print_operand_address (FILE *file, rtx addr) switch (GET_CODE (addr)) { case REG: - fprintf (file, asm_dialect == ASM_NORMAL ? "[" : "("); + if (asm_dialect == ASM_NORMAL) + fprintf (file, "["); bpf_print_register (file, addr, 0); - fprintf (file, asm_dialect == ASM_NORMAL ? "+0]" : "+0)"); + fprintf (file, asm_dialect == ASM_NORMAL ? "+0]" : "+0"); break; case PLUS: { @@ -944,11 +945,13 @@ bpf_print_operand_address (FILE *file, rtx addr) if (GET_CODE (op0) == REG && GET_CODE (op1) == CONST_INT) { - fprintf (file, asm_dialect == ASM_NORMAL ? "[" : "("); + if (asm_dialect == ASM_NORMAL) + fprintf (file, "["); bpf_print_register (file, op0, 0); fprintf (file, "+"); output_addr_const (file, op1); - fprintf (file, asm_dialect == ASM_NORMAL ? "]" : ")"); + if (asm_dialect == ASM_NORMAL) + fprintf (file, "]"); } else fatal_insn ("invalid address in operand", addr); diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md index 64342ea1de2..579a8213b09 100644 --- a/gcc/config/bpf/bpf.md +++ b/gcc/config/bpf/bpf.md @@ -260,7 +260,7 @@ (define_insn "zero_extendhidi2" "@ {and\t%0,0xffff|%0 &= 0xffff} {mov\t%0,%1\;and\t%0,0xffff|%0 = %1;%0 &= 0xffff} - {ldxh\t%0,%1|%0 = *(u16 *) %1}" + {ldxh\t%0,%1|%0 = *(u16 *) (%1)}" [(set_attr "type" "alu,alu,ldx")]) (define_insn "zero_extendqidi2" @@ -270,7 +270,7 @@ (define_insn "zero_extendqidi2" "@ {and\t%0,0xff|%0 &= 0xff} {mov\t%0,%1\;and\t%0,0xff|%0 = %1;%0 &= 0xff} - {ldxh\t%0,%1|%0 = *(u8 *) %1}" + {ldxh\t%0,%1|%0 = *(u8 *) (%1)}" [(set_attr "type" "alu,alu,ldx")]) (define_insn "zero_extendsidi2" @@ -280,7 +280,7 @@ (define_insn "zero_extendsidi2" "" "@ * return bpf_has_alu32 ? \"{mov32\t%0,%1|%0 = %1}\" : \"{mov\t%0,%1\;and\t%0,0xffffffff|%0 = %1;%0 &= 0xffffffff}\"; - {ldxw\t%0,%1|%0 = *(u32 *) %1}" + {ldxw\t%0,%1|%0 = *(u32 *) (%1)}" [(set_attr "type" "alu,ldx")]) ;;; Sign-extension @@ -319,11 +319,11 @@ (define_insn "*mov" (match_operand:MM 1 "mov_src_operand" " q,rI,B,r,I"))] "" "@ - {ldx\t%0,%1|%0 = *( *) %1} + {ldx\t%0,%1|%0 = *( *) (%1)} {mov\t%0,%1|%0 = %1} {lddw\t%0,%1|%0 = %1 ll} - {stx\t%0,%1|*( *) %0 = %1} - {st\t%0,%1|*( *) %0 = %1}" + {stx\t%0,%1|*( *) (%0) = %1} + {st\t%0,%1|*( *) (%0) = %1}" [(set_attr "type" "ldx,alu,alu,stx,st")]) ;;;; Shifts From patchwork Tue Jul 25 22:43:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 125901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp51009vqo; Tue, 25 Jul 2023 15:44:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlHqezdxYWiEr4xVQYMYGK/9FuzbHd59yFeAHQbbzKjaFMKjVbXyozY3emFZw9AHKS51pkeY X-Received: by 2002:a50:fc19:0:b0:522:3053:e64 with SMTP id i25-20020a50fc19000000b0052230530e64mr155869edr.13.1690325065949; Tue, 25 Jul 2023 15:44:25 -0700 (PDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r23-20020aa7d157000000b0052257f3f070si735803edo.59.2023.07.25.15.44.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 15:44:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=htktu8OD; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27B44385559F for ; Tue, 25 Jul 2023 22:44:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27B44385559F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690325059; bh=l71nQQ0Zfuk1ZdygDLvgfRMSn5o/lYFhCnjR50hZ2ds=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=htktu8ODXsqXXcUpl6ibWCzUCTMSPJFtFVjrJr6S4FJ1lNPnynATZEMVc0v0mfc8E xuFuDFm/DQ0TQGfOCS0A7hXVPKevzcJgwmAcEWVimahch2s3v9+uInX7PumWlYEV3H BaC+JYh15SLb0bkfo0N0ICMAv+qtPfMYotBLs0YA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 6E01C3858C52 for ; Tue, 25 Jul 2023 22:43:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E01C3858C52 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36PJIYOu020113 for ; Tue, 25 Jul 2023 22:43:25 GMT Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3s05hdx89j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 25 Jul 2023 22:43:24 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 36PLiY2K033427 for ; Tue, 25 Jul 2023 22:43:23 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3s05jbpm97-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 25 Jul 2023 22:43:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bkMcrQwU5yi/UnlyLI9ULmgKtbBJ5S/ekl0muOYFXeiz2fHjIcMUvVqgBCe3fq+0cTif4blSfY++kFBfs+4JoJZ8uK0rs//hLF6Waiby15zKqtcbFX0puz+UWrVLMmt6m0kH9pxElnCEXWsBT98XW4s54l0wF/uU3cunFxHn07K0U5rJTeT3tJIDU7FNwC1mazzWIC2fEVUMRlou8MGrkSuwu8zK/vCf8Er1faHTghXAowlO/OkjTUHGR6vUVHTUJYqUfkPE2X94gtnsYmLXvSlu/RoVsaVLvVKLwBhKOvSf9kXV7aVZfHvQlvvwsbGFjAuJg95hYKsTDcGK4K5nBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=l71nQQ0Zfuk1ZdygDLvgfRMSn5o/lYFhCnjR50hZ2ds=; b=B6AngJ9HISTtKLw4aPmEWMN3g8OUiiDfv+umjuuGC4fhTsi2+CvFtvjmVUs5JN4QPkpH+E7VsoGR+Ol0QfNAdTKBS98uo7noEk/72i9aox9AR+G+Y4lTcpNmypLZvNts826osw9FpulorMFBgkwiSbSEjCi24/LlXrySQSS1oBuvD/5ubpvtkD1GLWuHxU80mwB/uZZPG8hlY0FzqFK4KxNH/DmQ1rFCpBs/qvCkvwWvBKsGd9mGUniM0AC3Y0/TkPHQRoYtswtAy07Y8s7YchVERrIVmg/PP9O7k3HtFb0+W3gmALLgdwx7ka0o4O+9OATcihqt8A6SJGgg7zKSjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) by PH7PR10MB7837.namprd10.prod.outlook.com (2603:10b6:510:304::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 22:43:19 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::827f:8665:2052:16c5]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::827f:8665:2052:16c5%4]) with mapi id 15.20.6609.032; Tue, 25 Jul 2023 22:43:19 +0000 To: jose.marchesi@oracle.com Cc: gcc-patches@gcc.gnu.org Subject: [PATCH v2 2/2] bpf: add v3 atomic instructions Date: Tue, 25 Jul 2023 15:43:08 -0700 Message-Id: <20230725224308.12304-1-david.faust@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <87zg3j8wjj.fsf@oracle.com> References: <87zg3j8wjj.fsf@oracle.com> X-ClientProxiedBy: SN6PR2101CA0006.namprd21.prod.outlook.com (2603:10b6:805:106::16) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3213:EE_|PH7PR10MB7837:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a39ea3d-02d3-4e76-a0b1-08db8d608aa1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b1q4brLmxfe147tXbcXtscp7U7TvKSiFug8d6IMiI2MGAbiEYZlOg3fgQwaeQKnDWMtSXwJaFaINNZWpfdrNnHLPEiVt/qMnNANhqbYfnit16RtTJkUmH6aZh8MpQgwXEVzC95znzMarOzTLy0To2vBNShzwI3LgLOXKbMZ7yGyqZhZs3V3ldy7L522IsqwHUnlQ67GEHsVttlKlYUWoHtEqabFxud4obmYxKeiDELkYi4rQmKJUJzdqMr5i+ceXL4r0WLTYueFHEyMe8whK07Q0kd/VorGXyQequlsXHaZA8ZS32O8h4LkSHTgaHERx3hJbWdFnqcxUfGhYBbv24TaCUtYydWbfTSrIZ0LiVxOwB7ixSdxTmlriZfJxlUDz1uKE1J6poZXFBJptK1QGzdDezNCrfHCNSWi3SoO96PJwD8SvuF7AF8YC/ZnkO4d0eWtGA/3feRdb5QpsuD9Z9ji1M4eaYMfwAcg+sLpdzeW5n4XFIb5Ni+YeaYRqvS5J8Nq5V4L8x7rStKsZs2TFyNhKjWr0/SySLMLHei6X3Ztx8shmnFMInUstZwpKpRMabUPr333VEN7pqFMDLWTYrw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB3213.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(376002)(39860400002)(396003)(346002)(366004)(136003)(451199021)(478600001)(37006003)(6486002)(6666004)(6512007)(66476007)(2616005)(26005)(186003)(1076003)(6506007)(2906002)(30864003)(66556008)(66946007)(316002)(4326008)(6636002)(34206002)(8936002)(44832011)(8676002)(5660300002)(41300700001)(38100700002)(36756003)(86362001)(83380400001)(84970400001)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: whL3zinxvTHH1rtJC0UBDNfN1mr+M0KXIAONg8yyLQ7RFCDOglqXhUeCinWrfkWfkNhJvlbRzNKvtDuQI64y2yp6VtYDqW+tfoH0uhORptYMy3ewf4xR0DTj9jc4bG0G3lYq/wqUTy8uswrRXuoYk4B2poyiQpcCWeI42CgFr3siqjPN9CB1hQFqOl8nfj+teNM5rI063IR+XuhWNtm5LC+YWkt9ZHglKAtxmhzhjTeAD0+hNbaFUPfbT0c9JhGFXNrXQDWbHMAYjDQDSmf14cOTDoPZaeGduiWiq6jI1lw/UYlhvfE7DvQZ0Ufm+s1a5xbRW6p7BQToZG7x/HpB4F2FyVD3AEdQjdx3laPKGaMjfGl7Z9N7ZMNqdFfoRY2KIKMgTuy0I+p+5RhekH/tAfRaHCEMBu6OPLlHy0hxct59L3o4HUv19wWsjHZQfIx8Iq4n7JLzdPt3ocOJ1CANr7SBgm1fk8+H8/QIcLMSHFZ028ThExHcCaXidR8vcQ3pFjMU4rXo26L1esaN5lL8NcdY8Af44eznYhOS821Kbw8z1XORvTwIGKKAypLfv7E82+iJUX3UvoX1ZsdgoaHa3az7qbC1k+NTpj+/xD1SiM9LzUWhfth+vwRxP0r2CbvyYAE6FCe/Suw4XbwlNritK9GcAPuWOKY25QOx8Lm3p12jNo0Lv5rziQArGqFUajE/IdF4pIYvjPpCq4X+vfpOue87GJBtkDSJIjbC0FN16q4ABnozYYkFaAxED1HUemXpVUccM+mANLcrc8IwOET9y8a9KOJ7OYXnHjPmdywyoCoERrizIu6NVSUyeZTpHDezGro0BmcgHSzU48Ni5r9VcpMvAMnGvhG1oS/VRxHCIhKZOWWe2mDpLyMpHe86frWZNJv/JrHdoZPyVqs/n3Y/VAlPSB5BwVn/Flxm/SUaSggTDBSoB7huruVPSeQaObnnWyJkrNRf1SQA0Fe2vjN3h4D3GyBL3h1pdfzkfYpJbaOtdjZ2qSPY0bjBfWBQRINVPQpIQArsTBRpj2EtoiniaBn3Kpp8gL4szlnvRn9+T+2OEcZgD+cVesMq/60FmPRK2XeWikQSmXvPgTw4o94zyIUuu6JrV6FSjLi+1Q3UbdFlKhh3JUhaOem0i5bs/48hZIzGY2uuVaaf852kTz6+BOeijoOe64bkBc39CHWLxEQjoywCJtn3+PyMOFsBn/jJGHFkrjDUsqwGCUmBhKTZ9Mw/TTFu+rY4bt9dgOXmAZrQ8OPDLiv0TS3dAJf5d2vPoTcWObcD+FwhC58MWVMMJQhB3IAlafRo69VIvdeOCGfgqU5GB99AZrpAMwJ8K/LaJEJrzc0fKzYaWHFLYguTFGS+116sVsjxUw5O8S6Q9cCq235I8m+3XH4RImGsaKm7gR7lngBkkGHZTWUZTyH70FjnDATssfyBAx+zHaQA3XGYzTItXpMHrxZSxIWedWIHfu1mX2fwGN30KbEUfS21Eg01L/teZyIo+q0VUeLLrjjdeML3P8iqYsFmzdyEZ/W2PZBC485/VJm1NMRsiMkTziyXca2G2C3ZTApngH8Fc8bPLggltmqpQWapZMSM7ehH X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: uww8kFbO7g3isvOg9jldXvBNkLlhMUxIaz/S4OunODpqu18+ODl2KryTHYrpvQlucPjFi3Es35nvxxRxTK0YamLuqODRNFXQf7qaLMDFYxM6OKnEU3nQl5TYxKpp0sdmlLHot3lPCAGzYVzYk8QSnlMQF15v9lCBT5ezg0XQw7NAAH4lM6UeHD0wqceennbSmOUs0b3KrkwGlMWpSqDeWAR7JYXl070HOGFHsjHoHYaRa07/fqU1/b3g/T+RzxoiVBkOtNLikSBO67B40k5nSC0cCg/FE37OHyLg+4gQywI0UWexS7HIrDSuuqPpWiCE+djISuYZvsjhDzrVR7Uv6QtJINPZGH6CrhB+QzwE+G6yAFtVsoCKR0bzLMtM8k9mf+3rHmegUWym5X9SFOQNjjcB6nWG+52GV2aKcSlT3z9g2HHlqfn60jpMquyZFASvuJXO174XkaHh18M8Km/lIQLZmx6nutAz4Rk9g6FoHjl65iwivTj51YrnFq2TjDL/TZc+wS3WJzJbMSUkwyvpo5fsTOQSZYpHn3PZvhpaRB1nMCh8QgkQMAzCe/s2fpBz6DTZC7Igkq86U8CzecqVMoCCrpwRJ5ld0ET721hXVqn6F1ENYqxurGJ5fRuVNBr0TFyR6NZvhUQhCPwwgPWO5pOdRi2hsxX0zilK7zQ0aqRssoceqVJJQ46pkKegh6GUSXyoLFiewKd7HGN8+G1hh7eXBsrVSsg4cA0JDUP1td0A4rAlTjn1Qo2uniULegRk X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a39ea3d-02d3-4e76-a0b1-08db8d608aa1 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 22:43:19.1167 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5Oxqt9HDAcVl+3IBpXG+Ac8m18jrhsOjWNRhCU+ZTCePGSQnX4PBO2qSeLaaNilHWfEej+9ii7j3vVOIYdQBww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7837 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-25_12,2023-07-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307250193 X-Proofpoint-ORIG-GUID: tm-You-EtY6cv2bqtkUryWQJv7s6kuw0 X-Proofpoint-GUID: tm-You-EtY6cv2bqtkUryWQJv7s6kuw0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772432169048026465 X-GMAIL-MSGID: 1772434296159868828 [Changes from v1: fix merge issue in invoke.texi] This patch adds support for the general atomic operations introduced in eBPF v3. In addition to the existing atomic add instruction, this adds: - Atomic and, or, xor - Fetching versions of these operations (including add) - Atomic exchange - Atomic compare-and-exchange To control emission of these instructions, a new target option -m[no-]v3-atomics is added. This option is enabled by -mcpu=v3 and above. Support for these instructions was recently added in binutils. gcc/ * config/bpf/bpf.opt (mv3-atomics): New option. * config/bpf/bpf.cc (bpf_option_override): Handle it here. * config/bpf/bpf.h (enum_reg_class): Add R0 class. (REG_CLASS_NAMES): Likewise. (REG_CLASS_CONTENTS): Likewise. (REGNO_REG_CLASS): Handle R0. * config/bpf/bpf.md (UNSPEC_XADD): Rename to UNSPEC_AADD. (UNSPEC_AAND): New unspec. (UNSPEC_AOR): Likewise. (UNSPEC_AXOR): Likewise. (UNSPEC_AFADD): Likewise. (UNSPEC_AFAND): Likewise. (UNSPEC_AFOR): Likewise. (UNSPEC_AFXOR): Likewise. (UNSPEC_AXCHG): Likewise. (UNSPEC_ACMPX): Likewise. (atomic_add): Use UNSPEC_AADD and atomic type attribute. Move to... * config/bpf/atomic.md: ...Here. New file. * config/bpf/constraints.md (t): New constraint for R0. * doc/invoke.texi (eBPF Options): Document -mv3-atomics. gcc/testsuite/ * gcc.target/bpf/atomic-cmpxchg-1.c: New test. * gcc.target/bpf/atomic-cmpxchg-2.c: New test. * gcc.target/bpf/atomic-fetch-op-1.c: New test. * gcc.target/bpf/atomic-fetch-op-2.c: New test. * gcc.target/bpf/atomic-fetch-op-3.c: New test. * gcc.target/bpf/atomic-op-1.c: New test. * gcc.target/bpf/atomic-op-2.c: New test. * gcc.target/bpf/atomic-op-3.c: New test. * gcc.target/bpf/atomic-xchg-1.c: New test. * gcc.target/bpf/atomic-xchg-2.c: New test. --- gcc/config/bpf/atomic.md | 185 ++++++++++++++++++ gcc/config/bpf/bpf.cc | 3 + gcc/config/bpf/bpf.h | 6 +- gcc/config/bpf/bpf.md | 29 ++- gcc/config/bpf/bpf.opt | 4 + gcc/config/bpf/constraints.md | 3 + gcc/doc/invoke.texi | 8 +- .../gcc.target/bpf/atomic-cmpxchg-1.c | 19 ++ .../gcc.target/bpf/atomic-cmpxchg-2.c | 19 ++ .../gcc.target/bpf/atomic-fetch-op-1.c | 50 +++++ .../gcc.target/bpf/atomic-fetch-op-2.c | 50 +++++ .../gcc.target/bpf/atomic-fetch-op-3.c | 49 +++++ gcc/testsuite/gcc.target/bpf/atomic-op-1.c | 49 +++++ gcc/testsuite/gcc.target/bpf/atomic-op-2.c | 49 +++++ gcc/testsuite/gcc.target/bpf/atomic-op-3.c | 49 +++++ gcc/testsuite/gcc.target/bpf/atomic-xchg-1.c | 20 ++ gcc/testsuite/gcc.target/bpf/atomic-xchg-2.c | 20 ++ 17 files changed, 593 insertions(+), 19 deletions(-) create mode 100644 gcc/config/bpf/atomic.md create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-cmpxchg-1.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-cmpxchg-2.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-fetch-op-1.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-fetch-op-2.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-fetch-op-3.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-op-1.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-op-2.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-op-3.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-xchg-1.c create mode 100644 gcc/testsuite/gcc.target/bpf/atomic-xchg-2.c diff --git a/gcc/config/bpf/atomic.md b/gcc/config/bpf/atomic.md new file mode 100644 index 00000000000..caf8cc15cd4 --- /dev/null +++ b/gcc/config/bpf/atomic.md @@ -0,0 +1,185 @@ +;; Machine description for eBPF. +;; Copyright (C) 2023 Free Software Foundation, Inc. + +;; This file is part of GCC. + +;; GCC is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; GCC is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GCC; see the file COPYING3. If not see +;; . + + +(define_mode_iterator AMO [SI DI]) + +;;; Plain atomic modify operations. + +;; Non-fetching atomic add predates all other BPF atomic insns. +;; Use xadd{w,dw} for compatibility with older GAS without support +;; for v3 atomics. Newer GAS supports "aadd[32]" in line with the +;; other atomic operations. +(define_insn "atomic_add" + [(set (match_operand:AMO 0 "memory_operand" "+m") + (unspec_volatile:AMO + [(plus:AMO (match_dup 0) + (match_operand:AMO 1 "register_operand" "r")) + (match_operand:SI 2 "const_int_operand")] ;; Memory model. + UNSPEC_AADD))] + "" + "{xadd\t%0,%1|lock *( *)(%w0) += %w1}" + [(set_attr "type" "atomic")]) + +(define_insn "atomic_and" + [(set (match_operand:AMO 0 "memory_operand" "+m") + (unspec_volatile:AMO + [(and:AMO (match_dup 0) + (match_operand:AMO 1 "register_operand" "r")) + (match_operand:SI 2 "const_int_operand")] ;; Memory model. + UNSPEC_AAND))] + "bpf_has_v3_atomics" + "{aand\t%0,%1|lock *( *)(%w0) &= %w1}") + +(define_insn "atomic_or" + [(set (match_operand:AMO 0 "memory_operand" "+m") + (unspec_volatile:AMO + [(ior:AMO (match_dup 0) + (match_operand:AMO 1 "register_operand" "r")) + (match_operand:SI 2 "const_int_operand")] ;; Memory model. + UNSPEC_AOR))] + "bpf_has_v3_atomics" + "{aor\t%0,%1|lock *( *)(%w0) %|= %w1}") + +(define_insn "atomic_xor" + [(set (match_operand:AMO 0 "memory_operand" "+m") + (unspec_volatile:AMO + [(xor:AMO (match_dup 0) + (match_operand:AMO 1 "register_operand" "r")) + (match_operand:SI 2 "const_int_operand")] ;; Memory model. + UNSPEC_AXOR))] + "bpf_has_v3_atomics" + "{axor\t%0,%1|lock *( *)(%w0) ^= %w1}") + +;;; Feching (read-modify-store) versions of atomic operations. + +(define_insn "atomic_fetch_add" + [(set (match_operand:AMO 0 "register_operand" "=r") ; output + (match_operand:AMO 1 "memory_operand" "+m")) + (set (match_dup 1) + (unspec_volatile:AMO + [(plus:AMO (match_dup 1) + (match_operand:AMO 2 "nonmemory_operand" "0")) ; second operand to op + (match_operand:AMO 3 "const_int_operand")] ;; Memory model + UNSPEC_AFADD))] + "bpf_has_v3_atomics" + "{afadd\t%1,%0|%w0 = atomic_fetch_add(( *)(%1), %w0)}") + +(define_insn "atomic_fetch_and" + [(set (match_operand:AMO 0 "register_operand" "=r") + (match_operand:AMO 1 "memory_operand" "+m")) + (set (match_dup 1) + (unspec_volatile:AMO + [(and:AMO (match_dup 1) + (match_operand:AMO 2 "nonmemory_operand" "0")) + (match_operand:AMO 3 "const_int_operand")] + UNSPEC_AFAND))] + "bpf_has_v3_atomics" + "{afand\t%1,%0|%w0 = atomic_fetch_and(( *)(%1), %w0)}") + +(define_insn "atomic_fetch_or" + [(set (match_operand:AMO 0 "register_operand" "=r") + (match_operand:AMO 1 "memory_operand" "+m")) + (set (match_dup 1) + (unspec_volatile:AMO + [(ior:AMO (match_dup 1) + (match_operand:AMO 2 "nonmemory_operand" "0")) + (match_operand:AMO 3 "const_int_operand")] + UNSPEC_AFOR))] + "bpf_has_v3_atomics" + "{afor\t%1,%0|%w0 = atomic_fetch_or(( *)(%1), %w0)}") + +(define_insn "atomic_fetch_xor" + [(set (match_operand:AMO 0 "register_operand" "=r") + (match_operand:AMO 1 "memory_operand" "+m")) + (set (match_dup 1) + (unspec_volatile:AMO + [(xor:AMO (match_dup 1) + (match_operand:AMO 2 "nonmemory_operand" "0")) + (match_operand:AMO 3 "const_int_operand")] + UNSPEC_AFXOR))] + "bpf_has_v3_atomics" + "{afxor\t%1,%0|%w0 = atomic_fetch_xor(( *)(%1), %w0)}") + +;; Weird suffixes used in pseudo-c atomic compare-exchange insns. +(define_mode_attr pcaxsuffix [(SI "32_32") (DI "_64")]) + +(define_insn "atomic_exchange" + [(set (match_operand:AMO 0 "register_operand" "=r") + (unspec_volatile:AMO + [(match_operand:AMO 1 "memory_operand" "+m") + (match_operand:AMO 3 "const_int_operand")] + UNSPEC_AXCHG)) + (set (match_dup 1) + (match_operand:AMO 2 "nonmemory_operand" "0"))] + "bpf_has_v3_atomics" + "{axchg\t%1,%0|%w0 = xchg(%1, %w0)}") + +;; The eBPF atomic-compare-and-exchange instruction has the form +;; acmp [%dst+offset], %src +;; The instruction atomically compares the value addressed by %dst+offset +;; with register R0. If they match, the value at %dst+offset is overwritten +;; with the value of %src. Otherwise, no write occurs. In either case, the +;; original value of %dst+offset is zero-extended and loaded back into R0. + +(define_expand "atomic_compare_and_swap" + [(match_operand:SI 0 "register_operand" "=r") ;; bool success + (match_operand:AMO 1 "register_operand" "=r") ;; old value + (match_operand:AMO 2 "memory_operand" "+m") ;; memory + (match_operand:AMO 3 "register_operand") ;; expected + (match_operand:AMO 4 "register_operand") ;; desired + (match_operand:SI 5 "const_int_operand") ;; is_weak (unused) + (match_operand:SI 6 "const_int_operand") ;; success model (unused) + (match_operand:SI 7 "const_int_operand")] ;; failure model (unused) + "bpf_has_v3_atomics" +{ + /* Load the expected value (into R0 by constraint of below). */ + emit_move_insn (operands[1], operands[3]); + + /* Emit the acmp. */ + emit_insn (gen_atomic_compare_and_swap_1 (operands[1], operands[2], operands[3], operands[4])); + + /* Assume that the operation was successful. */ + emit_move_insn (operands[0], const1_rtx); + rtx_code_label *success_label = gen_label_rtx (); + + /* Compare value that was in memory (now in R0/op[1]) to expected value. + If they are equal, then the write occurred. Otherwise, indicate fail in output. */ + emit_cmp_and_jump_insns (operands[1], operands[3], EQ, 0, + GET_MODE (operands[1]), 1, success_label); + emit_move_insn (operands[0], const0_rtx); + + if (success_label) + { + emit_label (success_label); + LABEL_NUSES (success_label) = 1; + } + DONE; +}) + +(define_insn "atomic_compare_and_swap_1" + [(set (match_operand:AMO 0 "register_operand" "+t") ;; R0 is both input (expected value) + (unspec_volatile:AMO ;; and output (original value) + [(match_dup 0) ;; result depends on R0 + (match_operand:AMO 1 "memory_operand") ;; memory + (match_operand:AMO 2 "register_operand") ;; expected + (match_operand:AMO 3 "register_operand")] ;; desired + UNSPEC_ACMP))] + "bpf_has_v3_atomics" + "{acmp\t%1,%3|%w0 = cmpxchg(%1, %w0, %w3)}") diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 2e1e3e3abcf..0e07b416add 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -253,6 +253,9 @@ bpf_option_override (void) if (bpf_has_jmp32 == -1) bpf_has_jmp32 = (bpf_isa >= ISA_V3); + if (bpf_has_v3_atomics == -1) + bpf_has_v3_atomics = (bpf_isa >= ISA_V3); + if (bpf_has_bswap == -1) bpf_has_bswap = (bpf_isa >= ISA_V4); diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h index 9561bf59b80..ccba7f8b333 100644 --- a/gcc/config/bpf/bpf.h +++ b/gcc/config/bpf/bpf.h @@ -177,6 +177,7 @@ enum reg_class { NO_REGS, /* no registers in set. */ + R0, /* register r0. */ ALL_REGS, /* all registers. */ LIM_REG_CLASSES /* max value + 1. */ }; @@ -190,6 +191,7 @@ enum reg_class #define REG_CLASS_NAMES \ { \ "NO_REGS", \ + "R0", \ "ALL_REGS" \ } @@ -203,6 +205,7 @@ enum reg_class #define REG_CLASS_CONTENTS \ { \ 0x00000000, /* NO_REGS */ \ + 0x00000001, /* R0 */ \ 0x00000fff, /* ALL_REGS */ \ } @@ -210,7 +213,8 @@ enum reg_class register REGNO. In general there is more that one such class; choose a class which is "minimal", meaning that no smaller class also contains the register. */ -#define REGNO_REG_CLASS(REGNO) ((void)(REGNO), GENERAL_REGS) +#define REGNO_REG_CLASS(REGNO) \ + ((REGNO) == 0 ? R0 : GENERAL_REGS) /* A macro whose definition is the name of the class to which a valid base register must belong. A base register is one used in diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md index 579a8213b09..c782e545294 100644 --- a/gcc/config/bpf/bpf.md +++ b/gcc/config/bpf/bpf.md @@ -35,7 +35,16 @@ (define_insn_reservation "frobnicator" 814 (define_c_enum "unspec" [ UNSPEC_LDINDABS - UNSPEC_XADD + UNSPEC_AADD + UNSPEC_AAND + UNSPEC_AOR + UNSPEC_AXOR + UNSPEC_AFADD + UNSPEC_AFAND + UNSPEC_AFOR + UNSPEC_AFXOR + UNSPEC_AXCHG + UNSPEC_ACMP ]) ;;;; Constants @@ -67,11 +76,10 @@ (define_constants ;; st generic store instructions for immediates. ;; stx generic store instructions. ;; jmp jump instructions. -;; xadd atomic exchange-and-add instructions. ;; multi multiword sequence (or user asm statements). (define_attr "type" - "unknown,alu,alu32,end,ld,lddw,ldx,st,stx,jmp,xadd,multi" + "unknown,alu,alu32,end,ld,lddw,ldx,st,stx,jmp,multi,atomic" (const_string "unknown")) ;; Length of instruction in bytes. @@ -548,17 +556,4 @@ (define_insn "ldabs" "{ldabs\t%0|r0 = *( *) skb[%0]}" [(set_attr "type" "ld")]) -;;;; Atomic increments - -(define_mode_iterator AMO [SI DI]) - -(define_insn "atomic_add" - [(set (match_operand:AMO 0 "memory_operand" "+m") - (unspec_volatile:AMO - [(plus:AMO (match_dup 0) - (match_operand:AMO 1 "register_operand" "r")) - (match_operand:SI 2 "const_int_operand")] ;; Memory model. - UNSPEC_XADD))] - "" - "{xadd\t%0,%1|*( *) %0 += %1}" - [(set_attr "type" "xadd")]) +(include "atomic.md") diff --git a/gcc/config/bpf/bpf.opt b/gcc/config/bpf/bpf.opt index bd35f8dbd0c..b21cfcab9ea 100644 --- a/gcc/config/bpf/bpf.opt +++ b/gcc/config/bpf/bpf.opt @@ -59,6 +59,10 @@ mjmp32 Target Var(bpf_has_jmp32) Init(-1) Enable 32-bit jump instructions. +mv3-atomics +Target Var(bpf_has_v3_atomics) Init(-1) +Enable general atomic operations introduced in v3 ISA. + mbswap Target Var(bpf_has_bswap) Init(-1) Enable byte swap instructions. diff --git a/gcc/config/bpf/constraints.md b/gcc/config/bpf/constraints.md index 33f9177b8eb..199dd00c0cb 100644 --- a/gcc/config/bpf/constraints.md +++ b/gcc/config/bpf/constraints.md @@ -30,6 +30,9 @@ (define_constraint "S" "A constant call address." (match_code "const,symbol_ref,label_ref,const_int")) +(define_register_constraint "t" "R0" + "Register r0") + ;; ;; Memory constraints. ;; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index fa765d5a0dd..e0fd7bd5b72 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -947,7 +947,7 @@ Objective-C and Objective-C++ Dialects}. @emph{eBPF Options} @gccoptlist{-mbig-endian -mlittle-endian -mkernel=@var{version} -mframe-limit=@var{bytes} -mxbpf -mco-re -mno-co-re -mjmpext --mjmp32 -malu32 -mcpu=@var{version} -masm=@var{dialect}} +-mjmp32 -malu32 -mv3-atomics -mcpu=@var{version} -masm=@var{dialect}} @emph{FR30 Options} @gccoptlist{-msmall-model -mno-lsim} @@ -24716,6 +24716,11 @@ Enable byte swap instructions. Enabled for CPU v4 and above. Enable signed division and modulus instructions. Enabled for CPU v4 and above. +@opindex mv3-atomics +@item -mv3-atomics +Enable instructions for general atomic operations introduced in CPU v3. +Enabled for CPU v3 and above. + @opindex mcpu @item -mcpu=@var{version} This specifies which version of the eBPF ISA to target. Newer versions @@ -24735,6 +24740,7 @@ All features of v2, plus: @itemize @minus @item 32-bit jump operations, as in @option{-mjmp32} @item 32-bit ALU operations, as in @option{-malu32} +@item general atomic operations, as in @option{-mv3-atomics} @end itemize @item v4 diff --git a/gcc/testsuite/gcc.target/bpf/atomic-cmpxchg-1.c b/gcc/testsuite/gcc.target/bpf/atomic-cmpxchg-1.c new file mode 100644 index 00000000000..4bb6a7dba29 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-cmpxchg-1.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-mv3-atomics -O2" } */ + +int +foo (int *p, int *expected, int desired) +{ + return __atomic_compare_exchange (p, expected, &desired, 0, + __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); +} + +int +foo64 (long *p, long *expected, long desired) +{ + return __atomic_compare_exchange (p, expected, &desired, 0, + __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); +} + +/* { dg-final { scan-assembler "acmp\t.*" } } */ +/* { dg-final { scan-assembler "acmp32\t.*" } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-cmpxchg-2.c b/gcc/testsuite/gcc.target/bpf/atomic-cmpxchg-2.c new file mode 100644 index 00000000000..4036570ac60 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-cmpxchg-2.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-mno-v3-atomics -O2" } */ + +int +foo (int *p, int *expected, int desired) +{ + return __atomic_compare_exchange (p, expected, &desired, 0, + __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); +} + +int +foo64 (long *p, long *expected, long desired) +{ + return __atomic_compare_exchange (p, expected, &desired, 0, + __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); +} + +/* { dg-final { scan-assembler-not "acmp\t.*" } } */ +/* { dg-final { scan-assembler-not "acmp32\t.*" } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-1.c b/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-1.c new file mode 100644 index 00000000000..533e955fe88 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-1.c @@ -0,0 +1,50 @@ +/* Test 64-bit atomic-fetch-op instructions. */ + +/* { dg-do compile } */ +/* { dg-options "-mv3-atomics -O2" } */ + +long val; + +long +test_atomic_fetch_add (long x) +{ + return __atomic_fetch_add (&val, x, __ATOMIC_ACQUIRE); +} + +long +test_atomic_fetch_sub (long x) +{ + return __atomic_fetch_sub (&val, x, __ATOMIC_RELEASE); +} + +long +test_atomic_fetch_and (long x) +{ + return __atomic_fetch_and (&val, x, __ATOMIC_ACQUIRE); +} + +long +test_atomic_fetch_nand (long x) +{ + return __atomic_fetch_nand (&val, x, __ATOMIC_ACQUIRE); +} + +long +test_atomic_fetch_or (long x) +{ + return __atomic_fetch_or (&val, x, __ATOMIC_ACQUIRE); +} + +long +test_atomic_fetch_xor (long x) +{ + return __atomic_fetch_xor (&val, x, __ATOMIC_ACQUIRE); +} + +/* sub implemented in terms of add */ +/* { dg-final { scan-assembler-times "afadd\t" 2 } } */ +/* { dg-final { scan-assembler-times "afand\t" 1 } } */ +/* nand must use a compare-exchange loop */ +/* { dg-final { scan-assembler "acmp\t" } } */ +/* { dg-final { scan-assembler-times "afor\t" 1 } } */ +/* { dg-final { scan-assembler-times "afxor\t" 1 } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-2.c b/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-2.c new file mode 100644 index 00000000000..6b9ee6348b5 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-2.c @@ -0,0 +1,50 @@ +/* Test 32-bit atomic-fetch-op instructions. */ + +/* { dg-do compile } */ +/* { dg-options "-mv3-atomics -O2" } */ + +int val; + +int +test_atomic_fetch_add (int x) +{ + return __atomic_fetch_add (&val, x, __ATOMIC_ACQUIRE); +} + +int +test_atomic_fetch_sub (int x) +{ + return __atomic_fetch_sub (&val, x, __ATOMIC_RELEASE); +} + +int +test_atomic_fetch_and (int x) +{ + return __atomic_fetch_and (&val, x, __ATOMIC_ACQUIRE); +} + +int +test_atomic_fetch_nand (int x) +{ + return __atomic_fetch_nand (&val, x, __ATOMIC_ACQUIRE); +} + +int +test_atomic_fetch_or (int x) +{ + return __atomic_fetch_or (&val, x, __ATOMIC_ACQUIRE); +} + +int +test_atomic_fetch_xor (int x) +{ + return __atomic_fetch_xor (&val, x, __ATOMIC_ACQUIRE); +} + +/* sub implemented in terms of add */ +/* { dg-final { scan-assembler-times "afadd32\t" 2 } } */ +/* { dg-final { scan-assembler-times "afand32\t" 1 } } */ +/* nand must use a compare-exchange loop */ +/* { dg-final { scan-assembler "acmp32\t" } } */ +/* { dg-final { scan-assembler-times "afor32\t" 1 } } */ +/* { dg-final { scan-assembler-times "afxor32\t" 1 } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-3.c b/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-3.c new file mode 100644 index 00000000000..044a2f76474 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-fetch-op-3.c @@ -0,0 +1,49 @@ +/* Test atomic-fetch-op instructions are disabled with -mno-v3-atomics. */ + +/* { dg-do compile } */ +/* { dg-options "-mno-v3-atomics -O2" } */ + +long val; + +long +test_atomic_fetch_add (long x) +{ + return __atomic_fetch_add (&val, x, __ATOMIC_ACQUIRE); +} + +long +test_atomic_fetch_sub (long x) +{ + return __atomic_fetch_sub (&val, x, __ATOMIC_RELEASE); +} + +long +test_atomic_fetch_and (long x) +{ + return __atomic_fetch_and (&val, x, __ATOMIC_ACQUIRE); +} + +long +test_atomic_fetch_nand (long x) +{ + return __atomic_fetch_nand (&val, x, __ATOMIC_ACQUIRE); +} + +long +test_atomic_fetch_or (long x) +{ + return __atomic_fetch_or (&val, x, __ATOMIC_ACQUIRE); +} + +long +test_atomic_fetch_xor (long x) +{ + return __atomic_fetch_xor (&val, x, __ATOMIC_ACQUIRE); +} + +/* { dg-final { scan-assembler-not "afadd\t" } } */ +/* { dg-final { scan-assembler-not "afand\t" } } */ +/* { dg-final { scan-assembler-not "afor\t" } } */ +/* { dg-final { scan-assembler-not "afxor\t" } } */ +/* { dg-final { scan-assembler-not "acmp\t" } } */ +/* { dg-final { scan-assembler-not "axchg\t" } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-op-1.c b/gcc/testsuite/gcc.target/bpf/atomic-op-1.c new file mode 100644 index 00000000000..453c0ed47ce --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-op-1.c @@ -0,0 +1,49 @@ +/* Test 64-bit non-fetch atomic operations. */ +/* { dg-do compile } */ +/* { dg-options "-mv3-atomics -O2" } */ + +long val; + +void +test_atomic_add (long x) +{ + __atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_sub (long x) +{ + __atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_and (long x) +{ + __atomic_and_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_nand (long x) +{ + __atomic_nand_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_or (long x) +{ + __atomic_or_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_xor (long x) +{ + __atomic_xor_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +/* sub implemented in terms of add, and we output xadd to support older GAS. */ +/* { dg-final { scan-assembler-times "xadddw\t" 2 } } */ +/* { dg-final { scan-assembler-times "aand\t" 1 } } */ +/* nand must use an exchange loop */ +/* { dg-final { scan-assembler "acmp\t" } } */ +/* { dg-final { scan-assembler-times "aor\t" 1 } } */ +/* { dg-final { scan-assembler-times "axor\t" 1 } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-op-2.c b/gcc/testsuite/gcc.target/bpf/atomic-op-2.c new file mode 100644 index 00000000000..daacf42c00b --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-op-2.c @@ -0,0 +1,49 @@ +/* Test 32-bit non-fetch atomic operations. */ +/* { dg-do compile } */ +/* { dg-options "-mv3-atomics -O2" } */ + +int val; + +void +test_atomic_add (int x) +{ + __atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_sub (int x) +{ + __atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_and (int x) +{ + __atomic_and_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_nand (int x) +{ + __atomic_nand_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_or (int x) +{ + __atomic_or_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_xor (int x) +{ + __atomic_xor_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +/* sub implemented in terms of add, and we output xadd to support older GAS. */ +/* { dg-final { scan-assembler-times "xaddw\t" 2 } } */ +/* { dg-final { scan-assembler-times "aand32\t" 1 } } */ +/* nand must use an exchange loop */ +/* { dg-final { scan-assembler "acmp32\t" } } */ +/* { dg-final { scan-assembler-times "aor32\t" 1 } } */ +/* { dg-final { scan-assembler-times "axor32\t" 1 } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-op-3.c b/gcc/testsuite/gcc.target/bpf/atomic-op-3.c new file mode 100644 index 00000000000..b2ce2892634 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-op-3.c @@ -0,0 +1,49 @@ +/* Test that atomic insns are properly disabled with -mno-v3-atomics. */ +/* { dg-do compile } */ +/* { dg-options "-mno-v3-atomics -O2" } */ + +int val; + +void +test_atomic_add (int x) +{ + __atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_sub (int x) +{ + __atomic_add_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_and (int x) +{ + __atomic_and_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_nand (int x) +{ + __atomic_nand_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_or (int x) +{ + __atomic_or_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +void +test_atomic_xor (int x) +{ + __atomic_xor_fetch (&val, x, __ATOMIC_ACQUIRE); +} + +/* Without v3 atomics, only xadd{w,dw} is available. */ +/* { dg-final { scan-assembler-not "aadd" } } */ +/* { dg-final { scan-assembler-not "aand" } } */ +/* { dg-final { scan-assembler-not "aor" } } */ +/* { dg-final { scan-assembler-not "axor" } } */ +/* { dg-final { scan-assembler-not "axchg" } } */ +/* { dg-final { scan-assembler-not "acmp" } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-xchg-1.c b/gcc/testsuite/gcc.target/bpf/atomic-xchg-1.c new file mode 100644 index 00000000000..bab806393df --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-xchg-1.c @@ -0,0 +1,20 @@ +/* Test atomic exchange instruction. */ +/* { dg-do compile } */ +/* { dg-options "-mv3-atomics -O2" } */ + +int foo (int *p, int *new) +{ + int old; + __atomic_exchange (p, new, &old, __ATOMIC_RELAXED); + return old; +} + +int foo64 (long *p, long *new) +{ + long old; + __atomic_exchange (p, new, &old, __ATOMIC_SEQ_CST); + return old; +} + +/* { dg-final { scan-assembler-times "axchg\t.*" 1 } } */ +/* { dg-final { scan-assembler-times "axchg32\t.*" 1 } } */ diff --git a/gcc/testsuite/gcc.target/bpf/atomic-xchg-2.c b/gcc/testsuite/gcc.target/bpf/atomic-xchg-2.c new file mode 100644 index 00000000000..3b6324e966b --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/atomic-xchg-2.c @@ -0,0 +1,20 @@ +/* Test atomic exchange instruction is disabled with -mno-v3-atomics. */ +/* { dg-do compile } */ +/* { dg-options "-mno-v3-atomics -O2" } */ + +int foo (int *p, int *new) +{ + int old; + __atomic_exchange (p, new, &old, __ATOMIC_RELAXED); + return old; +} + +int foo64 (long *p, long *new) +{ + long old; + __atomic_exchange (p, new, &old, __ATOMIC_SEQ_CST); + return old; +} + +/* { dg-final { scan-assembler-not "axchg\t.*" } } */ +/* { dg-final { scan-assembler-not "axchg32\t.*" } } */