OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.target/] [spu/] [intrinsics-2.c] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 691 jeremybenn
/* { dg-do run } */
2
/* { dg-options "-std=c99" } */
3
#include <vec_types.h>
4
extern void abort (void);
5
extern void exit (int);
6
 
7
typedef union {
8
  vec_ullong2   vull;
9
  vec_double2   vd;
10
  unsigned int  ui[4];
11
  unsigned long long ull[2];
12
  double        d[2];
13
} v128;
14
 
15
static v128 a, b, c, d, a0, b0, a1, b1;
16
static int samples = 10;
17
unsigned int seed = 0;
18
 
19
unsigned int rand_local()
20
{
21
  seed = seed * 69607 + 54329;
22
  return (seed);
23
}
24
 
25
double rand_double(double min, double max)
26
{
27
  union {
28
    unsigned int ui[2];
29
    double d;
30
  } x;
31
 
32
  x.ui[0] = (rand_local() & 0x000FFFFF) | 0x3FF00000;
33
  x.ui[1] = rand_local();
34
  x.d -= 1.0;
35
  x.d *= max - min;
36
  x.d += min;
37
  return (x.d);
38
}
39
 
40
vec_double2 rand_vd(double min, double max)
41
{
42
  int i;
43
  static v128 val;
44
 
45
  for (i=0; i<2; i++) val.d[i] = rand_double(min, max);
46
  return (val.vd);
47
}
48
 
49
int test_spu_cmpeq()
50
{
51
  int i, j;
52
  unsigned long long exp;
53
 
54
  /* double */
55
  for (i=0; i<samples; i++) {
56
    a.vd = rand_vd(-4.0, 4.0);
57
    b.vd = rand_vd(-4.0, 4.0);
58
    d.vull = spu_cmpeq(a.vd, b.vd);
59
    for (j=0; j<2; j++) {
60
      exp = (a.d[j] == b.d[j]) ?
61
            (((unsigned long long)(0xFFFFFFFF) << 32)
62
             | (unsigned long long)(0xFFFFFFFF)) : 0;
63
      if (exp != d.ull[j]) abort();
64
    }
65
  }
66
 
67
  /* compare zeros  */
68
    d.vull = spu_cmpeq(a0.vd, b0.vd);
69
    for (j=0; j<2; j++) {
70
      exp = (a0.d[j] == b0.d[j]) ?
71
            (((unsigned long long)(0xFFFFFFFF) << 32)
72
             | (unsigned long long)(0xFFFFFFFF)) : 0;
73
      if (exp != d.ull[j]) abort();
74
    }
75
 
76
  /* compare NaNs  */
77
    d.vull = spu_cmpeq(a1.vd, b1.vd);
78
    for (j=0; j<2; j++) {
79
      exp = (a1.d[j] == b1.d[j]) ?
80
            (((unsigned long long)(0xFFFFFFFF) << 32)
81
             | (unsigned long long)(0xFFFFFFFF)) : 0;
82
      if (exp != d.ull[j]) abort();
83
    }
84
  return 0;
85
}
86
 
87
int test_spu_cmpgt()
88
{
89
  int i, j;
90
  unsigned long long exp;
91
 
92
  /* double */
93
  for (i=0; i<samples; i++) {
94
    a.vd = rand_vd(-4.0, 4.0);
95
    b.vd = rand_vd(-4.0, 4.0);
96
    d.vull = spu_cmpgt(a.vd, b.vd);
97
    for (j=0; j<2; j++) {
98
      exp = (a.d[j] > b.d[j]) ?
99
            (((unsigned long long)(0xFFFFFFFF) << 32)
100
             | (unsigned long long)(0xFFFFFFFF)) : 0;
101
      if (exp != d.ull[j]) abort();
102
    }
103
  }
104
 
105
  /* compare zeros  */
106
    d.vull = spu_cmpgt(a0.vd, b0.vd);
107
    for (j=0; j<2; j++) {
108
      exp = (a0.d[j] > b0.d[j]) ?
109
            (((unsigned long long)(0xFFFFFFFF) << 32)
110
             | (unsigned long long)(0xFFFFFFFF)) : 0;
111
      if (exp != d.ull[j]) abort();
112
    }
113
  /* compare NaNs  */
114
    d.vull = spu_cmpgt(a1.vd, b1.vd);
115
    for (j=0; j<2; j++) {
116
      exp = (a1.d[j] > b1.d[j]) ?
117
            (((unsigned long long)(0xFFFFFFFF) << 32)
118
             | (unsigned long long)(0xFFFFFFFF)) : 0;
119
      if (exp != d.ull[j]) abort();
120
    }
121
  return 0;
122
}
123
 
