From patchwork Tue Mar 21 07:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13182345 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 77BFEC74A5B for ; Tue, 21 Mar 2023 07:43:22 +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=oHlaSvdYs2O34Rvqk4uzYlnDqd6whwD1u4mAQ1Z6i8A=; b=bwe+OHUW7EzYuj WHAgEDdqZm+LSAGt6rPx9fWZhvztO7d3sROTFvbySSEDH58ySjWNLSY6Y2sWRh46NTF2w63QR+gFB YUPNUSyEltXwoedyrvhzGNW6cZ5luKSZuB9413Be0VoluQI+HYR5OSMzSs8bRRolcJl/1xt1hpWYW 3x4sFneA9kVCm7hcwEcoCsGKrIZQYCp4QtMIgAQXkAHKVcmV1UVnMDXH0jA88BEHSio7VS0WFtqsO 7K+jTP+2tP8yX6bnIzUej5Y8UBgr0thlDi5k/ww8pwZ6rv1GAZzc49icps8rskWXEACfVUT4j0HXu fX+FIVdFnAw8jMdVUNwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peWeH-00BZHk-2h; Tue, 21 Mar 2023 07:43:13 +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 1peWeE-00BZFe-1c for linux-riscv@lists.infradead.org; Tue, 21 Mar 2023 07:43:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679384586; 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=/yn+twTZLAkRdUYrcTaC/OxuB+ZzmlZ8IAyD5qH6ScI=; b=NBJ+lXR+Q5GOG2hhH7wbJ5MohgEgkjSjIM73FQDLFfCC2CfyaslrxPDGkq/ICi+LXhNDdI I510Se+zZVVqjEiv4yrkP5NT8G+fjacO1o6Btn8KoBgynFe2zGRl0IEfUYBViYWuWGK2Gz 57i396Qu18gc87miphb21KHtNTvEuU4= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-rwRxPin6NUiQSJS7m_qyTw-1; Tue, 21 Mar 2023 03:43:05 -0400 X-MC-Unique: rwRxPin6NUiQSJS7m_qyTw-1 Received: by mail-oi1-f199.google.com with SMTP id bf33-20020a056808192100b003872286998bso425620oib.23 for ; Tue, 21 Mar 2023 00:43:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679384584; 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=/yn+twTZLAkRdUYrcTaC/OxuB+ZzmlZ8IAyD5qH6ScI=; b=Z+NlX8SGvgGrWWHKtExsG2yFKxMzDTxVTeqZMwI2jkrOUYtIyb8CwZdzaZIV5Nl7t4 yV0MK3MfoboK5dw3raY2I8qX8NlCzymLNQZk1QfoWasA6Gon6DogY+9zOJ+g2RF4njQl L7slfhuMDrgo7j8eKy8slV6xUtIPR/QR6Pr2BoEZaSGB7dHAaFd/OhJQjucLBk4ynvGu Uo3jXjAnmoDzvQK33udaEgdpfpWI8HzkjuXlC0lZbcPNB5WhQ9/bfaQ41E0AdgZSnKF0 5Qfr5L1WoLWEiUxJe410GFx+DfM9s0pzlB1HY2VAI4ONgV7ZyItudP9X/zMEBZmvOY2i KDMg== X-Gm-Message-State: AO0yUKXIpKKPZb32GWhut7pHguwOM5Cr59e4xVm3k3lX8IhD7zzlpNFD bNZ/DTk4X+vKUJv2AmSah7eIJgCqbTn/FiO78m4CZdeozg18KZMdR0zxzILaPYln1M6RT8tc7St hoK7EGH7Ltld2ofksiiV91CEkW5mzWVlsJ1eTpcU= X-Received: by 2002:a05:6870:d38f:b0:177:9a8f:2a6a with SMTP id k15-20020a056870d38f00b001779a8f2a6amr638646oag.6.1679384584385; Tue, 21 Mar 2023 00:43:04 -0700 (PDT) X-Google-Smtp-Source: AK7set+5dYLqUwBoGwWqYbNO6rmNI6RXPTyQIcUwdLTaU41SFvlJEUkqNzr5SVTeAvo9r89hTVkcJg== X-Received: by 2002:a05:6870:d38f:b0:177:9a8f:2a6a with SMTP id k15-20020a056870d38f00b001779a8f2a6amr638640oag.6.1679384584181; Tue, 21 Mar 2023 00:43:04 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 00:43:03 -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 1/6] riscv/cmpxchg: Deduplicate cmpxchg() asm functions Date: Tue, 21 Mar 2023 04:42:44 -0300 Message-Id: <20230321074249.2221674-2-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_004310_633632_E261D5C8 X-CRM114-Status: GOOD ( 10.48 ) 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: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In this header every cmpxchg define (_relaxed, _acquire, _release, vanilla) contain it's own asm file, both for 4-byte variables an 8-byte variables, on a total of 8 versions of mostly the same asm. This is usually bad, as it means any change may be done in up to 8 different places. Unify those versions by creating a new define with enough parameters to generate any version of the previous 8. (This did not cause any change in generated asm) Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/cmpxchg.h | 102 ++++++++----------------------- 1 file changed, 24 insertions(+), 78 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 12debce235e52..21984d24cbfe7 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -163,6 +163,22 @@ * store NEW in MEM. Return the initial value in MEM. Success is * indicated by comparing RETURN with OLD. */ + +#define ___cmpxchg(lr_sfx, sc_sfx, prepend, append) \ +{ \ + __asm__ __volatile__ ( \ + prepend \ + "0: lr" lr_sfx " %0, %2\n" \ + " bne %0, %z3, 1f\n" \ + " sc" sc_sfx " %1, %z4, %2\n" \ + " bnez %1, 0b\n" \ + append \ + "1:\n" \ + : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ + : "rJ" ((long)__old), "rJ" (__new) \ + : "memory"); \ +} + #define __cmpxchg_relaxed(ptr, old, new, size) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ @@ -172,26 +188,10 @@ register unsigned int __rc; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - "0: lr.w %0, %2\n" \ - " bne %0, %z3, 1f\n" \ - " sc.w %1, %z4, %2\n" \ - " bnez %1, 0b\n" \ - "1:\n" \ - : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ - : "rJ" ((long)__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".w", ".w", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - "0: lr.d %0, %2\n" \ - " bne %0, %z3, 1f\n" \ - " sc.d %1, %z4, %2\n" \ - " bnez %1, 0b\n" \ - "1:\n" \ - : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ - : "rJ" (__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".d", ".d", "", ""); \ break; \ default: \ BUILD_BUG(); \ @@ -216,28 +216,10 @@ register unsigned int __rc; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - "0: lr.w %0, %2\n" \ - " bne %0, %z3, 1f\n" \ - " sc.w %1, %z4, %2\n" \ - " bnez %1, 0b\n" \ - RISCV_ACQUIRE_BARRIER \ - "1:\n" \ - : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ - : "rJ" ((long)__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".w", ".w", "", RISCV_ACQUIRE_BARRIER); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - "0: lr.d %0, %2\n" \ - " bne %0, %z3, 1f\n" \ - " sc.d %1, %z4, %2\n" \ - " bnez %1, 0b\n" \ - RISCV_ACQUIRE_BARRIER \ - "1:\n" \ - : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ - : "rJ" (__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".d", ".d", "", RISCV_ACQUIRE_BARRIER); \ break; \ default: \ BUILD_BUG(); \ @@ -262,28 +244,10 @@ register unsigned int __rc; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - RISCV_RELEASE_BARRIER \ - "0: lr.w %0, %2\n" \ - " bne %0, %z3, 1f\n" \ - " sc.w %1, %z4, %2\n" \ - " bnez %1, 0b\n" \ - "1:\n" \ - : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ - : "rJ" ((long)__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".w", ".w", RISCV_RELEASE_BARRIER, ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - RISCV_RELEASE_BARRIER \ - "0: lr.d %0, %2\n" \ - " bne %0, %z3, 1f\n" \ - " sc.d %1, %z4, %2\n" \ - " bnez %1, 0b\n" \ - "1:\n" \ - : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ - : "rJ" (__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".d", ".d", RISCV_RELEASE_BARRIER, ""); \ break; \ default: \ BUILD_BUG(); \ @@ -308,28 +272,10 @@ register unsigned int __rc; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - "0: lr.w %0, %2\n" \ - " bne %0, %z3, 1f\n" \ - " sc.w.rl %1, %z4, %2\n" \ - " bnez %1, 0b\n" \ - " fence rw, rw\n" \ - "1:\n" \ - : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ - : "rJ" ((long)__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".w", ".w.rl", "", " fence rw, rw\n"); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - "0: lr.d %0, %2\n" \ - " bne %0, %z3, 1f\n" \ - " sc.d.rl %1, %z4, %2\n" \ - " bnez %1, 0b\n" \ - " fence rw, rw\n" \ - "1:\n" \ - : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ - : "rJ" (__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".d", ".d.rl", "", " fence rw, rw\n"); \ break; \ default: \ BUILD_BUG(); \ From patchwork Tue Mar 21 07:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13182350 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: , 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) \ ({ \ From patchwork Tue Mar 21 07:42:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13182347 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 140C9C761A6 for ; Tue, 21 Mar 2023 07:43:23 +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=wUtW1eAZWGEOfeyOSBO3h233r8JnOnPh0aQ+a6Y2lwg=; b=POHZ2sfxb2QUWY 7nyXEPAPKyw7h+sIi+S5dzf0B0usSE0K0WvSoJ22JPbdmTdpCDFBomZD2bO3Nz694rurBrp7XJ87S Ce7iZtFX30SD1770iELks99Yq4pO420ykdHJI08x6B1YwBDCGcBuDVIxmDIZH1szgCf6D6AOlmiaQ CZwVl+DwoaebbzuKAqlbPQLlyi9a/0JWU8NJSag+XFQY/r/JcAmKkXY2VaiNkxworX7xgfDMJ/dCg U4na+il+vSY6CYptp+j/y/LHWgs0N9b5eZqud8p+XVlX5ET/IBF6HE8jASziMSXuZMBzkM++Om+bM huRHZiPgFPryxuWVqQDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peWeK-00BZJP-1e; Tue, 21 Mar 2023 07:43:16 +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 1peWeF-00BZGj-1j for linux-riscv@lists.infradead.org; Tue, 21 Mar 2023 07:43:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679384590; 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=XMfpmYwfPn+xgsAmrLdh6YxWI9aM4T+CUsR5ROJOFiM=; b=WXiTzDC1bvLxbtXhvDjowZ15d0F0JuknS25XaCLKpxGtQmaLHOGIymO557NBDzKPIdrUk0 Apvw/9Uzn7KE6wD5gFqmT8Peuu0n22lLMNEiznDLe3N+FTNmDUHP8uQW3yN75ey4Y1s3Ob AvNkLJ2YrXNLO38u1eYPyUZO00OTEXU= Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-FO0vn2k9N8uy0MDmsGTcdQ-1; Tue, 21 Mar 2023 03:43:09 -0400 X-MC-Unique: FO0vn2k9N8uy0MDmsGTcdQ-1 Received: by mail-ot1-f70.google.com with SMTP id n2-20020a9d6f02000000b0069f0faa4f7fso3444939otq.14 for ; Tue, 21 Mar 2023 00:43:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679384589; 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=XMfpmYwfPn+xgsAmrLdh6YxWI9aM4T+CUsR5ROJOFiM=; b=w1c4HtEXEhfBbBniHi1r0R0h+nRQrUVFIUULdQZnyyiV/MPAP9JintGcEsaSMLRdIX Tl3G95UzuI4ppFanTDNDKcRud3JrEPPaHOprFKld4nriPb1R8OK7Hab/g5kTe766gCwD sqmypJ0gemOm/K+pVmyhGzYTgNVUG80MordBF0ZO1MYkHaG7Fl3JdIgEV/PJXRoq5c6/ +++zrM7+/tsF8R+L8uxo7I4ZHvAKCpcdSR2nGhqSdldudfF8WGWxv8rAb7Yyst3HG9am pAZY42ldi3BI9YEGscsrLlND7yhE/7L30eFYnWOczcC/ZU8MRj+XeL/GBYzD2oAI1Bf1 XbsQ== X-Gm-Message-State: AO0yUKXju+P5RAX91Mz6IAlyQci93v0AVBC3PC2nsHX6IQOLCYf2YFW8 2MXUZOrnSyKZ52fKQYd3etxHql5SII3W/wm70K1itDhazEO5uYlN2gXto7vkX2RaqL00NE7Y24q YLxekLynQMeY0Uf7+rgFAt3qJGaHriU6bXJalJ/0= X-Received: by 2002:a05:6870:a686:b0:172:3d71:c248 with SMTP id i6-20020a056870a68600b001723d71c248mr667010oam.18.1679384588864; Tue, 21 Mar 2023 00:43:08 -0700 (PDT) X-Google-Smtp-Source: AK7set//h+rt/5rnzWZgDMDSljtrlf8yFkWx80HQCLbvaD/XbP8sCxWepJibqGOFz3BE31CrO/dz9g== X-Received: by 2002:a05:6870:a686:b0:172:3d71:c248 with SMTP id i6-20020a056870a68600b001723d71c248mr667004oam.18.1679384588690; Tue, 21 Mar 2023 00:43:08 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 00:43:08 -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 3/6] riscv/cmpxchg: Deduplicate arch_cmpxchg() macros Date: Tue, 21 Mar 2023 04:42:46 -0300 Message-Id: <20230321074249.2221674-4-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_004311_672071_C7344F58 X-CRM114-Status: UNSURE ( 9.34 ) X-CRM114-Notice: Please train this message. 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: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Every arch_cmpxchg define (_relaxed, _acquire, _release, vanilla) contain it's own define for creating tmp variables and calling the correct internal macro for the desired version. Those defines are mostly the same code, so there is no need to keep the 4 copies. Create a helper define to avoid code duplication. (This did not cause any change in generated asm) Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/cmpxchg.h | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index c7a13eec4dbcc..e49a2edc6f36c 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -202,46 +202,35 @@ #define __cmpxchg_relaxed(ptr, old, new, size) \ ___cmpxchg(ptr, old, new, size, "", "", "") -#define arch_cmpxchg_relaxed(ptr, o, n) \ +#define _arch_cmpxchg(order, ptr, o, n) \ ({ \ __typeof__(*(ptr)) _o_ = (o); \ __typeof__(*(ptr)) _n_ = (n); \ - (__typeof__(*(ptr))) __cmpxchg_relaxed((ptr), \ - _o_, _n_, sizeof(*(ptr))); \ + (__typeof__(*(ptr))) __cmpxchg ## order((ptr), \ + _o_, _n_, \ + sizeof(*(ptr)));\ }) +#define arch_cmpxchg_relaxed(ptr, o, n) \ + _arch_cmpxchg(_relaxed, ptr, o, n) + #define __cmpxchg_acquire(ptr, old, new, size) \ ___cmpxchg(ptr, old, new, size, "", "", RISCV_ACQUIRE_BARRIER) #define arch_cmpxchg_acquire(ptr, o, n) \ -({ \ - __typeof__(*(ptr)) _o_ = (o); \ - __typeof__(*(ptr)) _n_ = (n); \ - (__typeof__(*(ptr))) __cmpxchg_acquire((ptr), \ - _o_, _n_, sizeof(*(ptr))); \ -}) + _arch_cmpxchg(_acquire, ptr, o, n) #define __cmpxchg_release(ptr, old, new, size) \ ___cmpxchg(ptr, old, new, size, "", RISCV_RELEASE_BARRIER, "") #define arch_cmpxchg_release(ptr, o, n) \ -({ \ - __typeof__(*(ptr)) _o_ = (o); \ - __typeof__(*(ptr)) _n_ = (n); \ - (__typeof__(*(ptr))) __cmpxchg_release((ptr), \ - _o_, _n_, sizeof(*(ptr))); \ -}) + _arch_cmpxchg(_release, ptr, o, n) #define __cmpxchg(ptr, old, new, size) \ ___cmpxchg(ptr, old, new, size, ".rl", "", " fence rw, rw\n") #define arch_cmpxchg(ptr, o, n) \ -({ \ - __typeof__(*(ptr)) _o_ = (o); \ - __typeof__(*(ptr)) _n_ = (n); \ - (__typeof__(*(ptr))) __cmpxchg((ptr), \ - _o_, _n_, sizeof(*(ptr))); \ -}) + _arch_cmpxchg(, ptr, o, n) #define arch_cmpxchg_local(ptr, o, n) \ (__cmpxchg_relaxed((ptr), (o), (n), sizeof(*(ptr)))) From patchwork Tue Mar 21 07:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13182348 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 0D019C761AF for ; Tue, 21 Mar 2023 07:43:24 +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=saoOx5kjOYkSuSZCZC2GGU7PuZmKQ1e89W7xPHUSBxI=; b=tbTykpsD4qrsWQ GNiNx1nnqqPcE8Rn0s3Pm5aUJ+Ty3fErXGrQoM+P/xtbCLGEzIJbx4blhnTLwizyC2zbCobD8QAck Cb6YpVyhhHlpjZJH29kOi2koFeilqazwTFIt3v8OD0RDivF4ei4xxnSvfMeBBgl+L+id8OTYEhCMt sg7aUBBJ9/2UDsdKPAycP4X0Q4rXkwFFShagy4mPjIH7Zs+iECo4WkYNZrjkgVY55UCQ1xUnFgjeQ lzBfH1+EeTks8vw12Od2ww4g5a9Np8uVAHaosiLgLhAOkooQhpru90Xuf0v8j2Fq4lksPD6akyZBW kX15luzateOesAx16xhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peWeL-00BZJx-0i; Tue, 21 Mar 2023 07:43:17 +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 1peWeH-00BZHW-2H for linux-riscv@lists.infradead.org; Tue, 21 Mar 2023 07:43:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679384592; 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=uYmUB/WTTMvmBA0Z285enRAA2vTEDkWBaww5wTiZcXo=; b=AYyI7Zu/SznV60SGKzm7raLl9TjszWFAoeBM1rlqiPA0P/cCwehclTrcgFCrq4GR6GhI85 olEDkVdvN6wwcTz3iJKh6ULLBG4QRy5Qf3/xrG7zt8BDbHRM83JpjmfJpxYkdolQPOw54h OpWT0RGnw/fBbvvrwvCh6g7euzZe72I= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-LK9OjiVCPhK-pqoMeVHLRg-1; Tue, 21 Mar 2023 03:43:12 -0400 X-MC-Unique: LK9OjiVCPhK-pqoMeVHLRg-1 Received: by mail-oi1-f199.google.com with SMTP id n205-20020acabdd6000000b003846654dd65so6168803oif.19 for ; Tue, 21 Mar 2023 00:43:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679384591; 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=uYmUB/WTTMvmBA0Z285enRAA2vTEDkWBaww5wTiZcXo=; b=EAJwnQpbcMX4BmYJ/RajEOxUEsX3TR0L0jiCiM6yy/MPQJVkJps7BWIA8cSBzXk2nQ lm4cOAAHN/qGR0zLrIYL50kcQIjYVW/SmNB+h4ErWb5K+uvq6O84l5xY2fNGrAIjrXGy ugnyo0n5E9JvMg/OJP3/XOHCUJzBypis1BjcXqPvWZ2lyKh0QXCIAuEtdzznfxdkMiF5 dlv74fFiwpmoL6Qbm2H75hUnIZTtfKl2Xu5z0hlJvtiQJcFxfZvuLvUwgt+FQ4s4aadu o05rnFsYqrLtgvtz/+pKSxHyl0Y1nbfw4XuNygZBEwVQLqO6OLEHWThTy+9E2RHBIumz WHVw== X-Gm-Message-State: AO0yUKWWd48yU04ErLJ3H2GotwtkSB81v10J4dLBRLF6XhkEA6QKPU96 1Yu7HvWeIwcohOU6zeqNXb6pzQAg2mf6E7oevSsKf1zXAFv4R0g6zQhI0m5kh0WLxNezFVIkeIC utVu9I0clO41Oxuws2jHkrqki30xl X-Received: by 2002:a05:6870:6087:b0:16e:1aeb:d74b with SMTP id t7-20020a056870608700b0016e1aebd74bmr546842oae.33.1679384591350; Tue, 21 Mar 2023 00:43:11 -0700 (PDT) X-Google-Smtp-Source: AK7set8yT5HfmiKYU2SyLBb4cWhTZvsC1XCp0Rm1hcaLuS/6AU2e8J3Z++XLxX8CXeUurrVlfilkRQ== X-Received: by 2002:a05:6870:6087:b0:16e:1aeb:d74b with SMTP id t7-20020a056870608700b0016e1aebd74bmr546832oae.33.1679384590919; Tue, 21 Mar 2023 00:43:10 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 00:43:10 -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 4/6] riscv/cmpxchg: Deduplicate xchg() asm functions Date: Tue, 21 Mar 2023 04:42:47 -0300 Message-Id: <20230321074249.2221674-5-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_004313_826588_39A1C1D9 X-CRM114-Status: GOOD ( 10.54 ) 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: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In this header every xchg define (_relaxed, _acquire, _release, vanilla) contain it's own asm file, both for 4-byte variables an 8-byte variables, on a total of 8 versions of mostly the same asm. This is usually bad, as it means any change may be done in up to 8 different places. Unify those versions by creating a new define with enough parameters to generate any version of the previous 8. (This did not cause any change in generated asm) Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/cmpxchg.h | 63 ++++++++++---------------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index e49a2edc6f36c..715bf61e72c82 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -11,6 +11,17 @@ #include #include +#define ___xchg(sfx, prepend, append) \ +({ \ + __asm__ __volatile__ ( \ + prepend \ + " amoswap" sfx " %0, %2, %1\n" \ + append \ + : "=r" (__ret), "+A" (*__ptr) \ + : "r" (__new) \ + : "memory"); \ +}) + #define __xchg_relaxed(ptr, new, size) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ @@ -18,18 +29,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", "", ""); \ break; \ default: \ BUILD_BUG(); \ @@ -51,20 +54,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w %0, %2, %1\n" \ - RISCV_ACQUIRE_BARRIER \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", "", RISCV_ACQUIRE_BARRIER); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d %0, %2, %1\n" \ - RISCV_ACQUIRE_BARRIER \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", "", RISCV_ACQUIRE_BARRIER); \ break; \ default: \ BUILD_BUG(); \ @@ -86,20 +79,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - RISCV_RELEASE_BARRIER \ - " amoswap.w %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", RISCV_RELEASE_BARRIER, ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - RISCV_RELEASE_BARRIER \ - " amoswap.d %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", RISCV_RELEASE_BARRIER, ""); \ break; \ default: \ BUILD_BUG(); \ @@ -121,18 +104,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w.aqrl %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w.aqrl", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d.aqrl %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d.aqrl", "", ""); \ break; \ default: \ BUILD_BUG(); \ From patchwork Tue Mar 21 07:42:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13182349 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 558C6C6FD1D 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=6dH59x81M0Xxt/TW605N5K2lz+7ZwyyEQrFctVsSr0o=; b=uZewoII14l4ixX 1lm3jsXvR9/oWWDnJOq9YEUuIAnm8S/ywJYXG7ULV2CMjjM/TtxKS6YO4U5fwkapeJ/aaR2qCldG9 pIPsH0xIk2OWYnfzrcZGOxpjkeCgaZJ1gzTW+uX3ew1Z1HCVnqkpJuAid4JiU9XYCq0Ux6VNR3wKO l0Rk2zokTwofZmaaFKDforANzpexWo1rP18IuBGKCaMPCE8yPY2EP9t7IEpNzky7PGeXor5lUcfCu XSWs5x2Jfx5l7X/LcEwZui3k+VxVvcNSwDk7IYI7mqwbByvTxmq0KR/B4b4wbI0zOdAv2yzOhHd9A /ozRxvFKwBs4Nqp1xGlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peWeP-00BZLl-0B; 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-00BZIe-0E for linux-riscv@lists.infradead.org; Tue, 21 Mar 2023 07:43:17 +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=tlcmKFBm9EfeLOX/A4Ek+TTZZd7OjXZ+kA7z9b9Tay8=; b=atgDFtI6qe3p9INYrjxx1njWt33NDqzHv2/Zqsr7qMFCrVub1enB1BtCCiAX41ThgKk+C+ dCASaI+3wLr6IkDRKoavPs+b8ubRJxd8caOJNzemRKiPXXzh/ngF4Sw4+h2CrpQqarg8Ku 4G46cRijN7Q9nF0pRc4YvUwEXuLXiok= Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-491-nEuhjdkgMUqUufC8AiO0cA-1; Tue, 21 Mar 2023 03:43:14 -0400 X-MC-Unique: nEuhjdkgMUqUufC8AiO0cA-1 Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-17e11dd9a3dso3787238fac.10 for ; Tue, 21 Mar 2023 00:43:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679384593; 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=tlcmKFBm9EfeLOX/A4Ek+TTZZd7OjXZ+kA7z9b9Tay8=; b=LIOLR2bkhQNx5AsyalwKYdtKWiU8v2hOkAuUz/PvCbL/P2S/cOGvrYcPnUEuxTdN1T RDU9wuC4TtB5q9v8OG6KkCDNg1Fiq6pT8F11iF2T1NL+t+zPHr34p3foMNeAIcQqI4IH fJ3GsHi2hx6UQiZuIqMSNNPOiDPq7nD/gU5roMNw0fRxydW910KYXwHAC1a3SS4jbKuz mNuQ5T2H5UumNd4sS9BpIUv7OVL55xZDqVfql9usPMiN48iYsun0Bx+7KkgDKMP/Q9jE ET1puzB/XmUZEqDq0MBOKbLEBc+iMf6rQrudcQgbc1x+RDj+TpdWObkpLksMiAOFg17A gdIA== X-Gm-Message-State: AO0yUKVb7NfJPz2YX/87S3fzo03QZ8QoVzF+/jWQy6gK5SoPRhUpvUKn +t+vcxBn9qGjLqF9ZLVCFt6asoxQB6szsuh/+EmAWe/TMWuhc1Z+aTOaVSJcyv6E3CRMuy/pe15 JwKkbGFcLBGogEeE4L5OL32JiCVYS X-Received: by 2002:a05:6870:17a1:b0:17e:5166:e5ad with SMTP id r33-20020a05687017a100b0017e5166e5admr561226oae.44.1679384593434; Tue, 21 Mar 2023 00:43:13 -0700 (PDT) X-Google-Smtp-Source: AK7set/pyAqYnO67AML+s1dNtvHd917Gw9QhFgk20X96rex8UneHTfhT63wtlM0E2stD1HimfqKP8w== X-Received: by 2002:a05:6870:17a1:b0:17e:5166:e5ad with SMTP id r33-20020a05687017a100b0017e5166e5admr561219oae.44.1679384593178; Tue, 21 Mar 2023 00:43:13 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 00:43:12 -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 5/6] riscv/cmpxchg: Deduplicate xchg() macros Date: Tue, 21 Mar 2023 04:42:48 -0300 Message-Id: <20230321074249.2221674-6-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_200670_FBBB2783 X-CRM114-Status: GOOD ( 10.35 ) 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: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Every xchg define (_relaxed, _acquire, _release, vanilla) contain it's own define for creating tmp variables and selecting the correct asm code for given 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 | 62 ++++++-------------------------- 1 file changed, 10 insertions(+), 52 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 715bf61e72c82..23da4d8e6f0c8 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -11,7 +11,7 @@ #include #include -#define ___xchg(sfx, prepend, append) \ +#define ____xchg(sfx, prepend, append) \ ({ \ __asm__ __volatile__ ( \ prepend \ @@ -22,17 +22,17 @@ : "memory"); \ }) -#define __xchg_relaxed(ptr, new, size) \ +#define ___xchg(ptr, new, size, sfx, prepend, append) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ __typeof__(new) __new = (new); \ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - ___xchg(".w", "", ""); \ + ____xchg(".w" sfx, prepend, append); \ break; \ case 8: \ - ___xchg(".d", "", ""); \ + ____xchg(".d" sfx, prepend, append); \ break; \ default: \ BUILD_BUG(); \ @@ -40,6 +40,9 @@ __ret; \ }) +#define __xchg_relaxed(ptr, new, size) \ + ___xchg(ptr, new, size, "", "", "") + #define arch_xchg_relaxed(ptr, x) \ ({ \ __typeof__(*(ptr)) _x_ = (x); \ @@ -48,22 +51,7 @@ }) #define __xchg_acquire(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - switch (size) { \ - case 4: \ - ___xchg(".w", "", RISCV_ACQUIRE_BARRIER); \ - break; \ - case 8: \ - ___xchg(".d", "", RISCV_ACQUIRE_BARRIER); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___xchg(ptr, new, size, "", "", RISCV_ACQUIRE_BARRIER) #define arch_xchg_acquire(ptr, x) \ ({ \ @@ -73,22 +61,7 @@ }) #define __xchg_release(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - switch (size) { \ - case 4: \ - ___xchg(".w", RISCV_RELEASE_BARRIER, ""); \ - break; \ - case 8: \ - ___xchg(".d", RISCV_RELEASE_BARRIER, ""); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___xchg(ptr, new, size, "", RISCV_RELEASE_BARRIER, "") #define arch_xchg_release(ptr, x) \ ({ \ @@ -98,22 +71,7 @@ }) #define __xchg(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - switch (size) { \ - case 4: \ - ___xchg(".w.aqrl", "", ""); \ - break; \ - case 8: \ - ___xchg(".d.aqrl", "", ""); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___xchg(ptr, new, size, ".aqrl", "", "") #define arch_xchg(ptr, x) \ ({ \ From patchwork Tue Mar 21 07:42:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13182351 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 460E7C74A5B for ; Tue, 21 Mar 2023 07:43:32 +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=zrd1Z1+2UIuJEzwFK2800IC971An8Ra7ejujlUZG86I=; b=HSFWzw6+i2R48Y C0qYPs82uJhSfcYq4CYb9bV4eaunV/e2ZaT1z26Z2MeIKGrh4gB7NO9qJTvn533t0iyRi8j7uzxlT cnz+USZKkT0MEMNWLTLOTqlmsSA8diwWkKOFHmES+pBfK6MFu58zAey7qiBcWdMtjlqOMZyxIaKS2 r6VPfo4m7hVSO37cv3WQHjwvHm4MyL80Y6xeHCl53BfsoQrzJxxMsJghhN1LbcQaAorC3+8tMvZan EYOCwuPU3y0ybmQXEBIifzMEIR+NRk3oTmo9NFxr5hTkJ7Be+gIulBh5Ls8t7mlhG0lpJWId7zqHn lcRyyqDZrAoEn+b2H4Uw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peWeT-00BZOQ-1K; Tue, 21 Mar 2023 07:43:25 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1peWeP-00BZKW-1K for linux-riscv@lists.infradead.org; Tue, 21 Mar 2023 07:43:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679384597; 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=lpwvsmW/EIvjt3XpmgOB2tOjIn+1scWXRJYbQwzYCy4=; b=cA62bt3jo3ssRH1swGyrwCbcRPWYD6oJAQqW3lVJQiuWwyGomZLobYpSq2ZogZZLA5m6ra Dn7eCW3AsO/EzcCOetrRAnGOrhm9Qv4sxNwFOzKHNzXgkR2rzOLaW4JZ8CY+tyMZaYzjB4 F7sPIQiuT++p3OMGm7bLX2S+oNmw+JE= 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-280-khJLA3VYMyCVFK12QKdP-A-1; Tue, 21 Mar 2023 03:43:16 -0400 X-MC-Unique: khJLA3VYMyCVFK12QKdP-A-1 Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-17e3d37b3e6so2504469fac.22 for ; Tue, 21 Mar 2023 00:43:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679384595; 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=lpwvsmW/EIvjt3XpmgOB2tOjIn+1scWXRJYbQwzYCy4=; b=7VjX6nZ0aPyDjjoJsaqJHivTGidCrXw4bUubWzRYH/+NL3Otq89tz26fEg9RbXEwP/ OD8Snh3iXiSXTa+9aekeTwjd+m/g2VHuF6BaQX5NoQmk8k9aSKoFkLkFeU6Xw3n/yCY9 uNYUC5WV2tfj8vKgfVPEE0t3qu1G8H9E0y8pXQI4PERO4fHm4Ryik9mVh5WXEmds6ZIQ Vq/22eC8jXcNe+ly18bk56qkDWmIsnkVXCznCpc2TjruIexEfuKR+QoJZ3siaWswX0Fn NUO2EvuWtHld5iEauZShybdIFVwIdE2fEfZzGGNZSDoKCaBuOJfJaJO0h2SqiPjacLYA C+Ig== X-Gm-Message-State: AO0yUKVTJ29UJ7vg43J0D53gZh1PtKu8YRD29ltYY4E13zN3zSKuI4Qw Z2LcyakZYJT9QNDFM55tey9Xgsq6Zo3xZiidKSlrBtVx4sIXQaFeAmZGo27Cs0J3cu3hSeAlJQN ra5Gow95W1XW0NEv/nSjY3aEBlgZRfMtjPa5vIh8= X-Received: by 2002:a05:6870:96a3:b0:17a:aa09:5e2d with SMTP id o35-20020a05687096a300b0017aaa095e2dmr792356oaq.2.1679384595730; Tue, 21 Mar 2023 00:43:15 -0700 (PDT) X-Google-Smtp-Source: AK7set+xdtuBzqIzRLUy5fOxuDWGKLvUOQjLd8NO8+P4+E/SVNozGANIGtgUzqns1gUz4+yOt3JNVg== X-Received: by 2002:a05:6870:96a3:b0:17a:aa09:5e2d with SMTP id o35-20020a05687096a300b0017aaa095e2dmr792348oaq.2.1679384595495; Tue, 21 Mar 2023 00:43:15 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 00:43:15 -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 6/6] riscv/cmpxchg: Deduplicate arch_xchg() macros Date: Tue, 21 Mar 2023 04:42:49 -0300 Message-Id: <20230321074249.2221674-7-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_004321_552171_886184B0 X-CRM114-Status: UNSURE ( 9.51 ) X-CRM114-Notice: Please train this message. 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: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Every arch_xchg define (_relaxed, _acquire, _release, vanilla) contain it's own define for creating tmp variables and calling the correct internal macro for the desired version. Those defines are mostly the same code, so there is no need to keep the 4 copies. Create a helper define to avoid code duplication. (This did not cause any change in generated asm) Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/cmpxchg.h | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 23da4d8e6f0c8..d13da2286c82a 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -43,41 +43,33 @@ #define __xchg_relaxed(ptr, new, size) \ ___xchg(ptr, new, size, "", "", "") -#define arch_xchg_relaxed(ptr, x) \ +#define _arch_xchg(order, ptr, x) \ ({ \ __typeof__(*(ptr)) _x_ = (x); \ - (__typeof__(*(ptr))) __xchg_relaxed((ptr), \ - _x_, sizeof(*(ptr))); \ + (__typeof__(*(ptr))) __xchg ## order((ptr), \ + _x_, sizeof(*(ptr))); \ }) +#define arch_xchg_relaxed(ptr, x) \ + _arch_xchg(_relaxed, ptr, x) + #define __xchg_acquire(ptr, new, size) \ ___xchg(ptr, new, size, "", "", RISCV_ACQUIRE_BARRIER) #define arch_xchg_acquire(ptr, x) \ -({ \ - __typeof__(*(ptr)) _x_ = (x); \ - (__typeof__(*(ptr))) __xchg_acquire((ptr), \ - _x_, sizeof(*(ptr))); \ -}) + _arch_xchg(_acquire, ptr, x) #define __xchg_release(ptr, new, size) \ ___xchg(ptr, new, size, "", RISCV_RELEASE_BARRIER, "") #define arch_xchg_release(ptr, x) \ -({ \ - __typeof__(*(ptr)) _x_ = (x); \ - (__typeof__(*(ptr))) __xchg_release((ptr), \ - _x_, sizeof(*(ptr))); \ -}) + _arch_xchg(_release, ptr, x) #define __xchg(ptr, new, size) \ ___xchg(ptr, new, size, ".aqrl", "", "") #define arch_xchg(ptr, x) \ -({ \ - __typeof__(*(ptr)) _x_ = (x); \ - (__typeof__(*(ptr))) __xchg((ptr), _x_, sizeof(*(ptr))); \ -}) + _arch_xchg(, ptr, x) #define xchg32(ptr, x) \ ({ \