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
|
/* { dg-do run { target { powerpc*-*-linux* && lp64 } } } */
/* { dg-skip-if "" { powerpc*-*-darwin* } } */
/* { dg-skip-if "" { powerpc*-*-*spe* } } */
/* { dg-require-effective-target p8vector_hw } */
/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
/* { dg-options "-mcpu=power8 -O2" } */
#include <stddef.h>
#include <stdlib.h>
#include <altivec.h>
#include <string.h>
#ifdef DEBUG
#include <stdio.h>
#endif
typedef __int128_t __attribute__((__vector_size__(16))) vector_128_t;
typedef __int128_t scalar_128_t;
typedef unsigned long long scalar_64_t;
volatile scalar_64_t one = 1;
volatile scalar_64_t two = 2;
int
main (void)
{
scalar_128_t a = (((scalar_128_t)one) << 64) | ((scalar_128_t)two);
vector_128_t v1 = (vector_128_t) { a };
vector_128_t v2 = __builtin_pack_vector_int128 (one, two);
scalar_64_t x0 = __builtin_unpack_vector_int128 (v1, 0);
scalar_64_t x1 = __builtin_unpack_vector_int128 (v1, 1);
vector_128_t v3 = __builtin_pack_vector_int128 (x0, x1);
size_t i;
union {
scalar_128_t i128;
vector_128_t v128;
scalar_64_t u64;
unsigned char uc[sizeof (scalar_128_t)];
char c[sizeof (scalar_128_t)];
} u, u2;
#ifdef DEBUG
{
printf ("a = 0x");
u.i128 = a;
for (i = 0; i < sizeof (scalar_128_t); i++)
printf ("%.2x", u.uc[i]);
printf ("\nv1 = 0x");
u.v128 = v1;
for (i = 0; i < sizeof (scalar_128_t); i++)
printf ("%.2x", u.uc[i]);
printf ("\nv2 = 0x");
u.v128 = v2;
for (i = 0; i < sizeof (scalar_128_t); i++)
printf ("%.2x", u.uc[i]);
printf ("\nv3 = 0x");
u.v128 = v3;
for (i = 0; i < sizeof (scalar_128_t); i++)
printf ("%.2x", u.uc[i]);
printf ("\nx0 = 0x");
u.u64 = x0;
for (i = 0; i < sizeof (scalar_64_t); i++)
printf ("%.2x", u.uc[i]);
printf ("\nx1 = 0x");
u.u64 = x1;
for (i = 0; i < sizeof (scalar_64_t); i++)
printf ("%.2x", u.uc[i]);
printf ("\n");
}
#endif
u2.i128 = a;
u.v128 = v1;
if (memcmp (u.c, u2.c, sizeof (scalar_128_t)) != 0)
abort ();
u.v128 = v2;
if (memcmp (u.c, u2.c, sizeof (scalar_128_t)) != 0)
abort ();
u.v128 = v3;
if (memcmp (u.c, u2.c, sizeof (scalar_128_t)) != 0)
abort ();
return 0;
}
|