Commit e351ae85 by Andrew MacLeod Committed by Andrew Macleod

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
parent 29e339fd
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> 2011-11-17 Richard Henderson <rth@redhat.com>
* builtins.c (expand_builtin_mem_thread_fence): Remove. * builtins.c (expand_builtin_mem_thread_fence): Remove.
...@@ -6497,12 +6497,28 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode, ...@@ -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_4:
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_8: case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_8:
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_16: case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_16:
mode = {
get_builtin_sync_mode (fcode - BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1); unsigned int nargs, z;
target = expand_builtin_atomic_compare_exchange (mode, exp, target); VEC(tree,gc) *vec;
if (target)
return target; mode =
break; 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_1:
case BUILT_IN_ATOMIC_LOAD_2: case BUILT_IN_ATOMIC_LOAD_2:
......
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> 2011-10-17 Uros Bizjak <ubizjak@gmail.com>
* lib/gcc-simulate-thread.exp (simulate-thread): Run on all targets. * lib/gcc-simulate-thread.exp (simulate-thread): Run on all targets.
......
...@@ -19,17 +19,30 @@ __atomic_exchange (size_t size, void *obj, void *val, void *ret, int model) ...@@ -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 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) void *desired, int model1, int model2)
{ {
bool ret;
if (!memcmp (obj, expected, size)) if (!memcmp (obj, expected, size))
{ {
memcpy (obj, desired, size); memcpy (obj, desired, size);
return true; ret = true;
} }
memcpy (expected, obj, size); else
return false; {
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;
} }
......
...@@ -41,12 +41,12 @@ main () ...@@ -41,12 +41,12 @@ main ()
if (memcmp (&b, &ones, size)) if (memcmp (&b, &ones, size))
abort (); 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(); abort();
if (memcmp (&a, &zero, size)) if (memcmp (&a, &zero, size))
abort (); 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(); abort();
if (memcmp (&b, &zero, size)) if (memcmp (&b, &zero, size))
abort (); abort ();
......
...@@ -30,9 +30,15 @@ __atomic_store_1 (char *p, char v, int i) ...@@ -30,9 +30,15 @@ __atomic_store_1 (char *p, char v, int i)
*p = 1; *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) char __atomic_fetch_add_1 (char *p, char v, int i)
......
...@@ -31,7 +31,7 @@ main () ...@@ -31,7 +31,7 @@ main ()
if (ac != 1) if (ac != 1)
abort (); 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) if (as != 1)
abort (); abort ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment