From: Leonardo Bras <leobras@redhat.com>
To: Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Leonardo Bras <leobras@redhat.com>, Guo Ren <guoren@kernel.org>
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 [thread overview]
Message-ID: <20230321074249.2221674-3-leobras@redhat.com> (raw)
In-Reply-To: <20230321074249.2221674-1-leobras@redhat.com>
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 <leobras@redhat.com>
---
arch/riscv/include/asm/cmpxchg.h | 72 ++++++--------------------------
1 file changed, 12 insertions(+), 60 deletions(-)
diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h
index 21984d24cbfe7..c7a13eec4dbcc 100644
--- a/arch/riscv/include/asm/cmpxchg.h
+++ b/arch/riscv/include/asm/cmpxchg.h
@@ -164,8 +164,8 @@
* indicated by comparing RETURN with OLD.
*/
-#define ___cmpxchg(lr_sfx, sc_sfx, prepend, append) \
-{ \
+#define ____cmpxchg(lr_sfx, sc_sfx, prepend, append) \
+({ \
__asm__ __volatile__ ( \
prepend \
"0: lr" lr_sfx " %0, %2\n" \
@@ -177,9 +177,9 @@
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
: "rJ" ((long)__old), "rJ" (__new) \
: "memory"); \
-}
+})
-#define __cmpxchg_relaxed(ptr, old, new, size) \
+#define ___cmpxchg(ptr, old, new, size, sc_sfx, prepend, append) \
({ \
__typeof__(ptr) __ptr = (ptr); \
__typeof__(*(ptr)) __old = (old); \
@@ -188,10 +188,10 @@
register unsigned int __rc; \
switch (size) { \
case 4: \
- ___cmpxchg(".w", ".w", "", ""); \
+ ____cmpxchg(".w", ".w" sc_sfx, prepend, append); \
break; \
case 8: \
- ___cmpxchg(".d", ".d", "", ""); \
+ ____cmpxchg(".d", ".d" sc_sfx, prepend, append); \
break; \
default: \
BUILD_BUG(); \
@@ -199,6 +199,9 @@
__ret; \
})
+#define __cmpxchg_relaxed(ptr, old, new, size) \
+ ___cmpxchg(ptr, old, new, size, "", "", "")
+
#define arch_cmpxchg_relaxed(ptr, o, n) \
({ \
__typeof__(*(ptr)) _o_ = (o); \
@@ -208,24 +211,7 @@
})
#define __cmpxchg_acquire(ptr, old, new, size) \
-({ \
- __typeof__(ptr) __ptr = (ptr); \
- __typeof__(*(ptr)) __old = (old); \
- __typeof__(*(ptr)) __new = (new); \
- __typeof__(*(ptr)) __ret; \
- register unsigned int __rc; \
- switch (size) { \
- case 4: \
- ___cmpxchg(".w", ".w", "", RISCV_ACQUIRE_BARRIER); \
- break; \
- case 8: \
- ___cmpxchg(".d", ".d", "", RISCV_ACQUIRE_BARRIER); \
- break; \
- default: \
- BUILD_BUG(); \
- } \
- __ret; \
-})
+ ___cmpxchg(ptr, old, new, size, "", "", RISCV_ACQUIRE_BARRIER)
#define arch_cmpxchg_acquire(ptr, o, n) \
({ \
@@ -236,24 +222,7 @@
})
#define __cmpxchg_release(ptr, old, new, size) \
-({ \
- __typeof__(ptr) __ptr = (ptr); \
- __typeof__(*(ptr)) __old = (old); \
- __typeof__(*(ptr)) __new = (new); \
- __typeof__(*(ptr)) __ret; \
- register unsigned int __rc; \
- switch (size) { \
- case 4: \
- ___cmpxchg(".w", ".w", RISCV_RELEASE_BARRIER, ""); \
- break; \
- case 8: \
- ___cmpxchg(".d", ".d", RISCV_RELEASE_BARRIER, ""); \
- break; \
- default: \
- BUILD_BUG(); \
- } \
- __ret; \
-})
+ ___cmpxchg(ptr, old, new, size, "", RISCV_RELEASE_BARRIER, "")
#define arch_cmpxchg_release(ptr, o, n) \
({ \
@@ -264,24 +233,7 @@
})
#define __cmpxchg(ptr, old, new, size) \
-({ \
- __typeof__(ptr) __ptr = (ptr); \
- __typeof__(*(ptr)) __old = (old); \
- __typeof__(*(ptr)) __new = (new); \
- __typeof__(*(ptr)) __ret; \
- register unsigned int __rc; \
- switch (size) { \
- case 4: \
- ___cmpxchg(".w", ".w.rl", "", " fence rw, rw\n"); \
- break; \
- case 8: \
- ___cmpxchg(".d", ".d.rl", "", " fence rw, rw\n"); \
- break; \
- default: \
- BUILD_BUG(); \
- } \
- __ret; \
-})
+ ___cmpxchg(ptr, old, new, size, ".rl", "", " fence rw, rw\n")
#define arch_cmpxchg(ptr, o, n) \
({ \
--
2.40.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Leonardo Bras <leobras@redhat.com>
To: Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Leonardo Bras <leobras@redhat.com>, Guo Ren <guoren@kernel.org>
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 [thread overview]
Message-ID: <20230321074249.2221674-3-leobras@redhat.com> (raw)
In-Reply-To: <20230321074249.2221674-1-leobras@redhat.com>
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 <leobras@redhat.com>
---
arch/riscv/include/asm/cmpxchg.h | 72 ++++++--------------------------
1 file changed, 12 insertions(+), 60 deletions(-)
diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h
index 21984d24cbfe7..c7a13eec4dbcc 100644
--- a/arch/riscv/include/asm/cmpxchg.h
+++ b/arch/riscv/include/asm/cmpxchg.h
@@ -164,8 +164,8 @@
* indicated by comparing RETURN with OLD.
*/
-#define ___cmpxchg(lr_sfx, sc_sfx, prepend, append) \
-{ \
+#define ____cmpxchg(lr_sfx, sc_sfx, prepend, append) \
+({ \
__asm__ __volatile__ ( \
prepend \
"0: lr" lr_sfx " %0, %2\n" \
@@ -177,9 +177,9 @@
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
: "rJ" ((long)__old), "rJ" (__new) \
: "memory"); \
-}
+})
-#define __cmpxchg_relaxed(ptr, old, new, size) \
+#define ___cmpxchg(ptr, old, new, size, sc_sfx, prepend, append) \
({ \
__typeof__(ptr) __ptr = (ptr); \
__typeof__(*(ptr)) __old = (old); \
@@ -188,10 +188,10 @@
register unsigned int __rc; \
switch (size) { \
case 4: \
- ___cmpxchg(".w", ".w", "", ""); \
+ ____cmpxchg(".w", ".w" sc_sfx, prepend, append); \
break; \
case 8: \
- ___cmpxchg(".d", ".d", "", ""); \
+ ____cmpxchg(".d", ".d" sc_sfx, prepend, append); \
break; \
default: \
BUILD_BUG(); \
@@ -199,6 +199,9 @@
__ret; \
})
+#define __cmpxchg_relaxed(ptr, old, new, size) \
+ ___cmpxchg(ptr, old, new, size, "", "", "")
+
#define arch_cmpxchg_relaxed(ptr, o, n) \
({ \
__typeof__(*(ptr)) _o_ = (o); \
@@ -208,24 +211,7 @@
})
#define __cmpxchg_acquire(ptr, old, new, size) \
-({ \
- __typeof__(ptr) __ptr = (ptr); \
- __typeof__(*(ptr)) __old = (old); \
- __typeof__(*(ptr)) __new = (new); \
- __typeof__(*(ptr)) __ret; \
- register unsigned int __rc; \
- switch (size) { \
- case 4: \
- ___cmpxchg(".w", ".w", "", RISCV_ACQUIRE_BARRIER); \
- break; \
- case 8: \
- ___cmpxchg(".d", ".d", "", RISCV_ACQUIRE_BARRIER); \
- break; \
- default: \
- BUILD_BUG(); \
- } \
- __ret; \
-})
+ ___cmpxchg(ptr, old, new, size, "", "", RISCV_ACQUIRE_BARRIER)
#define arch_cmpxchg_acquire(ptr, o, n) \
({ \
@@ -236,24 +222,7 @@
})
#define __cmpxchg_release(ptr, old, new, size) \
-({ \
- __typeof__(ptr) __ptr = (ptr); \
- __typeof__(*(ptr)) __old = (old); \
- __typeof__(*(ptr)) __new = (new); \
- __typeof__(*(ptr)) __ret; \
- register unsigned int __rc; \
- switch (size) { \
- case 4: \
- ___cmpxchg(".w", ".w", RISCV_RELEASE_BARRIER, ""); \
- break; \
- case 8: \
- ___cmpxchg(".d", ".d", RISCV_RELEASE_BARRIER, ""); \
- break; \
- default: \
- BUILD_BUG(); \
- } \
- __ret; \
-})
+ ___cmpxchg(ptr, old, new, size, "", RISCV_RELEASE_BARRIER, "")
#define arch_cmpxchg_release(ptr, o, n) \
({ \
@@ -264,24 +233,7 @@
})
#define __cmpxchg(ptr, old, new, size) \
-({ \
- __typeof__(ptr) __ptr = (ptr); \
- __typeof__(*(ptr)) __old = (old); \
- __typeof__(*(ptr)) __new = (new); \
- __typeof__(*(ptr)) __ret; \
- register unsigned int __rc; \
- switch (size) { \
- case 4: \
- ___cmpxchg(".w", ".w.rl", "", " fence rw, rw\n"); \
- break; \
- case 8: \
- ___cmpxchg(".d", ".d.rl", "", " fence rw, rw\n"); \
- break; \
- default: \
- BUILD_BUG(); \
- } \
- __ret; \
-})
+ ___cmpxchg(ptr, old, new, size, ".rl", "", " fence rw, rw\n")
#define arch_cmpxchg(ptr, o, n) \
({ \
--
2.40.0
next prev parent reply other threads:[~2023-03-21 7:43 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 7:42 [RESEND RFC PATCH v2 0/6] Deduplicating RISCV cmpxchg.h macros Leonardo Bras
2023-03-21 7:42 ` Leonardo Bras
2023-03-21 7:42 ` [RESEND RFC PATCH v2 1/6] riscv/cmpxchg: Deduplicate cmpxchg() asm functions Leonardo Bras
2023-03-21 7:42 ` Leonardo Bras
2023-03-22 0:45 ` Andrea Parri
2023-03-22 0:45 ` Andrea Parri
2023-03-22 3:50 ` Leonardo Bras Soares Passos
2023-03-22 3:50 ` Leonardo Bras Soares Passos
2023-03-22 7:50 ` Andrea Parri
2023-03-22 7:50 ` Andrea Parri
2023-03-21 7:42 ` Leonardo Bras [this message]
2023-03-21 7:42 ` [RESEND RFC PATCH v2 2/6] riscv/cmpxchg: Deduplicate cmpxchg() macros Leonardo Bras
2023-03-21 7:42 ` [RESEND RFC PATCH v2 3/6] riscv/cmpxchg: Deduplicate arch_cmpxchg() macros Leonardo Bras
2023-03-21 7:42 ` Leonardo Bras
2023-03-21 7:42 ` [RESEND RFC PATCH v2 4/6] riscv/cmpxchg: Deduplicate xchg() asm functions Leonardo Bras
2023-03-21 7:42 ` Leonardo Bras
2023-03-21 7:42 ` [RESEND RFC PATCH v2 5/6] riscv/cmpxchg: Deduplicate xchg() macros Leonardo Bras
2023-03-21 7:42 ` Leonardo Bras
2023-03-21 7:42 ` [RESEND RFC PATCH v2 6/6] riscv/cmpxchg: Deduplicate arch_xchg() macros Leonardo Bras
2023-03-21 7:42 ` Leonardo Bras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230321074249.2221674-3-leobras@redhat.com \
--to=leobras@redhat.com \
--cc=aou@eecs.berkeley.edu \
--cc=guoren@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.