aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/pr87532-mc.c
blob: e5f79aa5dc1fe9b59f2bb9b3e2e4b34df5ade4dc (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
/* { 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)) unsigned __int128
get_auto_n_uint128 (vector unsigned __int128 a, int n)
{
  return __builtin_vec_extract (a, n);
}

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

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

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

__attribute ((noinline))
unsigned short get_auto_n_ushort (vector unsigned short a, int n)
{
  return __builtin_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));
}

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;
    }
}

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;
    }
}

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;
    }
}

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;
    }
}

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 ();
    }
 }

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 ();
    }
 }

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 ();
    }
 }

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 ();
    }
}

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 = {
    ((((unsigned __int128) 0xffeeddccbbaa9988ULL) << 64)
     | 0x0706050403020100ULL) };
  vector unsigned __int128 du;

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

  vector unsigned int x = { 0x99999, 0x01010, 0x77777, 0x33333 };
  vector unsigned int dx;

  vector unsigned char y = { 0x90, 0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20,
			     0x10, 0xf0, 0xe0, 0xd0, 0xc0, 0xb0, 0xa0, 0xff };
  vector unsigned char dy;

  vector unsigned short z = { 0x9988, 0x8877, 0x7766, 0x6655,
			      0x5544, 0x4433, 0x3322, 0x2211 };
  vector unsigned short dz;

  do_auto_uint128 (u);
  do_auto_ulong (v);
  do_auto_uint (x);
  do_auto_uchar (y);
  do_auto_ushort (z);

  du = deoptimize_uint128 (u);
  dv = deoptimize_ulong (v);
  dx = deoptimize_uint (x);
  dy = deoptimize_uchar (y);
  dz = deoptimize_ushort (z);

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