@@ -224,20 +224,6 @@
#endif
-#ifndef atomic_add_negative
-# define atomic_add_negative(mem, value) \
- ({ __typeof (value) __atg12_value = (value); \
- atomic_exchange_and_add (mem, __atg12_value) < -__atg12_value; })
-#endif
-
-
-#ifndef atomic_add_zero
-# define atomic_add_zero(mem, value) \
- ({ __typeof (value) __atg13_value = (value); \
- atomic_exchange_and_add (mem, __atg13_value) == -__atg13_value; })
-#endif
-
-
/* Atomically *mem &= mask and return the old value of *mem. */
#ifndef atomic_and_val
# define atomic_and_val(mem, mask) \
@@ -120,14 +120,6 @@ do_test (void)
ret = 1;
}
- mem = -21;
- atomic_add (&mem, 22);
- if (mem != 1)
- {
- puts ("atomic_add test failed");
- ret = 1;
- }
-
mem = 17;
atomic_decrement (&mem);
if (mem != 16)
@@ -190,102 +182,6 @@ do_test (void)
ret = 1;
}
- mem = -12;
- if (! atomic_add_negative (&mem, 10)
- || mem != -2)
- {
- puts ("atomic_add_negative test 1 failed");
- ret = 1;
- }
-
- mem = 0;
- if (atomic_add_negative (&mem, 100)
- || mem != 100)
- {
- puts ("atomic_add_negative test 2 failed");
- ret = 1;
- }
-
- mem = 15;
- if (atomic_add_negative (&mem, -10)
- || mem != 5)
- {
- puts ("atomic_add_negative test 3 failed");
- ret = 1;
- }
-
- mem = -12;
- if (atomic_add_negative (&mem, 14)
- || mem != 2)
- {
- puts ("atomic_add_negative test 4 failed");
- ret = 1;
- }
-
- mem = 0;
- if (! atomic_add_negative (&mem, -1)
- || mem != -1)
- {
- puts ("atomic_add_negative test 5 failed");
- ret = 1;
- }
-
- mem = -31;
- if (atomic_add_negative (&mem, 31)
- || mem != 0)
- {
- puts ("atomic_add_negative test 6 failed");
- ret = 1;
- }
-
- mem = -34;
- if (atomic_add_zero (&mem, 31)
- || mem != -3)
- {
- puts ("atomic_add_zero test 1 failed");
- ret = 1;
- }
-
- mem = -36;
- if (! atomic_add_zero (&mem, 36)
- || mem != 0)
- {
- puts ("atomic_add_zero test 2 failed");
- ret = 1;
- }
-
- mem = 113;
- if (atomic_add_zero (&mem, -13)
- || mem != 100)
- {
- puts ("atomic_add_zero test 3 failed");
- ret = 1;
- }
-
- mem = -18;
- if (atomic_add_zero (&mem, 20)
- || mem != 2)
- {
- puts ("atomic_add_zero test 4 failed");
- ret = 1;
- }
-
- mem = 10;
- if (atomic_add_zero (&mem, -20)
- || mem != -10)
- {
- puts ("atomic_add_zero test 5 failed");
- ret = 1;
- }
-
- mem = 10;
- if (! atomic_add_zero (&mem, -10)
- || mem != 0)
- {
- puts ("atomic_add_zero test 6 failed");
- ret = 1;
- }
-
/* Tests for C11-like atomics. */
mem = 11;
if (atomic_load_relaxed (&mem) != 11 || atomic_load_acquire (&mem) != 11)
@@ -278,7 +278,7 @@ make_request (int fd, pid_t pid)
{
free (result);
- atomic_add (&noai6ai_cached.usecnt, 2);
+ atomic_fetch_add_relaxed (&noai6ai_cached.usecnt, 2);
noai6ai_cached.seen_ipv4 = seen_ipv4;
noai6ai_cached.seen_ipv6 = seen_ipv6;
result = &noai6ai_cached;
@@ -349,7 +349,7 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6,
*in6ai = data->in6ai;
if (olddata != NULL && olddata->usecnt > 0
- && atomic_add_zero (&olddata->usecnt, -1))
+ && atomic_fetch_add_relaxed (&olddata->usecnt, -1) == 1)
free (olddata);
return;
@@ -377,7 +377,7 @@ __free_in6ai (struct in6addrinfo *ai)
(struct cached_data *) ((char *) ai
- offsetof (struct cached_data, in6ai));
- if (atomic_add_zero (&data->usecnt, -1))
+ if (atomic_fetch_add_relaxed (&data->usecnt, -1) == 1)
{
__libc_lock_lock (lock);
@@ -201,55 +201,6 @@
} \
})
-#define atomic_add_negative(mem, value) \
- ({ unsigned char __result; \
- __typeof (*(mem)) __tmp, __value = (value); \
- if (sizeof (*(mem)) == 1) \
- __asm __volatile ("\
- mova 1f,r0\n\
- mov r15,r1\n\
- .align 2\n\
- mov #(0f-1f),r15\n\
- 0: mov.b @%2,r2\n\
- add %1,r2\n\
- mov.b r2,@%2\n\
- 1: mov r1,r15\n\
- shal r2\n\
- movt %0"\
- : "=r" (__result), "=&r" (__tmp) : "u" (mem), "1" (__value) \
- : "r0", "r1", "r2", "t", "memory"); \
- else if (sizeof (*(mem)) == 2) \
- __asm __volatile ("\
- mova 1f,r0\n\
- mov r15,r1\n\
- .align 2\n\
- mov #(0f-1f),r15\n\
- 0: mov.w @%2,r2\n\
- add %1,r2\n\
- mov.w r2,@%2\n\
- 1: mov r1,r15\n\
- shal r2\n\
- movt %0"\
- : "=r" (__result), "=&r" (__tmp) : "u" (mem), "1" (__value) \
- : "r0", "r1", "r2", "t", "memory"); \
- else if (sizeof (*(mem)) == 4) \
- __asm __volatile ("\
- mova 1f,r0\n\
- mov r15,r1\n\
- .align 2\n\
- mov #(0f-1f),r15\n\
- 0: mov.l @%2,r2\n\
- add %1,r2\n\
- mov.l r2,@%2\n\
- 1: mov r1,r15\n\
- shal r2\n\
- movt %0"\
- : "=r" (__result), "=&r" (__tmp) : "u" (mem), "1" (__value) \
- : "r0", "r1", "r2", "t", "memory"); \
- else \
- abort (); \
- __result; })
-
#define atomic_add_zero(mem, value) \
({ unsigned char __result; \
__typeof (*(mem)) __tmp, __value = (value); \
@@ -122,82 +122,6 @@
#define atomic_exchange_and_add(mem, value) \
__sync_fetch_and_add (mem, value)
-#define __arch_add_body(lock, pfx, apfx, mem, value) \
- do { \
- if (__builtin_constant_p (value) && (value) == -1) \
- pfx##_decrement (mem); \
- else if (sizeof (*mem) == 1) \
- __asm __volatile (lock "addb %b1, %0" \
- : "=m" (*mem) \
- : IBR_CONSTRAINT (value), "m" (*mem)); \
- else if (sizeof (*mem) == 2) \
- __asm __volatile (lock "addw %w1, %0" \
- : "=m" (*mem) \
- : "ir" (value), "m" (*mem)); \
- else if (sizeof (*mem) == 4) \
- __asm __volatile (lock "addl %1, %0" \
- : "=m" (*mem) \
- : "ir" (value), "m" (*mem)); \
- else if (__HAVE_64B_ATOMICS) \
- __asm __volatile (lock "addq %q1, %0" \
- : "=m" (*mem) \
- : "ir" ((int64_t) cast_to_integer (value)), \
- "m" (*mem)); \
- else \
- do_add_val_64_acq (apfx, (mem), (value)); \
- } while (0)
-
-# define atomic_add(mem, value) \
- __arch_add_body (LOCK_PREFIX, atomic, __arch, mem, value)
-
-#define atomic_add_negative(mem, value) \
- ({ unsigned char __result; \
- if (sizeof (*mem) == 1) \
- __asm __volatile (LOCK_PREFIX "addb %b2, %0; sets %1" \
- : "=m" (*mem), "=qm" (__result) \
- : IBR_CONSTRAINT (value), "m" (*mem)); \
- else if (sizeof (*mem) == 2) \
- __asm __volatile (LOCK_PREFIX "addw %w2, %0; sets %1" \
- : "=m" (*mem), "=qm" (__result) \
- : "ir" (value), "m" (*mem)); \
- else if (sizeof (*mem) == 4) \
- __asm __volatile (LOCK_PREFIX "addl %2, %0; sets %1" \
- : "=m" (*mem), "=qm" (__result) \
- : "ir" (value), "m" (*mem)); \
- else if (__HAVE_64B_ATOMICS) \
- __asm __volatile (LOCK_PREFIX "addq %q2, %0; sets %1" \
- : "=m" (*mem), "=qm" (__result) \
- : "ir" ((int64_t) cast_to_integer (value)), \
- "m" (*mem)); \
- else \
- __atomic_link_error (); \
- __result; })
-
-
-#define atomic_add_zero(mem, value) \
- ({ unsigned char __result; \
- if (sizeof (*mem) == 1) \
- __asm __volatile (LOCK_PREFIX "addb %b2, %0; setz %1" \
- : "=m" (*mem), "=qm" (__result) \
- : IBR_CONSTRAINT (value), "m" (*mem)); \
- else if (sizeof (*mem) == 2) \
- __asm __volatile (LOCK_PREFIX "addw %w2, %0; setz %1" \
- : "=m" (*mem), "=qm" (__result) \
- : "ir" (value), "m" (*mem)); \
- else if (sizeof (*mem) == 4) \
- __asm __volatile (LOCK_PREFIX "addl %2, %0; setz %1" \
- : "=m" (*mem), "=qm" (__result) \
- : "ir" (value), "m" (*mem)); \
- else if (__HAVE_64B_ATOMICS) \
- __asm __volatile (LOCK_PREFIX "addq %q2, %0; setz %1" \
- : "=m" (*mem), "=qm" (__result) \
- : "ir" ((int64_t) cast_to_integer (value)), \
- "m" (*mem)); \
- else \
- __atomic_link_error (); \
- __result; })
-
-
#define __arch_decrement_body(lock, pfx, mem) \
do { \
if (sizeof (*mem) == 1) \