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 401 402 403 404 405 406 407
|
/* { dg-do run { target { { powerpc*-*-linux* && lp64 } && powerpc_altivec_ok } } } */
/* { dg-options "-O2 -fprofile -mprofile-kernel -maltivec -mabi=altivec" } */
#include <stdarg.h>
#include <signal.h>
#include <altivec.h>
#include <stdlib.h>
/* Testcase to check for ABI compliance of parameter passing
for the PowerPC64 ABI. */
void __attribute__((no_instrument_function))
sig_ill_handler (int sig)
{
exit(0);
}
extern void abort (void);
typedef struct
{
unsigned long gprs[8];
double fprs[13];
long pad;
vector int vrs[12];
} reg_parms_t;
volatile reg_parms_t gparms;
/* _mcount call is done on Linux ppc64 early in the prologue.
my_mcount will provide a entry point _mcount,
which will save all parameter registers to gparms.
Note that _mcount needs to restore lr to original value,
therefore use ctr to return.
*/
extern void my_mcount (void) asm ("_mcount");
void __attribute__((no_instrument_function, no_split_stack))
my_mcount (void)
{
asm volatile ("mflr 12\n\t"
"mtctr 12\n\t"
"mtlr 0\n\t"
"addis 12,2,gparms@got@ha\n\t"
"ld 12,gparms@got@l(12)\n\t"
"std 3,0(12)\n\t"
"std 4,8(12)\n\t"
"std 5,16(12)\n\t"
"std 6,24(12)\n\t"
"std 7,32(12)\n\t"
"std 8,40(12)\n\t"
"std 9,48(12)\n\t"
"std 10,56(12)\n\t"
"stfd 1,64(12)\n\t"
"stfd 2,72(12)\n\t"
"stfd 3,80(12)\n\t"
"stfd 4,88(12)\n\t"
"stfd 5,96(12)\n\t"
"stfd 6,104(12)\n\t"
"stfd 7,112(12)\n\t"
"stfd 8,120(12)\n\t"
"stfd 9,128(12)\n\t"
"stfd 10,136(12)\n\t"
"stfd 11,144(12)\n\t"
"stfd 12,152(12)\n\t"
"stfd 13,160(12)\n\t"
"li 0,176\n\t"
"stvx 2,12,0\n\t"
"li 0,192\n\t"
"stvx 3,12,0\n\t"
"li 0,208\n\t"
"stvx 4,12,0\n\t"
"li 0,224\n\t"
"stvx 5,12,0\n\t"
"li 0,240\n\t"
"stvx 6,12,0\n\t"
"li 0,256\n\t"
"stvx 7,12,0\n\t"
"li 0,272\n\t"
"stvx 8,12,0\n\t"
"li 0,288\n\t"
"stvx 9,12,0\n\t"
"li 0,304\n\t"
"stvx 10,12,0\n\t"
"li 0,320\n\t"
"stvx 11,12,0\n\t"
"li 0,336\n\t"
"stvx 12,12,0\n\t"
"li 0,352\n\t"
"stvx 13,12,0\n\t"
"bctr");
}
/* Stackframe structure relevant for parameter passing. */
typedef union
{
double d;
unsigned long l;
unsigned int i[2];
} parm_t;
typedef struct sf
{
struct sf *backchain;
long a1;
long a2;
long a3;
#if _CALL_ELF != 2
long a4;
long a5;
#endif
parm_t slot[100];
} stack_frame_t;
typedef union
{
unsigned int i[4];
unsigned long l[2];
vector int v;
} vector_int_t;
#ifdef __LITTLE_ENDIAN__
#define MAKE_SLOT(x, y) ((long)x | ((long)y << 32))
#else
#define MAKE_SLOT(x, y) ((long)y | ((long)x << 32))
#endif
/* Paramter passing.
s : gpr 3
v : vpr 2
i : gpr 7
*/
void __attribute__ ((noinline))
fcvi (char *s, vector int v, int i)
{
reg_parms_t lparms = gparms;
if (s != (char *) lparms.gprs[0])
abort();
if (!vec_all_eq (v, lparms.vrs[0]))
abort ();
if ((long) i != lparms.gprs[4])
abort();
}
/* Paramter passing.
s : gpr 3
v : vpr 2
w : vpr 3
*/
void __attribute__ ((noinline))
fcvv (char *s, vector int v, vector int w)
{
vector int a, c = {6, 8, 10, 12};
reg_parms_t lparms = gparms;
if (s != (char *) lparms.gprs[0])
abort();
if (!vec_all_eq (v, lparms.vrs[0]))
abort ();
if (!vec_all_eq (w, lparms.vrs[1]))
abort ();
a = vec_add (v,w);
if (!vec_all_eq (a, c))
abort ();
}
/* Paramter passing.
s : gpr 3
i : gpr 4
v : vpr 2
w : vpr 3
*/
void __attribute__ ((noinline))
fcivv (char *s, int i, vector int v, vector int w)
{
vector int a, c = {6, 8, 10, 12};
reg_parms_t lparms = gparms;
if (s != (char *) lparms.gprs[0])
abort();
if ((long) i != lparms.gprs[1])
abort();
if (!vec_all_eq (v, lparms.vrs[0]))
abort ();
if (!vec_all_eq (w, lparms.vrs[1]))
abort ();
a = vec_add (v,w);
if (!vec_all_eq (a, c))
abort ();
}
/* Paramter passing.
s : gpr 3
v : slot 2-3
w : slot 4-5
*/
void __attribute__ ((noinline))
fcevv (char *s, ...)
{
vector int a, c = {6, 8, 10, 12};
vector int v,w;
stack_frame_t *sp;
reg_parms_t lparms = gparms;
va_list arg;
va_start (arg, s);
if (s != (char *) lparms.gprs[0])
abort();
v = va_arg(arg, vector int);
w = va_arg(arg, vector int);
a = vec_add (v,w);
if (!vec_all_eq (a, c))
abort ();
/* Go back one frame. */
sp = __builtin_frame_address(0);
sp = sp->backchain;
if (sp->slot[2].l != MAKE_SLOT (1, 2)
|| sp->slot[4].l != MAKE_SLOT (5, 6))
abort();
}
/* Paramter passing.
s : gpr 3
i : gpr 4
j : gpr 5
v : slot 4-5
w : slot 6-7
*/
void __attribute__ ((noinline))
fciievv (char *s, int i, int j, ...)
{
vector int a, c = {6, 8, 10, 12};
vector int v,w;
stack_frame_t *sp;
reg_parms_t lparms = gparms;
va_list arg;
va_start (arg, j);
if (s != (char *) lparms.gprs[0])
abort();
if ((long) i != lparms.gprs[1])
abort();
if ((long) j != lparms.gprs[2])
abort();
v = va_arg(arg, vector int);
w = va_arg(arg, vector int);
a = vec_add (v,w);
if (!vec_all_eq (a, c))
abort ();
sp = __builtin_frame_address(0);
sp = sp->backchain;
if (sp->slot[4].l != MAKE_SLOT (1, 2)
|| sp->slot[6].l != MAKE_SLOT (5, 6))
abort();
}
void __attribute__ ((noinline))
fcvevv (char *s, vector int x, ...)
{
vector int a, c = {7, 10, 13, 16};
vector int v,w;
stack_frame_t *sp;
reg_parms_t lparms = gparms;
va_list arg;
va_start (arg, x);
v = va_arg(arg, vector int);
w = va_arg(arg, vector int);
a = vec_add (v,w);
a = vec_add (a, x);
if (!vec_all_eq (a, c))
abort ();
sp = __builtin_frame_address(0);
sp = sp->backchain;
if (sp->slot[4].l != MAKE_SLOT (1, 2)
|| sp->slot[6].l != MAKE_SLOT (5, 6))
abort();
}
int __attribute__((no_instrument_function, noinline))
main1()
{
char *s = "vv";
vector int v = {1, 2, 3, 4};
vector int w = {5, 6, 7, 8};
fcvi (s, v, 2);
fcvv (s, v, w);
fcivv (s, 1, v, w);
fcevv (s, v, w);
fciievv (s, 1, 2, v, w);
fcvevv (s, v, v, w);
return 0;
}
int __attribute__((no_instrument_function))
main()
{
/* Exit on systems without altivec. */
signal (SIGILL, sig_ill_handler);
/* Altivec instruction, 'vor %v0,%v0,%v0'. */
asm volatile (".long 0x10000484");
signal (SIGILL, SIG_DFL);
return main1 ();
}
/* Paramter passing.
Function called with no prototype.
s : gpr 3
v : vpr 2 gpr 5-6
w : vpr 3 gpr 7-8
x : vpr 4 gpr 9-10
y : vpr 5 slot 8-9
*/
void
fnp_cvvvv (char *s, vector int v, vector int w,
vector int x, vector int y)
{
vector int a, c = {12, 16, 20, 24};
reg_parms_t lparms = gparms;
stack_frame_t *sp;
vector_int_t v0, v1, v2, v3;
if (s != (char *) lparms.gprs[0])
abort();
if (!vec_all_eq (v, lparms.vrs[0]))
abort ();
if (!vec_all_eq (w, lparms.vrs[1]))
abort ();
if (!vec_all_eq (x, lparms.vrs[2]))
abort ();
if (!vec_all_eq (y, lparms.vrs[3]))
abort ();
a = vec_add (v,w);
a = vec_add (a,x);
a = vec_add (a,y);
if (!vec_all_eq (a, c))
abort ();
v0.v = lparms.vrs[0];
v1.v = lparms.vrs[1];
v2.v = lparms.vrs[2];
v3.v = lparms.vrs[3];
if (v0.l[0] != lparms.gprs[2])
abort ();
if (v0.l[1] != lparms.gprs[3])
abort ();
if (v1.l[0] != lparms.gprs[4])
abort ();
if (v1.l[1] != lparms.gprs[5])
abort ();
if (v2.l[0] != lparms.gprs[6])
abort ();
if (v2.l[1] != lparms.gprs[7])
abort ();
sp = __builtin_frame_address(0);
sp = sp->backchain;
if (sp->slot[8].l != v3.l[0])
abort ();
if (sp->slot[9].l != v3.l[1])
abort ();
}
|