From patchwork Thu Mar 2 15:24:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schulze Frielinghaus X-Patchwork-Id: 1750763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=xOYiXA8N; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PSFNS3T49z1yWw for ; Fri, 3 Mar 2023 02:27:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 520243858025 for ; Thu, 2 Mar 2023 15:27:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 520243858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677770864; bh=+v3ONVOUW0jtYgK/KTqlJk4chZKOWQuityYpZgaJt6U=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=xOYiXA8Ni4ViV5ZAF4xP5U3t/DhE010jrSYhb3fwFHeXt69QPFI7P85fWdnP7ses4 Q/HeNfytrXH8FQWH0HCaURISytZjuOX+7UHaw4RxiAZSCwRWq/sZcq6JVZxpjCeQ7k H6MkSv7acLospcVw4yrbZu5CTP5052vDzdq7IgPs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 7979D3858C5E for ; Thu, 2 Mar 2023 15:27:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7979D3858C5E Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 322E6ls4022198 for ; Thu, 2 Mar 2023 15:27:22 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3p2w96ajrp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 02 Mar 2023 15:27:21 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3226EP2L013020 for ; Thu, 2 Mar 2023 15:27:19 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3nybcq5ym3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 02 Mar 2023 15:27:19 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 322FRGju26345920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Mar 2023 15:27:16 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 191E52004B; Thu, 2 Mar 2023 15:27:16 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E852E20040; Thu, 2 Mar 2023 15:27:15 +0000 (GMT) Received: from a8345010.lnxne.boe (unknown [9.152.108.100]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTPS; Thu, 2 Mar 2023 15:27:15 +0000 (GMT) To: krebbel@linux.ibm.com, gcc-patches@gcc.gnu.org Cc: Stefan Schulze Frielinghaus Subject: [PATCH] s390: libatomic: Fix 16 byte atomic {cas,load,store} Date: Thu, 2 Mar 2023 16:24:51 +0100 Message-Id: <20230302152450.1486452-1-stefansf@linux.ibm.com> X-Mailer: git-send-email 2.39.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _lLPob67e7AbNuLoX_zLPWaNu1mq4JFY X-Proofpoint-GUID: _lLPob67e7AbNuLoX_zLPWaNu1mq4JFY X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-02_08,2023-03-02_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303020130 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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: Stefan Schulze Frielinghaus via Gcc-patches From: Stefan Schulze Frielinghaus Reply-To: Stefan Schulze Frielinghaus Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This is a follow-up to commit a4c6bd0821099f6b8c0f64a96ffd9d01a025c413 introducing a runtime check for alignment for 16 byte atomic compare-exchange, load, and store. Bootstrapped and regtested on s390. Ok for mainline and gcc-{12,11,10}? libatomic/ChangeLog: * config/s390/cas_n.c: New file. * config/s390/load_n.c: New file. * config/s390/store_n.c: New file. --- libatomic/config/s390/cas_n.c | 65 +++++++++++++++++++++++++++++++++ libatomic/config/s390/load_n.c | 57 +++++++++++++++++++++++++++++ libatomic/config/s390/store_n.c | 54 +++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 libatomic/config/s390/cas_n.c create mode 100644 libatomic/config/s390/load_n.c create mode 100644 libatomic/config/s390/store_n.c diff --git a/libatomic/config/s390/cas_n.c b/libatomic/config/s390/cas_n.c new file mode 100644 index 00000000000..44b7152ca5d --- /dev/null +++ b/libatomic/config/s390/cas_n.c @@ -0,0 +1,65 @@ +/* Copyright (C) 2018-2023 Free Software Foundation, Inc. + + This file is part of the GNU Atomic Library (libatomic). + + Libatomic 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 of the License, or + (at your option) any later version. + + Libatomic 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 + + +/* Analog to config/s390/exch_n.c. */ + +#if !DONE && N == 16 +bool +SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, + int smodel, int fmodel UNUSED) +{ + if (!((uintptr_t)mptr & 0xf)) + { + return __atomic_compare_exchange_n ( + (UTYPE *)__builtin_assume_aligned (mptr, 16), eptr, newval, false, + __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); + } + else + { + UTYPE oldval; + UWORD magic; + bool ret; + + pre_seq_barrier (smodel); + magic = protect_start (mptr); + + oldval = *mptr; + ret = (oldval == *eptr); + if (ret) + *mptr = newval; + else + *eptr = oldval; + + protect_end (mptr, magic); + post_seq_barrier (smodel); + + return ret; + } +} +#define DONE 1 +#endif /* N == 16 */ + +#include "../../cas_n.c" diff --git a/libatomic/config/s390/load_n.c b/libatomic/config/s390/load_n.c new file mode 100644 index 00000000000..335d2f8b2c3 --- /dev/null +++ b/libatomic/config/s390/load_n.c @@ -0,0 +1,57 @@ +/* Copyright (C) 2018-2023 Free Software Foundation, Inc. + + This file is part of the GNU Atomic Library (libatomic). + + Libatomic 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 of the License, or + (at your option) any later version. + + Libatomic 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 + + +/* Analog to config/s390/exch_n.c. */ + +#if !DONE && N == 16 +UTYPE +SIZE(libat_load) (UTYPE *mptr, int smodel) +{ + if (!((uintptr_t)mptr & 0xf)) + { + return __atomic_load_n ((UTYPE *)__builtin_assume_aligned (mptr, 16), + __ATOMIC_SEQ_CST); + } + else + { + UTYPE ret; + UWORD magic; + + pre_seq_barrier (smodel); + magic = protect_start (mptr); + + ret = *mptr; + + protect_end (mptr, magic); + post_seq_barrier (smodel); + + return ret; + } +} +#define DONE 1 +#endif /* N == 16 */ + +#include "../../load_n.c" diff --git a/libatomic/config/s390/store_n.c b/libatomic/config/s390/store_n.c new file mode 100644 index 00000000000..9e5b2b8213d --- /dev/null +++ b/libatomic/config/s390/store_n.c @@ -0,0 +1,54 @@ +/* Copyright (C) 2018-2023 Free Software Foundation, Inc. + + This file is part of the GNU Atomic Library (libatomic). + + Libatomic 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 of the License, or + (at your option) any later version. + + Libatomic 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 + + +/* Analog to config/s390/exch_n.c. */ + +#if !DONE && N == 16 +void +SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) +{ + if (!((uintptr_t)mptr & 0xf)) + { + __atomic_store_n ((UTYPE *)__builtin_assume_aligned (mptr, 16), newval, + __ATOMIC_SEQ_CST); + } + else + { + UWORD magic; + + pre_seq_barrier (smodel); + magic = protect_start (mptr); + + *mptr = newval; + + protect_end (mptr, magic); + post_seq_barrier (smodel); + } +} +#define DONE 1 +#endif /* N == 16 */ + +#include "../../store_n.c"