124
int test_spu_cmpabseq()
125
{
126
  int i, j;
127
  unsigned long long exp;
128
 
129
  /* double */
130
  for (i=0; i<samples; i++) {
131
    a.vd = rand_vd(-4.0, 4.0);
132
    b.vd = rand_vd(-4.0, 4.0);
133
    d.vull = spu_cmpabseq(a.vd, b.vd);
134
    for (j=0; j<2; j++) {
135
      exp = ((a.d[j] == b.d[j]) || (-a.d[j] == b.d[j]) || (a.d[j] == -b.d[j])) ?
136
            (((unsigned long long)(0xFFFFFFFF) << 32)
137
             | (unsigned long long)(0xFFFFFFFF)) : 0;
138
      if (exp != d.ull[j]) abort();
139
    }
140
  }
141
 
142
  /* compare zeros  */
143
    d.vull = spu_cmpabseq(a0.vd, b0.vd);
144
    for (j=0; j<2; j++) {
145
      exp = ((a0.d[j] == b0.d[j]) || (-a0.d[j] == b0.d[j]) || (a0.d[j] == -b0.d[j])) ?
146
            (((unsigned long long)(0xFFFFFFFF) << 32)
147
             | (unsigned long long)(0xFFFFFFFF)) : 0;
148
      if (exp != d.ull[j]) abort();
149
    }
150
 
151
  /* compare NaNs  */
152
    d.vull = spu_cmpabseq(a1.vd, b1.vd);
153
    for (j=0; j<2; j++) {
154
      exp = ((a1.d[j] == b1.d[j]) || (-a1.d[j] == b1.d[j]) || (a1.d[j] == -b1.d[j])) ?
155
            (((unsigned long long)(0xFFFFFFFF) << 32)
156
             | (unsigned long long)(0xFFFFFFFF)) : 0;
157
      if (exp != d.ull[j]) abort();
158
    }
159
  return 0;
160
}
161
 
162
int test_spu_cmpabsgt()
163
{
164
  int i, j;
165
  unsigned long long exp;
166
  double abs_a, abs_b;
167
 
168
  /* double */
169
  for (i=0; i<samples; i++) {
170
    a.vd = rand_vd(-4.0, 4.0);
171
    b.vd = rand_vd(-4.0, 4.0);
172
    d.vull = spu_cmpabsgt(a.vd, b.vd);
173
    for (j=0; j<2; j++) {
174
      double abs_a = (a.d[j] < 0.0) ? -a.d[j] : a.d[j];
175
      double abs_b = (b.d[j] < 0.0) ? -b.d[j] : b.d[j];
176
      exp = (abs_a > abs_b) ?
177
            (((unsigned long long)(0xFFFFFFFF) << 32)
178
             | (unsigned long long)(0xFFFFFFFF)) : 0;
179
      if (exp != d.ull[j]) abort();
180
    }
181
  }
182
 
183
  /* compare zeros  */
184
    d.vull = spu_cmpabsgt(a0.vd, b0.vd);
185
    for (j=0; j<2; j++) {
186
      abs_a = (a0.d[j] < 0.0) ? -a0.d[j] : a0.d[j];
187
      abs_b = (b0.d[j] < 0.0) ? -b0.d[j] : b0.d[j];
188
      exp = (abs_a > abs_b) ?
189
            (((unsigned long long)(0xFFFFFFFF) << 32)
190
             | (unsigned long long)(0xFFFFFFFF)) : 0;
191
      if (exp != d.ull[j]) abort();
192
    }
193
  /* compare NaNs  */
194
    d.vull = spu_cmpabsgt(a1.vd, b1.vd);
195
    for (j=0; j<2; j++) {
196
      abs_a = (a1.d[j] < 0.0) ? -a1.d[j] : a1.d[j];
197
      abs_b = (b1.d[j] < 0.0) ? -b1.d[j] : b1.d[j];
198
      exp = (abs_a > abs_b) ?
199
            (((unsigned long long)(0xFFFFFFFF) << 32)
200
             | (unsigned long long)(0xFFFFFFFF)) : 0;
201
      if (exp != d.ull[j]) abort();
202
    }
203
  return 0;
204
}
205
 
