builtins.c (expand_builtin): Remove 4th parameter representing weak/strong mode when...

2011-11-17  Andrew MacLeod  <amacleod@redhat.com>

	* builtins.c (expand_builtin): Remove 4th parameter representing 
	weak/strong mode when __atomic_compare_exchange becomes a library call.

	* gcc.dg/atomic-generic-aux.c (__atomic_compare_exchange): Fail if 
	memory model parameters don't match expected values.
	* gcc.dg/atomic-generic.c: Pass specific memory model parameters to
	__atomic_compare_exchange.
	* gcc.dg/atomic-noinline.c: Pass specific memory model parameters to
	__atomic_compare_exchange_n.
	* gcc.dg/atomic-noinline-aux.c (__atomic_compare_exchange_2): Remove
	weak/strong parameter and fail if memory models aren't correct.

From-SVN: r181453
This commit is contained in:
Andrew MacLeod 2011-11-17 20:51:51 +00:00 committed by Andrew Macleod
parent 29e339fd2e
commit e351ae8587
7 changed files with 66 additions and 15 deletions

View File

@ -1,3 +1,8 @@
2011-11-17 Andrew MacLeod <amacleod@redhat.com>
* builtins.c (expand_builtin): Remove 4th parameter representing
weak/strong mode when __atomic_compare_exchange becomes a library call.
2011-11-17 Richard Henderson <rth@redhat.com>
* builtins.c (expand_builtin_mem_thread_fence): Remove.

View File

@ -6497,12 +6497,28 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_4:
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_8:
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_16:
mode =
get_builtin_sync_mode (fcode - BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1);
target = expand_builtin_atomic_compare_exchange (mode, exp, target);
if (target)
return target;
break;
{
unsigned int nargs, z;
VEC(tree,gc) *vec;
mode =
get_builtin_sync_mode (fcode - BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1);
target = expand_builtin_atomic_compare_exchange (mode, exp, target);
if (target)
return target;
/* If this is turned into an external library call, the weak parameter
must be dropped to match the expected parameter list. */
nargs = call_expr_nargs (exp);
vec = VEC_alloc (tree, gc, nargs - 1);
for (z = 0; z < 3; z++)
VEC_quick_push (tree, vec, CALL_EXPR_ARG (exp, z));
/* Skip the boolean weak parameter. */
for (z = 4; z < 6; z++)
VEC_quick_push (tree, vec, CALL_EXPR_ARG (exp, z));
exp = build_call_vec (TREE_TYPE (exp), CALL_EXPR_FN (exp), vec);
break;
}
case BUILT_IN_ATOMIC_LOAD_1:
case BUILT_IN_ATOMIC_LOAD_2:

View File

@ -1,3 +1,14 @@
2011-11-17 Andrew MacLeod <amacleod@redhat.com>
* gcc.dg/atomic-generic-aux.c (__atomic_compare_exchange): Fail if
memory model parameters don't match expected values.
* gcc.dg/atomic-generic.c: Pass specific memory model parameters to
__atomic_compare_exchange.
* gcc.dg/atomic-noinline.c: Pass specific memory model parameters to
__atomic_compare_exchange_n.
* gcc.dg/atomic-noinline-aux.c (__atomic_compare_exchange_2): Remove
weak/strong parameter and fail if memory models aren't correct.
2011-10-17 Uros Bizjak <ubizjak@gmail.com>
* lib/gcc-simulate-thread.exp (simulate-thread): Run on all targets.

View File

@ -19,17 +19,30 @@ __atomic_exchange (size_t size, void *obj, void *val, void *ret, int model)
}
/* Note that the external version of this routine has the boolean weak/strong
parameter removed. This is required by teh external library. */
bool
__atomic_compare_exchange (size_t size, void *obj, void *expected,
__atomic_compare_exchange (size_t size, void *obj, void *expected,
void *desired, int model1, int model2)
{
bool ret;
if (!memcmp (obj, expected, size))
{
memcpy (obj, desired, size);
return true;
ret = true;
}
memcpy (expected, obj, size);
return false;
else
{
memcpy (expected, obj, size);
ret = false;
}
/* Make sure the parameters have been properly adjusted for the external
function call (no weak/strong parameter. */
if (model1 != __ATOMIC_SEQ_CST || model2 != __ATOMIC_ACQUIRE)
ret = !ret;
return ret;
}

View File

@ -41,12 +41,12 @@ main ()
if (memcmp (&b, &ones, size))
abort ();
if (!__atomic_compare_exchange (&a, &b, &zero, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
if (!__atomic_compare_exchange (&a, &b, &zero, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
abort();
if (memcmp (&a, &zero, size))
abort ();
if (__atomic_compare_exchange (&a, &b, &ones, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
if (__atomic_compare_exchange (&a, &b, &ones, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
abort();
if (memcmp (&b, &zero, size))
abort ();

View File

@ -30,9 +30,15 @@ __atomic_store_1 (char *p, char v, int i)
*p = 1;
}
int __atomic_compare_exchange_2 (short *p, short *a, short b, int x, int y, int z)
int __atomic_compare_exchange_2 (short *p, short *a, short b, int y, int z)
{
*p = 1;
/* Fail if the memory models aren't correct as that will indicate the external
call has failed to remove the weak/strong parameter as required by the
library. */
if (y != __ATOMIC_SEQ_CST || z != __ATOMIC_ACQUIRE)
*p = 0;
else
*p = 1;
}
char __atomic_fetch_add_1 (char *p, char v, int i)

View File

@ -31,7 +31,7 @@ main ()
if (ac != 1)
abort ();
__atomic_compare_exchange_n (&as, &bs, cs, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
__atomic_compare_exchange_n (&as, &bs, cs, 0, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
if (as != 1)
abort ();