aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/pr89765-mc.c
blob: 8384536058bd89edeaacb0644e23e1ac3b656a5b (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/* { dg-do run { target int128 } } */
/* { dg-require-effective-target vsx_hw } */
/* { dg-options "-mvsx -O2" } */

/* This test should run the same on any target that supports vsx
   instructions.  Intentionally not specifying cpu in order to test
   all code generation paths.  */

#include <stdlib.h>
#include <stddef.h>
#include <altivec.h>

#include <stdio.h>

static vector unsigned __int128
deoptimize_uint128 (vector unsigned __int128  a)
{
  __asm__ (" # %x0" : "+v" (a));
  return a;
}

static vector unsigned long long int
deoptimize_ulong (vector unsigned long long int a)
{
  __asm__ (" # %x0" : "+v" (a));
  return a;
}

static vector unsigned int
deoptimize_uint (vector unsigned int a)
{
  __asm__ (" # %x0" : "+v" (a));
  return a;
}

static vector unsigned char
deoptimize_uchar (vector unsigned char a)
{
  __asm__ (" # %x0" : "+v" (a));
  return a;
}

static vector unsigned short
deoptimize_ushort (vector unsigned short a)
{
  __asm__ (" # %x0" : "+v" (a));
  return a;
}

__attribute ((noinline))
vector unsigned __int128
set_auto_n_uint128 (vector unsigned __int128 a, int n, unsigned __int128 x)
{
  return vec_insert (x, a, n);
}

__attribute ((noinline))
vector unsigned long long int
set_auto_n_ulong (vector unsigned long long int a, int n,
		  unsigned long long int x)
{
  return vec_insert (x, a, n);
}

__attribute ((noinline))
vector unsigned int
set_auto_n_uint (vector unsigned int a, int n, unsigned int x)
{
  return vec_insert (x, a, n);
}

__attribute ((noinline))
vector unsigned char
set_auto_n_uchar (vector unsigned char a, int n, unsigned char x)
{
  return vec_insert (x, a, n);
}

__attribute ((noinline))
vector unsigned short
set_auto_n_ushort (vector unsigned short a, int n, unsigned short x)
{
  return vec_insert (x, a, n);
}

__attribute ((noinline))
unsigned __int128
get_auto_n_uint128 (vector unsigned __int128 a, int n)
{
  return vec_extract (a, n);
}

__attribute ((noinline))
unsigned long long int
get_auto_n_ulong (vector unsigned long long int a, int n)
{
  return vec_extract (a, n);
}

__attribute ((noinline))
unsigned int
get_auto_n_uint (vector unsigned int a, int n)
{
  return vec_extract (a, n);
}

__attribute ((noinline))
unsigned char
get_auto_n_uchar (vector unsigned char a, int n)
{
  return vec_extract (a, n);
}

__attribute ((noinline))
unsigned short
get_auto_n_ushort (vector unsigned short a, int n)
{
  return vec_extract (a, n);
}

int check_uint128_element (int i, unsigned __int128 entry)
{
  printf ("checking uint128 entry at index %d\n", i);

  return (entry == ((((unsigned __int128) 0xffeeddccbbaa9988ULL) << 64)
		    | 0x0706050403020100ULL));
}

unsigned __int128 get_uint128_element (int i)
{
  return ((((unsigned __int128) 0xffeeddccbbaa9988ULL) << 64)
	  | 0x0706050403020100ULL);
}

int check_ulong_element (int i, unsigned long long int entry)
{
  printf ("checking ulong entry 0x%llx at index %d\n", entry, i);

  switch (i % 2)
    {
      case 0: return (entry == 0x9999901010ULL);
      case 1: return (entry == 0x7777733333ULL);
      default:
	return 0;
    }
}

unsigned long long int get_ulong_element (int i)
{
  switch (i % 2)
    {
    case 0: return 0x9999901010ULL;
    case 1: return 0x7777733333ULL;
    }
}

int check_uint_element (int i, unsigned int entry)
{
  printf ("checking uint entry 0x%x at index %d\n", entry, i);

  switch (i % 4)
    {
    case 0: return (entry == 0x99999);
    case 1: return (entry == 0x01010);
    case 2: return (entry == 0x77777);
    case 3: return (entry == 0x33333);
    default:
      return 0;
    }
}

unsigned int get_uint_element (int i)
{
  switch (i % 4)
    {
    case 0: return 0x99999;
    case 1: return 0x01010;
    case 2: return 0x77777;
    case 3: return 0x33333;
    }
}

int check_uchar_element (int i, unsigned char entry)
{
  printf ("checking uchar entry 0x%x at index %d\n", entry, i);
  switch (i % 16)
    {
    case 0: return (entry == 0x90);
    case 1: return (entry == 0x80);
    case 2: return (entry == 0x70);
    case 3: return (entry == 0x60);
    case 4: return (entry == 0x50);
    case 5: return (entry == 0x40);
    case 6: return (entry == 0x30);
    case 7: return (entry == 0x20);
    case 8: return (entry == 0x10);
    case 9: return (entry == 0xf0);
    case 10: return (entry == 0xe0);
    case 11: return (entry == 0xd0);
    case 12: return (entry == 0xc0);
    case 13: return (entry == 0xb0);
    case 14: return (entry == 0xa0);
    case 15: return (entry == 0xff);
    default:
      return 0;
    }
}

unsigned char get_uchar_element (int i)
{
  switch (i % 16)
    {
    case 0: return 0x90;
    case 1: return 0x80;
    case 2: return 0x70;
    case 3: return 0x60;
    case 4: return 0x50;
    case 5: return 0x40;
    case 6: return 0x30;
    case 7: return 0x20;
    case 8: return 0x10;
    case 9: return 0xf0;
    case 10: return 0xe0;
    case 11: return 0xd0;
    case 12: return 0xc0;
    case 13: return 0xb0;
    case 14: return 0xa0;
    case 15: return 0xff;
    }
}

int check_ushort_element (int i, unsigned short entry)
{
  printf ("checking ushort entry 0x%x at index %d\n", entry, i);
  switch (i % 8)
    {
    case 0: return (entry == 0x9988);
    case 1: return (entry == 0x8877);
    case 2: return (entry == 0x7766);
    case 3: return (entry == 0x6655);
    case 4: return (entry == 0x5544);
    case 5: return (entry == 0x4433);
    case 6: return (entry == 0x3322);
    case 7: return (entry == 0x2211);
    default:
      return 0;
    }
}

unsigned short get_ushort_element (int i)
{
  switch (i % 8)
    {
    case 0: return 0x9988;
    case 1: return 0x8877;
    case 2: return 0x7766;
    case 3: return 0x6655;
    case 4: return 0x5544;
    case 5: return 0x4433;
    case 6: return 0x3322;
    case 7: return 0x2211;
    }
}

vector unsigned __int128
init_auto_uint128 (vector unsigned __int128 a)
{
  int i;
  for (i = 0; i < 32; i += 3)
    a = set_auto_n_uint128 (a, i, get_uint128_element (i));
  return a;
}

void do_auto_uint128 (vector unsigned __int128 a)
{
  int i;
  unsigned __int128 c;
  for (i = 0; i < 32; i += 3)
    {
      c = get_auto_n_uint128 (a, i);
      if (!check_uint128_element (i, c)) abort ();
    }
}

vector unsigned long long int
init_auto_ulong (vector unsigned long long int a)
{
  int i;
  for (i = 0; i < 32; i += 3)
    a = set_auto_n_ulong (a, i, get_ulong_element (i));
  return a;
}

void do_auto_ulong (vector unsigned long long int a)
{
  int i;
  unsigned long long int c;
  for (i = 0; i < 32; i += 3)
    {
      c = get_auto_n_ulong (a, i);
      if (!check_ulong_element (i, c)) abort ();
    }
 }

vector unsigned int init_auto_uint (vector unsigned int a)
{
  int i;
  for (i = 0; i < 32; i += 3)
    a = set_auto_n_uint (a, i, get_uint_element (i));
  return a;
}

void do_auto_uint (vector unsigned int a)
{
  int i;
  unsigned int c;
  for (i = 0; i < 32; i += 3)
    {
      c = get_auto_n_uint (a, i);
      if (!check_uint_element (i, c)) abort ();
    }
 }

vector unsigned short init_auto_ushort ( vector unsigned short a )
{
  int i;
  for (i = 0; i < 32; i += 3)
    a = set_auto_n_ushort (a, i, get_ushort_element (i));
  return a;
}

void do_auto_ushort (vector unsigned short a)
{
  int i;
  unsigned short c;
  for (i = 0; i < 32; i += 3)
    {
      c = get_auto_n_ushort (a, i);
      if (!check_ushort_element (i, c)) abort ();
    }
}

vector unsigned char init_auto_uchar (vector unsigned char a)
{
  int i;
  for (i = 0; i < 32; i += 3)
    a = set_auto_n_uchar (a, i, get_uchar_element (i));
  return a;
}

void do_auto_uchar (vector unsigned char a)
{
  int i;
  unsigned char c;
  for (i = 0; i < 32; i += 3)
    {
      c = get_auto_n_uchar (a, i);
      if (!check_uchar_element (i, c)) abort ();
    }
}

int
main (void)
{
  size_t i;

  vector unsigned __int128 u = { 0 };
  vector unsigned __int128 du;

  vector unsigned long long int v = { 0, 0 };
  vector unsigned long long int dv;

  vector unsigned int x = { 0, 0, 0, 0 };
  vector unsigned int dx;

  vector unsigned char y = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  vector unsigned char dy;

  vector unsigned short z = { 0, 0, 0, 0, 0, 0, 0, 0 };
  vector unsigned short dz;

  du = init_auto_uint128 (u);
  dv = init_auto_ulong (v);
  dx = init_auto_uint (x);
  dy = init_auto_uchar (y);
  dz = init_auto_ushort (z);

  du = deoptimize_uint128 (du);
  dv = deoptimize_ulong (dv);
  dx = deoptimize_uint (dx);
  dy = deoptimize_uchar (dy);
  dz = deoptimize_ushort (dz);

  do_auto_uint128 (du);
  do_auto_ulong (dv);
  do_auto_uint (dx);
  do_auto_uchar (dy);
  do_auto_ushort (dz);
  return 0;
}