This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gomp4] nvptx libgcc atomic routines


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]