annotate gcc/testsuite/gcc.dg/simulate-thread/atomic-other-longlong.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* { dg-do link } */
kono
parents:
diff changeset
2 /* { dg-require-effective-target sync_long_long_runtime } */
kono
parents:
diff changeset
3 /* { dg-options "" } */
kono
parents:
diff changeset
4 /* { dg-options "-march=pentium" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
kono
parents:
diff changeset
5 /* { dg-final { simulate-thread } } */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 #include <stdio.h>
kono
parents:
diff changeset
9 #include "simulate-thread.h"
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 /* Test all the __sync routines for proper atomicity on 8 byte values. */
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 unsigned long long zero = 0;
kono
parents:
diff changeset
14 unsigned long long max = ~0;
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 unsigned long long changing_value = 0;
kono
parents:
diff changeset
17 unsigned long long value = 0;
kono
parents:
diff changeset
18 unsigned long long ret;
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 void test_abort()
kono
parents:
diff changeset
21 {
kono
parents:
diff changeset
22 static int reported = 0;
kono
parents:
diff changeset
23 if (!reported)
kono
parents:
diff changeset
24 {
kono
parents:
diff changeset
25 printf ("FAIL: improper execution of __sync builtin.\n");
kono
parents:
diff changeset
26 reported = 1;
kono
parents:
diff changeset
27 }
kono
parents:
diff changeset
28 }
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 void simulate_thread_other_threads ()
kono
parents:
diff changeset
31 {
kono
parents:
diff changeset
32 }
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 int simulate_thread_step_verify ()
kono
parents:
diff changeset
35 {
kono
parents:
diff changeset
36 if (value != zero && value != max)
kono
parents:
diff changeset
37 {
kono
parents:
diff changeset
38 printf ("FAIL: invalid intermediate result for value.\n");
kono
parents:
diff changeset
39 return 1;
kono
parents:
diff changeset
40 }
kono
parents:
diff changeset
41 return 0;
kono
parents:
diff changeset
42 }
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 int simulate_thread_final_verify ()
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 if (value != 0)
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 printf ("FAIL: invalid final result for value.\n");
kono
parents:
diff changeset
49 return 1;
kono
parents:
diff changeset
50 }
kono
parents:
diff changeset
51 return 0;
kono
parents:
diff changeset
52 }
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 /* All values written to 'value' alternate between 'zero' and 'max'. Any other
kono
parents:
diff changeset
55 value detected by simulate_thread_step_verify() between instructions would indicate
kono
parents:
diff changeset
56 that the value was only partially written, and would thus fail this
kono
parents:
diff changeset
57 atomicity test.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 This function tests each different __atomic routine once, with the
kono
parents:
diff changeset
60 exception of the load instruction which requires special testing. */
kono
parents:
diff changeset
61 __attribute__((noinline))
kono
parents:
diff changeset
62 void simulate_thread_main()
kono
parents:
diff changeset
63 {
kono
parents:
diff changeset
64 ret = __atomic_exchange_n (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
65 if (ret != zero || value != max)
kono
parents:
diff changeset
66 test_abort();
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 __atomic_store_n (&value, zero, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
69 if (value != zero)
kono
parents:
diff changeset
70 test_abort();
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 ret = __atomic_fetch_add (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
73 if (value != max || ret != zero)
kono
parents:
diff changeset
74 test_abort ();
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 ret = __atomic_fetch_sub (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
77 if (value != zero || ret != max)
kono
parents:
diff changeset
78 test_abort ();
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 ret = __atomic_fetch_or (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
81 if (value != max || ret != zero)
kono
parents:
diff changeset
82 test_abort ();
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 ret = __atomic_fetch_and (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
85 if (value != max || ret != max)
kono
parents:
diff changeset
86 test_abort ();
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 ret = __atomic_fetch_xor (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
89 if (value != zero || ret != max)
kono
parents:
diff changeset
90 test_abort ();
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 ret = __atomic_add_fetch (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
93 if (value != max || ret != max)
kono
parents:
diff changeset
94 test_abort ();
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 ret = __atomic_sub_fetch (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
97 if (value != zero || ret != zero)
kono
parents:
diff changeset
98 test_abort ();
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 ret = __atomic_or_fetch (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
101 if (value != max || ret != max)
kono
parents:
diff changeset
102 test_abort ();
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 ret = __atomic_and_fetch (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
105 if (value != max || ret != max)
kono
parents:
diff changeset
106 test_abort ();
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 ret = __atomic_xor_fetch (&value, max, __ATOMIC_SEQ_CST);
kono
parents:
diff changeset
109 if (value != zero || ret != zero)
kono
parents:
diff changeset
110 test_abort ();
kono
parents:
diff changeset
111 }
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 int main ()
kono
parents:
diff changeset
114 {
kono
parents:
diff changeset
115 simulate_thread_main ();
kono
parents:
diff changeset
116 simulate_thread_done ();
kono
parents:
diff changeset
117 return 0;
kono
parents:
diff changeset
118 }