From patchwork Thu Jun 1 04:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 70428 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AAE3F3857727 for ; Thu, 1 Jun 2023 04:27:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2108.outbound.protection.outlook.com [40.107.255.108]) by sourceware.org (Postfix) with ESMTPS id C41D63858D20 for ; Thu, 1 Jun 2023 04:27:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C41D63858D20 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=KA+AecXn39zTKLITjnAOz1dEoOuLIp8dHmTLZCxahKKZXm95x0AxG2F4eMu6V26LZg9wm0p5O68RLQiDkOO7ZLqaARcLXlI0iGGhXZqG2/PD9G8jG1HI5WgVVpMW3+qVfy5miRicMU1Gc+KXTh7zEQ1c82jyi3YBdUTzjCGPvrOt/q5pTGrhIzoh4lie86t9KPXMYWSqBZDbgmyaaHkvaW2XrmFWdEJ2DFgIZAjJrfb+ZBud83rJvWlOrUoWR6ZsswaTFTXo7/u8qYrOkLSLiLnuss+vypcyqnDvcq8aGb0l7idCU3f1+acALB2u9ZtssQanStDdiYNtOThVeET9xA== 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=v4HEDPPLq+5RB9yp7nLDJFXMeqeJ/Lg7WBPK8JL3uQQ=; b=J6TFYNFvD3teLmBzbyedy4H2AJQSOEnvpmKMJ3ORJXJU9J9g+hhzHDrT3v1CVDu6w1L/5aS3bOKKwO1Y01oKFzFcvp5yCQq6gQfH+ZEf9GrITRA6W3yfQFgZucp6n58a8Tgmyu/UYHoLQnsmobhbFCiLTTLhLMY/LjMwMcb3RpePS6+Rk5Hzd0Xg/BtpMlZ1HayxXrYGUrcrZVrkUjjL67r3yEBhlutLfEie38321DQuYoHGb2ppBMiGRyU2F8uf12jV6bvYB8/GVhwpj5xkc0xpPc8ttAxnKPMcEmdCD6Ll+9+KroL2O5YHv6XIOpkDog5wMZLRqTrC0XBispUplg== 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=v4HEDPPLq+5RB9yp7nLDJFXMeqeJ/Lg7WBPK8JL3uQQ=; b=LKFO4Qk5i/ADPopBiDuBzemORfx+2NhY8i8sfuIIQgH+M+df06ZnwM1lU0Nc5I2b8u9n13CIQ1G1EU8i71+NUZQJuQWBB8dXLSTnWRBC3WBV786jDoaIDAlV0LLlDpTu3jVPNqTmfdTe7CpIdRxt2KNViZhsPIyC7GkJtpalCI4= 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 PSAPR04MB4390.apcprd04.prod.outlook.com (2603:1096:301:3b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.22; Thu, 1 Jun 2023 04:27:17 +0000 Received: from TYZPR04MB6117.apcprd04.prod.outlook.com ([fe80::4016:87b:f0d1:b150]) by TYZPR04MB6117.apcprd04.prod.outlook.com ([fe80::4016:87b:f0d1:b150%7]) with mapi id 15.20.6433.024; Thu, 1 Jun 2023 04:27:17 +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, jeffreyalaw@gmail.com, YunQiang Su Subject: [PATCH v5] MIPS: Add speculation_barrier support Date: Thu, 1 Jun 2023 12:26:58 +0800 Message-Id: <20230601042658.2128162-1-yunqiang.su@cipunited.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0009.apcprd06.prod.outlook.com (2603:1096:4:186::17) To TYZPR04MB6117.apcprd04.prod.outlook.com (2603:1096:400:25a::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR04MB6117:EE_|PSAPR04MB4390:EE_ X-MS-Office365-Filtering-Correlation-Id: d6333c5b-98ce-4bc7-7f57-08db62587b89 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UfpxxAePzwoFj4RDZnI7Q9sb0pph+3Tf7P5LrdesQzH7YJb7jjiOJaGZBa9DVpUeXPiHjLG+oFr8o9xidDk1v5iWFGuv/w/+39ph0sZ+L3sQXRCERV6G4evOKHRasbxhBCaRDB1sbnEObGhf7ynj/QZnlulZrJ5jWbBaRr5rDJNioHLlfRFdpPEIh95L/CMKZy0C19Y49XJBgBDQ/27bJQrkNLMEf6TmM10KvCy1BoQaYZtDnSAHBZg1hRQVbMzSSLpNlxu/LsHJZkxqgjC976nI7NltJcLyt5dMmQvdM226jLvvGcgjVeYbRocU+l63rtmv+6ghE2jdK6mCnbCw2F9xWkM7zbgslMFUuFaiZFSP07U1qen4MGi4SELx9ulOpja3I3NJsY5TtLsQ3oXUFAjV0g7BnVQY5kBAackiQaUwRsS5mNkxCNhUuVKMh3x4KI+Y3z97fByFJ4RATz66W7KtiYCVcB+ljOSKpKJTfJzopTf8DJwv/W6Nxef0FJ7QJ0uLAHhJDs9qchQhU9fIt8h9Wdaa08ShJzOFz6rc1byzXxFSII+A4rHhpZ9DZtQwiftfbv0ebf+9Wrv89EBeYdl3056m16DT28/Ji5LXNxotTgxtq4n2SDksWIRtwBEB 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)(346002)(136003)(396003)(39830400003)(376002)(366004)(451199021)(5660300002)(38350700002)(8936002)(8676002)(38100700002)(26005)(83380400001)(1076003)(6506007)(66946007)(66476007)(36756003)(66556008)(186003)(52116002)(6666004)(316002)(6512007)(86362001)(2616005)(6916009)(6486002)(4326008)(41300700001)(107886003)(2906002)(478600001)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IwMdDMZGEc+3S5KXTepl1TC1yuNv6Q7Fd1a7v5ZAVBqpi4M5Qe1O8TWgwvFM43SM6nLTEOwLaz1KqSGufMCtzb7c3o7fA+32OSnHeKOvBSOFztJ95qmdxf2blD/xvbTo5e6tgYlIR8yMgMypbMglCWH8WRqWhs33WDDXjHaRJ+bdJcQwj7PYX+4R/N+3p62zy8FAkkQKSENc6bXIeQxGZPO6hjnDrPGcmExcGMv7zPT6hOI2fjbi5M8QzSFnpjqBpG2W0PucAgNoCgy1wIvdSjKkxtwxR1Da8HZiY998Y5SBvrgRyhutFNI7LNGksZ0ScgICOKneKwE2gyrjc76iyuYxolN1m34PHYSsBvxNVA/0V2C/dkc1dANReNuwFe9vkur+KQNnvfU+sVT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S4M89Wo5dosfyFc4UcTAkSrfGLEujma/54USHKVh87u8YjjZcpf7R9vf6uukes2FtckYe+1mcIepwJgi2B33sgFwLtyWQv6Qrf6CoM5G8F8zeGQ2bVdq9Zjt5/SFKgnIc1TnFKg== X-OriginatorOrg: cipunited.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6333c5b-98ce-4bc7-7f57-08db62587b89 X-MS-Exchange-CrossTenant-AuthSource: TYZPR04MB6117.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2023 04:27:17.5533 (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: HSqf2C2b3ENHC8ZvkHRgDNwfDsbXJSNRQT7q3VJGPdsjNjV4vmjzxYkP5rSxeLsvpOkmzVHkcZWBUHOgxlmxO/lJbjr9YEdQlpFcYU9w840= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR04MB4390 X-Spam-Status: No, score=-13.0 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 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 included in lib1funcs.S now. --- gcc/config/mips/mips-protos.h | 2 + gcc/config/mips/mips.cc | 12 ++++++ gcc/config/mips/mips.md | 12 ++++++ libgcc/config/mips/lib1funcs.S | 65 ++++++++++++++++++++++++++++++ libgcc/config/mips/libgcc-mips.ver | 21 ++++++++++ libgcc/config/mips/t-mips | 7 ++++ libgcc/config/mips/t-mips16 | 3 +- 7 files changed, 120 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 ca491b981a3..c1d1691306e 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,14 @@ mips_avoid_hazard (rtx_insn *after, rtx_insn *insn, int *hilo_delay, } } +/* Emit a speculation barrier. + JR.HB is needed, so we 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..97a3655e8ab --- /dev/null +++ b/libgcc/config/mips/lib1funcs.S @@ -0,0 +1,65 @@ +/* Copyright (C) 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 +#if __mips >= 2 + sync /* complementation barrier for memory. */ +#elif defined (__linux) + /* MIPS1 has no sync, while Linux can trap&emu sync. */ + /* FIXME: Will somebody use linux/gcc for MIPS1/baremetal? */ + .word 0x0000000f +#endif + + +#if __mips_isa_rev >= 1 + /* Binutils claims that JR in R1 can do same as jr.hb. + R6 changes the encoding of jr.hb. */ + jr.hb $ra /* Jump with instruction hazard barrier. */ +#else + /* ssnop is actually available since R5500, + and it will be decoded as nop on earlier processors. + gas can only recognize it with -march=mips1 since 2.21. + MIPS1 to MIPSr1: R10000 have 7 stage pipeline, + so 8 ssnop is sufficient to block all speculation on all CPUs. */ + .rept 8 + .word 0x00000040 /* The encoding of ssnop. */ + .endr + /* jr.hb will be decoded as jr on earlier processors. */ + .word 0x03e00408 /* The encoding of jr.hb $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..68f8d2bbd51 --- /dev/null +++ b/libgcc/config/mips/libgcc-mips.ver @@ -0,0 +1,21 @@ +# 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 +# . + +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 \