From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBA66C74A5B for ; Tue, 21 Mar 2023 07:43:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HrnfMkVdr1iBQbdv/u580xcdbEk/Z0dD1KXW6DxKMGw=; b=nYjYHwvJruJM1h uauLBPXstdCCk4Vz92m0FI47vzRrfxKiSVkdCB4R3l5O/JBQEl6tjM6hO4Aj75E0YcJ05LxKbZ53G aXJsxDzXFDdUzpA1ofHx8gCtMOEZ0vSM82lV/XRqAfaJOk69DUM94ZFo3+Jv6mnuTh047HnyGZmzS eiIXdIwCKQkE9RNgMpPiYg8B2Q3rX9edIj13dIMK2E5pIujN3db/CxKoAyBLgA+7m4YrdVjO8V9x0 xBd7ookmuAvxm0P6FlztqSStFgg6omdpYBHDt6mSAP8xs6oh3ZKDO7MjRJKNlHhSPdoSJJB5HrMed pVFB1lNxYYyZq80eiP6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peWeP-00BZMI-25; Tue, 21 Mar 2023 07:43:21 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1peWeK-00BZJB-2T for linux-riscv@lists.infradead.org; Tue, 21 Mar 2023 07:43:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679384595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TPnhvOcPIzsxcdPaGdi9oJi4cZ44pFeBuguAKI/S1NE=; b=BsS5SVdruLJt0lDUpNV0zjmVCGz4dn85NZIkEuSlsfHqZcu1duog3dPFWZnOIY2hyKO5bq 3HP/tyeABXA92T2DyGkE7nAQEyKFdCgDbPSF5+ELqK08kSDdGjeM3yJG8dhHRVNunpRJG3 O6yZFJExXRaAAdF9dD8jDuB6SuS89Oc= Received: from mail-oa1-f71.google.com (mail-oa1-f71.google.com [209.85.160.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-261-T7MCmvpdPBaiOLGr1lG5rw-1; Tue, 21 Mar 2023 03:43:07 -0400 X-MC-Unique: T7MCmvpdPBaiOLGr1lG5rw-1 Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-1778b36a88dso8235465fac.17 for ; Tue, 21 Mar 2023 00:43:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679384586; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TPnhvOcPIzsxcdPaGdi9oJi4cZ44pFeBuguAKI/S1NE=; b=pVaIZsoptSeWOSticiVIiTSbFjM7iYz5C8TNTSErLhgucXpE9XEJJNor494kytHuNk ThUaGSi3CBobHclN62yEfUd2YZQktHB02fuwjYOLs+CKriUNh1AkKfytJNrH2QAMYLvg x/j6mq+fKss/vMaPED4QBCskkOR0Uob9/RbJ2wjmt1szCgnYR2Wh1csYS8sDpyPVRxyu o5RptZ+g8dJZ4H2hCd1280mU1wTU88hu9KvX9g+3Bppf4B6yWRoQTFiTtxb6YFUyTVX0 l/pMuAvBqNUO0JJ2icFuSH+vh7Rgr1va7ZOsTppXlAPX6IUi34+ecvU84egiu528JYrb ooSQ== X-Gm-Message-State: AO0yUKVIf2a2T5hexws2EKNKC/4Fv8m4WfoKhPFvzwpmJjFtQMiVStPR UNplqCohOA8c7R/yQcogLXjB9jcRK8Lka5IRT4Y6iR0iJSC+oGhQE1CzJqFUY1xcZwWLdeTjiiJ 6NS3IAsg5NvaBRE36kYZ37DkbxwDY X-Received: by 2002:a05:6870:b022:b0:17a:f324:84ef with SMTP id y34-20020a056870b02200b0017af32484efmr443835oae.59.1679384586649; Tue, 21 Mar 2023 00:43:06 -0700 (PDT) X-Google-Smtp-Source: AK7set9b8yamhEH0q7gTigIbJe6gd98wbZe5VUiij8zGy8NAuWEbdR53tgMM8Yl9DhbMWzVFsWMIvw== X-Received: by 2002:a05:6870:b022:b0:17a:f324:84ef with SMTP id y34-20020a056870b02200b0017af32484efmr443822oae.59.1679384586423; Tue, 21 Mar 2023 00:43:06 -0700 (PDT) Received: from localhost.localdomain ([179.111.176.145]) by smtp.gmail.com with ESMTPSA id az15-20020a05687c230f00b0016a37572d17sm4047729oac.2.2023.03.21.00.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 00:43:06 -0700 (PDT) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Leonardo Bras , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RESEND RFC PATCH v2 2/6] riscv/cmpxchg: Deduplicate cmpxchg() macros Date: Tue, 21 Mar 2023 04:42:45 -0300 Message-Id: <20230321074249.2221674-3-leobras@redhat.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230321074249.2221674-1-leobras@redhat.com> References: <20230321074249.2221674-1-leobras@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230321_004316_889550_6AEA8410 X-CRM114-Status: GOOD ( 10.15 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Every cmpxchg define (_relaxed, _acquire, _release, vanilla) contain it's own define for creating tmp variables and selecting the correct asm code for give variable size. All those defines are mostly the same code (other than specific barriers), so there is no need to keep the 4 copies. Unify those under a more general define, that can reproduce the previous 4 versions. (This did not cause any change in generated asm) Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/cmpxchg.h | 72 ++++++-------------------------- 1 file changed, 12 insertions(+), 60 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 21984d24cbfe7..c7a13eec4dbcc 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -164,8 +164,8 @@ * indicated by comparing RETURN with OLD. */ -#define ___cmpxchg(lr_sfx, sc_sfx, prepend, append) \ -{ \ +#define ____cmpxchg(lr_sfx, sc_sfx, prepend, append) \ +({ \ __asm__ __volatile__ ( \ prepend \ "0: lr" lr_sfx " %0, %2\n" \ @@ -177,9 +177,9 @@ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "rJ" ((long)__old), "rJ" (__new) \ : "memory"); \ -} +}) -#define __cmpxchg_relaxed(ptr, old, new, size) \ +#define ___cmpxchg(ptr, old, new, size, sc_sfx, prepend, append) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ __typeof__(*(ptr)) __old = (old); \ @@ -188,10 +188,10 @@ register unsigned int __rc; \ switch (size) { \ case 4: \ - ___cmpxchg(".w", ".w", "", ""); \ + ____cmpxchg(".w", ".w" sc_sfx, prepend, append); \ break; \ case 8: \ - ___cmpxchg(".d", ".d", "", ""); \ + ____cmpxchg(".d", ".d" sc_sfx, prepend, append); \ break; \ default: \ BUILD_BUG(); \ @@ -199,6 +199,9 @@ __ret; \ }) +#define __cmpxchg_relaxed(ptr, old, new, size) \ + ___cmpxchg(ptr, old, new, size, "", "", "") + #define arch_cmpxchg_relaxed(ptr, o, n) \ ({ \ __typeof__(*(ptr)) _o_ = (o); \ @@ -208,24 +211,7 @@ }) #define __cmpxchg_acquire(ptr, old, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(*(ptr)) __old = (old); \ - __typeof__(*(ptr)) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - register unsigned int __rc; \ - switch (size) { \ - case 4: \ - ___cmpxchg(".w", ".w", "", RISCV_ACQUIRE_BARRIER); \ - break; \ - case 8: \ - ___cmpxchg(".d", ".d", "", RISCV_ACQUIRE_BARRIER); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___cmpxchg(ptr, old, new, size, "", "", RISCV_ACQUIRE_BARRIER) #define arch_cmpxchg_acquire(ptr, o, n) \ ({ \ @@ -236,24 +222,7 @@ }) #define __cmpxchg_release(ptr, old, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(*(ptr)) __old = (old); \ - __typeof__(*(ptr)) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - register unsigned int __rc; \ - switch (size) { \ - case 4: \ - ___cmpxchg(".w", ".w", RISCV_RELEASE_BARRIER, ""); \ - break; \ - case 8: \ - ___cmpxchg(".d", ".d", RISCV_RELEASE_BARRIER, ""); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___cmpxchg(ptr, old, new, size, "", RISCV_RELEASE_BARRIER, "") #define arch_cmpxchg_release(ptr, o, n) \ ({ \ @@ -264,24 +233,7 @@ }) #define __cmpxchg(ptr, old, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(*(ptr)) __old = (old); \ - __typeof__(*(ptr)) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - register unsigned int __rc; \ - switch (size) { \ - case 4: \ - ___cmpxchg(".w", ".w.rl", "", " fence rw, rw\n"); \ - break; \ - case 8: \ - ___cmpxchg(".d", ".d.rl", "", " fence rw, rw\n"); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___cmpxchg(ptr, old, new, size, ".rl", "", " fence rw, rw\n") #define arch_cmpxchg(ptr, o, n) \ ({ \ -- 2.40.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv