Received: by 10.213.65.68 with SMTP id h4csp1741604imn; Sun, 1 Apr 2018 13:43:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx48IhONt7jvw+3T1UgtjJI5sYllmEMMTC2nIDLfDfHSVdycHKkKRQZSTYJlsUDNxjbsTZv6R X-Received: by 10.98.10.131 with SMTP id 3mr5482226pfk.112.1522615429475; Sun, 01 Apr 2018 13:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522615429; cv=none; d=google.com; s=arc-20160816; b=QQQz7Ue1teEk+gKORWxtaMtlxGiunfs8+xjzccGuUGvdN8hMlE8KqUPnBwdePEaOBE 6sHKR8V3ryVSRO6jgQiUSQU9cK1Et7M+AvmvqrFJGJVsF+aPWY9oyKrHQ+ePkZjYBEry LGcUjEwDCyNKjRGayzYY2sD5C0pysTcXEXoFvS0JQE6dBA84gTtN6V3Q4CfGUpvGluhl gOfQMjgDNuQzIkcgzzGiGcV6W2dHQJ1VgRtumi0dP8p1Mj7Dc2iK/EYvzU9PMfTJLRVj pxFVYcmLBbZnFR+WQnWIxgwh3FN8Jz5zPd8cKWWDqdDmSvgkXEeixUACxEagDoP7M44H jeWQ== 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=yaYtV2YimHgcdS/qlah3g1qyKIKnufAq0yYkbYYjeg8=; b=Pqj0um3C9wLcyA0xxgZxeHJdJQpj6xdfW5FrTnhXHg6nHVcvNEX6vOk9Xes3yta6GA 8Bbrgmz0qWixZRXdzX2xFqGPPg0axKs2/OcL4uis0w9udfHzt4/2VzTpKulqa506WGcN uNVyNTQOxgmaWQPioDdbuntHb11LuqSQqmZGCDx6DN/DmQsWx9oUa/9wvIHfnzdLtwhn J5xKRux8qxK7qMU47Lj/SPg5kOiqvWsQepth1FighUyX9Mt9ikKYoQtU1HWBLyOKe33z votUPXJawJpwtOvCJReWTeDZSLEg1UV6hFIVW5O1tYcYlSUkwfXYaq/FJ3ZyGRrhPWex 1pQQ== 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 v2si8971113pgf.530.2018.04.01.13.43.35; Sun, 01 Apr 2018 13:43:49 -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 S1754203AbeDAUlb (ORCPT + 99 others); Sun, 1 Apr 2018 16:41:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43052 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753951AbeDAUl3 (ORCPT ); Sun, 1 Apr 2018 16:41:29 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F4C2406E96B for ; Sun, 1 Apr 2018 20:41:28 +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 166022166BC7; Sun, 1 Apr 2018 20:41:27 +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 12/45] C++: x86: Turn cmpxchg_double() & co. into inline template functions From: David Howells To: linux-kernel@vger.kernel.org Date: Sun, 01 Apr 2018 21:41:27 +0100 Message-ID: <152261528761.30503.4314337036821536020.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.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sun, 01 Apr 2018 20:41:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sun, 01 Apr 2018 20:41:28 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 cmpxchg_double() 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.h | 93 +++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h index 4bbf947c88a2..2ffe1c621eb1 100644 --- a/arch/x86/include/asm/cmpxchg.h +++ b/arch/x86/include/asm/cmpxchg.h @@ -180,27 +180,76 @@ static inline P sync_cmpxchg(P *ptr, P old, N rep) # include #endif -#define __cmpxchg_double(pfx, p1, p2, o1, o2, n1, n2) \ -({ \ - bool __ret; \ - __typeof__(*(p1)) __old1 = (o1), __new1 = (n1); \ - __typeof__(*(p2)) __old2 = (o2), __new2 = (n2); \ - BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \ - BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \ - VM_BUG_ON((unsigned long)(p1) % (2 * sizeof(long))); \ - VM_BUG_ON((unsigned long)((p1) + 1) != (unsigned long)(p2)); \ - asm volatile(pfx "cmpxchg%c4b %2; sete %0" \ - : "=a" (__ret), "+d" (__old2), \ - "+m" (*(p1)), "+m" (*(p2)) \ - : "i" (2 * sizeof(long)), "a" (__old1), \ - "b" (__new1), "c" (__new2)); \ - __ret; \ -}) - -#define cmpxchg_double(p1, p2, o1, o2, n1, n2) \ - __cmpxchg_double(LOCK_PREFIX, p1, p2, o1, o2, n1, n2) - -#define cmpxchg_double_local(p1, p2, o1, o2, n1, n2) \ - __cmpxchg_double(, p1, p2, o1, o2, n1, n2) +template +static inline bool __cmpxchg_double(P1 *p1, P2 *p2, + P1 old1, P2 old2, + N1 rep1, N2 rep2, + enum cmpxchg_lock lock = __lock_always) +{ + bool ret; + + if (sizeof(P1) != sizeof(long)) __cmpxchg_wrong_size(); + if (sizeof(P2) != sizeof(long)) __cmpxchg_wrong_size(); + + //VM_BUG_ON((unsigned long)(p1) % (2 * sizeof(long))); + //VM_BUG_ON((unsigned long)((p1) + 1) != (unsigned long)(p2)); + + switch (lock) { + case __lock_local: + asm volatile("cmpxchg%c4b %[ptr1]" + CC_SET(z) + : CC_OUT(z) (ret), + [old2]"+d" (old2), + [ptr1] "+m" (*p1), + [ptr2] "+m" (*p2) + : "i" (2 * sizeof(long)), + [old1] "a" (old1), + [rep1] "b" (rep1), + [rep2] "c" (rep2)); + break; + case __lock_smp: + asm volatile(LOCK_PREFIX "cmpxchg%c4b %[ptr1]" + CC_SET(z) + : CC_OUT(z) (ret), + [old2]"+d" (old2), + [ptr1] "+m" (*p1), + [ptr2] "+m" (*p2) + : "i" (2 * sizeof(long)), + [old1] "a" (old1), + [rep1] "b" (rep1), + [rep2] "c" (rep2)); + break; + case __lock_always: + asm volatile("lock; cmpxchg%c4b %[ptr1]" + CC_SET(z) + : CC_OUT(z) (ret), + [old2]"+d" (old2), + [ptr1] "+m" (*p1), + [ptr2] "+m" (*p2) + : "i" (2 * sizeof(long)), + [old1] "a" (old1), + [rep1] "b" (rep1), + [rep2] "c" (rep2)); + break; + } + + return ret; +} + +template +static inline bool cmpxchg_double(P1 *p1, P2 *p2, + P1 old1, P2 old2, + N1 rep1, N2 rep2) +{ + return __cmpxchg_double(p1, p2, old1, old2, rep1, rep2, __lock_always); +} + +template +static inline bool cmpxchg_double_local(P1 *p1, P2 *p2, + P1 old1, P2 old2, + N1 rep1, N2 rep2) +{ + return __cmpxchg_double(p1, p2, old1, old2, rep1, rep2, __lock_local); +} #endif /* ASM_X86_CMPXCHG_H */