summaryrefslogtreecommitdiffstats
path: root/qemu/tests/tcg/alpha/test-cond.c
blob: 74adffaa695871530ad0ee59d7af261c6c0b93fc (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifdef TEST_CMOV

#define TEST_COND(N) 				\
int test_##N (long a)				\
{						\
  int res = 1;					\
						\
  asm ("cmov"#N" %1,$31,%0"			\
       : "+r" (res) : "r" (a));			\
  return !res;					\
}

#else

#define TEST_COND(N) 				\
int test_##N (long a)				\
{						\
  int res = 1;					\
						\
  asm ("b"#N" %1,1f\n\t"			\
       "addq $31,$31,%0\n\t"			\
       "1: unop\n"				\
       : "+r" (res) : "r" (a));			\
  return res;					\
}

#endif

TEST_COND(eq)
TEST_COND(ne)
TEST_COND(ge)
TEST_COND(gt)
TEST_COND(lbc)
TEST_COND(lbs)
TEST_COND(le)
TEST_COND(lt)

static struct {
  int (*func)(long);
  long v;
  int r;
} vectors[] =
  {
    {test_eq, 0, 1},
    {test_eq, 1, 0},

    {test_ne, 0, 0},
    {test_ne, 1, 1},

    {test_ge, 0, 1},
    {test_ge, 1, 1},
    {test_ge, -1, 0},

    {test_gt, 0, 0},
    {test_gt, 1, 1},
    {test_gt, -1, 0},

    {test_lbc, 0, 1},
    {test_lbc, 1, 0},
    {test_lbc, -1, 0},

    {test_lbs, 0, 0},
    {test_lbs, 1, 1},
    {test_lbs, -1, 1},

    {test_le, 0, 1},
    {test_le, 1, 0},
    {test_le, -1, 1},

    {test_lt, 0, 0},
    {test_lt, 1, 0},
    {test_lt, -1, 1},
  };

int main (void)
{
  int i;

  for (i = 0; i < sizeof (vectors)/sizeof(vectors[0]); i++)
    if ((*vectors[i].func)(vectors[i].v) != vectors[i].r) {
      write(1, "Failed\n", 7);
      return 1;
    }
  write(1, "OK\n", 3);
  return 0;
}