aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/htm-1.c
blob: f27e32ca281a074c1c0080840c970a0353a2952e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* { dg-do run { target { powerpc*-*-* && htm_hw } } } */
/* { dg-require-effective-target powerpc_htm_ok } */
/* { dg-options "-mhtm" } */

/* Program to test PowerPC HTM instructions.  */

#include <stdlib.h>
#include <htmintrin.h>

int
main (void)
{
  long i;
  unsigned long mask = 0;

repeat:
  if (__builtin_tbegin (0))
    {
      mask++;
    }
  else
    abort();

  if (mask == 1)
    {
      __builtin_tsuspend ();

      if (_HTM_STATE (__builtin_tcheck ()) != _HTM_SUSPENDED)
	abort ();

      __builtin_tresume ();

      if (_HTM_STATE (__builtin_tcheck ()) != _HTM_TRANSACTIONAL)
	abort ();
    }
  else
    mask++;

  if (_HTM_STATE (__builtin_tendall ()) != _HTM_TRANSACTIONAL)
    abort ();

  if (mask == 1)
    goto repeat;

  if (_HTM_STATE (__builtin_tendall ()) != _HTM_NONTRANSACTIONAL)
    abort ();

  if (mask != 3)
    abort ();

  return 0;
}