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