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