From patchwork Mon Mar 5 09:11:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Krebbel X-Patchwork-Id: 881358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-474268-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jzVVj2vW"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zvvLV29LTz9sZ9 for ; Mon, 5 Mar 2018 20:12:17 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id; q=dns; s=default; b=UTESNxgZa1u/aSU vZf8dUS1co7sDhsECbysrg1Y0bYmkTw2j/3vkanPhLdkceXLVqQMX0zwRXxO2N/L Dx4sm0dTEihpcrFw7rlXSVh9oCLTAnQF9WqoAjLd9KdTSeX3SVtacJ0RDUVneijw JzLeugHeyvcnkdX+XEBj0xmt17iQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id; s=default; bh=VckfUXVDJiSwBFiDOHFIZ 5K5OuE=; b=jzVVj2vW3/kMY7P9790gx7+YuZltd/RM63ernzP/iS/damwcNXxJM bDpBAsIEuv3tAcyJdW+8pERxW86d7DcT0/fANAusuCKO3uRxzkKkkUgx7tfsQoWW HBBPWg1VvHIFGDS9JPq91Wj7n1AC91qYigbnw9MMH77mUSeWxv/oUQ= Received: (qmail 63064 invoked by alias); 5 Mar 2018 09:12:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 62742 invoked by uid 89); 5 Mar 2018 09:12:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Mar 2018 09:12:04 +0000 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2593wku156403 for ; Mon, 5 Mar 2018 04:12:02 -0500 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 2gh0xsd71w-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 05 Mar 2018 04:12:02 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 5 Mar 2018 09:12:00 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 5 Mar 2018 09:11:59 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w259BxKj39649362 for ; Mon, 5 Mar 2018 09:11:59 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 741EA11C052 for ; Mon, 5 Mar 2018 09:04:47 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5422511C04C for ; Mon, 5 Mar 2018 09:04:47 +0000 (GMT) Received: from maggie.boeblingen.de.ibm.com (unknown [9.152.212.134]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS for ; Mon, 5 Mar 2018 09:04:47 +0000 (GMT) From: Andreas Krebbel To: gcc-patches@gcc.gnu.org Subject: [PATCH] S/390: libatomic: Fix 16 byte atomic exchange Date: Mon, 5 Mar 2018 10:11:58 +0100 X-TM-AS-GCONF: 00 x-cbid: 18030509-0040-0000-0000-0000043AD072 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18030509-0041-0000-0000-000020DDE10C Message-Id: <20180305091158.21211-1-krebbel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-05_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803050108 X-IsSubscribed: yes The compiler builtin will use the hardware instruction cdsg if the memory operand is properly aligned and will fall back to the library call otherwise. In case the compiler for one part is able to detect that the location is aligned and fails to do so for another usage of the hw instruction and the sw fall back would be mixed on the same memory location. To avoid this the library fall back also has to use the hardware instruction if possible. Bootstrapped and regression tested on s390x. I'll wait a few days for comments before committing it. libatomic/ChangeLog: 2018-03-05 Andreas Krebbel * config/s390/exch_n.c: New file. * configure.tgt: Add the config directory for s390. --- libatomic/config/s390/exch_n.c | 69 ++++++++++++++++++++++++++++++++++++++++++ libatomic/configure.tgt | 5 +++ 2 files changed, 74 insertions(+) create mode 100644 libatomic/config/s390/exch_n.c diff --git a/libatomic/config/s390/exch_n.c b/libatomic/config/s390/exch_n.c new file mode 100644 index 0000000..b2340b4 --- /dev/null +++ b/libatomic/config/s390/exch_n.c @@ -0,0 +1,69 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. + Contributed by Andreas Krebbel + + 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 + + +/* The compiler builtin will use the hardware instruction cdsg if the + memory operand is properly aligned and will fall back to the + library call otherwise. + + In case the compiler for one part is able to detect that the + location is aligned and fails to do so for another usage of the hw + instruction and the sw fall back would be mixed on the same memory + location. To avoid this the library fall back also has to use the + hardware instruction if possible. */ + +#if !DONE && N == 16 +UTYPE +SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel UNUSED) +{ + if (!((uintptr_t)mptr & 0xf)) + { + /* Use the builtin only if the memory operand is 16 byte + aligned. */ + return __atomic_exchange_n ((UTYPE *)__builtin_assume_aligned (mptr, 16), + newval, __ATOMIC_SEQ_CST); + } + else + { + UTYPE oldval; + UWORD magic; + + pre_seq_barrier (smodel); + magic = protect_start (mptr); + + oldval = *mptr; + *mptr = newval; + + protect_end (mptr, magic); + post_seq_barrier (smodel); + + return oldval; + } +} +#define DONE 1 +#endif /* N == 16 */ + +#include "../../exch_n.c" diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt index 807ef10..ea8c34f 100644 --- a/libatomic/configure.tgt +++ b/libatomic/configure.tgt @@ -129,6 +129,11 @@ case "${target}" in config_path="${config_path} linux/arm posix" ;; + s390*-*-linux*) + # OS support for atomic primitives. + config_path="${config_path} s390 posix" + ;; + *-*-linux* | *-*-gnu* | *-*-k*bsd*-gnu \ | *-*-netbsd* | *-*-freebsd* | *-*-openbsd* | *-*-dragonfly* \ | *-*-solaris2* | *-*-sysv4* | *-*-irix6* | *-*-osf* | *-*-hpux11* \