This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gomp4] nvptx libgcc atomic routines
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Thomas Schwinge <thomas at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Cesar Philippidis <cesar at codesourcery dot com>
- Date: Thu, 14 May 2015 10:12:04 +0200
- Subject: Re: [gomp4] nvptx libgcc atomic routines
- Authentication-results: sourceware.org; auth=none
- References: <5527F84E dot 1080605 at mentor dot com> <87y4ksjkmk dot fsf at schwinge dot name>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, May 13, 2015 at 10:19:31PM +0200, Thomas Schwinge wrote:
> +/* Kernel helper for compare-and-exchange. */
> +static int
> +nvidia_cas (int oldval, int newval, int *ptr)
> +{
> + int ret;
> +
> + asm volatile ("atom.cas.b32 %0, [%1], %2, %3;" : "=r"(ret) : "r"(ptr),
> + "r"(oldval), "r"(newval));
> +
> + return ret;
> +}
Why? Can't you just use __sync_*_compare_and_swap or __atomic_* ?
> +#define OP_AND_FETCH_WORD(OP, PFX_OP, INF_OP) \
> + int HIDDEN \
> + __sync_##OP##_and_fetch_4 (int *ptr, int val) \
> + { \
> + int tmp, failure; \
> + \
> + do { \
> + tmp = *ptr; \
> + failure = __kernel_cmpxchg (tmp, PFX_OP (tmp INF_OP val), ptr); \
> + } while (failure != 0); \
> + \
> + return PFX_OP (tmp INF_OP val); \
> + }
Again, why? I thought 32-bit and 64-bit atomics are supported inline.
> +int HIDDEN
> +__sync_val_compare_and_swap_4 (int *ptr, int oldval, int newval)
> +{
> + int actual_oldval, fail;
> +
> + while (1)
> + {
> + actual_oldval = *ptr;
> +
> + if (oldval != actual_oldval)
> + return actual_oldval;
> +
> + fail = __kernel_cmpxchg (actual_oldval, newval, ptr);
> +
> + if (!fail)
> + return oldval;
> + }
> +}
Likewise.
> +typedef unsigned char bool;
> +
> +bool HIDDEN
> +__sync_bool_compare_and_swap_4 (int *ptr, int oldval, int newval)
> +{
> + int failure = __kernel_cmpxchg (oldval, newval, ptr);
> + return (failure == 0);
> +}
Likewise. Why the unsigned char bool? Just use _Bool instead?
> +int HIDDEN
> +__sync_lock_test_and_set_4 (int *ptr, int val)
> +{
> + int failure, oldval;
> +
> + do {
> + oldval = *ptr;
> + failure = __kernel_cmpxchg (oldval, val, ptr);
> + } while (failure != 0);
> +
> + return oldval;
> +}
Ditto.
> +SYNC_LOCK_RELEASE (int, 4)
Ditto.
Jakub