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)
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
);
37 static void test_load(void)
40 for (i
= ALIGN
; i
< 2*ALIGN
; ++i
)
41 for (j
= 1; j
<= 2*ALIGN
; ++j
)
45 libat_load (j
, b
+ i
, a
, 0);
46 if (memcmp (a
, pb
, j
) != 0) abort ();
50 static void test_store(void)
53 for (i
= ALIGN
; i
< 2*ALIGN
; ++i
)
54 for (j
= 1; j
<= 2*ALIGN
; ++j
)
59 libat_store (j
, a
+ i
, pb
, 0);
60 if (memcmp (a
, b
, MAX
) != 0) abort ();
64 static void test_exch(void)
67 for (i
= ALIGN
; i
< 2 * ALIGN
; ++i
)
68 for (j
= 1; j
<= 2*ALIGN
; ++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 ();
79 libat_exchange (j
, a
+ i
, c
+ i
, c
+ i
, 0);
81 memcpy(b
+ i
, pb
+ i
, j
);
82 if (memcmp (b
, a
, MAX
) != 0) abort ();
84 memcpy(b
+ i
, pa
+ i
, j
);
85 if (memcmp (b
, c
, MAX
) != 0) abort ();
89 static void test_cas(void)
92 for (i
= ALIGN
; i
< 2 * ALIGN
; ++i
)
93 for (j
= 1; j
<= 2*ALIGN
; ++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 ();
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 ();
116 for (i
= 0; i
< MAX
; ++i
)