aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.target/i386/sse2-mul-1.c
blob: 9cdc12763b0b97cdcff6aacba82d4f5f3095d29b (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* { dg-do run } */
/* { dg-require-effective-target sse2 } */
/* { dg-options "-O3 -msse2" } */

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

#ifndef TEST
#define TEST sse2_test
#endif

#include CHECK_H

#include <stdlib.h>

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

#define N 512
static short a1[N], a2[N], a3[N];
static unsigned short b1[N], b2[N], b3[N];
static int c1[N], c2[N], c3[N];
static unsigned int d1[N], d2[N], d3[N];
static long long e1[N], e2[N], e3[N];
static unsigned long long g1[N], g2[N], g3[N];

__attribute__((noinline, noclone)) void
f1 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    a1[i] = a2[i] * a3[i];
}

__attribute__((noinline, noclone)) void
f2 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    b1[i] = b2[i] * b3[i];
}

__attribute__((noinline, noclone)) void
f3 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    c1[i] = c2[i] * c3[i];
}

__attribute__((noinline, noclone)) void
f4 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    d1[i] = d2[i] * d3[i];
}

__attribute__((noinline, noclone)) void
f5 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    e1[i] = e2[i] * e3[i];
}

__attribute__((noinline, noclone)) void
f6 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    g1[i] = g2[i] * g3[i];
}

__attribute__((noinline, noclone)) void
f7 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    c1[i] = a2[i] * a3[i];
}

__attribute__((noinline, noclone)) void
f8 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    d1[i] = (unsigned int) b2[i] * b3[i];
}

__attribute__((noinline, noclone)) void
f9 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    e1[i] = (long long) c2[i] * (long long) c3[i];
}

__attribute__((noinline, noclone)) void
f10 (void)
{
  int i;
  for (i = 0; i < N; ++i)
    g1[i] = (unsigned long long) d2[i] * (unsigned long long) d3[i];
}

__attribute__((noinline, noclone)) int
f11 (void)
{
  int i, r = 0;
  for (i = 0; i < N; ++i)
    r += a2[i] * a3[i];
  return r;
}

__attribute__((noinline, noclone)) unsigned int
f12 (void)
{
  int i;
  unsigned r = 0;
  for (i = 0; i < N; ++i)
    r += (unsigned int) b2[i] * b3[i];
  return r;
}

__attribute__((noinline, noclone)) long long
f13 (void)
{
  int i;
  long long r = 0;
  for (i = 0; i < N; ++i)
    r += (long long) c2[i] * (long long) c3[i];
  return r;
}

__attribute__((noinline, noclone)) unsigned long long
f14 (void)
{
  int i;
  unsigned long long r = 0;
  for (i = 0; i < N; ++i)
    r += (unsigned long long) d2[i] * (unsigned long long) d3[i];
  return r;
}

static void
TEST (void)
{
  int i;
  int s1 = 0;
  unsigned int s2 = 0;
  long long s3 = 0;
  unsigned long long s4 = 0;
  for (i = 0; i < N; ++i)
    {
      asm volatile ("" : : "r" (&s1) : "memory");
      asm volatile ("" : : "r" (&s2) : "memory");
      asm volatile ("" : : "r" (&s3) : "memory");
      asm volatile ("" : : "r" (&s4) : "memory");
      b2[i] = (int) random ();
      b3[i] = (int) random ();
      a2[i] = b2[i];
      a3[i] = b3[i];
      d2[i] = (((int) random ()) << 16) | b2[i];
      d3[i] = (((int) random ()) << 16) | b3[i];
      c2[i] = d2[i];
      c3[i] = d3[i];
      s1 += a2[i] * a3[i];
      s2 += (unsigned int) b2[i] * b3[i];
      s3 += (long long) c2[i] * (long long) c3[i];
      s4 += (unsigned long long) d2[i] * (unsigned long long) d3[i];
    }
  f1 ();
  f2 ();
  f3 ();
  f4 ();
  f5 ();
  f6 ();
  for (i = 0; i < N; ++i)
    {
      if (a1[i] != (short) (a2[i] * a3[i]))
	abort ();
      if (b1[i] != (unsigned short) (b2[i] * b3[i]))
	abort ();
      if (c1[i] != c2[i] * c3[i])
	abort ();
      if (d1[i] != d2[i] * d3[i])
	abort ();
      if (e1[i] != e2[i] * e3[i])
	abort ();
      if (g1[i] != g2[i] * g3[i])
	abort ();
    }
  f7 ();
  f8 ();
  f9 ();
  f10 ();
  for (i = 0; i < N; ++i)
    {
      if (c1[i] != a2[i] * a3[i])
	abort ();
      if (d1[i] != b2[i] * b3[i])
	abort ();
      if (e1[i] != (long long) c2[i] * (long long) c3[i])
	abort ();
      if (g1[i] != (unsigned long long) d2[i] * (unsigned long long) d3[i])
	abort ();
    }
  if (f11 () != s1 || f12 () != s2 || f13 () != s3 || f14 () != s4)
    abort ();
}