mirror of
git://repo.or.cz/tinycc.git
synced 2026-06-17 15:44:18 +08:00
Enable atomic test for all targets
This commit is contained in:
parent
7657d871c1
commit
717a510a19
@ -14,18 +14,12 @@
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
#if defined __x86_64__ || defined __aarch64__ || defined __riscv
|
||||
#define HAS_64BITS
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
atomic_flag flag;
|
||||
atomic_uchar uc;
|
||||
atomic_ushort us;
|
||||
atomic_uint ui;
|
||||
#ifdef HAS_64BITS
|
||||
atomic_size_t ul;
|
||||
#endif
|
||||
} counter_type;
|
||||
|
||||
static
|
||||
@ -38,9 +32,7 @@ void *adder_simple(void *arg)
|
||||
atomic_fetch_add_explicit(&counter->uc, 1, memory_order_relaxed);
|
||||
atomic_fetch_add_explicit(&counter->us, 1, memory_order_relaxed);
|
||||
atomic_fetch_add_explicit(&counter->ui, 1, memory_order_relaxed);
|
||||
#ifdef HAS_64BITS
|
||||
atomic_fetch_add_explicit(&counter->ul, 1, memory_order_relaxed);
|
||||
#endif
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -56,15 +48,11 @@ void *adder_cmpxchg(void *arg)
|
||||
unsigned char xchgc;
|
||||
unsigned short xchgs;
|
||||
unsigned int xchgi;
|
||||
#ifdef HAS_64BITS
|
||||
size_t xchgl;
|
||||
#endif
|
||||
unsigned char cmpc = atomic_load_explicit(&counter->uc, memory_order_relaxed);
|
||||
unsigned short cmps = atomic_load_explicit(&counter->us, memory_order_relaxed);
|
||||
unsigned int cmpi = atomic_load_explicit(&counter->ui, memory_order_relaxed);
|
||||
#ifdef HAS_64BITS
|
||||
size_t cmpl = atomic_load_explicit(&counter->ul, memory_order_relaxed);
|
||||
#endif
|
||||
|
||||
do {
|
||||
xchgc = (cmpc + 1);
|
||||
@ -78,12 +66,10 @@ void *adder_cmpxchg(void *arg)
|
||||
xchgi = (cmpi + 1);
|
||||
} while (!atomic_compare_exchange_strong_explicit(&counter->ui,
|
||||
&cmpi, xchgi, memory_order_relaxed, memory_order_relaxed));
|
||||
#ifdef HAS_64BITS
|
||||
do {
|
||||
xchgl = (cmpl + 1);
|
||||
} while (!atomic_compare_exchange_strong_explicit(&counter->ul,
|
||||
&cmpl, xchgl, memory_order_relaxed, memory_order_relaxed));
|
||||
#endif
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -100,9 +86,7 @@ void *adder_test_and_set(void *arg)
|
||||
++counter->uc;
|
||||
++counter->us;
|
||||
++counter->ui;
|
||||
#ifdef HAS_64BITS
|
||||
++counter->ul;
|
||||
#endif
|
||||
atomic_flag_clear(&counter->flag);
|
||||
}
|
||||
|
||||
@ -120,9 +104,7 @@ void atomic_counter_test(void *(*adder)(void *arg))
|
||||
atomic_init(&counter.uc, 0);
|
||||
atomic_init(&counter.us, 0);
|
||||
atomic_init(&counter.ui, 0);
|
||||
#ifdef HAS_64BITS
|
||||
atomic_init(&counter.ul, 0);
|
||||
#endif
|
||||
|
||||
for (index = 0; index < NR_THREADS; ++index)
|
||||
BUG_ON(pthread_create(&thread[index], NULL, adder, (void *)&counter));
|
||||
@ -133,9 +115,7 @@ void atomic_counter_test(void *(*adder)(void *arg))
|
||||
if (atomic_load(&counter.uc) == ((NR_THREADS * NR_STEPS) & 0xffu)
|
||||
&& atomic_load(&counter.us) == ((NR_THREADS * NR_STEPS) & 0xffffu)
|
||||
&& atomic_load(&counter.ui) == (NR_THREADS * NR_STEPS)
|
||||
#ifdef HAS_64BITS
|
||||
&& atomic_load(&counter.ul) == (NR_THREADS * NR_STEPS)
|
||||
#endif
|
||||
)
|
||||
printf("SUCCESS\n");
|
||||
else
|
||||
|
||||
@ -63,12 +63,7 @@ int main()
|
||||
#define OP1(func, v, e1, e2) atomic_##func(&c, v) == e1 && c == e2
|
||||
#define OP2(func, v, e1, e2) atomic_##func(&s, v) == e1 && s == e2
|
||||
#define OP4(func, v, e1, e2) atomic_##func(&i, v) == e1 && i == e2
|
||||
#if defined __x86_64__ || defined __aarch64__ || defined __riscv
|
||||
#define OP8(func, v, e1, e2) atomic_##func(&l, v) == e1 && l == e2
|
||||
#define HAS_64BITS
|
||||
#else
|
||||
#define OP8(func, v, e1, e2) 1
|
||||
#endif
|
||||
|
||||
#define OP(func, v, e1, e2) printf ("%s: %s\n", #func, \
|
||||
OP1(func,v,e1,e2) && OP2(func,v,e1,e2) && \
|
||||
@ -80,16 +75,12 @@ int main()
|
||||
atomic_char c;
|
||||
atomic_short s;
|
||||
atomic_int i;
|
||||
#ifdef HAS_64BITS
|
||||
atomic_size_t l;
|
||||
#endif
|
||||
|
||||
atomic_init(&c, 0);
|
||||
atomic_init(&s, 0);
|
||||
atomic_init(&i, 0);
|
||||
#ifdef HAS_64BITS
|
||||
atomic_init(&l, 0);
|
||||
#endif
|
||||
|
||||
OP(fetch_add, 10, 0, 10);
|
||||
OP(fetch_sub, 5, 10, 5);
|
||||
@ -108,13 +99,8 @@ typedef __SIZE_TYPE__ size64_t;
|
||||
__atomic_##func(&s, v, __ATOMIC_SEQ_CST) == e1 && s == e2
|
||||
#define OP4(func, v, e1, e2)\
|
||||
__atomic_##func(&i, v, __ATOMIC_SEQ_CST) == e1 && i == e2
|
||||
#if defined __x86_64__ || defined __aarch64__ || defined __riscv
|
||||
#define OP8(func, v, e1, e2)\
|
||||
__atomic_##func(&l, v, __ATOMIC_SEQ_CST) == e1 && l == e2
|
||||
#define HAS_64BITS
|
||||
#else
|
||||
#define OP8(func, v, e1, e2) 1
|
||||
#endif
|
||||
|
||||
#define OP(func, v, e1, e2) printf ("%s: %s\n", #func, \
|
||||
OP1(func,v,e1,e2) && OP2(func,v,e1,e2) && \
|
||||
@ -126,16 +112,12 @@ int main()
|
||||
signed char c;
|
||||
short s;
|
||||
int i;
|
||||
#ifdef HAS_64BITS
|
||||
size64_t l;
|
||||
#endif
|
||||
|
||||
atomic_init(&c, 0);
|
||||
atomic_init(&s, 0);
|
||||
atomic_init(&i, 0);
|
||||
#ifdef HAS_64BITS
|
||||
atomic_init(&l, 0);
|
||||
#endif
|
||||
|
||||
OP(fetch_add, 10, 0, 10);
|
||||
OP(fetch_sub, 5, 10, 5);
|
||||
@ -147,9 +129,7 @@ int main()
|
||||
atomic_init(&c, 0);
|
||||
atomic_init(&s, 0);
|
||||
atomic_init(&i, 0);
|
||||
#ifdef HAS_64BITS
|
||||
atomic_init(&l, 0);
|
||||
#endif
|
||||
|
||||
OP(add_fetch, 10, 10, 10);
|
||||
OP(sub_fetch, 5, 5, 5);
|
||||
|
||||
@ -38,22 +38,22 @@ nand_fetch: SUCCESS
|
||||
1
|
||||
|
||||
[test_atomic_error_1]
|
||||
125_atomic_misc.c:176: error: pointer expected
|
||||
125_atomic_misc.c:156: error: pointer expected
|
||||
|
||||
[test_atomic_error_2]
|
||||
125_atomic_misc.c:183: error: integral or integer-sized pointer target type expected
|
||||
125_atomic_misc.c:163: error: integral or integer-sized pointer target type expected
|
||||
|
||||
[test_atomic_error_3]
|
||||
125_atomic_misc.c:190: error: integral or integer-sized pointer target type expected
|
||||
125_atomic_misc.c:170: error: integral or integer-sized pointer target type expected
|
||||
|
||||
[test_atomic_error_4]
|
||||
125_atomic_misc.c:198: error: pointer target type mismatch in argument 2
|
||||
125_atomic_misc.c:178: error: pointer target type mismatch in argument 2
|
||||
|
||||
[test_atomic_warn_1]
|
||||
125_atomic_misc.c:206: warning: assignment makes integer from pointer without a cast
|
||||
125_atomic_misc.c:186: warning: assignment makes integer from pointer without a cast
|
||||
|
||||
[test_atomic_warn_2]
|
||||
125_atomic_misc.c:216: warning: assignment from incompatible pointer type
|
||||
125_atomic_misc.c:196: warning: assignment from incompatible pointer type
|
||||
|
||||
[test_atomic_warn_3]
|
||||
125_atomic_misc.c:224: warning: assignment of read-only location
|
||||
125_atomic_misc.c:204: warning: assignment of read-only location
|
||||
|
||||
Loading…
Reference in New Issue
Block a user