1 /* { dg-do run { target { powerpc*-*-* && htm_hw } } } */
2 /* { dg-require-effective-target powerpc_htm_ok } */
3 /* { dg-options "-mhtm" } */
4 
5 /* Program to test PowerPC HTM instructions.  */
6 
7 #include <stdlib.h>
8 #include <htmintrin.h>
9 
10 int
main(void)11 main (void)
12 {
13   long i;
14   unsigned long mask = 0;
15 
16 repeat:
17   if (__builtin_tbegin (0))
18     {
19       mask++;
20     }
21   else
22     abort();
23 
24   if (mask == 1)
25     {
26       __builtin_tsuspend ();
27 
28       if (_HTM_STATE (__builtin_tcheck ()) != _HTM_SUSPENDED)
29 	abort ();
30 
31       __builtin_tresume ();
32 
33       if (_HTM_STATE (__builtin_tcheck ()) != _HTM_TRANSACTIONAL)
34 	abort ();
35     }
36   else
37     mask++;
38 
39   if (_HTM_STATE (__builtin_tendall ()) != _HTM_TRANSACTIONAL)
40     abort ();
41 
42   if (mask == 1)
43     goto repeat;
44 
45   if (_HTM_STATE (__builtin_tendall ()) != _HTM_NONTRANSACTIONAL)
46     abort ();
47 
48   if (mask != 3)
49     abort ();
50 
51   return 0;
52 }
53