From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2133.outbound.protection.outlook.com [40.107.117.133]) by sourceware.org (Postfix) with ESMTPS id 263763858D37 for ; Fri, 28 Apr 2023 13:13:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 263763858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cipunited.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cipunited.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CD3IOUhwvc9Wq2gdUwEcNwC9+uZVRaJ1Bh0rkid4C2O/EZ+i9RQ0K22dWcY5wODutbYjCZ+gbk938IAF9bhIBv8RAnQP4eyyUcvQetk1Waa+Fgl6DLoD178LJjkkadvn2kkQTscOae+Zo10/zSjESrwzCCLcUcJCDclzangaLOsglFjnrtwv5g9Bnfs/vcI6xw6tYd4zv8lSifQuoBVVjEJpZ6zDxG8qNS8dr4U9R6PV/xcoDfPr7oX0d6+DriRrP8fkZriJpUTngMHR8uoVonEP2ib6PcJvaiZVeGZpdZo9hstAHMPswKzKw4dYyFGiqmo2DWx4POKkZ8N603yVVQ== 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=46f55umZsqOcYdAK2NOlZABWjiQWd2cYX/vG6kVxcz8=; b=HcFrdIkw/tDGXM6D6U3w9ZcxqXFIcLO9AyPZP7VQSsA69OtK2HaDhw1TVZ+Frhfr5FmgADBzcouLEZoa90lEDmKcmAgVK9jpj2bE61fmLuAKdLXqbFQDk8y/BlBbVCGTBYiEhJDjP7IvqJTxSnmmWnW36hAn/yLm105y9+qe/OeMHm1ngB29V0JAeIPMFzPbAFDJ/9QoAmmHW/IWyETMl/pRm/VGg6ez9crN4ah2cWq/FG5ovmegoyAzlYln3H4c331XUkYI6S3retE2M/J3x532vK2aQGWzbg76xkNwn8fmgfap5RSJj/COWrUHiBSvkC1uwGZ8r2gvXeVPt0ertA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cipunited.com; dmarc=pass action=none header.from=cipunited.com; dkim=pass header.d=cipunited.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cipunited.onmicrosoft.com; s=selector1-cipunited-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=46f55umZsqOcYdAK2NOlZABWjiQWd2cYX/vG6kVxcz8=; b=jSRE4ePgEbXE1wvYJnEoYbVevh6K2vwpEYRaGNkk3IXhbn+ZGJlQzo55PvaMonVVIBwCYzMkkqdI9pqpY8EXzkv9jIxvBoIQwlIbGc6VOmLWkwyZmCbFVvj7+K7g60L00tWkUGqv9DBvK5WCyoDedHYfqlz7hayNc5O/wrIKrfE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cipunited.com; Received: from TYZPR04MB6117.apcprd04.prod.outlook.com (2603:1096:400:25a::9) by TYZPR04MB5736.apcprd04.prod.outlook.com (2603:1096:400:1fa::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Fri, 28 Apr 2023 13:13:10 +0000 Received: from TYZPR04MB6117.apcprd04.prod.outlook.com ([fe80::4016:87b:f0d1:b150]) by TYZPR04MB6117.apcprd04.prod.outlook.com ([fe80::4016:87b:f0d1:b150%6]) with mapi id 15.20.6340.023; Fri, 28 Apr 2023 13:13:10 +0000 From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: macro@orcam.me.uk, jiaxun.yang@flygoat.com, syq@debian.org, richard.sandiford@arm.com, YunQiang Su Subject: [PATCH v2] MIPS: add speculation_barrier support Date: Fri, 28 Apr 2023 21:12:49 +0800 Message-Id: <20230428131249.713463-1-yunqiang.su@cipunited.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230428123327.686353-1-yunqiang.su@cipunited.com> References: <20230428123327.686353-1-yunqiang.su@cipunited.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TYCP286CA0161.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:383::6) To TYZPR04MB6117.apcprd04.prod.outlook.com (2603:1096:400:25a::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR04MB6117:EE_|TYZPR04MB5736:EE_ X-MS-Office365-Filtering-Correlation-Id: fc6ce3f0-ac0f-4727-91d7-08db47ea5043 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yYtezorDAzZ8OmqN/zFodqyUcKsLqh7YkD2NyQmHsmlEQG7+feaWlqfkXYHo22M6oehOVlpM/z4uFYrI7cYsg+p6VqLW/Sf6A0d7VDlfnKluXDF/WbuHfTgkISZq+qnKxAG1LCA4A5+VODwk63aK5vi1ILhJT1D7Z0yY4bJDlmE4Z1v7wuqgqy72eVVKGrmKdtq2K3vPmgzq6ujg2yc2M9kRygUb6L/5CtzGg8ku4P1CFEkshJlrdDuEcgv5I60+lIrlEOG9L1fvRFnejNSWv+YN5gWbNDh++ge7U7SAXjNf49xhhkzMQuhSCqjYvapdLloyJma1AHbOcQAZ4xSJBssWfq8EzrOub5diUVzfds6kDqw204USxyNYbiMHncsijVkcuF/8Tp2ahNZ7EeRIMuffa1QvM/KKgg4xk40wabWyAk4EkzmKcXT58XajwBREydxB3B0p+EUSH9ch8nYndwSshG56a9uLK7UlB6D2KuMfx8/mEEfIkJhjH6lUjWncBkW+8GgWkoxUcS3Sol1QXhC8k9DCSR7WkQHMCddrSD7qymmsbZaj4ToaTYyHSsjjhD6ZJ0Bp2qVbldYy38LueA44ai8p61Aeq70QUFh1MIQhGLlfDkbFxdaZ7nCFEdxt X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYZPR04MB6117.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(39830400003)(346002)(396003)(376002)(366004)(451199021)(36756003)(38100700002)(52116002)(6486002)(41300700001)(6666004)(8676002)(8936002)(38350700002)(2616005)(316002)(66476007)(66556008)(6916009)(66946007)(83380400001)(4326008)(186003)(6506007)(26005)(6512007)(1076003)(86362001)(478600001)(107886003)(2906002)(5660300002)(2004002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Lm/qVveisQkDSzNOyKgHWumCeS+hu4dDnA00DF7W240NvxH0QahIQWJyn2X7?= =?us-ascii?Q?DimteMrWsNGHoWbz2OXVzIAmnE0mAHz+8BZo+T9tteisPUaLGgs7kAbo91oV?= =?us-ascii?Q?yvTQC5xMf9TaKwDFW+0pQKPSXwnCp9oNbIvlAxdP+Dd4wx5JFxu7OT5O7obw?= =?us-ascii?Q?x4L11DGwHWuyOzr16Z6wxrtCEEIAvZ7QLQoOuR372JMIzz1yguUO71w8RcCF?= =?us-ascii?Q?8X2GJp6f+s2zCILJ3g6QbesYFgadqWdgTvUAyIfFe8ChR3z33yUdwa8rjWij?= =?us-ascii?Q?56NHJP+YJL7s+r2Kg5gf6KdFx2TklHNcILXXQNRxegylt0xkfQXkHYCxx0Uz?= =?us-ascii?Q?kkr3Tfc4JWH2XrtC8Vceq0keU/YhkGuFMFo9DHM4H2TIF5a5593uM+hRsXjV?= =?us-ascii?Q?dddMC/IkvZ2Je6CLXWa4IzdbNUuhi1ZPcrkRnSULObewTi/3xw6Wxz6SefT7?= =?us-ascii?Q?pBeo40DJmoOf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2AowuAu5FpvgOwCXIswgL?= =?us-ascii?Q?LJix69RWSC/lO4t38cz9s2ku6+zlLAZxC5bvpxaJ1bQ90cQOy6cPcRFhOWle?= =?us-ascii?Q?SNm0HBmADyJObcdclT5MIlyXsLWlRQNwitptLxY8bHMBEpl/n6k2zqG5aUrM?= =?us-ascii?Q?Q5dm9Tn9+GJYTfL9NdMmwJEU8sNFXSErPgxD0flU+sqO/UUgBB5YKsrhiGkK?= =?us-ascii?Q?GG+bVHOZRjCi9+FnQSO+FVUoTob19TJiQcb6V1LM4Ed09QIjn23zHlL2OyRe?= =?us-ascii?Q?KA=3D=3D?= X-OriginatorOrg: cipunited.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc6ce3f0-ac0f-4727-91d7-08db47ea5043 X-MS-Exchange-CrossTenant-AuthSource: TYZPR04MB6117.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2023 13:13:09.9395 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e31cf5b5-ee69-4d5f-9c69-edeeda2458c0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pabNqfxs0mkLHjvpFYBubkWHmyYNqy5m+HM9OC4Exh4xZ4GpxVvROHDMO0WnTOjdkK1HuZxIxVLkEE5cnVeYTkYqL3KVbP9jBgYd3g6FE44= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR04MB5736 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,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: speculation_barrier for MIPS needs sync+jr.hb (r2+), so we implement __speculation_barrier in libgcc, like arm32 does. gcc/ChangeLog: * config/mips/mips-protos.h (mips_emit_speculation_barrier): New prototype. * config/mips/mips.cc (speculation_barrier_libfunc): New static variable. (mips_init_libfuncs): Initialize it. (mips_emit_speculation_barrier): New function. * config/mips/mips.md (speculation_barrier): Call mips_emit_speculation_barrier. libgcc/ChangeLog: * config/mips/lib1funcs.S: New file. define __speculation_barrier and include mips16.S. * config/mips/t-mips: define LIB1ASMSRC as mips/lib1funcs.S. define LIB1ASMFUNCS as _speculation_barrier. set version info for __speculation_barrier. * config/mips/libgcc-mips.ver: New file. * config/mips/t-mips16: don't define LIB1ASMSRC as mips16.S is included in lib1funcs.S now. --- gcc/config/mips/mips-protos.h | 2 + gcc/config/mips/mips.cc | 13 +++++++ gcc/config/mips/mips.md | 12 ++++++ libgcc/config/mips/lib1funcs.S | 60 ++++++++++++++++++++++++++++++ libgcc/config/mips/libgcc-mips.ver | 21 +++++++++++ libgcc/config/mips/t-mips | 7 ++++ libgcc/config/mips/t-mips16 | 3 +- 7 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 libgcc/config/mips/lib1funcs.S create mode 100644 libgcc/config/mips/libgcc-mips.ver diff --git a/gcc/config/mips/mips-protos.h b/gcc/config/mips/mips-protos.h index 20483469105..da7902c235b 100644 --- a/gcc/config/mips/mips-protos.h +++ b/gcc/config/mips/mips-protos.h @@ -388,4 +388,6 @@ extern void mips_register_frame_header_opt (void); extern void mips_expand_vec_cond_expr (machine_mode, machine_mode, rtx *); extern void mips_expand_vec_cmp_expr (rtx *); +extern void mips_emit_speculation_barrier_function (void); + #endif /* ! GCC_MIPS_PROTOS_H */ diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index ca822758b41..139707fda34 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -13611,6 +13611,9 @@ mips_autovectorize_vector_modes (vector_modes *modes, bool) return 0; } + +static GTY(()) rtx speculation_barrier_libfunc; + /* Implement TARGET_INIT_LIBFUNCS. */ static void @@ -13680,6 +13683,7 @@ mips_init_libfuncs (void) synchronize_libfunc = init_one_libfunc ("__sync_synchronize"); init_sync_libfuncs (UNITS_PER_WORD); } + speculation_barrier_libfunc = init_one_libfunc ("__speculation_barrier"); } /* Build up a multi-insn sequence that loads label TARGET into $AT. */ @@ -19092,6 +19096,15 @@ mips_avoid_hazard (rtx_insn *after, rtx_insn *insn, int *hilo_delay, } } +/* Emit a speculation barrier. + JR.HB is needed, so we need to put + speculation_barrier_libfunc in libgcc */ +void +mips_emit_speculation_barrier_function () +{ + emit_library_call (speculation_barrier_libfunc, LCT_NORMAL, VOIDmode); +} + /* A SEQUENCE is breakable iff the branch inside it has a compact form and the target has compact branches. */ diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md index ac1d77afc7d..5d04ac566dd 100644 --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -160,6 +160,8 @@ ;; The `.insn' pseudo-op. UNSPEC_INSN_PSEUDO UNSPEC_JRHB + + VUNSPEC_SPECULATION_BARRIER ]) (define_constants @@ -7455,6 +7457,16 @@ mips_expand_conditional_move (operands); DONE; }) + +(define_expand "speculation_barrier" + [(unspec_volatile [(const_int 0)] VUNSPEC_SPECULATION_BARRIER)] + "" + " + mips_emit_speculation_barrier_function (); + DONE; + " +) + ;; ;; .................... diff --git a/libgcc/config/mips/lib1funcs.S b/libgcc/config/mips/lib1funcs.S new file mode 100644 index 00000000000..45d74e2e762 --- /dev/null +++ b/libgcc/config/mips/lib1funcs.S @@ -0,0 +1,60 @@ +/* Copyright (C) 1995-2023 Free Software Foundation, Inc. + +This file 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. + +This file 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "mips16.S" + +#ifdef L_speculation_barrier + +/* MIPS16e1 has no sync/jr.hb instructions, and MIPS16e2 lacks of jr.hb. + So, we use normal MIPS code here, just like what we do for __sync_* */ + .set nomips16 + + .set noreorder + .globl __speculation_barrier + .ent __speculation_barrier + +__speculation_barrier: + .set push +/* MIPS1 has no sync, and in fact it doesn't need it at all. + We wish that all newer CPUs should run software with MIPS2+ */ +#if __mips >= 2 + sync /* complementation barrier for memory */ +#endif +#if __mips_isa_rev >= 2 +/* MIPSr2+: sync+jr.hb is enough */ + jr.hb $ra /* Jump with instruction hazard barrier */ +#else +/* Make ssnop available, ssnop only recognized by GAS since mips32, + however it's actually available since R5500, + and it will be decoded as nop on earlier processors */ + .set mips32 +/* MIPS1 to MIPSr1: R10000 have 7 stage pipeline, + so 8 ssnop is sufficient to block all speculation on all CPUs */ + .rept 8 + ssnop + .endr + jr $ra +#endif + .set pop + .end __speculation_barrier + + .set reorder +#endif diff --git a/libgcc/config/mips/libgcc-mips.ver b/libgcc/config/mips/libgcc-mips.ver new file mode 100644 index 00000000000..f0e9fc54965 --- /dev/null +++ b/libgcc/config/mips/libgcc-mips.ver @@ -0,0 +1,21 @@ +# Copyright (C) 2008-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 +# . + +GCC_14.0 { + __speculation_barrier +} diff --git a/libgcc/config/mips/t-mips b/libgcc/config/mips/t-mips index 4fb8e136217..d05ef7cbf74 100644 --- a/libgcc/config/mips/t-mips +++ b/libgcc/config/mips/t-mips @@ -7,3 +7,10 @@ softfp_truncations := softfp_exclude_libgcc2 := n LIB2ADD_ST += $(srcdir)/config/mips/lib2funcs.c + + +LIB1ASMSRC = mips/lib1funcs.S +LIB1ASMFUNCS = _speculation_barrier + +# Version these symbols if building libgcc.so. +SHLIB_MAPFILES += $(srcdir)/config/mips/libgcc-mips.ver diff --git a/libgcc/config/mips/t-mips16 b/libgcc/config/mips/t-mips16 index 2bad5119d51..5fd9d60d7a3 100644 --- a/libgcc/config/mips/t-mips16 +++ b/libgcc/config/mips/t-mips16 @@ -16,8 +16,7 @@ # along with GCC; see the file COPYING3. If not see # . -LIB1ASMSRC = mips/mips16.S -LIB1ASMFUNCS = _m16addsf3 _m16subsf3 _m16mulsf3 _m16divsf3 \ +LIB1ASMFUNCS += _m16addsf3 _m16subsf3 _m16mulsf3 _m16divsf3 \ _m16eqsf2 _m16nesf2 _m16gtsf2 _m16gesf2 _m16lesf2 _m16ltsf2 \ _m16unordsf2 \ _m16fltsisf _m16fix_truncsfsi _m16fltunsisf \ -- 2.30.2