Tighten condition in vect/pr85586.c (PR 85654)
[official-gcc.git] / gcc / testsuite / gcc.dg / simulate-thread / simulate-thread.h
blob22c05084ee74e469c2e6e02f35038ec78b402ea8
1 int simulate_thread_fini = 0;
3 void __attribute__((noinline))
4 simulate_thread_done ()
6 simulate_thread_fini = 1;
9 /* A hostile thread is one which changes a memory location so quickly
10 that another thread may never see the same value again. This is
11 simulated when simulate_thread_other_thread() is defined to modify
12 a memory location every cycle.
14 A process implementing a dependency on this value can run into
15 difficulties with such a hostile thread. For instance,
16 implementing an add with a compare_and_swap loop goes something
17 like:
19 expected = *mem;
20 loop:
21 new = expected += value;
22 if (!succeed (expected = compare_and_swap (mem, expected, new)))
23 goto loop;
25 If the content of 'mem' are changed every cycle by
26 simulate_thread_other_thread () this will become an infinite loop
27 since the value *mem will never be 'expected' by the time the
28 compare_and_swap is executed.
30 HOSTILE_THREAD_THRESHOLD defines the number of intructions which a
31 program will execute before triggering the hostile thread
32 pause. The pause will last for HOSTILE_THREAD_PAUSE instructions,
33 and then the counter will reset and begin again. During the pause
34 period, simulate_thread_other_thread will not be called.
36 This provides a chance for forward progress to be made and the
37 infinite loop to be avoided.
39 If the testcase defines HOSTILE_PAUSE_ERROR, then it will be
40 considered a RUNTIME FAILURE if the hostile pause is triggered.
41 This will allow to test for guaranteed forward progress routines.
43 If the default values for HOSTILE_THREAD_THRESHOLD or
44 HOSTILE_THREAD_PAUSE are insufficient, then the testcase may
45 override these by defining the values before including this file.
47 Most testcase are intended to run for very short periods of time,
48 so these defaults are considered to be high enough to not trigger
49 on a typical case, but not drag the test time out too much if a
50 hostile condition is interferring. */
53 /* Define the threshold instruction count to start pausing the hostile
54 thread. To avoid huge potential log files when things are not going well,
55 set this number very low. If a test specifically requires that the forward
56 progress guarantee is made, this number should be raised by the testcase. */
57 #if !defined (HOSTILE_THREAD_THRESHOLD)
58 #define HOSTILE_THREAD_THRESHOLD 50
59 #endif
61 /* Define the length of pause in cycles for the hostile thread to pause to
62 allow forward progress to be made. If this number is too low, a
63 compare_and_swap loop may not have time to finish, especially on a
64 128 bit operation. */
65 #if !defined (HOSTILE_THREAD_PAUSE)
66 #define HOSTILE_THREAD_PAUSE 20
67 #endif
69 /* Define the number of instructions which are allowed to be executed before
70 the testcase is deemed to fail. This is primarily to avoid huge log files
71 when a testcase goes into an infinte loop. */
72 #if !defined (INSN_COUNT_THRESHOLD)
73 #define INSN_COUNT_THRESHOLD 10000
74 #endif
76 void simulate_thread_other_threads (void);
77 int simulate_thread_final_verify (void);
79 static int simulate_thread_hostile_pause = 0;
81 /* This function wraps simulate_thread_other_threads an monitors for
82 an infinite loop. If the threshold value HOSTILE_THREAD_THRESHOLD
83 is reached, the other_thread process is paused for
84 HOSTILE_THREAD_PAUSE cycles before resuming, and the counters start
85 again. */
86 int
87 simulate_thread_wrapper_other_threads()
89 static int insn_count = 0;
90 static int hostile_count = 0;
91 static int hostile_pause = 0;
93 if (++insn_count >= INSN_COUNT_THRESHOLD)
95 printf ("FAIL: Testcase exceeded maximum instruction count threshold\n");
96 return 1;
99 if (++hostile_count >= HOSTILE_THREAD_THRESHOLD)
101 if (!simulate_thread_hostile_pause)
102 simulate_thread_hostile_pause = 1;
104 /* Count cycles before calling the hostile thread again. */
105 if (hostile_pause++ < HOSTILE_THREAD_PAUSE)
106 return 0;
108 /* Reset the pause counter, as well as the thread counter. */
109 hostile_pause = 0;
110 hostile_count = 0;
112 simulate_thread_other_threads ();
113 return 0;
117 /* If the test case defines HOSTILE_PAUSE_ERROR, then the test case
118 will fail execution if it had a hostile pause. */
120 simulate_thread_wrapper_final_verify ()
122 int ret = simulate_thread_final_verify ();
123 #if defined (HOSTILE_PAUSE_ERROR)
124 if (simulate_thread_hostile_pause)
126 printf ("FAIL: Forward progress made only by pausing hostile thread\n");
127 ret = ret | 1; /* 0 indicates proper comnpletion. */
129 #endif
130 return ret;