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
11 main (void)
12 {
13 long i;
14 unsigned long mask = 0;
15 unsigned long retry_count = 0;
16
17 repeat:
18 if (__builtin_tbegin (0))
19 {
20 mask++;
21 retry_count = 0;
22 }
23 else
24 {
25 /* Retry a limited number of times before aborting. */
26 if (retry_count++ < 10)
27 goto repeat;
28 abort ();
29 }
30
31 if (mask == 1)
32 {
33 __builtin_tsuspend ();
34
35 if (_HTM_STATE (__builtin_tcheck ()) != _HTM_SUSPENDED)
36 abort ();
37
38 __builtin_tresume ();
39
40 if (_HTM_STATE (__builtin_tcheck ()) != _HTM_TRANSACTIONAL)
41 abort ();
42 }
43 else
44 mask++;
45
46 if (_HTM_STATE (__builtin_tendall ()) != _HTM_TRANSACTIONAL)
47 abort ();
48
49 if (mask == 1)
50 goto repeat;
51
52 if (_HTM_STATE (__builtin_tendall ()) != _HTM_NONTRANSACTIONAL)
53 abort ();
54
55 if (mask != 3)
56 abort ();
57
58 return 0;
59 }