From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 87E973858D35 for ; Wed, 26 Jul 2023 16:27:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87E973858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36QGFqfO029482 for ; Wed, 26 Jul 2023 16:27:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : content-type : mime-version; s=corp-2023-03-30; bh=z+JogwFCw9urbZ0YlmQfdVvUpgZv09Wd17dkK2xnydk=; b=bhPaO7F6ebubb6kC81zV1jUfbeBxo3363jI9lx7KYoZMMYv0BJ78+1k9jjbWmOera/HQ npoho3tWuooKm1mMdLWF9a+u2ruQHvELhgfTxHOVbPiFjQxAOmsnK/8crp5W8zML+s9k r0wkbMBMoAwD4EDTK11OOyYR717ojqA5Isz+2zlioZ5v1v9+Yih0sE3bZKYIiCs0Tlhb CjtwqbinRceD6AUTvarWBaa7vqTDHE07AJdhrxbUWqs7smBLJ9ZnTnQlPv9C5/rL7nkN lLCSE0fTLIVu+E5Wv/gY+V0n6n4RGDpV4rEmj+NwMTMaZjaNFFYmA/V/BHr4vj6cUcJ0 lQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3s05q1yxcn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 26 Jul 2023 16:27:38 +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 36QFauMM029491 for ; Wed, 26 Jul 2023 16:27:37 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2044.outbound.protection.outlook.com [104.47.66.44]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3s05j6eq0s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 26 Jul 2023 16:27:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I2hv95XEjXnG7xOSoJoGkPQpZwiOo0vEc9asntmMWzCU/LSCGbJB2mkFKQbR5pErnrydrl7uwk/NQgOAfWo7oEZcq2KcUeEbcFpMlu/3Bkd75nw9b9wLeUMypoCui9g6wpot7LMItphk2C8Xevngwp7axK6bfVFTlBq7Bg1oh924kogiilby/bfzy+TQyWprAuNlV8XM0I60vM87/ter0Bj3/KLSbsPFfBxVwa6TvgLaxUl9d8naen6/JnWnX/C5a/USd/JqiX9nHXX3rfTSaJTrkrn7pF6rKo+lCAVsyJ3doKFwWmjAB/dRe/1998RWHbUY4mbLqxBfpdJ9LBb/fA== 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=z+JogwFCw9urbZ0YlmQfdVvUpgZv09Wd17dkK2xnydk=; b=ERZkG1tG8tp5lmjwb1HQtdHr0pqVv+dqCO78YjxiJCEsHPhOVeZ01S3xFPEBSRtLHVxx+PvSFS8E1axnQ4B38Ohp5RohZGrq8XoO8mJf1kwwQJCpd1Mrlr5MXmCZVL0Y0Bq5ZRJmSAQ9kOWPwM5z46ilnPbmIpz97ql+4n4eL1DD96G3w4ua5yhY+xE0oC4GwjBFejR3tlgOgfXPSYsA2ghLwAk1GMSn3YVXhw+WVwyvd83ofO20qcrXwWZn1LpEBbfcf+GUBjopzIhAqpxYrMtS2hnGDTO5HLe0F1c6s/75NKLw8X5VxdT+ZiV6If6sibltYfDqie/iicB5kW/dKA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z+JogwFCw9urbZ0YlmQfdVvUpgZv09Wd17dkK2xnydk=; b=x80/nmdQG6JWQpkIxFj5QuZA/262V/LLmVBvRcCZ6HImUtkD1uosgwBIZENqD5uUOOgiX/sHCZQJ8ioa+6JbxXR5uCtLBV1ernvipQZ+pFAezQZyAXp9lcxuM99hURjW775r/ftd7jttXt1qe+o0Y/93+aP0OON+WNJNDKaqxS4= Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by SJ0PR10MB4672.namprd10.prod.outlook.com (2603:10b6:a03:2af::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Wed, 26 Jul 2023 16:27:34 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::d5ed:aedb:b99f:6f19]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::d5ed:aedb:b99f:6f19%3]) with mapi id 15.20.6609.032; Wed, 26 Jul 2023 16:27:34 +0000 From: "Jose E. Marchesi" To: David Faust Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH v2 2/2] bpf: add v3 atomic instructions In-Reply-To: <20230725224308.12304-1-david.faust@oracle.com> (David Faust's message of "Tue, 25 Jul 2023 15:43:08 -0700") References: <87zg3j8wjj.fsf@oracle.com> <20230725224308.12304-1-david.faust@oracle.com> Date: Wed, 26 Jul 2023 18:27:28 +0200 Message-ID: <87y1j24ozz.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Content-Type: text/plain X-ClientProxiedBy: LO4P123CA0125.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:192::22) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|SJ0PR10MB4672:EE_ X-MS-Office365-Filtering-Correlation-Id: 380ed3bf-c5c9-40c1-af92-08db8df53790 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ywqw48M7CI1lOXP5WGNXWU/Re0CYrJ84vdJ1JoQtNN2JWcqOnnkJMURGmgNTxxIItIkjG/k8+Ug0sjC3A8KVFDG7ilvVBMsw9gN4unVXLcRQv+h0Ewiqn6ZAqxfQaPgDCt/n669DbvmUEwYq+r6NjfxNt8wNJ/DsW/zbrRlAsd3xXrPc/HpWTE4jTnkL+IFJa6zP3fxccG4VibBQHnJ+FgGvPuS9cH7ZyoGABSsOJp1xsTGbwvX4yeHu5nMKBMSa0QFNXxQ0Z5Th7i//+BBujj/7nQTLQB7WPCagwQsJk2LW0eo46RIH3UvXFBZ8H++ej83vyzIy8JJUIzoDprkiR/6i1UDrZrEuOLglxhCZcJ9EppJCJg8wmJN8Jlg25JvL3wqkmgPkPzoyB5/80g/On7YZBf0Gr+L4YIY9qNLopG0ENZsVsPFaAn1IGsabUqTufmmJwG9IAUu77AxaOLeaawdb4Xx4VV/08wI0m/2O2blCv2/6F55i/24VLXW/xfQvFbbTuGMrzU2BTbFzP0OS+Qlfmnb3NeQi9K8xR5lkibsW3oMjGep8tUFYWCiT6+WgD4f//nOK/nUMdIlrJZNKAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2888.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(366004)(346002)(136003)(396003)(39860400002)(451199021)(8676002)(6512007)(66946007)(36756003)(6486002)(6666004)(66476007)(66556008)(8936002)(6862004)(4326008)(2906002)(5660300002)(6506007)(2616005)(6636002)(316002)(186003)(86362001)(83380400001)(26005)(41300700001)(478600001)(84970400001)(38100700002)(37006003)(30864003)(2004002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Nymy1ocR6UT+e1hC709GcljRzP6+NF/ATgEUh99cR3W3hGL1WNVCp8Jt4Sxa?= =?us-ascii?Q?04nunW3ngVjvtcsJp6c4R+w1BGJyAE6WM0Ob/ZmbJLJian2nosdL0UEbTZ+J?= =?us-ascii?Q?eF/TZ1WRa1EiPqgXTJn5G3pHFr/9V16y5YHo2ixRUv8oS/5hJdFL0/UXKY9W?= =?us-ascii?Q?hAIbdLgX7JTAgEJK5EuCYSN4Ui8V3HGsCK1x+m23gVQPLRX1NXtvjR6BHk98?= =?us-ascii?Q?NXKb8yFuY98xO+81Vtp6MoWvnYi6LswpJad97rV7ry1Z1b4Auegasm/fwMVy?= =?us-ascii?Q?cyC7JHSnhoCm1WUOm51czl6rmaeC/SvMM0/MP/CYxLTyqpdiJUoocIlvZCAJ?= =?us-ascii?Q?jLX8LM1f+5AUkpdoPhVy4pYsxD4xbY7jvtgQSW8xhyg9Grd+5DChR9wFwQVg?= =?us-ascii?Q?scgGtpcZcnuPZ+pHFZ+764u8tmijXTzs4w+kOP0ffOHHn7WLFMnBfCeNUh0A?= =?us-ascii?Q?tOo9MsQ//JtiZMav+3WZJL40QgV9TV5M9xssMDpvPrZZPtGUorZtGJ3zASfw?= =?us-ascii?Q?3eWby2yZsjSKi032KE3y1ez6ane7nEoM5iXKCcUbejek/a7oUlfhzSLa16Gw?= =?us-ascii?Q?zMyglFwDmAy6/tIrLWOo4owestixZXv1lTkn7bfND2+/s1p8eY/UWsMcf7r3?= =?us-ascii?Q?t1Arb71czvw6l15r8ZsRqNxEdXUkIVeCiBhNMeoO1/K1ciYxlFII8GXOP9Hp?= =?us-ascii?Q?KN+E8L5k4Ba0gcK6aYLGFsSpJjEfUTKVYV/dEPbKwhFSYFkfe7Zjf1okpctY?= =?us-ascii?Q?DRubYsN+bfMx1cRFfT4THzBHNoODFVuQFFrEgRRSQJqthxrAxsi0xbpcwJjt?= =?us-ascii?Q?qKtUGj0Bo2fbqVdjMrP/gvVbYRhVwntYWgOwbzJgUUNCVim77MB1sE4498X/?= =?us-ascii?Q?Jpb9G0c6xgMoMOPzTGjTKCzBxMtvjG+mEnVX0ucSTJJ7ti6ABOp2C42y4qlA?= =?us-ascii?Q?YvTJbDde54bIfAKFqTxlgj0WcdFpR1R2UZnD7ja4NqFbpuVkqf4clJ6RtHny?= =?us-ascii?Q?IbLhpiHmv9xFeozUwScosZXR5vdts8SDdjDuY8I3Fx777psQTwD13KVgc0t2?= =?us-ascii?Q?jh9x+gw7ncllmOlf4l3zDlLSh3DjuZDYlJv1Ib9tiDbJKYYO9ODUbp2rjk4y?= =?us-ascii?Q?lOQrzfjhmsZIMrDXmGSm3V8jZXvVBqR6u23ysbq3KiMXBauEWSkkzBNvayWm?= =?us-ascii?Q?tBzMxeBs4nPBAreRmMAZmNyMMvAt9lc27/4utVOA/LiCyTY4+yQgYjD4vkbG?= =?us-ascii?Q?bRiBmTlkTudOyzTRYrQ9zzxuDVUhB+GKnbg7iEkgnvCHHaietSd7ny3C/yj/?= =?us-ascii?Q?ZAg/Ft19jYMp6WoCyIT7NdcvmBG3rtrVYrLnlXkNTJ1qRB/dmdgzq5E8DCT+?= =?us-ascii?Q?/AOGsyjRbdUMcJelJ0uXneVbel2D7I6iSB+1s3SYxStTzWLg9Cz9F6X0z5b1?= =?us-ascii?Q?o2L5neKYxyobGb47qIQmoohZQKBFeET5AUFRFZRL+w3pttDdC/O3yC8IdkZa?= =?us-ascii?Q?MRNCWOAKxT2BMLgnjIwf0gyzGTH0phgQTde9G4Vq/LIqWtogJ8kGWQk57o62?= =?us-ascii?Q?eI7tv0alIYXAo8HuHuQIn9j3Mm8KODKQPmDI9OhHq/6ZYacraZH+uiCtkrod?= =?us-ascii?Q?Kg=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: q4R9JtWGlKVFcuFHsthnSKM3wMiAx9/C3cIOCc9B8UY0LDsO0L0cu34EHjxO22eQo5IfR7VvQp8idUsPXtGTWcdj8O+No2LyCS1n7W0a2o7g7vQmEXPVvi1eGf4y8LpYrXeFEVxrbYaYNV40L4NLv0yyHHPXUnX99DXzadMtC3PV/iUGb57xGVHNyJ2RAOlJN/XHjSybNeflQgJhrlbR66RvZ96jnHkf+OUe67jveMUl4Xg5Kw/olWIl9I0lM5A2YWL5tJmH5Za/SMlmk0FEWirlJRuSzG49di4k5cxI0UtwoUDJh0WncKjNuUalaDxqXP7PQFmZwHpb8t4W69+oD/mQOJp3wJNgINGDv8WMvflne7IXSGbGO/ft/58x6vVd5D4ABcURHX42hLRlqPFbuvG397J4S3xDjvsjpNdHwocWfKrLstRQ/jMK7fHKRt0p+mlTtOBIxcKtX8I88UsAqe02SQpvW+MzDYU7rmpP/aIILG3DnMaeaEXX7JViv/QiFUXQh59gnHPdEv3zGs6kd5BjfSn5wTu2WBy5AoUE8+Z5uYzif+lQMKwQiKpU6YXxwJjO9YRHcaIyaqpA9C/a+ZMxpPIX2AKH7glJeB6xv9+Cf83hxUDSTVFiU3OZxwWZMP/MzWxpw1VdW4nX278keeSBEiGeYeUGS0K0dLGGkVqiFW0gWQeglNubMj3iRWsoyqEAkP9mzBIGTwNIYW2ComEFr4+be4PP05Y5qt53kI30gGqFToQvjQxhq131b88N X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 380ed3bf-c5c9-40c1-af92-08db8df53790 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2023 16:27:34.5788 (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: T+GjLpJnE1wWiaCnEtq7KeMyZnPRiieWfNYTFuWxa4C7Swoyit/mxEXw3u+z5KuuXdYb8Lgu2XoLLP6/Mlp37Badq8GMJUGfQbweiagO6xA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4672 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-26_07,2023-07-26_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-2307260146 X-Proofpoint-GUID: jE1yl5Exxea0auBxqj1-UreZXRDUdiad X-Proofpoint-ORIG-GUID: jE1yl5Exxea0auBxqj1-UreZXRDUdiad X-Spam-Status: No, score=-12.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 List-Id: OK. Thanks! > [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.*" } } */