This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] [amdgcn] Add support for sub-word sync_compare_and_swap operations
- From: Andrew Stubbs <andrew_stubbs at mentor dot com>
- To: Kwok Cheung Yeung <kcy at codesourcery dot com>, Andrew Stubbs <ams at codesourcery dot com>, <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 8 Jan 2020 11:42:00 +0000
- Subject: Re: [PATCH] [amdgcn] Add support for sub-word sync_compare_and_swap operations
- Ironport-sdr: rdZjaqLTAnRrcsos5UHIPA5aoxNckaVpM3eXECipRVTINNoh1tGOhNot7h1hQ3c98tYPoB9yhM Ic/Oq/oWNL/qVqPNE5TlWFiSYHja4lnFDeiF/BwXOYQmBovUREfDhVI/Z5x6paKvE4lsx3vKym R+hLtEfrygEg/4gOPOF2aLDrnfFTHmsiEy/6ryjeqFt3/x5MrljNiF2DoIl2YAoPyxsCX8F4Rh yt5Yq294rzyJjuOl+qL3/dnhQWUqGAQw9Ii8fVZhryTZB0O6vmvpFyuskThFNIce/DvG7SVusu wmQ=
- Ironport-sdr: XVsI188MK/+mWoDrEE4q56Gs3SqqKhwPsbBvZWjXDtYYBmDMn9kk5D6cfc9TZfyZHUHK+bDK6C qz6ZykEXQBJ/f48mWHHfl9S3BMVPQfVRBGc+jdh1QDKZTtb+qYyazrB3//bjHoBvMFjEKPa3+Y WBboKE003rpuew9Qnl8vxxkJ+uoqhQ4dAWLTsvK+pN4w7o6916knltV/CmHK+gdZYdBYr0wUrk cnemnRDMojxvFEed+QxbEmqR0VA6AUuksgynr88oVYXR+5qO3PjtjuC3z3BSFePEtXrswT20R7 kuw=
- References: <08f0684c-0a25-547b-827c-54e9266532d9@codesourcery.com>
On 08/01/2020 11:07, Kwok Cheung Yeung wrote:
+#define __sync_subword_compare_and_swap(type, size) \
Macro parameters are conventionally upper case.
+ \
+type \
+__sync_val_compare_and_swap_##size (type *ptr, type oldval, type
newval) \
+{ \
+ unsigned int *wordptr \
+ = (unsigned int *)((unsigned long long) ptr & ~3ULL); \
Please use "intptr_t" rather than "unsigned long long" (which should
probably have been "unsigned long" anyway).
+ int shift = ((unsigned long long) ptr & 3ULL) * 8; \
+ unsigned int valmask = (1 << (size * 8)) - 1; \
+ unsigned int wordmask = ~(valmask << shift); \
+ unsigned int oldword = *wordptr; \
+ for (;;) \
+ { \
+ type prevval = (oldword >> shift) & valmask; \
+ if (__builtin_expect (prevval != oldval, 0)) \
+ return prevval; \
+ unsigned int newword = oldword & wordmask; \
+ newword |= ((unsigned int) newval) << shift; \
+ unsigned int prevword \
+ = __sync_val_compare_and_swap_4 (wordptr, oldword,
newword); \
+ if (__builtin_expect (prevword == oldword, 1)) \
+ return oldval; \
+ oldword = prevword; \
+ } \
+} \
+ \
+bool \
+__sync_bool_compare_and_swap_##size (type *ptr, type oldval, type
newval) \
+{ \
+ return __sync_val_compare_and_swap_##size(ptr, oldval, newval) ==
oldval; \
Space before '('.
I presume all the '\' are lined up, but the patch has got mangled in the
email. Please use an inline attachment.
+}
+
+__sync_subword_compare_and_swap (unsigned char, 1)
+__sync_subword_compare_and_swap (unsigned short, 2)
+
diff --git a/libgcc/config/gcn/t-amdgcn b/libgcc/config/gcn/t-amdgcn
index adbd866..fe7b5fa 100644
--- a/libgcc/config/gcn/t-amdgcn
+++ b/libgcc/config/gcn/t-amdgcn
@@ -1,4 +1,5 @@
-LIB2ADD += $(srcdir)/config/gcn/lib2-divmod.c \
+LIB2ADD += $(srcdir)/config/gcn/atomic.c \
+ $(srcdir)/config/gcn/lib2-divmod.c \
$(srcdir)/config/gcn/lib2-divmod-hi.c \
$(srcdir)/config/gcn/unwind-gcn.c
Andrew