aix: TLS DWARF symbol decorations.
[official-gcc.git] / libatomic / testsuite / libatomic.c / generic-2.c
blobaa0014d2dc07b461b72ad519f17d88711fddd510
1 /* { dg-do run } */
3 #include <stdlib.h>
4 #include <string.h>
5 #include <stdbool.h>
7 /* Avoid using the builtins, calling directly to the library functions
8 of the same name, so that we get direct access to the size_t and
9 don't have to create myriad types of different sizes. */
11 #define C2_(X,Y) X ## Y
12 #define C2(X,Y) C2_(X,Y)
14 #define S2(X) #X
15 #define S(X) S2(X)
17 #define ASMNAME(X) __asm__(S(C2(__USER_LABEL_PREFIX__,X)))
18 #define MAN(X) ASMNAME(C2(__atomic_,X))
20 void libat_load (size_t, void *, void *, int) MAN(load);
21 void libat_store (size_t, void *, void *, int) MAN(store);
22 void libat_exchange (size_t, void *, void *, void *, int) MAN(exchange);
23 bool libat_compare_exchange (size_t, void *, void *, void *, int, int)
24 MAN(compare_exchange);
25 bool libat_is_lock_free (size_t, void *) MAN(is_lock_free);
28 #define ALIGN 16
29 #define MAX 4*ALIGN
31 static char a[MAX];
32 static char b[MAX];
33 static char c[MAX];
34 static char pa[MAX];
35 static char pb[MAX];
37 static void test_load(void)
39 int i, j;
40 for (i = ALIGN; i < 2*ALIGN; ++i)
41 for (j = 1; j <= 2*ALIGN; ++j)
43 memcpy(b, pa, MAX);
44 memcpy(b + i, pb, j);
45 libat_load (j, b + i, a, 0);
46 if (memcmp (a, pb, j) != 0) abort ();
50 static void test_store(void)
52 int i, j;
53 for (i = ALIGN; i < 2*ALIGN; ++i)
54 for (j = 1; j <= 2*ALIGN; ++j)
56 memcpy(a, pa, MAX);
57 memcpy(b, pa, MAX);
58 memcpy(b + i, pb, j);
59 libat_store (j, a + i, pb, 0);
60 if (memcmp (a, b, MAX) != 0) abort ();
64 static void test_exch(void)
66 int i, j;
67 for (i = ALIGN; i < 2 * ALIGN; ++i)
68 for (j = 1; j <= 2*ALIGN; ++j)
70 memcpy(a, pa, MAX);
71 memcpy(b, pa, MAX);
72 memcpy(b + i, pb, j);
73 libat_exchange (j, a + i, pb, c, 0);
74 if (memcmp (a, b, MAX) != 0) abort ();
75 if (memcmp (c, pa + i, j) != 0) abort ();
77 memcpy(a, pa, MAX);
78 memcpy(c, pb, MAX);
79 libat_exchange (j, a + i, c + i, c + i, 0);
80 memcpy(b, pa, MAX);
81 memcpy(b + i, pb + i, j);
82 if (memcmp (b, a, MAX) != 0) abort ();
83 memcpy(b, pb, MAX);
84 memcpy(b + i, pa + i, j);
85 if (memcmp (b, c, MAX) != 0) abort ();
89 static void test_cas(void)
91 int i, j;
92 for (i = ALIGN; i < 2 * ALIGN; ++i)
93 for (j = 1; j <= 2*ALIGN; ++j)
95 memcpy(a, pa, MAX);
96 memcpy(b, pa, MAX);
97 memcpy(c, pa, MAX);
98 memcpy(b + i, pb, j);
99 if (!libat_compare_exchange (j, a + i, c + i, pb, 0, 0)) abort ();
100 if (memcmp (c, pa, MAX) != 0) abort ();
101 if (memcmp (a, b, MAX) != 0) abort ();
103 memcpy(a, pb, MAX);
104 memcpy(b, pa, MAX);
105 memcpy(c, pa, MAX);
106 memcpy(b + i, pb + i, j);
107 if (libat_compare_exchange (j, a + i, c + i, pb, 0, 0)) abort ();
108 if (memcmp (a, pb, MAX) != 0) abort ();
109 if (memcmp (b, c, MAX) != 0) abort ();
113 int main (void)
115 int i;
116 for (i = 0; i < MAX; ++i)
118 pa[i] = i * 2;
119 pb[i] = i * 2 + 1;
122 test_load ();
123 test_store ();
124 test_exch ();
125 test_cas ();
127 return 0;