Received: by 10.213.65.68 with SMTP id h4csp1741602imn; Sun, 1 Apr 2018 13:43:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx48A601k2P0Sot/jjlB6DwsYcO1npWnualjz5Mfuro2lzZxFxlR06ll0HAmc8cdAJhKpT1d6 X-Received: by 10.99.115.9 with SMTP id o9mr4677821pgc.332.1522615428883; Sun, 01 Apr 2018 13:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522615428; cv=none; d=google.com; s=arc-20160816; b=qN0kBKHxdq3o4ikI+EPV1+wDuzfJjJcELe+VUSqJEGoao1j5FFA9vctjhX7DN1efMI oNZ2/1LBGgJxZaLX7l90gHayT7vgNjCD1ePtBIJAopAsseYUe0fFMihIoqQnGg1K7UO8 rIf8VzLBQD8QD9/EHmfoOECSfMYHm0fDN96naoZolrk5BCsk2EUmewu2mbnKSi3Zvv8z ZwppBb7+Vf39AcP8dwNUWhaGFxFP9cNpiws5V3zsNNW38+3PnSTfNDkOBGJfCQg6HM3Q MUGd5FTotTQQ4Wv1j2kM5jprm+k6JuBjS20w65721D3mGDvC+IO/8kJqlF5FU2vbYIiP MZlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject :organization:arc-authentication-results; bh=TGNq1oYqfb7rNDRlbl6sDI4vWWVUeKinP8eKKSOT08s=; b=G/K+rHgtsl4oajN/WGXQSjpUL81s+3UdPtKEsMIFinyf1IupUAFJ2IMtREOiXmzcwj 4pWLWWYKYD8YIh57lFSwbVwN8NaMUQdjM01msGWl5pOzdGhXRwev/YtQ6GF29SovWE7I WG7UDetZN1/KTCvPBysAEn0aBB/sX09ewuRC97Iqz/VAxzPxOT0Fd3oxuL1FO6aWWWl1 DMmaw8CInhAUqOhrwQq44ldMri760mA7ogjJlhPkSa1SmQ/Wtp18XI0jKBUxSNQWxQTl cKTvhoGutCq0R1RO8+lG/1iO9wali+fkxl8S8Zdy7Glp6n6r1v+NS28dDEHEXsEOOcGZ NVnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y7-v6si8390501plk.347.2018.04.01.13.43.35; Sun, 01 Apr 2018 13:43:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754220AbeDAUlh (ORCPT + 99 others); Sun, 1 Apr 2018 16:41:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37938 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753951AbeDAUlf (ORCPT ); Sun, 1 Apr 2018 16:41:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 717A3406804A for ; Sun, 1 Apr 2018 20:41:34 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-59.rdu2.redhat.com [10.10.120.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DFCA111DCF0; Sun, 1 Apr 2018 20:41:34 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 13/45] C++: x86: Turn cmpxchg64() & co. into inline template functions From: David Howells To: linux-kernel@vger.kernel.org Date: Sun, 01 Apr 2018 21:41:33 +0100 Message-ID: <152261529364.30503.14203436620412946271.stgit@warthog.procyon.org.uk> In-Reply-To: <152261521484.30503.16131389653845029164.stgit@warthog.procyon.org.uk> References: <152261521484.30503.16131389653845029164.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 01 Apr 2018 20:41:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 01 Apr 2018 20:41:34 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Turn cmpxchg64() and similar functions into inline C++ template functions. This produces more robust source as the all the casting the C macros require is then unnecessary. Signed-off-by: David Howells --- arch/x86/include/asm/cmpxchg_64.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/cmpxchg_64.h b/arch/x86/include/asm/cmpxchg_64.h index 03cad196a301..55beb7fc036d 100644 --- a/arch/x86/include/asm/cmpxchg_64.h +++ b/arch/x86/include/asm/cmpxchg_64.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 -*- c++ -*- */ #ifndef _ASM_X86_CMPXCHG_64_H #define _ASM_X86_CMPXCHG_64_H @@ -7,17 +7,23 @@ static inline void set_64bit(volatile u64 *ptr, u64 val) *ptr = val; } -#define cmpxchg64(ptr, o, n) \ -({ \ - BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ - cmpxchg((ptr), (o), (n)); \ -}) +template +static inline P cmpxchg64(P *ptr, P old, N rep) +{ + P ret = old; + if (sizeof(P) != 8) + __cmpxchg_wrong_size(); + return cmpxchg(ptr, ret, rep); +} -#define cmpxchg64_local(ptr, o, n) \ -({ \ - BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ - cmpxchg_local((ptr), (o), (n)); \ -}) +template +static inline P cmpxchg64_local(P *ptr, P old, N rep) +{ + P ret = old; + if (sizeof(P) != 8) + __cmpxchg_wrong_size(); + return cmpxchg_local(ptr, ret, rep); +} #define system_has_cmpxchg_double() boot_cpu_has(X86_FEATURE_CX16)