From nobody Sun Feb 8 14:11:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B616FC74A5B for ; Tue, 21 Mar 2023 07:44:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230107AbjCUHoA (ORCPT ); Tue, 21 Mar 2023 03:44:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbjCUHn5 (ORCPT ); Tue, 21 Mar 2023 03:43:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BFD55252 for ; Tue, 21 Mar 2023 00:43:07 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/yn+twTZLAkRdUYrcTaC/OxuB+ZzmlZ8IAyD5qH6ScI=; b=HsXhQXGtq8VocuhFzm9NsJZZxewh+a20SzX4L2elP1pBRza5t/gcVkFI3cB7ficS3UxGcd gSErxTCE8i984A3zuBukCnRsD0ivAn5uYeXKtC4X3ErIgA/tot08Q64LsiUNXm2fBFYbRQ 6eJNjRhhM++CSWde9b8V8eIKSpVxm/Y= Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-146-EEzNwstNO_61107J7_rtDg-1; Tue, 21 Mar 2023 03:43:05 -0400 X-MC-Unique: EEzNwstNO_61107J7_rtDg-1 Received: by mail-oo1-f71.google.com with SMTP id w5-20020a4a9785000000b0052521223553so4319822ooi.2 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=IGMYIHiAacvptDdaLdPv1/V6AlPgjBdgySHCR7zlGAZPaG8/4ulHVO+ym1A6SD4sg/ wIHIOEVHkA6L3v3nlBK55Wp/SSeEI1NObTHQiifNOwgVLAJX4ePqF987BfWdQstoau0E icVZuuMsjiPK77W8YDG7IA5r/cJD7hRFibaAcEQR8YVxQGiXAOUCq26UVC3jhGdYitr1 hjGY+gLKF5pClzB0BUgrkJvaQcT8ACWw6qUIhOolBm7lR/ztaSPGk2Vri7POBNh7gRdP 5m5a7RVvunBOcoXoZhTXIIJfam0lsKJ7M6/mhKZkTjbklxiYckz1NCmSw9aAs3yhMSec ZCEQ== X-Gm-Message-State: AO0yUKXf3c37Vu9MfGbdsVVGLSar7IBi9IdjfPk4VPiQoxvw/AXsTCZ7 l4f7W/8BHNJuCUdKC+0lGyv7lusq5naImMvdLEX/ZRLw47SbmKiN3XE1aAgUX2otfwbYJpERVmc OWOm5FoGC0txNe0eQBLLE6XUZ X-Received: by 2002:a05:6870:d38f:b0:177:9a8f:2a6a with SMTP id k15-20020a056870d38f00b001779a8f2a6amr638648oag.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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/cmpx= chg.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" \ + : "=3D&r" (__ret), "=3D&r" (__rc), "+A" (*__ptr) \ + : "rJ" ((long)__old), "rJ" (__new) \ + : "memory"); \ +} + #define __cmpxchg_relaxed(ptr, old, new, size) \ ({ \ __typeof__(ptr) __ptr =3D (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" \ - : "=3D&r" (__ret), "=3D&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" \ - : "=3D&r" (__ret), "=3D&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" \ - : "=3D&r" (__ret), "=3D&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" \ - : "=3D&r" (__ret), "=3D&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" \ - : "=3D&r" (__ret), "=3D&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" \ - : "=3D&r" (__ret), "=3D&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" \ - : "=3D&r" (__ret), "=3D&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" \ - : "=3D&r" (__ret), "=3D&r" (__rc), "+A" (*__ptr) \ - : "rJ" (__old), "rJ" (__new) \ - : "memory"); \ + ___cmpxchg(".d", ".d.rl", "", " fence rw, rw\n"); \ break; \ default: \ BUILD_BUG(); \ --=20 2.40.0 From nobody Sun Feb 8 14:11:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B87DCC74A5B for ; Tue, 21 Mar 2023 07:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbjCUHoI (ORCPT ); Tue, 21 Mar 2023 03:44:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbjCUHoC (ORCPT ); Tue, 21 Mar 2023 03:44:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FA653B21E for ; Tue, 21 Mar 2023 00:43:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679384588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TPnhvOcPIzsxcdPaGdi9oJi4cZ44pFeBuguAKI/S1NE=; b=JHYUv+hrEFkPdd9pBtsUBEDJmhcXaoDVsjL03cYhnTrMQzro1EnFAVUItSm/9iNN5GFVxk xzZ9ZG9GUAG9k6HZRsIaX2SSLeomEyQW8k+0rysgc2QvTfTbotfIlJpz3miRscNm/TD+B5 28yNcOKQfjc6ZVXRzP272uO7ZOf5mRo= Received: from mail-oa1-f72.google.com (mail-oa1-f72.google.com [209.85.160.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-270-JysRyL8iPsOLELlAyS4OXQ-1; Tue, 21 Mar 2023 03:43:07 -0400 X-MC-Unique: JysRyL8iPsOLELlAyS4OXQ-1 Received: by mail-oa1-f72.google.com with SMTP id 586e51a60fabf-17714741d9dso8122278fac.4 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=nD9KTceiCUMGcPbfImO/6+vDQ56tBp8XZVOmW3ESWhlH2JDjoNGDTUmnEWIBao2aHm cIBgup31aYkB4E/DJ7HZXt/v9uf5mxajBTlLcxNV/WDKPd93T9Dsbab4NYIx5Z/18npU fzQaPRZOZRB6/ed9gBWg6VFsGyik2jwE/T2lrpzqwsF5YEP+Q1s2W3ODHd4hOhmOt//B dBIS+2gZAJgS72nkNJCAHPDpjBhnx2Hm6fge40VGwhv8APxb//CiKVPmpvN4h04DLYyg 9G2IXbd9Mdg3c5Utz8vQpPmVUMQUkxOk274zhExfatTUPwR+rYxjDV0dtMcEvUt2qjPy Lk6Q== X-Gm-Message-State: AO0yUKV9mipB8iucTtjqDsUrYLbrHTeQKlNdIyiFhWIcoTq4Up7Kjopd wOf0YfKHNvDPkowChyEx6zzZ2cfauVHFUB10xvNShTb66lSEs4zdjGZ577Q0xSe42MUfSWybtgX qG68QU/GAaIT7WIyarb57A3Eh X-Received: by 2002:a05:6870:b022:b0:17a:f324:84ef with SMTP id y34-20020a056870b02200b0017af32484efmr443832oae.59.1679384586647; 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/cmpx= chg.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. */ =20 -#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 @@ : "=3D&r" (__ret), "=3D&r" (__rc), "+A" (*__ptr) \ : "rJ" ((long)__old), "rJ" (__new) \ : "memory"); \ -} +}) =20 -#define __cmpxchg_relaxed(ptr, old, new, size) \ +#define ___cmpxchg(ptr, old, new, size, sc_sfx, prepend, append) \ ({ \ __typeof__(ptr) __ptr =3D (ptr); \ __typeof__(*(ptr)) __old =3D (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; \ }) =20 +#define __cmpxchg_relaxed(ptr, old, new, size) \ + ___cmpxchg(ptr, old, new, size, "", "", "") + #define arch_cmpxchg_relaxed(ptr, o, n) \ ({ \ __typeof__(*(ptr)) _o_ =3D (o); \ @@ -208,24 +211,7 @@ }) =20 #define __cmpxchg_acquire(ptr, old, new, size) \ -({ \ - __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(*(ptr)) __old =3D (old); \ - __typeof__(*(ptr)) __new =3D (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) =20 #define arch_cmpxchg_acquire(ptr, o, n) \ ({ \ @@ -236,24 +222,7 @@ }) =20 #define __cmpxchg_release(ptr, old, new, size) \ -({ \ - __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(*(ptr)) __old =3D (old); \ - __typeof__(*(ptr)) __new =3D (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, "") =20 #define arch_cmpxchg_release(ptr, o, n) \ ({ \ @@ -264,24 +233,7 @@ }) =20 #define __cmpxchg(ptr, old, new, size) \ -({ \ - __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(*(ptr)) __old =3D (old); \ - __typeof__(*(ptr)) __new =3D (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") =20 #define arch_cmpxchg(ptr, o, n) \ ({ \ --=20 2.40.0 From nobody Sun Feb 8 14:11:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 057B8C74A5B for ; Tue, 21 Mar 2023 07:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230253AbjCUHoL (ORCPT ); Tue, 21 Mar 2023 03:44:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbjCUHoC (ORCPT ); Tue, 21 Mar 2023 03:44:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D20812BC0 for ; Tue, 21 Mar 2023 00:43:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679384591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XMfpmYwfPn+xgsAmrLdh6YxWI9aM4T+CUsR5ROJOFiM=; b=MSHiYrRYsot4pTzKm//qwphesOHsy8RZk7sbZxAStprBKYS56FxQKKPQwmi0Eo+o7q3kkO PO/D1MZ/GGwqprmBeBMoMyr3QeJnm6oyJDVhder2HniypwzyJL/AXX8ApZTr+1aCm7PCFg O2XahZBAFo/UYzuiy2S924Rxx4mydws= Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-Q_EhCMXZOeOgZyIssoa1dg-1; Tue, 21 Mar 2023 03:43:09 -0400 X-MC-Unique: Q_EhCMXZOeOgZyIssoa1dg-1 Received: by mail-ot1-f69.google.com with SMTP id a11-20020a05683012cb00b0068bdd21c8d7so6755145otq.2 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=SOu4jqpX6UtK23TfjHPKJ1kx88rZZoUMe+hEJnY4VTgh+6IS051eRllWp3ZSqxd9Gb V4FPEVpBmkkCK66QqTSOP1Wwpybjn0Mu3lRqzAw4MrU+mOGOmHK0cd4hzCuy18EKdhuf KfzHts8FeklpGm5KcQ/gTd7CQYmXG94atlDYWQx7EtTcNNVOX0lpJIMN9aiRHKlYNXfW Lyi1jQnWQd0EqiY4RVWHEay0dFO+BjrB+e4FL4N1g7zyWHatLSeI/mBMaRbQg7cIzMdQ qAhlB4MoguXRNVdfj+eNmYLO+7wUbP+M4gKyM064pN08b7Isdfx5o8BQiVuNUKdBtTNr ySog== X-Gm-Message-State: AO0yUKUfP5dpzD8Xy6fmZEiZmJ4Uowg1Cs/sZo1VMl03tP8C1wlz5YWY 5aCZ8FnfXgFs+/ONBwR4foG2o5RYjQTanq0rX8MXXILJx7VjUnBNp1OMcKGqNu8cSiT+7LiLpQY 6NYTvXUetkVyZEvQ8A/ib44LG X-Received: by 2002:a05:6870:a686:b0:172:3d71:c248 with SMTP id i6-20020a056870a68600b001723d71c248mr667007oam.18.1679384588863; 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/cmpx= chg.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, "", "", "") =20 -#define arch_cmpxchg_relaxed(ptr, o, n) \ +#define _arch_cmpxchg(order, ptr, o, n) \ ({ \ __typeof__(*(ptr)) _o_ =3D (o); \ __typeof__(*(ptr)) _n_ =3D (n); \ - (__typeof__(*(ptr))) __cmpxchg_relaxed((ptr), \ - _o_, _n_, sizeof(*(ptr))); \ + (__typeof__(*(ptr))) __cmpxchg ## order((ptr), \ + _o_, _n_, \ + sizeof(*(ptr)));\ }) =20 +#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) =20 #define arch_cmpxchg_acquire(ptr, o, n) \ -({ \ - __typeof__(*(ptr)) _o_ =3D (o); \ - __typeof__(*(ptr)) _n_ =3D (n); \ - (__typeof__(*(ptr))) __cmpxchg_acquire((ptr), \ - _o_, _n_, sizeof(*(ptr))); \ -}) + _arch_cmpxchg(_acquire, ptr, o, n) =20 #define __cmpxchg_release(ptr, old, new, size) \ ___cmpxchg(ptr, old, new, size, "", RISCV_RELEASE_BARRIER, "") =20 #define arch_cmpxchg_release(ptr, o, n) \ -({ \ - __typeof__(*(ptr)) _o_ =3D (o); \ - __typeof__(*(ptr)) _n_ =3D (n); \ - (__typeof__(*(ptr))) __cmpxchg_release((ptr), \ - _o_, _n_, sizeof(*(ptr))); \ -}) + _arch_cmpxchg(_release, ptr, o, n) =20 #define __cmpxchg(ptr, old, new, size) \ ___cmpxchg(ptr, old, new, size, ".rl", "", " fence rw, rw\n") =20 #define arch_cmpxchg(ptr, o, n) \ -({ \ - __typeof__(*(ptr)) _o_ =3D (o); \ - __typeof__(*(ptr)) _n_ =3D (n); \ - (__typeof__(*(ptr))) __cmpxchg((ptr), \ - _o_, _n_, sizeof(*(ptr))); \ -}) + _arch_cmpxchg(, ptr, o, n) =20 #define arch_cmpxchg_local(ptr, o, n) \ (__cmpxchg_relaxed((ptr), (o), (n), sizeof(*(ptr)))) --=20 2.40.0 From nobody Sun Feb 8 14:11:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B016C6FD1D for ; Tue, 21 Mar 2023 07:44:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230311AbjCUHoP (ORCPT ); Tue, 21 Mar 2023 03:44:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230234AbjCUHoF (ORCPT ); Tue, 21 Mar 2023 03:44:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E93973B646 for ; Tue, 21 Mar 2023 00:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679384593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uYmUB/WTTMvmBA0Z285enRAA2vTEDkWBaww5wTiZcXo=; b=NAWHlrzTgTylWKzWEeYUJBxJ3ylNkhLoVToWSMktSWnjrlarIThrp9O5wzwB6hhMlPCZFw a0ic32PmvlhYsy5+Tw3YLpuBAikP13a0rR2OGqNEuFGAbDAtcNafbF/BYVeMCXcqjGwnp7 /7UpiFLyod3SOR/EPU8Dfpv3aOTxhpA= Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-5BtWiOiXN4avUkJrDlqBmg-1; Tue, 21 Mar 2023 03:43:12 -0400 X-MC-Unique: 5BtWiOiXN4avUkJrDlqBmg-1 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-176347f3b28so8210070fac.23 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=lpbG6xIDv4X5Yp8mYfFFRm8ncTYCmdn7MSAmzKR4ep3dN7PaGhUKBb6gTfXcDofOYJ xhDRrupn7N1PovDOvsjtj9nKpjd/9ONAFn4o1TpHJWJ+5YGViN4VH8i0gif1zti/n6rh WDiM2D8jGs1HYw1F7YfwreJUHHjcxrrKPbM887Gpe3+4Ie5H6sfm2AkfcO//1U4bR7h8 b5ulgvI2KTg5Dqcb2pd55LsSIl6Qq5jFfUas2dxXcNpJAzmZD5yxYmKhiCEXaScwqX9C 0Iv120j8/Kkb5OYzoWMZxs1L81j9L5xHo8CMvm2oDE1igfzeypRLaUMxW4Ikl2EEY4Ho pVrw== X-Gm-Message-State: AO0yUKXxPPoiIwUTSlMNRwpv+34dd9a5eY8/274Kqh+jh0N1+qpeJiL5 q3P0ET1homnp+GkNZWUCTkgVsUXzLQKdhSprXQ7cYg3Z2FfA+pgdk+dszPKouzhuqAFQSjuycX0 q/yeZm9Ek79OylbNTGQFVZh5Y X-Received: by 2002:a05:6870:6087:b0:16e:1aeb:d74b with SMTP id t7-20020a056870608700b0016e1aebd74bmr546844oae.33.1679384591353; 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/cmpx= chg.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 =20 +#define ___xchg(sfx, prepend, append) \ +({ \ + __asm__ __volatile__ ( \ + prepend \ + " amoswap" sfx " %0, %2, %1\n" \ + append \ + : "=3Dr" (__ret), "+A" (*__ptr) \ + : "r" (__new) \ + : "memory"); \ +}) + #define __xchg_relaxed(ptr, new, size) \ ({ \ __typeof__(ptr) __ptr =3D (ptr); \ @@ -18,18 +29,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w %0, %2, %1\n" \ - : "=3Dr" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d %0, %2, %1\n" \ - : "=3Dr" (__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 \ - : "=3Dr" (__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 \ - : "=3Dr" (__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" \ - : "=3Dr" (__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" \ - : "=3Dr" (__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" \ - : "=3Dr" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w.aqrl", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d.aqrl %0, %2, %1\n" \ - : "=3Dr" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d.aqrl", "", ""); \ break; \ default: \ BUILD_BUG(); \ --=20 2.40.0 From nobody Sun Feb 8 14:11:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8243CC74A5B for ; Tue, 21 Mar 2023 07:44:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbjCUHoZ (ORCPT ); Tue, 21 Mar 2023 03:44:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbjCUHoM (ORCPT ); Tue, 21 Mar 2023 03:44:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E38573B0D2 for ; Tue, 21 Mar 2023 00:43:17 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tlcmKFBm9EfeLOX/A4Ek+TTZZd7OjXZ+kA7z9b9Tay8=; b=FELvU8iTG6OCnY0D5kD65zbDo9uRms/WyLCQeOkHy+BsWHJNMTX8CLu2NasoGQsjhWKmyw Bfts1MI/npbylIsHf3VA/PW/kHut2paZ92biOXn23mWZ16AXENl1p/tf2BrimmFqqG6n3y Pqub/T5QRA/wpx1t9ZoCB/l/rriD2Wc= 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-515-TCO51j4sN2SX95TmbVHPEg-1; Tue, 21 Mar 2023 03:43:14 -0400 X-MC-Unique: TCO51j4sN2SX95TmbVHPEg-1 Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-17714741d9dso8122386fac.4 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=ZoVCGRDXWnkQYO1AD/fOe/cgUAcLqM98ZSEUBJMEEE75rPF/t7D97e9Lhm3kNrc+DQ 3iGkXUfFOgs3sgunvTB5KsYgdvVM0VXt/XP4/zx0AZdgblXeyqmstARcmGmU6BuRE5OC 5G1STdw3c5KJ457NCSI1B528H7pPhyl7tVkC3HF3bzpkaL6JoJzHDmWcTmOWS8lQ9lm3 46G5qpNdmuHUluIaGWMEHgR40rm3DfLG2p0WN/FR4U+I/v5a1Jsz7ps7jbMjyP7GqmFE La8u4x9QE24AA+snNF0Bs1fBWI1OcmOW8EITpBJYMGqU7nQc3Bo3pwTOqj7AAAEsKxtn z8zg== X-Gm-Message-State: AO0yUKX1lwmXVwUwiqkNqwHGyO0ZVt526wxpmBFkhKcW/1CEO5iw7j/g jAqjSfahokNGgW5gC2aJbypIVXcEteZUxZFqOFdEJc7DzDBGjVmbdQBX7xOADju9FRuecyX5M+Y E8dGXtEwp7LqpRqofEqDERWhWH3gt1V0CM4A= X-Received: by 2002:a05:6870:17a1:b0:17e:5166:e5ad with SMTP id r33-20020a05687017a100b0017e5166e5admr561228oae.44.1679384593435; 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/cmpx= chg.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 =20 -#define ___xchg(sfx, prepend, append) \ +#define ____xchg(sfx, prepend, append) \ ({ \ __asm__ __volatile__ ( \ prepend \ @@ -22,17 +22,17 @@ : "memory"); \ }) =20 -#define __xchg_relaxed(ptr, new, size) \ +#define ___xchg(ptr, new, size, sfx, prepend, append) \ ({ \ __typeof__(ptr) __ptr =3D (ptr); \ __typeof__(new) __new =3D (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; \ }) =20 +#define __xchg_relaxed(ptr, new, size) \ + ___xchg(ptr, new, size, "", "", "") + #define arch_xchg_relaxed(ptr, x) \ ({ \ __typeof__(*(ptr)) _x_ =3D (x); \ @@ -48,22 +51,7 @@ }) =20 #define __xchg_acquire(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(new) __new =3D (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) =20 #define arch_xchg_acquire(ptr, x) \ ({ \ @@ -73,22 +61,7 @@ }) =20 #define __xchg_release(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(new) __new =3D (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, "") =20 #define arch_xchg_release(ptr, x) \ ({ \ @@ -98,22 +71,7 @@ }) =20 #define __xchg(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(new) __new =3D (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", "", "") =20 #define arch_xchg(ptr, x) \ ({ \ --=20 2.40.0 From nobody Sun Feb 8 14:11:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAD92C6FD1D for ; Tue, 21 Mar 2023 07:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjCUHo3 (ORCPT ); Tue, 21 Mar 2023 03:44:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbjCUHoM (ORCPT ); Tue, 21 Mar 2023 03:44:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA1923B234 for ; Tue, 21 Mar 2023 00:43:18 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lpwvsmW/EIvjt3XpmgOB2tOjIn+1scWXRJYbQwzYCy4=; b=XiishRQkhasmsB5J7T9XB80Ca6j8p4a5E2yXNxgiyYzlCZtLSMHxRPlf6qavKPuSoPl5K6 TGxbxBm6zlKnt1DI/pj6BuwmrQPaM+0ANe7qAMWXiL89WrQ+pImOhG9xPdyPrVGk3AXHZX TQJAIAEqwY0AR8QEy0p6Vk/31TbxoCE= Received: from mail-oa1-f72.google.com (mail-oa1-f72.google.com [209.85.160.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-Zz7OnAslP4aw7TIls2l_Jw-1; Tue, 21 Mar 2023 03:43:16 -0400 X-MC-Unique: Zz7OnAslP4aw7TIls2l_Jw-1 Received: by mail-oa1-f72.google.com with SMTP id 586e51a60fabf-17e11dd9a3dso3787270fac.10 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=030OcqNiTfRAOwj0LMblI/YjAIgV7tp70pBywvaryYUta5fzYLRjMNnPq6Kh306Bah JePMR4ttujfhtKvDMZEuobG8RXFOmTmRNJOlPD8Zi9z1QgdhRveNIGUgVQeqT3rJP4fX TVi3l9xb7iSRFx1ZS8nPvHvk5OYHxlP00YX4UaDIONPnCABRt8NhLxwbTsrfmXpJUIN7 K5eJqIY9xgMPDLGERnJXpLSY2AJ9oAIP0yacv0cx6LDRo/v6ifrE2gN9d0MYyg/5A8oy XVWYjYHjSpEM8VV6CNWNJ13RGxpUAuzvM6xOH41bjTLh5ofvxTcLQ36wZGeScAXTGt4U xNZQ== X-Gm-Message-State: AO0yUKVIpquI8ZDCtI1YGyC4eeIcWULWdW4582fYROPk98nOXYp7Sfth N+tahiBekd9emkK4dRdiQ9/H/TE0UaQ4FQErgiyl6UcXBsJG50KvrHSmUC8C38xtHWEskU7M+kO tVuRYZtkS3nWn+/jf62kxWZSD X-Received: by 2002:a05:6870:96a3:b0:17a:aa09:5e2d with SMTP id o35-20020a05687096a300b0017aaa095e2dmr792353oaq.2.1679384595729; 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/cmpx= chg.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, "", "", "") =20 -#define arch_xchg_relaxed(ptr, x) \ +#define _arch_xchg(order, ptr, x) \ ({ \ __typeof__(*(ptr)) _x_ =3D (x); \ - (__typeof__(*(ptr))) __xchg_relaxed((ptr), \ - _x_, sizeof(*(ptr))); \ + (__typeof__(*(ptr))) __xchg ## order((ptr), \ + _x_, sizeof(*(ptr))); \ }) =20 +#define arch_xchg_relaxed(ptr, x) \ + _arch_xchg(_relaxed, ptr, x) + #define __xchg_acquire(ptr, new, size) \ ___xchg(ptr, new, size, "", "", RISCV_ACQUIRE_BARRIER) =20 #define arch_xchg_acquire(ptr, x) \ -({ \ - __typeof__(*(ptr)) _x_ =3D (x); \ - (__typeof__(*(ptr))) __xchg_acquire((ptr), \ - _x_, sizeof(*(ptr))); \ -}) + _arch_xchg(_acquire, ptr, x) =20 #define __xchg_release(ptr, new, size) \ ___xchg(ptr, new, size, "", RISCV_RELEASE_BARRIER, "") =20 #define arch_xchg_release(ptr, x) \ -({ \ - __typeof__(*(ptr)) _x_ =3D (x); \ - (__typeof__(*(ptr))) __xchg_release((ptr), \ - _x_, sizeof(*(ptr))); \ -}) + _arch_xchg(_release, ptr, x) =20 #define __xchg(ptr, new, size) \ ___xchg(ptr, new, size, ".aqrl", "", "") =20 #define arch_xchg(ptr, x) \ -({ \ - __typeof__(*(ptr)) _x_ =3D (x); \ - (__typeof__(*(ptr))) __xchg((ptr), _x_, sizeof(*(ptr))); \ -}) + _arch_xchg(, ptr, x) =20 #define xchg32(ptr, x) \ ({ \ --=20 2.40.0