summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/xop-vshift-1.c
blob: ee3d2990390ab8ef354b9ef3f0769e2418e46e49 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* { dg-do run } */
/* { dg-options "-O3 -mxop" } */
/* { dg-require-effective-target xop } */

#ifndef CHECK_H
#define CHECK_H "xop-check.h"
#endif

#ifndef TEST
#define TEST xop_test
#endif

#include CHECK_H

#define N 64

#ifndef TYPE1
#define TYPE1 int
#define TYPE2 long long
#endif

/* mingw runtime don't provide random().  */
#ifdef __MINGW32__
#define random rand
#endif

signed TYPE1 a[N], b[N], g[N];
unsigned TYPE1 c[N], h[N];
signed TYPE2 d[N], e[N], j[N];
unsigned TYPE2 f[N], k[N];

__attribute__((noinline)) void
f1 (void)
{
  int i;
  for (i = 0; i < N; i++)
    g[i] = a[i] << b[i];
}

__attribute__((noinline)) void
f2 (void)
{
  int i;
  for (i = 0; i < N; i++)
    g[i] = a[i] >> b[i];
}

__attribute__((noinline)) void
f3 (void)
{
  int i;
  for (i = 0; i < N; i++)
    h[i] = c[i] >> b[i];
}

__attribute__((noinline)) void
f4 (void)
{
  int i;
  for (i = 0; i < N; i++)
    j[i] = d[i] << e[i];
}

__attribute__((noinline)) void
f5 (void)
{
  int i;
  for (i = 0; i < N; i++)
    j[i] = d[i] >> e[i];
}

__attribute__((noinline)) void
f6 (void)
{
  int i;
  for (i = 0; i < N; i++)
    k[i] = f[i] >> e[i];
}

__attribute__((noinline)) void
f7 (void)
{
  int i;
  for (i = 0; i < N; i++)
    j[i] = d[i] << b[i];
}

__attribute__((noinline)) void
f8 (void)
{
  int i;
  for (i = 0; i < N; i++)
    j[i] = d[i] >> b[i];
}

__attribute__((noinline)) void
f9 (void)
{
  int i;
  for (i = 0; i < N; i++)
    k[i] = f[i] >> b[i];
}

static void
TEST ()
{
  int i;
  for (i = 0; i < N; i++)
    {
      asm ("");
      c[i] = (random () << 1) | (random () & 1);
      b[i] = (i * 85) & (sizeof (TYPE1) * __CHAR_BIT__ - 1);
      a[i] = c[i];
      d[i] = (random () << 1) | (random () & 1);
      d[i] |= (unsigned long long) c[i] << 32;
      e[i] = (i * 85) & (sizeof (TYPE2) * __CHAR_BIT__ - 1);
      f[i] = d[i];
    }
  f1 ();
  f3 ();
  f4 ();
  f6 ();
  for (i = 0; i < N; i++)
    if (g[i] != (signed TYPE1) (a[i] << b[i])
	|| h[i] != (unsigned TYPE1) (c[i] >> b[i])
	|| j[i] != (signed TYPE2) (d[i] << e[i])
	|| k[i] != (unsigned TYPE2) (f[i] >> e[i]))
      abort ();
  f2 ();
  f5 ();
  f9 ();
  for (i = 0; i < N; i++)
    if (g[i] != (signed TYPE1) (a[i] >> b[i])
	|| j[i] != (signed TYPE2) (d[i] >> e[i])
	|| k[i] != (unsigned TYPE2) (f[i] >> b[i]))
      abort ();
  f7 ();
  for (i = 0; i < N; i++)
    if (j[i] != (signed TYPE2) (d[i] << b[i]))
      abort ();
  f8 ();
  for (i = 0; i < N; i++)
    if (j[i] != (signed TYPE2) (d[i] >> b[i]))
      abort ();
}