From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=+v3ONVOUW0jtYgK/KTqlJk4chZKOWQuityYpZgaJt6U=; b=IEqfdAlnvtwv1SCZvZxWJo6wtpVMhTAPrcMYBUdSb+kDIx2z/zuWFgldyGPRvJhiWPyH TLP67TOr62WYlO3HGVCVPFS7BJEG4jcNsh2AIvH/aJiCQNVkP1lMjrEeLjOuiNVIQsmu ySwlgXCfr/IXAhawyWoAM0d8miK5vH9RQEbop9iSaob8zmhspD23Rwt2WfwexP6/iLqt CP4jY28QtMx6dD7TKjSoP/REbzeiH9vjOmz1M0dKvAh1aveFfB8HfNk4+NVnykqxTrxS 9p6l8fjwhDUGVMJhzmywccDMCGeZ6GpHKMxTN+PrTzUrtlvZmB6Se/6DU0NsNw17pn6F Gg== 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) From: Stefan Schulze Frielinghaus 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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" -- 2.39.1