[committed] Fix previously latent bug in reorg affecting cris port
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / vec-ldl-1.c
blob46b3b53b05517169c94a1d21cbf4a936373fc14f
1 /* { dg-do run { target powerpc*-*-* } } */
2 /* { dg-require-effective-target vsx_hw } */
3 /* { dg-options "-mvsx -O0 -Wall" } */
5 #include <altivec.h>
6 #include <stdlib.h>
8 /* vec_ldl and vec_lvxl (an alias for vec_ldl) do an aligned vector
9 * load from memory, marking the fetched memory as least recently used
10 * (hinting that we do not anticipate a need to fetch this vector
11 * again within the near future.)
13 * vector <TYPE> result = vec_ldl (int offset, <TYPE> *address)
14 * vector <TYPE> result = vec_ldl (int offset, vector <TYPE> *address)
16 * The effect of these instructions is to perform the following:
18 * resuilt = *((vector <TTYPE> *)((((char *) address) + offset) & ~0x0f))
20 * This test exercises the following new prototypes of the vec_ldl
21 * service which were added in late March 2018:
23 * vector bool int vec_ldl (int, bool int *)
24 * vector bool short vec_ldl (int, bool short *)
25 * vector bool char vec_ldl (int, bool char *)
26 * vector double vec_ldl (int, double *)
27 * vector long long int vec_ldl (int, long long int *)
28 * vector unsigned long long int vec_ldl (int, unsigned long long int *)
29 * vector bool long long vec_ldl (int, bool long long *)
32 static signed char ca[64] __attribute__((aligned(16)));
33 static unsigned char uca[64] __attribute__((aligned(16)));
35 static vector signed char *vcp = (vector signed char *) ca;
36 static unsigned vector char *vucp = (vector unsigned char *) uca;
38 static short sa[32] __attribute__((aligned(16)));
39 static unsigned short usa[32] __attribute__((aligned(16)));
41 static vector short *vsp = (vector short *) sa;
42 static unsigned vector short *vusp = (vector unsigned short *) usa;
44 static int ia[16] __attribute__((aligned(16)));
45 static unsigned int uia[16] __attribute__((aligned(16)));
47 static vector int *vip = (vector int *) ia;
48 static unsigned vector int *vuip = (vector unsigned int *) uia;
50 static long long la[8] __attribute__((aligned(16)));
51 static unsigned long long ula[8] __attribute__((aligned(16)));
53 static vector long long *vlp = (vector long long *) la;
54 static unsigned vector long long *vulp = (vector unsigned long long *) ula;
56 static double da[8] __attribute__((aligned(16)));
57 static vector double *vdp = (vector double *) da;
60 void
61 doInitialization ()
63 unsigned int i;
65 for (i = 0; i < 64; i++)
66 ca[i] = uca[i] = i;
68 for (i = 0; i < 32; i++)
69 sa[i] = usa[i] = i;
71 for (i = 0; i < 16; i++)
72 ia[i] = uia[i] = i;
74 for (i = 0; i < 8; i++)
75 la[i] = ula[i] = i;
77 for (i = 0; i < 8; i++)
78 da[i] = 0.125 * i;
81 int
82 main (int argc, char *argv[])
84 vector long long int lv;
85 vector unsigned long long int ulv;
86 vector int iv;
87 vector unsigned int uiv;
88 vector short sv;
89 vector unsigned short usv;
90 vector signed char cv;
91 vector unsigned char ucv;
92 vector double dv;
94 doInitialization ();
96 /* Do vector of char. */
97 for (int i = 0; i < 16; i++) {
98 /* Focus on ca[16] ... ca[31]. */
99 cv = vec_ldl (i+16, ca); /* compiler: invalid parameter combination */
100 if (cv[4] != ca[20])
101 abort ();
102 /* Focus on uca[32] ... uca[47]. */
103 ucv = vec_ldl (i+32, uca);
104 if (ucv[7] != uca[39])
105 abort ();
106 /* Focus on ca[0] ... ca[15]. */
107 cv = vec_ldl (i, vcp);
108 if (cv[3] != ca[3])
109 abort ();
110 /* Focus on ca[0] ... ca[15] while i <= 8.
111 Focus on ca[16] ... ca[31] while i > 8. */
112 ucv = vec_ldl (i+7, vucp);
113 if ((i+7 > 15) && (ucv[13] != uca[29]))
114 abort ();
115 if ((i + 7 <= 15) && (ucv[13] != uca[13]))
116 abort ();
119 /* Do vector of short. */
120 for (int i = 0; i < 16; i++) {
121 /* Focus on sa[8] ... sa[15]. */
122 sv = vec_ldl (i+16, sa);
123 if (sv[4] != sa[12])
124 abort ();
125 /* Focus on usa[24] ... usa[31]. */
126 usv = vec_ldl (i+48, usa);
127 if (usv[7] != usa[31])
128 abort ();
129 /* Focus on sa[0] ... sa[7]. */
130 sv = vec_ldl (i, vsp);
131 if (sv[3] != sa[3])
132 abort ();
133 /* Focus on usa[0] ... usa[7] while i <= 8.
134 Focus on usa[8] ... usa[15] while i > 8. */
135 usv = vec_ldl (i+7, vusp);
136 if ((i+7 > 15) && (usv[5] != usa[13]))
137 abort ();
138 if ((i + 7 <= 15) && (usv[5] != usa[5]))
139 abort ();
142 /* Do vector of int. */
143 for (int i = 0; i < 16; i++) {
144 /* Focus on ia[8] ... ia[11]. */
145 iv = vec_ldl (i+32, ia);
146 if (iv[3] != ia[11])
147 abort ();
148 /* Focus on uia[12] ... uia[15]. */
149 uiv = vec_ldl (i+48, uia);
150 if (uiv[2] != uia[14])
151 abort ();
152 /* Focus on ia[0] ... ia[3]. */
153 iv = vec_ldl (i, vip);
154 if (iv[3] != ia[3])
155 abort ();
156 /* Focus on uia[0] ... uia[3] while i <= 8.
157 Focus on uia[4] ... uia[7] while i > 8. */
158 uiv = vec_ldl (i+7, vuip);
159 if ((i+7 > 15) && (uiv[1] != uia[5]))
160 abort ();
161 if ((i + 7 <= 15) && (uiv[1] != uia[1]))
162 abort ();
165 /* Do vector of long long int. */
166 for (int i = 0; i < 16; i++) {
167 /* Focus on la[4] ... la[5]. */
168 lv = vec_ldl (i+32, la);
169 if (lv[1] != la[5])
170 abort ();
171 /* Focus on ula[6] ... ula[7]. */
172 ulv = vec_ldl (i+48, ula);
173 if (ulv[0] != uia[6])
174 abort ();
175 /* Focus on la[0] ... la[1]. */
176 lv = vec_ldl (i, vlp);
177 if (iv[1] != la[1])
178 abort ();
179 /* Focus on ula[0] ... uia[1] while i <= 8.
180 Focus on uia[2] ... uia[3] while i > 8. */
181 ulv = vec_ldl (i+7, vulp);
182 if ((i+7 > 15) && (ulv[1] != ula[3]))
183 abort ();
184 if ((i + 7 <= 15) && (ulv[1] != ula[1]))
185 abort ();
188 /* Do vector of double. */
189 for (int i = 0; i < 16; i++) {
190 /* Focus on da[2] ... da[3]. */
191 dv = vec_ldl (i+16, da);
192 if (dv[1] != da[3])
193 abort ();
194 /* Focus on da[6] ... da[7]. */
195 dv = vec_ldl (i+48, vdp);
196 if (dv[0] != da[6])
197 abort ();
198 /* Focus on da[0] ... da[1]. */
199 dv = vec_ldl (i, da);
200 if (dv[1] != da[1])
201 abort ();
202 /* Focus on da[0] ... da[1] while i <= 8.
203 Focus on da[2] ... da[3] while i > 8. */
204 dv = vec_ldl (i+7, vdp);
205 if ((i+7 <= 15) && (dv[1] != da[1]))
206 abort ();
207 if ((i + 7 > 15) && (dv[1] != da[3]))
208 abort ();
210 return 0;