206
int test_spu_testsv()
207
{
208
  int i, j;
209
  unsigned long long exp;
210
  struct _samples {
211
    unsigned long long v;
212
    unsigned int sv;
213
 } samples[] = {
214
  {0x0000000000000000ULL, SPU_SV_POS_ZERO},
215
  {0x8000000000000000ULL, SPU_SV_NEG_ZERO},
216
  {0x0000000000000001ULL, SPU_SV_POS_DENORM},
217
  {0x0000000080000000ULL, SPU_SV_POS_DENORM},
218
  {0x0000000100000000ULL, SPU_SV_POS_DENORM},
219
  {0x0008000000000000ULL, SPU_SV_POS_DENORM},
220
  {0x000FFFFFFFFFFFFFULL, SPU_SV_POS_DENORM},
221
  {0x00000000FFF00000ULL, SPU_SV_POS_DENORM},
222
  {0x8000000000000001ULL, SPU_SV_NEG_DENORM},
223
  {0x8000000080000000ULL, SPU_SV_NEG_DENORM},
224
  {0x8000000100000000ULL, SPU_SV_NEG_DENORM},
225
  {0x8008000000000000ULL, SPU_SV_NEG_DENORM},
226
  {0x800FFFFFFFFFFFFFULL, SPU_SV_NEG_DENORM},
227
  {0x80000000FFF00000ULL, SPU_SV_NEG_DENORM},
228
  {0x0010000000000000ULL, 0},
229
  {0x0010000000000001ULL, 0},
230
  {0x3FF0000000000000ULL, 0},
231
  {0x3FF00000FFF00000ULL, 0},
232
  {0xBFF0000000000000ULL, 0},
233
  {0xBFF00000FFF00000ULL, 0},
234
  {0x7FE0000000000000ULL, 0},
235
  {0x7FEFFFFFFFFFFFFFULL, 0},
236
  {0x8010000000000000ULL, 0},
237
  {0x8010000000000001ULL, 0},
238
  {0xFFE0000000000000ULL, 0},
239
  {0xFFEFFFFFFFFFFFFFULL, 0},
240
  {0x7FF0000000000000ULL, SPU_SV_POS_INFINITY},
241
  {0xFFF0000000000000ULL, SPU_SV_NEG_INFINITY},
242
  {0x7FF0000000000001ULL, SPU_SV_NAN},
243
  {0x7FF0000080000000ULL, SPU_SV_NAN},
244
  {0x7FF0000100000000ULL, SPU_SV_NAN},
245
  {0x7FFFFFFFFFFFFFFFULL, SPU_SV_NAN},
246
  {0xFFF0000000000001ULL, SPU_SV_NAN},
247
  {0xFFF0000080000000ULL, SPU_SV_NAN},
248
  {0xFFF0000100000000ULL, SPU_SV_NAN},
249
  {0xFFFFFFFFFFFFFFFFULL, SPU_SV_NAN}
250
 };
251
 
252
  unsigned char cnt = sizeof(samples)/sizeof(struct _samples);
253
  int e0;
254
    for (e0=0; e0<cnt; e0++)
255
    {
256
      a.ull[0] = samples[e0].v;
257
      a.d[1] = rand_double(-1, -4);
258
 
259
      d.vull = spu_testsv(a.vd, SPU_SV_NEG_DENORM);
260
      exp = (SPU_SV_NEG_DENORM & samples[e0].sv) ? 0xFFFFFFFFFFFFFFFFULL : 0ULL;
261
      if (exp != d.ull[0] || d.ull[1] != 0) abort();
262
 
263
      d.vull = spu_testsv(a.vd, SPU_SV_POS_DENORM);
264
      exp = (SPU_SV_POS_DENORM & samples[e0].sv) ? 0xFFFFFFFFFFFFFFFFULL : 0ULL;
265
      if (exp != d.ull[0] || d.ull[1] != 0) abort();
266
 
267
      d.vull = spu_testsv(a.vd, SPU_SV_NEG_ZERO);
268
      exp = (SPU_SV_NEG_ZERO & samples[e0].sv) ? 0xFFFFFFFFFFFFFFFFULL : 0ULL;
269
      if (exp != d.ull[0] || d.ull[1] != 0) abort();
270
 
271
      d.vull = spu_testsv(a.vd, SPU_SV_POS_ZERO);
272
      exp = (SPU_SV_POS_ZERO & samples[e0].sv) ? 0xFFFFFFFFFFFFFFFFULL : 0ULL;
273
      if (exp != d.ull[0] || d.ull[1] != 0) abort();
274
 
275
      d.vull = spu_testsv(a.vd, SPU_SV_NEG_INFINITY);
276
      exp = (SPU_SV_NEG_INFINITY & samples[e0].sv) ? 0xFFFFFFFFFFFFFFFFULL : 0ULL;
277
      if (exp != d.ull[0] || d.ull[1] != 0) abort();
278
 
279
      d.vull = spu_testsv(a.vd, SPU_SV_POS_INFINITY);
280
      exp = (SPU_SV_POS_INFINITY & samples[e0].sv) ? 0xFFFFFFFFFFFFFFFFULL : 0ULL;
281
      if (exp != d.ull[0] || d.ull[1] != 0) abort();
282
 
283
      d.vull = spu_testsv(a.vd, SPU_SV_NAN);
284
      exp = (SPU_SV_NAN & samples[e0].sv) ? 0xFFFFFFFFFFFFFFFFULL : 0ULL;
285
      if (exp != d.ull[0] || d.ull[1] != 0) abort();
286
   }
287
  return 0;
288
}
289
 
290
int main()
291
{
292
  /* +0.0 and -0.0  */
293
  a0.d[0] = 0.0; a0.d[1] = -0.0; b0.d[0] = -0.0; b0.d[1] = 0.0;
294
  /* NaN  */
295
  a1.d[0] = 0.0/0.0; a1.d[1] = 0.0/-0.0; b1.d[0] = -0.0/0.0;  b1.d[1] = -0.0/-0.0;
296
 
297
  test_spu_cmpeq();
298
  test_spu_cmpabseq();
299
  test_spu_cmpgt();
300
  test_spu_cmpabsgt();
301
  test_spu_testsv();
302
  return 0;
303
}
304
 
305
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.