boehm-gc: revert all CACAO-specific modifications; this is now an exact copy of the...
[cacao.git] / src / mm / boehm-gc / libatomic_ops-1.2 / tests / test_atomic_include.h
1 /*
2  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
3  *
4  * This file is covered by the GNU general public license, version 2.
5  * see doc/COPYING for details.
6  */
7
8 void test_atomic(void);
9 void test_atomic_release(void);
10 void test_atomic_acquire(void);
11 void test_atomic_read(void);
12 void test_atomic_write(void);
13 void test_atomic_full(void);
14 void test_atomic_release_write(void);
15 void test_atomic_acquire_read(void);
16
17 /* Some basic sanity tests.  These do not test the barrier semantics. */
18
19 #undef TA_assert
20 #define TA_assert(e) \
21   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: )\n", \
22                     __FILE__, __LINE__), exit(1); }
23
24 #undef MISSING
25 #define MISSING(name) \
26   fprintf(stderr, "Missing: %s\n", #name "")
27
28 void test_atomic(void)
29 {
30   AO_t x;
31   unsigned char b;
32   unsigned short s;
33   unsigned int zz;
34 # if defined(AO_HAVE_test_and_set)
35     AO_TS_t z = AO_TS_INITIALIZER;
36 # endif
37 # if defined(AO_HAVE_double_t)
38     AO_double_t w;
39     w.AO_val1 = 0;
40     w.AO_val2 = 0;
41 # endif
42
43 # if defined(AO_HAVE_nop)
44     AO_nop();
45 # else
46     MISSING(AO_nop);
47 # endif
48 # if defined(AO_HAVE_store)
49     AO_store(&x, 13);
50     TA_assert (x == 13);
51 # else
52     MISSING(AO_store);
53     x = 13;
54 # endif
55 # if defined(AO_HAVE_load)
56     TA_assert(AO_load(&x) == 13);
57 # else
58     MISSING(AO_load);
59 # endif
60 # if defined(AO_HAVE_test_and_set)
61     assert(AO_test_and_set(&z) == AO_TS_CLEAR);
62     assert(AO_test_and_set(&z) == AO_TS_SET);
63     assert(AO_test_and_set(&z) == AO_TS_SET);
64     AO_CLEAR(&z);
65 # else
66     MISSING(AO_test_and_set);
67 # endif
68 # if defined(AO_HAVE_fetch_and_add)
69     TA_assert(AO_fetch_and_add(&x, 42) == 13);
70     TA_assert(AO_fetch_and_add(&x, -42) == 55);
71 # else
72     MISSING(AO_fetch_and_add);
73 # endif
74 # if defined(AO_HAVE_fetch_and_add1)
75     TA_assert(AO_fetch_and_add1(&x) == 13);
76 # else
77     MISSING(AO_fetch_and_add1);
78     ++x;
79 # endif
80 # if defined(AO_HAVE_fetch_and_sub1)
81     TA_assert(AO_fetch_and_sub1(&x) == 14);
82 # else
83     MISSING(AO_fetch_and_sub1);
84     --x;
85 # endif
86 # if defined(AO_HAVE_short_store)
87     AO_short_store(&s, 13);
88 # else
89     MISSING(AO_short_store);
90     s = 13;
91 # endif
92 # if defined(AO_HAVE_short_load)
93     TA_assert(AO_short_load(&s) == 13);
94 # else
95     MISSING(AO_short_load);
96 # endif
97 # if defined(AO_HAVE_short_fetch_and_add)
98     TA_assert(AO_short_fetch_and_add(&s, 42) == 13);
99     TA_assert(AO_short_fetch_and_add(&s, -42) == 55);
100 # else
101     MISSING(AO_short_fetch_and_add);
102 # endif
103 # if defined(AO_HAVE_short_fetch_and_add1)
104     TA_assert(AO_short_fetch_and_add1(&s) == 13);
105 # else
106     MISSING(AO_short_fetch_and_add1);
107     ++s;
108 # endif
109 # if defined(AO_HAVE_short_fetch_and_sub1)
110     TA_assert(AO_short_fetch_and_sub1(&s) == 14);
111 # else
112     MISSING(AO_short_fetch_and_sub1);
113     --s;
114 # endif
115 # if defined(AO_HAVE_char_store)
116     AO_char_store(&b, 13);
117 # else
118     MISSING(AO_char_store);
119     b = 13;
120 # endif
121 # if defined(AO_HAVE_char_load)
122     TA_assert(AO_char_load(&b) == 13);
123 # else
124     MISSING(AO_char_load);
125 # endif
126 # if defined(AO_HAVE_char_fetch_and_add)
127     TA_assert(AO_char_fetch_and_add(&b, 42) == 13);
128     TA_assert(AO_char_fetch_and_add(&b, -42) == 55);
129 # else
130     MISSING(AO_char_fetch_and_add);
131 # endif
132 # if defined(AO_HAVE_char_fetch_and_add1)
133     TA_assert(AO_char_fetch_and_add1(&b) == 13);
134 # else
135     MISSING(AO_char_fetch_and_add1);
136     ++b;
137 # endif
138 # if defined(AO_HAVE_char_fetch_and_sub1)
139     TA_assert(AO_char_fetch_and_sub1(&b) == 14);
140 # else
141     MISSING(AO_char_fetch_and_sub1);
142     --b;
143 # endif
144 # if defined(AO_HAVE_int_store)
145     AO_int_store(&zz, 13);
146 # else
147     MISSING(AO_int_store);
148     zz = 13;
149 # endif
150 # if defined(AO_HAVE_int_load)
151     TA_assert(AO_int_load(&zz) == 13);
152 # else
153     MISSING(AO_int_load);
154 # endif
155 # if defined(AO_HAVE_int_fetch_and_add)
156     TA_assert(AO_int_fetch_and_add(&zz, 42) == 13);
157     TA_assert(AO_int_fetch_and_add(&zz, -42) == 55);
158 # else
159     MISSING(AO_int_fetch_and_add);
160 # endif
161 # if defined(AO_HAVE_int_fetch_and_add1)
162     TA_assert(AO_int_fetch_and_add1(&zz) == 13);
163 # else
164     MISSING(AO_int_fetch_and_add1);
165     ++zz;
166 # endif
167 # if defined(AO_HAVE_int_fetch_and_sub1)
168     TA_assert(AO_int_fetch_and_sub1(&zz) == 14);
169 # else
170     MISSING(AO_int_fetch_and_sub1);
171     --zz;
172 # endif
173 # if defined(AO_HAVE_compare_and_swap)
174     TA_assert(!AO_compare_and_swap(&x, 14, 42));
175     TA_assert(x == 13);
176     TA_assert(AO_compare_and_swap(&x, 13, 42));
177     TA_assert(x == 42);
178 # else
179     MISSING(AO_compare_and_swap);
180 # endif
181 # if defined(AO_HAVE_or)
182     AO_or(&x, 66);
183     TA_assert(x == 106);
184 # else
185     MISSING(AO_or);
186     x |= 34;
187 # endif
188 # if defined(AO_HAVE_compare_double_and_swap_double)
189     TA_assert(!AO_compare_double_and_swap_double(&w, 17, 42, 12, 13));
190     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
191     TA_assert(AO_compare_double_and_swap_double(&w, 0, 0, 12, 13));
192     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
193     TA_assert(AO_compare_double_and_swap_double(&w, 12, 13, 17, 42));
194     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
195     w.AO_val1 = 0; w.AO_val2 = 0;
196 # else
197     MISSING(AO_compare_double_and_swap_double);
198 # endif
199 # if defined(AO_HAVE_compare_and_swap_double)
200     TA_assert(!AO_compare_and_swap_double(&w, 17, 12, 13));
201     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
202     TA_assert(AO_compare_and_swap_double(&w, 0, 12, 13));
203     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
204     TA_assert(AO_compare_and_swap_double(&w, 12, 17, 42));
205     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
206 # else
207     MISSING(AO_compare_and_swap_double);
208 # endif
209 }
210
211
212     
213 /*
214  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
215  *
216  * This file is covered by the GNU general public license, version 2.
217  * see doc/COPYING for details.
218  */
219
220 /* Some basic sanity tests.  These do not test the barrier semantics. */
221
222 #undef TA_assert
223 #define TA_assert(e) \
224   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _release)\n", \
225                     __FILE__, __LINE__), exit(1); }
226
227 #undef MISSING
228 #define MISSING(name) \
229   fprintf(stderr, "Missing: %s\n", #name "_release")
230
231 void test_atomic_release(void)
232 {
233   AO_t x;
234   unsigned char b;
235   unsigned short s;
236   unsigned int zz;
237 # if defined(AO_HAVE_test_and_set_release)
238     AO_TS_t z = AO_TS_INITIALIZER;
239 # endif
240 # if defined(AO_HAVE_double_t)
241     AO_double_t w;
242     w.AO_val1 = 0;
243     w.AO_val2 = 0;
244 # endif
245
246 # if defined(AO_HAVE_nop_release)
247     AO_nop_release();
248 # else
249     MISSING(AO_nop);
250 # endif
251 # if defined(AO_HAVE_store_release)
252     AO_store_release(&x, 13);
253     TA_assert (x == 13);
254 # else
255     MISSING(AO_store);
256     x = 13;
257 # endif
258 # if defined(AO_HAVE_load_release)
259     TA_assert(AO_load_release(&x) == 13);
260 # else
261     MISSING(AO_load);
262 # endif
263 # if defined(AO_HAVE_test_and_set_release)
264     assert(AO_test_and_set_release(&z) == AO_TS_CLEAR);
265     assert(AO_test_and_set_release(&z) == AO_TS_SET);
266     assert(AO_test_and_set_release(&z) == AO_TS_SET);
267     AO_CLEAR(&z);
268 # else
269     MISSING(AO_test_and_set);
270 # endif
271 # if defined(AO_HAVE_fetch_and_add_release)
272     TA_assert(AO_fetch_and_add_release(&x, 42) == 13);
273     TA_assert(AO_fetch_and_add_release(&x, -42) == 55);
274 # else
275     MISSING(AO_fetch_and_add);
276 # endif
277 # if defined(AO_HAVE_fetch_and_add1_release)
278     TA_assert(AO_fetch_and_add1_release(&x) == 13);
279 # else
280     MISSING(AO_fetch_and_add1);
281     ++x;
282 # endif
283 # if defined(AO_HAVE_fetch_and_sub1_release)
284     TA_assert(AO_fetch_and_sub1_release(&x) == 14);
285 # else
286     MISSING(AO_fetch_and_sub1);
287     --x;
288 # endif
289 # if defined(AO_HAVE_short_store_release)
290     AO_short_store_release(&s, 13);
291 # else
292     MISSING(AO_short_store);
293     s = 13;
294 # endif
295 # if defined(AO_HAVE_short_load_release)
296     TA_assert(AO_short_load(&s) == 13);
297 # else
298     MISSING(AO_short_load);
299 # endif
300 # if defined(AO_HAVE_short_fetch_and_add_release)
301     TA_assert(AO_short_fetch_and_add_release(&s, 42) == 13);
302     TA_assert(AO_short_fetch_and_add_release(&s, -42) == 55);
303 # else
304     MISSING(AO_short_fetch_and_add);
305 # endif
306 # if defined(AO_HAVE_short_fetch_and_add1_release)
307     TA_assert(AO_short_fetch_and_add1_release(&s) == 13);
308 # else
309     MISSING(AO_short_fetch_and_add1);
310     ++s;
311 # endif
312 # if defined(AO_HAVE_short_fetch_and_sub1_release)
313     TA_assert(AO_short_fetch_and_sub1_release(&s) == 14);
314 # else
315     MISSING(AO_short_fetch_and_sub1);
316     --s;
317 # endif
318 # if defined(AO_HAVE_char_store_release)
319     AO_char_store_release(&b, 13);
320 # else
321     MISSING(AO_char_store);
322     b = 13;
323 # endif
324 # if defined(AO_HAVE_char_load_release)
325     TA_assert(AO_char_load(&b) == 13);
326 # else
327     MISSING(AO_char_load);
328 # endif
329 # if defined(AO_HAVE_char_fetch_and_add_release)
330     TA_assert(AO_char_fetch_and_add_release(&b, 42) == 13);
331     TA_assert(AO_char_fetch_and_add_release(&b, -42) == 55);
332 # else
333     MISSING(AO_char_fetch_and_add);
334 # endif
335 # if defined(AO_HAVE_char_fetch_and_add1_release)
336     TA_assert(AO_char_fetch_and_add1_release(&b) == 13);
337 # else
338     MISSING(AO_char_fetch_and_add1);
339     ++b;
340 # endif
341 # if defined(AO_HAVE_char_fetch_and_sub1_release)
342     TA_assert(AO_char_fetch_and_sub1_release(&b) == 14);
343 # else
344     MISSING(AO_char_fetch_and_sub1);
345     --b;
346 # endif
347 # if defined(AO_HAVE_int_store_release)
348     AO_int_store_release(&zz, 13);
349 # else
350     MISSING(AO_int_store);
351     zz = 13;
352 # endif
353 # if defined(AO_HAVE_int_load_release)
354     TA_assert(AO_int_load(&zz) == 13);
355 # else
356     MISSING(AO_int_load);
357 # endif
358 # if defined(AO_HAVE_int_fetch_and_add_release)
359     TA_assert(AO_int_fetch_and_add_release(&zz, 42) == 13);
360     TA_assert(AO_int_fetch_and_add_release(&zz, -42) == 55);
361 # else
362     MISSING(AO_int_fetch_and_add);
363 # endif
364 # if defined(AO_HAVE_int_fetch_and_add1_release)
365     TA_assert(AO_int_fetch_and_add1_release(&zz) == 13);
366 # else
367     MISSING(AO_int_fetch_and_add1);
368     ++zz;
369 # endif
370 # if defined(AO_HAVE_int_fetch_and_sub1_release)
371     TA_assert(AO_int_fetch_and_sub1_release(&zz) == 14);
372 # else
373     MISSING(AO_int_fetch_and_sub1);
374     --zz;
375 # endif
376 # if defined(AO_HAVE_compare_and_swap_release)
377     TA_assert(!AO_compare_and_swap_release(&x, 14, 42));
378     TA_assert(x == 13);
379     TA_assert(AO_compare_and_swap_release(&x, 13, 42));
380     TA_assert(x == 42);
381 # else
382     MISSING(AO_compare_and_swap);
383 # endif
384 # if defined(AO_HAVE_or_release)
385     AO_or_release(&x, 66);
386     TA_assert(x == 106);
387 # else
388     MISSING(AO_or);
389     x |= 34;
390 # endif
391 # if defined(AO_HAVE_compare_double_and_swap_double_release)
392     TA_assert(!AO_compare_double_and_swap_double_release(&w, 17, 42, 12, 13));
393     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
394     TA_assert(AO_compare_double_and_swap_double_release(&w, 0, 0, 12, 13));
395     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
396     TA_assert(AO_compare_double_and_swap_double_release(&w, 12, 13, 17, 42));
397     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
398     w.AO_val1 = 0; w.AO_val2 = 0;
399 # else
400     MISSING(AO_compare_double_and_swap_double);
401 # endif
402 # if defined(AO_HAVE_compare_and_swap_double_release)
403     TA_assert(!AO_compare_and_swap_double_release(&w, 17, 12, 13));
404     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
405     TA_assert(AO_compare_and_swap_double_release(&w, 0, 12, 13));
406     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
407     TA_assert(AO_compare_and_swap_double_release(&w, 12, 17, 42));
408     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
409 # else
410     MISSING(AO_compare_and_swap_double);
411 # endif
412 }
413
414
415     
416 /*
417  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
418  *
419  * This file is covered by the GNU general public license, version 2.
420  * see doc/COPYING for details.
421  */
422
423 /* Some basic sanity tests.  These do not test the barrier semantics. */
424
425 #undef TA_assert
426 #define TA_assert(e) \
427   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _acquire)\n", \
428                     __FILE__, __LINE__), exit(1); }
429
430 #undef MISSING
431 #define MISSING(name) \
432   fprintf(stderr, "Missing: %s\n", #name "_acquire")
433
434 void test_atomic_acquire(void)
435 {
436   AO_t x;
437   unsigned char b;
438   unsigned short s;
439   unsigned int zz;
440 # if defined(AO_HAVE_test_and_set_acquire)
441     AO_TS_t z = AO_TS_INITIALIZER;
442 # endif
443 # if defined(AO_HAVE_double_t)
444     AO_double_t w;
445     w.AO_val1 = 0;
446     w.AO_val2 = 0;
447 # endif
448
449 # if defined(AO_HAVE_nop_acquire)
450     AO_nop_acquire();
451 # else
452     MISSING(AO_nop);
453 # endif
454 # if defined(AO_HAVE_store_acquire)
455     AO_store_acquire(&x, 13);
456     TA_assert (x == 13);
457 # else
458     MISSING(AO_store);
459     x = 13;
460 # endif
461 # if defined(AO_HAVE_load_acquire)
462     TA_assert(AO_load_acquire(&x) == 13);
463 # else
464     MISSING(AO_load);
465 # endif
466 # if defined(AO_HAVE_test_and_set_acquire)
467     assert(AO_test_and_set_acquire(&z) == AO_TS_CLEAR);
468     assert(AO_test_and_set_acquire(&z) == AO_TS_SET);
469     assert(AO_test_and_set_acquire(&z) == AO_TS_SET);
470     AO_CLEAR(&z);
471 # else
472     MISSING(AO_test_and_set);
473 # endif
474 # if defined(AO_HAVE_fetch_and_add_acquire)
475     TA_assert(AO_fetch_and_add_acquire(&x, 42) == 13);
476     TA_assert(AO_fetch_and_add_acquire(&x, -42) == 55);
477 # else
478     MISSING(AO_fetch_and_add);
479 # endif
480 # if defined(AO_HAVE_fetch_and_add1_acquire)
481     TA_assert(AO_fetch_and_add1_acquire(&x) == 13);
482 # else
483     MISSING(AO_fetch_and_add1);
484     ++x;
485 # endif
486 # if defined(AO_HAVE_fetch_and_sub1_acquire)
487     TA_assert(AO_fetch_and_sub1_acquire(&x) == 14);
488 # else
489     MISSING(AO_fetch_and_sub1);
490     --x;
491 # endif
492 # if defined(AO_HAVE_short_store_acquire)
493     AO_short_store_acquire(&s, 13);
494 # else
495     MISSING(AO_short_store);
496     s = 13;
497 # endif
498 # if defined(AO_HAVE_short_load_acquire)
499     TA_assert(AO_short_load(&s) == 13);
500 # else
501     MISSING(AO_short_load);
502 # endif
503 # if defined(AO_HAVE_short_fetch_and_add_acquire)
504     TA_assert(AO_short_fetch_and_add_acquire(&s, 42) == 13);
505     TA_assert(AO_short_fetch_and_add_acquire(&s, -42) == 55);
506 # else
507     MISSING(AO_short_fetch_and_add);
508 # endif
509 # if defined(AO_HAVE_short_fetch_and_add1_acquire)
510     TA_assert(AO_short_fetch_and_add1_acquire(&s) == 13);
511 # else
512     MISSING(AO_short_fetch_and_add1);
513     ++s;
514 # endif
515 # if defined(AO_HAVE_short_fetch_and_sub1_acquire)
516     TA_assert(AO_short_fetch_and_sub1_acquire(&s) == 14);
517 # else
518     MISSING(AO_short_fetch_and_sub1);
519     --s;
520 # endif
521 # if defined(AO_HAVE_char_store_acquire)
522     AO_char_store_acquire(&b, 13);
523 # else
524     MISSING(AO_char_store);
525     b = 13;
526 # endif
527 # if defined(AO_HAVE_char_load_acquire)
528     TA_assert(AO_char_load(&b) == 13);
529 # else
530     MISSING(AO_char_load);
531 # endif
532 # if defined(AO_HAVE_char_fetch_and_add_acquire)
533     TA_assert(AO_char_fetch_and_add_acquire(&b, 42) == 13);
534     TA_assert(AO_char_fetch_and_add_acquire(&b, -42) == 55);
535 # else
536     MISSING(AO_char_fetch_and_add);
537 # endif
538 # if defined(AO_HAVE_char_fetch_and_add1_acquire)
539     TA_assert(AO_char_fetch_and_add1_acquire(&b) == 13);
540 # else
541     MISSING(AO_char_fetch_and_add1);
542     ++b;
543 # endif
544 # if defined(AO_HAVE_char_fetch_and_sub1_acquire)
545     TA_assert(AO_char_fetch_and_sub1_acquire(&b) == 14);
546 # else
547     MISSING(AO_char_fetch_and_sub1);
548     --b;
549 # endif
550 # if defined(AO_HAVE_int_store_acquire)
551     AO_int_store_acquire(&zz, 13);
552 # else
553     MISSING(AO_int_store);
554     zz = 13;
555 # endif
556 # if defined(AO_HAVE_int_load_acquire)
557     TA_assert(AO_int_load(&zz) == 13);
558 # else
559     MISSING(AO_int_load);
560 # endif
561 # if defined(AO_HAVE_int_fetch_and_add_acquire)
562     TA_assert(AO_int_fetch_and_add_acquire(&zz, 42) == 13);
563     TA_assert(AO_int_fetch_and_add_acquire(&zz, -42) == 55);
564 # else
565     MISSING(AO_int_fetch_and_add);
566 # endif
567 # if defined(AO_HAVE_int_fetch_and_add1_acquire)
568     TA_assert(AO_int_fetch_and_add1_acquire(&zz) == 13);
569 # else
570     MISSING(AO_int_fetch_and_add1);
571     ++zz;
572 # endif
573 # if defined(AO_HAVE_int_fetch_and_sub1_acquire)
574     TA_assert(AO_int_fetch_and_sub1_acquire(&zz) == 14);
575 # else
576     MISSING(AO_int_fetch_and_sub1);
577     --zz;
578 # endif
579 # if defined(AO_HAVE_compare_and_swap_acquire)
580     TA_assert(!AO_compare_and_swap_acquire(&x, 14, 42));
581     TA_assert(x == 13);
582     TA_assert(AO_compare_and_swap_acquire(&x, 13, 42));
583     TA_assert(x == 42);
584 # else
585     MISSING(AO_compare_and_swap);
586 # endif
587 # if defined(AO_HAVE_or_acquire)
588     AO_or_acquire(&x, 66);
589     TA_assert(x == 106);
590 # else
591     MISSING(AO_or);
592     x |= 34;
593 # endif
594 # if defined(AO_HAVE_compare_double_and_swap_double_acquire)
595     TA_assert(!AO_compare_double_and_swap_double_acquire(&w, 17, 42, 12, 13));
596     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
597     TA_assert(AO_compare_double_and_swap_double_acquire(&w, 0, 0, 12, 13));
598     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
599     TA_assert(AO_compare_double_and_swap_double_acquire(&w, 12, 13, 17, 42));
600     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
601     w.AO_val1 = 0; w.AO_val2 = 0;
602 # else
603     MISSING(AO_compare_double_and_swap_double);
604 # endif
605 # if defined(AO_HAVE_compare_and_swap_double_acquire)
606     TA_assert(!AO_compare_and_swap_double_acquire(&w, 17, 12, 13));
607     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
608     TA_assert(AO_compare_and_swap_double_acquire(&w, 0, 12, 13));
609     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
610     TA_assert(AO_compare_and_swap_double_acquire(&w, 12, 17, 42));
611     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
612 # else
613     MISSING(AO_compare_and_swap_double);
614 # endif
615 }
616
617
618     
619 /*
620  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
621  *
622  * This file is covered by the GNU general public license, version 2.
623  * see doc/COPYING for details.
624  */
625
626 /* Some basic sanity tests.  These do not test the barrier semantics. */
627
628 #undef TA_assert
629 #define TA_assert(e) \
630   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _read)\n", \
631                     __FILE__, __LINE__), exit(1); }
632
633 #undef MISSING
634 #define MISSING(name) \
635   fprintf(stderr, "Missing: %s\n", #name "_read")
636
637 void test_atomic_read(void)
638 {
639   AO_t x;
640   unsigned char b;
641   unsigned short s;
642   unsigned int zz;
643 # if defined(AO_HAVE_test_and_set_read)
644     AO_TS_t z = AO_TS_INITIALIZER;
645 # endif
646 # if defined(AO_HAVE_double_t)
647     AO_double_t w;
648     w.AO_val1 = 0;
649     w.AO_val2 = 0;
650 # endif
651
652 # if defined(AO_HAVE_nop_read)
653     AO_nop_read();
654 # else
655     MISSING(AO_nop);
656 # endif
657 # if defined(AO_HAVE_store_read)
658     AO_store_read(&x, 13);
659     TA_assert (x == 13);
660 # else
661     MISSING(AO_store);
662     x = 13;
663 # endif
664 # if defined(AO_HAVE_load_read)
665     TA_assert(AO_load_read(&x) == 13);
666 # else
667     MISSING(AO_load);
668 # endif
669 # if defined(AO_HAVE_test_and_set_read)
670     assert(AO_test_and_set_read(&z) == AO_TS_CLEAR);
671     assert(AO_test_and_set_read(&z) == AO_TS_SET);
672     assert(AO_test_and_set_read(&z) == AO_TS_SET);
673     AO_CLEAR(&z);
674 # else
675     MISSING(AO_test_and_set);
676 # endif
677 # if defined(AO_HAVE_fetch_and_add_read)
678     TA_assert(AO_fetch_and_add_read(&x, 42) == 13);
679     TA_assert(AO_fetch_and_add_read(&x, -42) == 55);
680 # else
681     MISSING(AO_fetch_and_add);
682 # endif
683 # if defined(AO_HAVE_fetch_and_add1_read)
684     TA_assert(AO_fetch_and_add1_read(&x) == 13);
685 # else
686     MISSING(AO_fetch_and_add1);
687     ++x;
688 # endif
689 # if defined(AO_HAVE_fetch_and_sub1_read)
690     TA_assert(AO_fetch_and_sub1_read(&x) == 14);
691 # else
692     MISSING(AO_fetch_and_sub1);
693     --x;
694 # endif
695 # if defined(AO_HAVE_short_store_read)
696     AO_short_store_read(&s, 13);
697 # else
698     MISSING(AO_short_store);
699     s = 13;
700 # endif
701 # if defined(AO_HAVE_short_load_read)
702     TA_assert(AO_short_load(&s) == 13);
703 # else
704     MISSING(AO_short_load);
705 # endif
706 # if defined(AO_HAVE_short_fetch_and_add_read)
707     TA_assert(AO_short_fetch_and_add_read(&s, 42) == 13);
708     TA_assert(AO_short_fetch_and_add_read(&s, -42) == 55);
709 # else
710     MISSING(AO_short_fetch_and_add);
711 # endif
712 # if defined(AO_HAVE_short_fetch_and_add1_read)
713     TA_assert(AO_short_fetch_and_add1_read(&s) == 13);
714 # else
715     MISSING(AO_short_fetch_and_add1);
716     ++s;
717 # endif
718 # if defined(AO_HAVE_short_fetch_and_sub1_read)
719     TA_assert(AO_short_fetch_and_sub1_read(&s) == 14);
720 # else
721     MISSING(AO_short_fetch_and_sub1);
722     --s;
723 # endif
724 # if defined(AO_HAVE_char_store_read)
725     AO_char_store_read(&b, 13);
726 # else
727     MISSING(AO_char_store);
728     b = 13;
729 # endif
730 # if defined(AO_HAVE_char_load_read)
731     TA_assert(AO_char_load(&b) == 13);
732 # else
733     MISSING(AO_char_load);
734 # endif
735 # if defined(AO_HAVE_char_fetch_and_add_read)
736     TA_assert(AO_char_fetch_and_add_read(&b, 42) == 13);
737     TA_assert(AO_char_fetch_and_add_read(&b, -42) == 55);
738 # else
739     MISSING(AO_char_fetch_and_add);
740 # endif
741 # if defined(AO_HAVE_char_fetch_and_add1_read)
742     TA_assert(AO_char_fetch_and_add1_read(&b) == 13);
743 # else
744     MISSING(AO_char_fetch_and_add1);
745     ++b;
746 # endif
747 # if defined(AO_HAVE_char_fetch_and_sub1_read)
748     TA_assert(AO_char_fetch_and_sub1_read(&b) == 14);
749 # else
750     MISSING(AO_char_fetch_and_sub1);
751     --b;
752 # endif
753 # if defined(AO_HAVE_int_store_read)
754     AO_int_store_read(&zz, 13);
755 # else
756     MISSING(AO_int_store);
757     zz = 13;
758 # endif
759 # if defined(AO_HAVE_int_load_read)
760     TA_assert(AO_int_load(&zz) == 13);
761 # else
762     MISSING(AO_int_load);
763 # endif
764 # if defined(AO_HAVE_int_fetch_and_add_read)
765     TA_assert(AO_int_fetch_and_add_read(&zz, 42) == 13);
766     TA_assert(AO_int_fetch_and_add_read(&zz, -42) == 55);
767 # else
768     MISSING(AO_int_fetch_and_add);
769 # endif
770 # if defined(AO_HAVE_int_fetch_and_add1_read)
771     TA_assert(AO_int_fetch_and_add1_read(&zz) == 13);
772 # else
773     MISSING(AO_int_fetch_and_add1);
774     ++zz;
775 # endif
776 # if defined(AO_HAVE_int_fetch_and_sub1_read)
777     TA_assert(AO_int_fetch_and_sub1_read(&zz) == 14);
778 # else
779     MISSING(AO_int_fetch_and_sub1);
780     --zz;
781 # endif
782 # if defined(AO_HAVE_compare_and_swap_read)
783     TA_assert(!AO_compare_and_swap_read(&x, 14, 42));
784     TA_assert(x == 13);
785     TA_assert(AO_compare_and_swap_read(&x, 13, 42));
786     TA_assert(x == 42);
787 # else
788     MISSING(AO_compare_and_swap);
789 # endif
790 # if defined(AO_HAVE_or_read)
791     AO_or_read(&x, 66);
792     TA_assert(x == 106);
793 # else
794     MISSING(AO_or);
795     x |= 34;
796 # endif
797 # if defined(AO_HAVE_compare_double_and_swap_double_read)
798     TA_assert(!AO_compare_double_and_swap_double_read(&w, 17, 42, 12, 13));
799     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
800     TA_assert(AO_compare_double_and_swap_double_read(&w, 0, 0, 12, 13));
801     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
802     TA_assert(AO_compare_double_and_swap_double_read(&w, 12, 13, 17, 42));
803     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
804     w.AO_val1 = 0; w.AO_val2 = 0;
805 # else
806     MISSING(AO_compare_double_and_swap_double);
807 # endif
808 # if defined(AO_HAVE_compare_and_swap_double_read)
809     TA_assert(!AO_compare_and_swap_double_read(&w, 17, 12, 13));
810     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
811     TA_assert(AO_compare_and_swap_double_read(&w, 0, 12, 13));
812     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
813     TA_assert(AO_compare_and_swap_double_read(&w, 12, 17, 42));
814     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
815 # else
816     MISSING(AO_compare_and_swap_double);
817 # endif
818 }
819
820
821     
822 /*
823  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
824  *
825  * This file is covered by the GNU general public license, version 2.
826  * see doc/COPYING for details.
827  */
828
829 /* Some basic sanity tests.  These do not test the barrier semantics. */
830
831 #undef TA_assert
832 #define TA_assert(e) \
833   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _write)\n", \
834                     __FILE__, __LINE__), exit(1); }
835
836 #undef MISSING
837 #define MISSING(name) \
838   fprintf(stderr, "Missing: %s\n", #name "_write")
839
840 void test_atomic_write(void)
841 {
842   AO_t x;
843   unsigned char b;
844   unsigned short s;
845   unsigned int zz;
846 # if defined(AO_HAVE_test_and_set_write)
847     AO_TS_t z = AO_TS_INITIALIZER;
848 # endif
849 # if defined(AO_HAVE_double_t)
850     AO_double_t w;
851     w.AO_val1 = 0;
852     w.AO_val2 = 0;
853 # endif
854
855 # if defined(AO_HAVE_nop_write)
856     AO_nop_write();
857 # else
858     MISSING(AO_nop);
859 # endif
860 # if defined(AO_HAVE_store_write)
861     AO_store_write(&x, 13);
862     TA_assert (x == 13);
863 # else
864     MISSING(AO_store);
865     x = 13;
866 # endif
867 # if defined(AO_HAVE_load_write)
868     TA_assert(AO_load_write(&x) == 13);
869 # else
870     MISSING(AO_load);
871 # endif
872 # if defined(AO_HAVE_test_and_set_write)
873     assert(AO_test_and_set_write(&z) == AO_TS_CLEAR);
874     assert(AO_test_and_set_write(&z) == AO_TS_SET);
875     assert(AO_test_and_set_write(&z) == AO_TS_SET);
876     AO_CLEAR(&z);
877 # else
878     MISSING(AO_test_and_set);
879 # endif
880 # if defined(AO_HAVE_fetch_and_add_write)
881     TA_assert(AO_fetch_and_add_write(&x, 42) == 13);
882     TA_assert(AO_fetch_and_add_write(&x, -42) == 55);
883 # else
884     MISSING(AO_fetch_and_add);
885 # endif
886 # if defined(AO_HAVE_fetch_and_add1_write)
887     TA_assert(AO_fetch_and_add1_write(&x) == 13);
888 # else
889     MISSING(AO_fetch_and_add1);
890     ++x;
891 # endif
892 # if defined(AO_HAVE_fetch_and_sub1_write)
893     TA_assert(AO_fetch_and_sub1_write(&x) == 14);
894 # else
895     MISSING(AO_fetch_and_sub1);
896     --x;
897 # endif
898 # if defined(AO_HAVE_short_store_write)
899     AO_short_store_write(&s, 13);
900 # else
901     MISSING(AO_short_store);
902     s = 13;
903 # endif
904 # if defined(AO_HAVE_short_load_write)
905     TA_assert(AO_short_load(&s) == 13);
906 # else
907     MISSING(AO_short_load);
908 # endif
909 # if defined(AO_HAVE_short_fetch_and_add_write)
910     TA_assert(AO_short_fetch_and_add_write(&s, 42) == 13);
911     TA_assert(AO_short_fetch_and_add_write(&s, -42) == 55);
912 # else
913     MISSING(AO_short_fetch_and_add);
914 # endif
915 # if defined(AO_HAVE_short_fetch_and_add1_write)
916     TA_assert(AO_short_fetch_and_add1_write(&s) == 13);
917 # else
918     MISSING(AO_short_fetch_and_add1);
919     ++s;
920 # endif
921 # if defined(AO_HAVE_short_fetch_and_sub1_write)
922     TA_assert(AO_short_fetch_and_sub1_write(&s) == 14);
923 # else
924     MISSING(AO_short_fetch_and_sub1);
925     --s;
926 # endif
927 # if defined(AO_HAVE_char_store_write)
928     AO_char_store_write(&b, 13);
929 # else
930     MISSING(AO_char_store);
931     b = 13;
932 # endif
933 # if defined(AO_HAVE_char_load_write)
934     TA_assert(AO_char_load(&b) == 13);
935 # else
936     MISSING(AO_char_load);
937 # endif
938 # if defined(AO_HAVE_char_fetch_and_add_write)
939     TA_assert(AO_char_fetch_and_add_write(&b, 42) == 13);
940     TA_assert(AO_char_fetch_and_add_write(&b, -42) == 55);
941 # else
942     MISSING(AO_char_fetch_and_add);
943 # endif
944 # if defined(AO_HAVE_char_fetch_and_add1_write)
945     TA_assert(AO_char_fetch_and_add1_write(&b) == 13);
946 # else
947     MISSING(AO_char_fetch_and_add1);
948     ++b;
949 # endif
950 # if defined(AO_HAVE_char_fetch_and_sub1_write)
951     TA_assert(AO_char_fetch_and_sub1_write(&b) == 14);
952 # else
953     MISSING(AO_char_fetch_and_sub1);
954     --b;
955 # endif
956 # if defined(AO_HAVE_int_store_write)
957     AO_int_store_write(&zz, 13);
958 # else
959     MISSING(AO_int_store);
960     zz = 13;
961 # endif
962 # if defined(AO_HAVE_int_load_write)
963     TA_assert(AO_int_load(&zz) == 13);
964 # else
965     MISSING(AO_int_load);
966 # endif
967 # if defined(AO_HAVE_int_fetch_and_add_write)
968     TA_assert(AO_int_fetch_and_add_write(&zz, 42) == 13);
969     TA_assert(AO_int_fetch_and_add_write(&zz, -42) == 55);
970 # else
971     MISSING(AO_int_fetch_and_add);
972 # endif
973 # if defined(AO_HAVE_int_fetch_and_add1_write)
974     TA_assert(AO_int_fetch_and_add1_write(&zz) == 13);
975 # else
976     MISSING(AO_int_fetch_and_add1);
977     ++zz;
978 # endif
979 # if defined(AO_HAVE_int_fetch_and_sub1_write)
980     TA_assert(AO_int_fetch_and_sub1_write(&zz) == 14);
981 # else
982     MISSING(AO_int_fetch_and_sub1);
983     --zz;
984 # endif
985 # if defined(AO_HAVE_compare_and_swap_write)
986     TA_assert(!AO_compare_and_swap_write(&x, 14, 42));
987     TA_assert(x == 13);
988     TA_assert(AO_compare_and_swap_write(&x, 13, 42));
989     TA_assert(x == 42);
990 # else
991     MISSING(AO_compare_and_swap);
992 # endif
993 # if defined(AO_HAVE_or_write)
994     AO_or_write(&x, 66);
995     TA_assert(x == 106);
996 # else
997     MISSING(AO_or);
998     x |= 34;
999 # endif
1000 # if defined(AO_HAVE_compare_double_and_swap_double_write)
1001     TA_assert(!AO_compare_double_and_swap_double_write(&w, 17, 42, 12, 13));
1002     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
1003     TA_assert(AO_compare_double_and_swap_double_write(&w, 0, 0, 12, 13));
1004     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
1005     TA_assert(AO_compare_double_and_swap_double_write(&w, 12, 13, 17, 42));
1006     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
1007     w.AO_val1 = 0; w.AO_val2 = 0;
1008 # else
1009     MISSING(AO_compare_double_and_swap_double);
1010 # endif
1011 # if defined(AO_HAVE_compare_and_swap_double_write)
1012     TA_assert(!AO_compare_and_swap_double_write(&w, 17, 12, 13));
1013     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
1014     TA_assert(AO_compare_and_swap_double_write(&w, 0, 12, 13));
1015     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
1016     TA_assert(AO_compare_and_swap_double_write(&w, 12, 17, 42));
1017     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
1018 # else
1019     MISSING(AO_compare_and_swap_double);
1020 # endif
1021 }
1022
1023
1024     
1025 /*
1026  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
1027  *
1028  * This file is covered by the GNU general public license, version 2.
1029  * see doc/COPYING for details.
1030  */
1031
1032 /* Some basic sanity tests.  These do not test the barrier semantics. */
1033
1034 #undef TA_assert
1035 #define TA_assert(e) \
1036   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _full)\n", \
1037                     __FILE__, __LINE__), exit(1); }
1038
1039 #undef MISSING
1040 #define MISSING(name) \
1041   fprintf(stderr, "Missing: %s\n", #name "_full")
1042
1043 void test_atomic_full(void)
1044 {
1045   AO_t x;
1046   unsigned char b;
1047   unsigned short s;
1048   unsigned int zz;
1049 # if defined(AO_HAVE_test_and_set_full)
1050     AO_TS_t z = AO_TS_INITIALIZER;
1051 # endif
1052 # if defined(AO_HAVE_double_t)
1053     AO_double_t w;
1054     w.AO_val1 = 0;
1055     w.AO_val2 = 0;
1056 # endif
1057
1058 # if defined(AO_HAVE_nop_full)
1059     AO_nop_full();
1060 # else
1061     MISSING(AO_nop);
1062 # endif
1063 # if defined(AO_HAVE_store_full)
1064     AO_store_full(&x, 13);
1065     TA_assert (x == 13);
1066 # else
1067     MISSING(AO_store);
1068     x = 13;
1069 # endif
1070 # if defined(AO_HAVE_load_full)
1071     TA_assert(AO_load_full(&x) == 13);
1072 # else
1073     MISSING(AO_load);
1074 # endif
1075 # if defined(AO_HAVE_test_and_set_full)
1076     assert(AO_test_and_set_full(&z) == AO_TS_CLEAR);
1077     assert(AO_test_and_set_full(&z) == AO_TS_SET);
1078     assert(AO_test_and_set_full(&z) == AO_TS_SET);
1079     AO_CLEAR(&z);
1080 # else
1081     MISSING(AO_test_and_set);
1082 # endif
1083 # if defined(AO_HAVE_fetch_and_add_full)
1084     TA_assert(AO_fetch_and_add_full(&x, 42) == 13);
1085     TA_assert(AO_fetch_and_add_full(&x, -42) == 55);
1086 # else
1087     MISSING(AO_fetch_and_add);
1088 # endif
1089 # if defined(AO_HAVE_fetch_and_add1_full)
1090     TA_assert(AO_fetch_and_add1_full(&x) == 13);
1091 # else
1092     MISSING(AO_fetch_and_add1);
1093     ++x;
1094 # endif
1095 # if defined(AO_HAVE_fetch_and_sub1_full)
1096     TA_assert(AO_fetch_and_sub1_full(&x) == 14);
1097 # else
1098     MISSING(AO_fetch_and_sub1);
1099     --x;
1100 # endif
1101 # if defined(AO_HAVE_short_store_full)
1102     AO_short_store_full(&s, 13);
1103 # else
1104     MISSING(AO_short_store);
1105     s = 13;
1106 # endif
1107 # if defined(AO_HAVE_short_load_full)
1108     TA_assert(AO_short_load(&s) == 13);
1109 # else
1110     MISSING(AO_short_load);
1111 # endif
1112 # if defined(AO_HAVE_short_fetch_and_add_full)
1113     TA_assert(AO_short_fetch_and_add_full(&s, 42) == 13);
1114     TA_assert(AO_short_fetch_and_add_full(&s, -42) == 55);
1115 # else
1116     MISSING(AO_short_fetch_and_add);
1117 # endif
1118 # if defined(AO_HAVE_short_fetch_and_add1_full)
1119     TA_assert(AO_short_fetch_and_add1_full(&s) == 13);
1120 # else
1121     MISSING(AO_short_fetch_and_add1);
1122     ++s;
1123 # endif
1124 # if defined(AO_HAVE_short_fetch_and_sub1_full)
1125     TA_assert(AO_short_fetch_and_sub1_full(&s) == 14);
1126 # else
1127     MISSING(AO_short_fetch_and_sub1);
1128     --s;
1129 # endif
1130 # if defined(AO_HAVE_char_store_full)
1131     AO_char_store_full(&b, 13);
1132 # else
1133     MISSING(AO_char_store);
1134     b = 13;
1135 # endif
1136 # if defined(AO_HAVE_char_load_full)
1137     TA_assert(AO_char_load(&b) == 13);
1138 # else
1139     MISSING(AO_char_load);
1140 # endif
1141 # if defined(AO_HAVE_char_fetch_and_add_full)
1142     TA_assert(AO_char_fetch_and_add_full(&b, 42) == 13);
1143     TA_assert(AO_char_fetch_and_add_full(&b, -42) == 55);
1144 # else
1145     MISSING(AO_char_fetch_and_add);
1146 # endif
1147 # if defined(AO_HAVE_char_fetch_and_add1_full)
1148     TA_assert(AO_char_fetch_and_add1_full(&b) == 13);
1149 # else
1150     MISSING(AO_char_fetch_and_add1);
1151     ++b;
1152 # endif
1153 # if defined(AO_HAVE_char_fetch_and_sub1_full)
1154     TA_assert(AO_char_fetch_and_sub1_full(&b) == 14);
1155 # else
1156     MISSING(AO_char_fetch_and_sub1);
1157     --b;
1158 # endif
1159 # if defined(AO_HAVE_int_store_full)
1160     AO_int_store_full(&zz, 13);
1161 # else
1162     MISSING(AO_int_store);
1163     zz = 13;
1164 # endif
1165 # if defined(AO_HAVE_int_load_full)
1166     TA_assert(AO_int_load(&zz) == 13);
1167 # else
1168     MISSING(AO_int_load);
1169 # endif
1170 # if defined(AO_HAVE_int_fetch_and_add_full)
1171     TA_assert(AO_int_fetch_and_add_full(&zz, 42) == 13);
1172     TA_assert(AO_int_fetch_and_add_full(&zz, -42) == 55);
1173 # else
1174     MISSING(AO_int_fetch_and_add);
1175 # endif
1176 # if defined(AO_HAVE_int_fetch_and_add1_full)
1177     TA_assert(AO_int_fetch_and_add1_full(&zz) == 13);
1178 # else
1179     MISSING(AO_int_fetch_and_add1);
1180     ++zz;
1181 # endif
1182 # if defined(AO_HAVE_int_fetch_and_sub1_full)
1183     TA_assert(AO_int_fetch_and_sub1_full(&zz) == 14);
1184 # else
1185     MISSING(AO_int_fetch_and_sub1);
1186     --zz;
1187 # endif
1188 # if defined(AO_HAVE_compare_and_swap_full)
1189     TA_assert(!AO_compare_and_swap_full(&x, 14, 42));
1190     TA_assert(x == 13);
1191     TA_assert(AO_compare_and_swap_full(&x, 13, 42));
1192     TA_assert(x == 42);
1193 # else
1194     MISSING(AO_compare_and_swap);
1195 # endif
1196 # if defined(AO_HAVE_or_full)
1197     AO_or_full(&x, 66);
1198     TA_assert(x == 106);
1199 # else
1200     MISSING(AO_or);
1201     x |= 34;
1202 # endif
1203 # if defined(AO_HAVE_compare_double_and_swap_double_full)
1204     TA_assert(!AO_compare_double_and_swap_double_full(&w, 17, 42, 12, 13));
1205     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
1206     TA_assert(AO_compare_double_and_swap_double_full(&w, 0, 0, 12, 13));
1207     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
1208     TA_assert(AO_compare_double_and_swap_double_full(&w, 12, 13, 17, 42));
1209     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
1210     w.AO_val1 = 0; w.AO_val2 = 0;
1211 # else
1212     MISSING(AO_compare_double_and_swap_double);
1213 # endif
1214 # if defined(AO_HAVE_compare_and_swap_double_full)
1215     TA_assert(!AO_compare_and_swap_double_full(&w, 17, 12, 13));
1216     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
1217     TA_assert(AO_compare_and_swap_double_full(&w, 0, 12, 13));
1218     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
1219     TA_assert(AO_compare_and_swap_double_full(&w, 12, 17, 42));
1220     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
1221 # else
1222     MISSING(AO_compare_and_swap_double);
1223 # endif
1224 }
1225
1226
1227     
1228 /*
1229  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
1230  *
1231  * This file is covered by the GNU general public license, version 2.
1232  * see doc/COPYING for details.
1233  */
1234
1235 /* Some basic sanity tests.  These do not test the barrier semantics. */
1236
1237 #undef TA_assert
1238 #define TA_assert(e) \
1239   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _release_write)\n", \
1240                     __FILE__, __LINE__), exit(1); }
1241
1242 #undef MISSING
1243 #define MISSING(name) \
1244   fprintf(stderr, "Missing: %s\n", #name "_release_write")
1245
1246 void test_atomic_release_write(void)
1247 {
1248   AO_t x;
1249   unsigned char b;
1250   unsigned short s;
1251   unsigned int zz;
1252 # if defined(AO_HAVE_test_and_set_release_write)
1253     AO_TS_t z = AO_TS_INITIALIZER;
1254 # endif
1255 # if defined(AO_HAVE_double_t)
1256     AO_double_t w;
1257     w.AO_val1 = 0;
1258     w.AO_val2 = 0;
1259 # endif
1260
1261 # if defined(AO_HAVE_nop_release_write)
1262     AO_nop_release_write();
1263 # else
1264     MISSING(AO_nop);
1265 # endif
1266 # if defined(AO_HAVE_store_release_write)
1267     AO_store_release_write(&x, 13);
1268     TA_assert (x == 13);
1269 # else
1270     MISSING(AO_store);
1271     x = 13;
1272 # endif
1273 # if defined(AO_HAVE_load_release_write)
1274     TA_assert(AO_load_release_write(&x) == 13);
1275 # else
1276     MISSING(AO_load);
1277 # endif
1278 # if defined(AO_HAVE_test_and_set_release_write)
1279     assert(AO_test_and_set_release_write(&z) == AO_TS_CLEAR);
1280     assert(AO_test_and_set_release_write(&z) == AO_TS_SET);
1281     assert(AO_test_and_set_release_write(&z) == AO_TS_SET);
1282     AO_CLEAR(&z);
1283 # else
1284     MISSING(AO_test_and_set);
1285 # endif
1286 # if defined(AO_HAVE_fetch_and_add_release_write)
1287     TA_assert(AO_fetch_and_add_release_write(&x, 42) == 13);
1288     TA_assert(AO_fetch_and_add_release_write(&x, -42) == 55);
1289 # else
1290     MISSING(AO_fetch_and_add);
1291 # endif
1292 # if defined(AO_HAVE_fetch_and_add1_release_write)
1293     TA_assert(AO_fetch_and_add1_release_write(&x) == 13);
1294 # else
1295     MISSING(AO_fetch_and_add1);
1296     ++x;
1297 # endif
1298 # if defined(AO_HAVE_fetch_and_sub1_release_write)
1299     TA_assert(AO_fetch_and_sub1_release_write(&x) == 14);
1300 # else
1301     MISSING(AO_fetch_and_sub1);
1302     --x;
1303 # endif
1304 # if defined(AO_HAVE_short_store_release_write)
1305     AO_short_store_release_write(&s, 13);
1306 # else
1307     MISSING(AO_short_store);
1308     s = 13;
1309 # endif
1310 # if defined(AO_HAVE_short_load_release_write)
1311     TA_assert(AO_short_load(&s) == 13);
1312 # else
1313     MISSING(AO_short_load);
1314 # endif
1315 # if defined(AO_HAVE_short_fetch_and_add_release_write)
1316     TA_assert(AO_short_fetch_and_add_release_write(&s, 42) == 13);
1317     TA_assert(AO_short_fetch_and_add_release_write(&s, -42) == 55);
1318 # else
1319     MISSING(AO_short_fetch_and_add);
1320 # endif
1321 # if defined(AO_HAVE_short_fetch_and_add1_release_write)
1322     TA_assert(AO_short_fetch_and_add1_release_write(&s) == 13);
1323 # else
1324     MISSING(AO_short_fetch_and_add1);
1325     ++s;
1326 # endif
1327 # if defined(AO_HAVE_short_fetch_and_sub1_release_write)
1328     TA_assert(AO_short_fetch_and_sub1_release_write(&s) == 14);
1329 # else
1330     MISSING(AO_short_fetch_and_sub1);
1331     --s;
1332 # endif
1333 # if defined(AO_HAVE_char_store_release_write)
1334     AO_char_store_release_write(&b, 13);
1335 # else
1336     MISSING(AO_char_store);
1337     b = 13;
1338 # endif
1339 # if defined(AO_HAVE_char_load_release_write)
1340     TA_assert(AO_char_load(&b) == 13);
1341 # else
1342     MISSING(AO_char_load);
1343 # endif
1344 # if defined(AO_HAVE_char_fetch_and_add_release_write)
1345     TA_assert(AO_char_fetch_and_add_release_write(&b, 42) == 13);
1346     TA_assert(AO_char_fetch_and_add_release_write(&b, -42) == 55);
1347 # else
1348     MISSING(AO_char_fetch_and_add);
1349 # endif
1350 # if defined(AO_HAVE_char_fetch_and_add1_release_write)
1351     TA_assert(AO_char_fetch_and_add1_release_write(&b) == 13);
1352 # else
1353     MISSING(AO_char_fetch_and_add1);
1354     ++b;
1355 # endif
1356 # if defined(AO_HAVE_char_fetch_and_sub1_release_write)
1357     TA_assert(AO_char_fetch_and_sub1_release_write(&b) == 14);
1358 # else
1359     MISSING(AO_char_fetch_and_sub1);
1360     --b;
1361 # endif
1362 # if defined(AO_HAVE_int_store_release_write)
1363     AO_int_store_release_write(&zz, 13);
1364 # else
1365     MISSING(AO_int_store);
1366     zz = 13;
1367 # endif
1368 # if defined(AO_HAVE_int_load_release_write)
1369     TA_assert(AO_int_load(&zz) == 13);
1370 # else
1371     MISSING(AO_int_load);
1372 # endif
1373 # if defined(AO_HAVE_int_fetch_and_add_release_write)
1374     TA_assert(AO_int_fetch_and_add_release_write(&zz, 42) == 13);
1375     TA_assert(AO_int_fetch_and_add_release_write(&zz, -42) == 55);
1376 # else
1377     MISSING(AO_int_fetch_and_add);
1378 # endif
1379 # if defined(AO_HAVE_int_fetch_and_add1_release_write)
1380     TA_assert(AO_int_fetch_and_add1_release_write(&zz) == 13);
1381 # else
1382     MISSING(AO_int_fetch_and_add1);
1383     ++zz;
1384 # endif
1385 # if defined(AO_HAVE_int_fetch_and_sub1_release_write)
1386     TA_assert(AO_int_fetch_and_sub1_release_write(&zz) == 14);
1387 # else
1388     MISSING(AO_int_fetch_and_sub1);
1389     --zz;
1390 # endif
1391 # if defined(AO_HAVE_compare_and_swap_release_write)
1392     TA_assert(!AO_compare_and_swap_release_write(&x, 14, 42));
1393     TA_assert(x == 13);
1394     TA_assert(AO_compare_and_swap_release_write(&x, 13, 42));
1395     TA_assert(x == 42);
1396 # else
1397     MISSING(AO_compare_and_swap);
1398 # endif
1399 # if defined(AO_HAVE_or_release_write)
1400     AO_or_release_write(&x, 66);
1401     TA_assert(x == 106);
1402 # else
1403     MISSING(AO_or);
1404     x |= 34;
1405 # endif
1406 # if defined(AO_HAVE_compare_double_and_swap_double_release_write)
1407     TA_assert(!AO_compare_double_and_swap_double_release_write(&w, 17, 42, 12, 13));
1408     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
1409     TA_assert(AO_compare_double_and_swap_double_release_write(&w, 0, 0, 12, 13));
1410     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
1411     TA_assert(AO_compare_double_and_swap_double_release_write(&w, 12, 13, 17, 42));
1412     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
1413     w.AO_val1 = 0; w.AO_val2 = 0;
1414 # else
1415     MISSING(AO_compare_double_and_swap_double);
1416 # endif
1417 # if defined(AO_HAVE_compare_and_swap_double_release_write)
1418     TA_assert(!AO_compare_and_swap_double_release_write(&w, 17, 12, 13));
1419     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
1420     TA_assert(AO_compare_and_swap_double_release_write(&w, 0, 12, 13));
1421     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
1422     TA_assert(AO_compare_and_swap_double_release_write(&w, 12, 17, 42));
1423     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
1424 # else
1425     MISSING(AO_compare_and_swap_double);
1426 # endif
1427 }
1428
1429
1430     
1431 /*
1432  * Copyright (c) 2003 by Hewlett-Packard Company.  All rights reserved.
1433  *
1434  * This file is covered by the GNU general public license, version 2.
1435  * see doc/COPYING for details.
1436  */
1437
1438 /* Some basic sanity tests.  These do not test the barrier semantics. */
1439
1440 #undef TA_assert
1441 #define TA_assert(e) \
1442   if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: _acquire_read)\n", \
1443                     __FILE__, __LINE__), exit(1); }
1444
1445 #undef MISSING
1446 #define MISSING(name) \
1447   fprintf(stderr, "Missing: %s\n", #name "_acquire_read")
1448
1449 void test_atomic_acquire_read(void)
1450 {
1451   AO_t x;
1452   unsigned char b;
1453   unsigned short s;
1454   unsigned int zz;
1455 # if defined(AO_HAVE_test_and_set_acquire_read)
1456     AO_TS_t z = AO_TS_INITIALIZER;
1457 # endif
1458 # if defined(AO_HAVE_double_t)
1459     AO_double_t w;
1460     w.AO_val1 = 0;
1461     w.AO_val2 = 0;
1462 # endif
1463
1464 # if defined(AO_HAVE_nop_acquire_read)
1465     AO_nop_acquire_read();
1466 # else
1467     MISSING(AO_nop);
1468 # endif
1469 # if defined(AO_HAVE_store_acquire_read)
1470     AO_store_acquire_read(&x, 13);
1471     TA_assert (x == 13);
1472 # else
1473     MISSING(AO_store);
1474     x = 13;
1475 # endif
1476 # if defined(AO_HAVE_load_acquire_read)
1477     TA_assert(AO_load_acquire_read(&x) == 13);
1478 # else
1479     MISSING(AO_load);
1480 # endif
1481 # if defined(AO_HAVE_test_and_set_acquire_read)
1482     assert(AO_test_and_set_acquire_read(&z) == AO_TS_CLEAR);
1483     assert(AO_test_and_set_acquire_read(&z) == AO_TS_SET);
1484     assert(AO_test_and_set_acquire_read(&z) == AO_TS_SET);
1485     AO_CLEAR(&z);
1486 # else
1487     MISSING(AO_test_and_set);
1488 # endif
1489 # if defined(AO_HAVE_fetch_and_add_acquire_read)
1490     TA_assert(AO_fetch_and_add_acquire_read(&x, 42) == 13);
1491     TA_assert(AO_fetch_and_add_acquire_read(&x, -42) == 55);
1492 # else
1493     MISSING(AO_fetch_and_add);
1494 # endif
1495 # if defined(AO_HAVE_fetch_and_add1_acquire_read)
1496     TA_assert(AO_fetch_and_add1_acquire_read(&x) == 13);
1497 # else
1498     MISSING(AO_fetch_and_add1);
1499     ++x;
1500 # endif
1501 # if defined(AO_HAVE_fetch_and_sub1_acquire_read)
1502     TA_assert(AO_fetch_and_sub1_acquire_read(&x) == 14);
1503 # else
1504     MISSING(AO_fetch_and_sub1);
1505     --x;
1506 # endif
1507 # if defined(AO_HAVE_short_store_acquire_read)
1508     AO_short_store_acquire_read(&s, 13);
1509 # else
1510     MISSING(AO_short_store);
1511     s = 13;
1512 # endif
1513 # if defined(AO_HAVE_short_load_acquire_read)
1514     TA_assert(AO_short_load(&s) == 13);
1515 # else
1516     MISSING(AO_short_load);
1517 # endif
1518 # if defined(AO_HAVE_short_fetch_and_add_acquire_read)
1519     TA_assert(AO_short_fetch_and_add_acquire_read(&s, 42) == 13);
1520     TA_assert(AO_short_fetch_and_add_acquire_read(&s, -42) == 55);
1521 # else
1522     MISSING(AO_short_fetch_and_add);
1523 # endif
1524 # if defined(AO_HAVE_short_fetch_and_add1_acquire_read)
1525     TA_assert(AO_short_fetch_and_add1_acquire_read(&s) == 13);
1526 # else
1527     MISSING(AO_short_fetch_and_add1);
1528     ++s;
1529 # endif
1530 # if defined(AO_HAVE_short_fetch_and_sub1_acquire_read)
1531     TA_assert(AO_short_fetch_and_sub1_acquire_read(&s) == 14);
1532 # else
1533     MISSING(AO_short_fetch_and_sub1);
1534     --s;
1535 # endif
1536 # if defined(AO_HAVE_char_store_acquire_read)
1537     AO_char_store_acquire_read(&b, 13);
1538 # else
1539     MISSING(AO_char_store);
1540     b = 13;
1541 # endif
1542 # if defined(AO_HAVE_char_load_acquire_read)
1543     TA_assert(AO_char_load(&b) == 13);
1544 # else
1545     MISSING(AO_char_load);
1546 # endif
1547 # if defined(AO_HAVE_char_fetch_and_add_acquire_read)
1548     TA_assert(AO_char_fetch_and_add_acquire_read(&b, 42) == 13);
1549     TA_assert(AO_char_fetch_and_add_acquire_read(&b, -42) == 55);
1550 # else
1551     MISSING(AO_char_fetch_and_add);
1552 # endif
1553 # if defined(AO_HAVE_char_fetch_and_add1_acquire_read)
1554     TA_assert(AO_char_fetch_and_add1_acquire_read(&b) == 13);
1555 # else
1556     MISSING(AO_char_fetch_and_add1);
1557     ++b;
1558 # endif
1559 # if defined(AO_HAVE_char_fetch_and_sub1_acquire_read)
1560     TA_assert(AO_char_fetch_and_sub1_acquire_read(&b) == 14);
1561 # else
1562     MISSING(AO_char_fetch_and_sub1);
1563     --b;
1564 # endif
1565 # if defined(AO_HAVE_int_store_acquire_read)
1566     AO_int_store_acquire_read(&zz, 13);
1567 # else
1568     MISSING(AO_int_store);
1569     zz = 13;
1570 # endif
1571 # if defined(AO_HAVE_int_load_acquire_read)
1572     TA_assert(AO_int_load(&zz) == 13);
1573 # else
1574     MISSING(AO_int_load);
1575 # endif
1576 # if defined(AO_HAVE_int_fetch_and_add_acquire_read)
1577     TA_assert(AO_int_fetch_and_add_acquire_read(&zz, 42) == 13);
1578     TA_assert(AO_int_fetch_and_add_acquire_read(&zz, -42) == 55);
1579 # else
1580     MISSING(AO_int_fetch_and_add);
1581 # endif
1582 # if defined(AO_HAVE_int_fetch_and_add1_acquire_read)
1583     TA_assert(AO_int_fetch_and_add1_acquire_read(&zz) == 13);
1584 # else
1585     MISSING(AO_int_fetch_and_add1);
1586     ++zz;
1587 # endif
1588 # if defined(AO_HAVE_int_fetch_and_sub1_acquire_read)
1589     TA_assert(AO_int_fetch_and_sub1_acquire_read(&zz) == 14);
1590 # else
1591     MISSING(AO_int_fetch_and_sub1);
1592     --zz;
1593 # endif
1594 # if defined(AO_HAVE_compare_and_swap_acquire_read)
1595     TA_assert(!AO_compare_and_swap_acquire_read(&x, 14, 42));
1596     TA_assert(x == 13);
1597     TA_assert(AO_compare_and_swap_acquire_read(&x, 13, 42));
1598     TA_assert(x == 42);
1599 # else
1600     MISSING(AO_compare_and_swap);
1601 # endif
1602 # if defined(AO_HAVE_or_acquire_read)
1603     AO_or_acquire_read(&x, 66);
1604     TA_assert(x == 106);
1605 # else
1606     MISSING(AO_or);
1607     x |= 34;
1608 # endif
1609 # if defined(AO_HAVE_compare_double_and_swap_double_acquire_read)
1610     TA_assert(!AO_compare_double_and_swap_double_acquire_read(&w, 17, 42, 12, 13));
1611     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
1612     TA_assert(AO_compare_double_and_swap_double_acquire_read(&w, 0, 0, 12, 13));
1613     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
1614     TA_assert(AO_compare_double_and_swap_double_acquire_read(&w, 12, 13, 17, 42));
1615     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
1616     w.AO_val1 = 0; w.AO_val2 = 0;
1617 # else
1618     MISSING(AO_compare_double_and_swap_double);
1619 # endif
1620 # if defined(AO_HAVE_compare_and_swap_double_acquire_read)
1621     TA_assert(!AO_compare_and_swap_double_acquire_read(&w, 17, 12, 13));
1622     TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
1623     TA_assert(AO_compare_and_swap_double_acquire_read(&w, 0, 12, 13));
1624     TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
1625     TA_assert(AO_compare_and_swap_double_acquire_read(&w, 12, 17, 42));
1626     TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
1627 # else
1628     MISSING(AO_compare_and_swap_double);
1629 # endif
1630 }
1631
1632
1633