1 // REQUIRES: powerpc-registered-target
2 // RUN: %clang_cc1 -faltivec -triple powerpc64le-unknown-unknown \
3 // RUN: -target-feature +crypto -target-feature +power8-vector \
4 // RUN: -emit-llvm %s -o - | FileCheck %s
5
6 // RUN: %clang_cc1 -faltivec -triple powerpc64-unknown-unknown \
7 // RUN: -target-feature +crypto -target-feature +power8-vector \
8 // RUN: -emit-llvm %s -o - | FileCheck %s
9 #include <altivec.h>
10 #define B_INIT1 { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, \
11 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 };
12 #define B_INIT2 { 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, \
13 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x70 };
14 #define H_INIT1 { 0x0102, 0x0304, 0x0506, 0x0708, \
15 0x090A, 0x0B0C, 0x0D0E, 0x0F10 };
16 #define H_INIT2 { 0x7172, 0x7374, 0x7576, 0x7778, \
17 0x797A, 0x7B7C, 0x7D7E, 0x7F70 };
18 #define W_INIT1 { 0x01020304, 0x05060708, \
19 0x090A0B0C, 0x0D0E0F10 };
20 #define W_INIT2 { 0x71727374, 0x75767778, \
21 0x797A7B7C, 0x7D7E7F70 };
22 #define D_INIT1 { 0x0102030405060708, \
23 0x090A0B0C0D0E0F10 };
24 #define D_INIT2 { 0x7172737475767778, \
25 0x797A7B7C7D7E7F70 };
26
27 // CHECK-LABEL: define <16 x i8> @test_vpmsumb
test_vpmsumb(void)28 vector unsigned char test_vpmsumb(void)
29 {
30 vector unsigned char a = B_INIT1
31 vector unsigned char b = B_INIT2
32 return __builtin_altivec_crypto_vpmsumb(a, b);
33 // CHECK: @llvm.ppc.altivec.crypto.vpmsumb
34 }
35
36 // CHECK-LABEL: define <8 x i16> @test_vpmsumh
test_vpmsumh(void)37 vector unsigned short test_vpmsumh(void)
38 {
39 vector unsigned short a = H_INIT1
40 vector unsigned short b = H_INIT2
41 return __builtin_altivec_crypto_vpmsumh(a, b);
42 // CHECK: @llvm.ppc.altivec.crypto.vpmsumh
43 }
44
45 // CHECK-LABEL: define <4 x i32> @test_vpmsumw
test_vpmsumw(void)46 vector unsigned int test_vpmsumw(void)
47 {
48 vector unsigned int a = W_INIT1
49 vector unsigned int b = W_INIT2
50 return __builtin_altivec_crypto_vpmsumw(a, b);
51 // CHECK: @llvm.ppc.altivec.crypto.vpmsumw
52 }
53
54 // CHECK-LABEL: define <2 x i64> @test_vpmsumd
test_vpmsumd(void)55 vector unsigned long long test_vpmsumd(void)
56 {
57 vector unsigned long long a = D_INIT1
58 vector unsigned long long b = D_INIT2
59 return __builtin_altivec_crypto_vpmsumd(a, b);
60 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
61 }
62
63 // CHECK-LABEL: define <2 x i64> @test_vsbox
test_vsbox(void)64 vector unsigned long long test_vsbox(void)
65 {
66 vector unsigned long long a = D_INIT1
67 return __builtin_altivec_crypto_vsbox(a);
68 // CHECK: @llvm.ppc.altivec.crypto.vsbox
69 }
70
71 // CHECK-LABEL: define <16 x i8> @test_vpermxorb
test_vpermxorb(void)72 vector unsigned char test_vpermxorb(void)
73 {
74 vector unsigned char a = B_INIT1
75 vector unsigned char b = B_INIT2
76 vector unsigned char c = B_INIT2
77 return __builtin_altivec_crypto_vpermxor(a, b, c);
78 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
79 }
80
81 // CHECK-LABEL: define <8 x i16> @test_vpermxorh
test_vpermxorh(void)82 vector unsigned short test_vpermxorh(void)
83 {
84 vector unsigned short a = H_INIT1
85 vector unsigned short b = H_INIT2
86 vector unsigned short c = H_INIT2
87 return __builtin_altivec_crypto_vpermxor(a, b, c);
88 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
89 }
90
91 // CHECK-LABEL: define <4 x i32> @test_vpermxorw
test_vpermxorw(void)92 vector unsigned int test_vpermxorw(void)
93 {
94 vector unsigned int a = W_INIT1
95 vector unsigned int b = W_INIT2
96 vector unsigned int c = W_INIT2
97 return __builtin_altivec_crypto_vpermxor(a, b, c);
98 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
99 }
100
101 // CHECK-LABEL: define <2 x i64> @test_vpermxord
test_vpermxord(void)102 vector unsigned long long test_vpermxord(void)
103 {
104 vector unsigned long long a = D_INIT1
105 vector unsigned long long b = D_INIT2
106 vector unsigned long long c = D_INIT2
107 return __builtin_altivec_crypto_vpermxor(a, b, c);
108 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
109 }
110
111 // CHECK-LABEL: define <2 x i64> @test_vcipher
test_vcipher(void)112 vector unsigned long long test_vcipher(void)
113 {
114 vector unsigned long long a = D_INIT1
115 vector unsigned long long b = D_INIT2
116 return __builtin_altivec_crypto_vcipher(a, b);
117 // CHECK: @llvm.ppc.altivec.crypto.vcipher
118 }
119
120 // CHECK-LABEL: define <2 x i64> @test_vcipherlast
test_vcipherlast(void)121 vector unsigned long long test_vcipherlast(void)
122 {
123 vector unsigned long long a = D_INIT1
124 vector unsigned long long b = D_INIT2
125 return __builtin_altivec_crypto_vcipherlast(a, b);
126 // CHECK: @llvm.ppc.altivec.crypto.vcipherlast
127 }
128
129 // CHECK-LABEL: @test_vncipher
test_vncipher(void)130 vector unsigned long long test_vncipher(void)
131 {
132 vector unsigned long long a = D_INIT1
133 vector unsigned long long b = D_INIT2
134 return __builtin_altivec_crypto_vncipher(a, b);
135 // CHECK: @llvm.ppc.altivec.crypto.vncipher
136 }
137
138 // CHECK-LABEL: define <2 x i64> @test_vncipherlast
test_vncipherlast(void)139 vector unsigned long long test_vncipherlast(void)
140 {
141 vector unsigned long long a = D_INIT1
142 vector unsigned long long b = D_INIT2
143 return __builtin_altivec_crypto_vncipherlast(a, b);
144 // CHECK: @llvm.ppc.altivec.crypto.vncipherlast
145 }
146
147 // CHECK-LABEL: define <4 x i32> @test_vshasigmaw
test_vshasigmaw(void)148 vector unsigned int test_vshasigmaw(void)
149 {
150 vector unsigned int a = W_INIT1
151 return __builtin_altivec_crypto_vshasigmaw(a, 1, 15);
152 // CHECK: @llvm.ppc.altivec.crypto.vshasigmaw
153 }
154
155 // CHECK-LABEL: define <2 x i64> @test_vshasigmad
test_vshasigmad(void)156 vector unsigned long long test_vshasigmad(void)
157 {
158 vector unsigned long long a = D_INIT2
159 return __builtin_altivec_crypto_vshasigmad(a, 1, 15);
160 // CHECK: @llvm.ppc.altivec.crypto.vshasigmad
161 }
162
163 // Test cases for the builtins the way they are exposed to
164 // users through altivec.h
165 // CHECK-LABEL: define <16 x i8> @test_vpmsumb_e
test_vpmsumb_e(void)166 vector unsigned char test_vpmsumb_e(void)
167 {
168 vector unsigned char a = B_INIT1
169 vector unsigned char b = B_INIT2
170 return __builtin_crypto_vpmsumb(a, b);
171 // CHECK: @llvm.ppc.altivec.crypto.vpmsumb
172 }
173
174 // CHECK-LABEL: define <8 x i16> @test_vpmsumh_e
test_vpmsumh_e(void)175 vector unsigned short test_vpmsumh_e(void)
176 {
177 vector unsigned short a = H_INIT1
178 vector unsigned short b = H_INIT2
179 return __builtin_crypto_vpmsumb(a, b);
180 // CHECK: @llvm.ppc.altivec.crypto.vpmsumh
181 }
182
183 // CHECK-LABEL: define <4 x i32> @test_vpmsumw_e
test_vpmsumw_e(void)184 vector unsigned int test_vpmsumw_e(void)
185 {
186 vector unsigned int a = W_INIT1
187 vector unsigned int b = W_INIT2
188 return __builtin_crypto_vpmsumb(a, b);
189 // CHECK: @llvm.ppc.altivec.crypto.vpmsumw
190 }
191
192 // CHECK-LABEL: define <2 x i64> @test_vpmsumd_e
test_vpmsumd_e(void)193 vector unsigned long long test_vpmsumd_e(void)
194 {
195 vector unsigned long long a = D_INIT1
196 vector unsigned long long b = D_INIT2
197 return __builtin_crypto_vpmsumb(a, b);
198 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
199 }
200
201 // CHECK-LABEL: define <2 x i64> @test_vsbox_e
test_vsbox_e(void)202 vector unsigned long long test_vsbox_e(void)
203 {
204 vector unsigned long long a = D_INIT1
205 return __builtin_crypto_vsbox(a);
206 // CHECK: @llvm.ppc.altivec.crypto.vsbox
207 }
208
209 // CHECK-LABEL: define <16 x i8> @test_vpermxorb_e
test_vpermxorb_e(void)210 vector unsigned char test_vpermxorb_e(void)
211 {
212 vector unsigned char a = B_INIT1
213 vector unsigned char b = B_INIT2
214 vector unsigned char c = B_INIT2
215 return __builtin_crypto_vpermxor(a, b, c);
216 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
217 }
218
219 // CHECK-LABEL: define <8 x i16> @test_vpermxorh_e
test_vpermxorh_e(void)220 vector unsigned short test_vpermxorh_e(void)
221 {
222 vector unsigned short a = H_INIT1
223 vector unsigned short b = H_INIT2
224 vector unsigned short c = H_INIT2
225 return __builtin_crypto_vpermxor(a, b, c);
226 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
227 }
228
229 // CHECK-LABEL: define <4 x i32> @test_vpermxorw_e
test_vpermxorw_e(void)230 vector unsigned int test_vpermxorw_e(void)
231 {
232 vector unsigned int a = W_INIT1
233 vector unsigned int b = W_INIT2
234 vector unsigned int c = W_INIT2
235 return __builtin_crypto_vpermxor(a, b, c);
236 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
237 }
238
239 // CHECK-LABEL: define <2 x i64> @test_vpermxord_e
test_vpermxord_e(void)240 vector unsigned long long test_vpermxord_e(void)
241 {
242 vector unsigned long long a = D_INIT1
243 vector unsigned long long b = D_INIT2
244 vector unsigned long long c = D_INIT2
245 return __builtin_crypto_vpermxor(a, b, c);
246 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
247 }
248
249 // CHECK-LABEL: define <2 x i64> @test_vcipher_e
test_vcipher_e(void)250 vector unsigned long long test_vcipher_e(void)
251 {
252 vector unsigned long long a = D_INIT1
253 vector unsigned long long b = D_INIT2
254 return __builtin_crypto_vcipher(a, b);
255 // CHECK: @llvm.ppc.altivec.crypto.vcipher
256 }
257
258 // CHECK-LABEL: define <2 x i64> @test_vcipherlast_e
test_vcipherlast_e(void)259 vector unsigned long long test_vcipherlast_e(void)
260 {
261 vector unsigned long long a = D_INIT1
262 vector unsigned long long b = D_INIT2
263 return __builtin_crypto_vcipherlast(a, b);
264 // CHECK: @llvm.ppc.altivec.crypto.vcipherlast
265 }
266
267 // CHECK-LABEL: define <2 x i64> @test_vncipher_e
test_vncipher_e(void)268 vector unsigned long long test_vncipher_e(void)
269 {
270 vector unsigned long long a = D_INIT1
271 vector unsigned long long b = D_INIT2
272 return __builtin_crypto_vncipher(a, b);
273 // CHECK: @llvm.ppc.altivec.crypto.vncipher
274 }
275
276 // CHECK-LABEL: define <2 x i64> @test_vncipherlast_e
test_vncipherlast_e(void)277 vector unsigned long long test_vncipherlast_e(void)
278 {
279 vector unsigned long long a = D_INIT1
280 vector unsigned long long b = D_INIT2
281 return __builtin_crypto_vncipherlast(a, b);
282 // CHECK: @llvm.ppc.altivec.crypto.vncipherlast
283 }
284
285 // CHECK-LABEL: define <4 x i32> @test_vshasigmaw_e
test_vshasigmaw_e(void)286 vector unsigned int test_vshasigmaw_e(void)
287 {
288 vector unsigned int a = W_INIT1
289 return __builtin_crypto_vshasigmaw(a, 1, 15);
290 // CHECK: @llvm.ppc.altivec.crypto.vshasigmaw
291 }
292
293 // CHECK-LABEL: define <2 x i64> @test_vshasigmad_e
test_vshasigmad_e(void)294 vector unsigned long long test_vshasigmad_e(void)
295 {
296 vector unsigned long long a = D_INIT2
297 return __builtin_crypto_vshasigmad(a, 0, 15);
298 // CHECK: @llvm.ppc.altivec.crypto.vshasigmad
299 }
300
301 // CHECK-LABEL: @test_vec_sbox_be
test_vec_sbox_be(void)302 vector unsigned char test_vec_sbox_be(void)
303 {
304 vector unsigned char a = B_INIT1
305 return vec_sbox_be(a);
306 // CHECK: @llvm.ppc.altivec.crypto.vsbox
307 }
308
309 // CHECK-LABEL: @test_vec_cipher_be
test_vec_cipher_be(void)310 vector unsigned char test_vec_cipher_be(void)
311 {
312 vector unsigned char a = B_INIT1
313 vector unsigned char b = B_INIT2
314 return vec_cipher_be(a, b);
315 // CHECK: @llvm.ppc.altivec.crypto.vcipher
316 }
317
318 // CHECK-LABEL: @test_vec_cipherlast_be
test_vec_cipherlast_be(void)319 vector unsigned char test_vec_cipherlast_be(void)
320 {
321 vector unsigned char a = B_INIT1
322 vector unsigned char b = B_INIT2
323 return vec_cipherlast_be(a, b);
324 // CHECK: @llvm.ppc.altivec.crypto.vcipherlast
325 }
326
327 // CHECK-LABEL: @test_vec_ncipher_be
test_vec_ncipher_be(void)328 vector unsigned char test_vec_ncipher_be(void)
329 {
330 vector unsigned char a = B_INIT1
331 vector unsigned char b = B_INIT2
332 return vec_ncipher_be(a, b);
333 // CHECK: @llvm.ppc.altivec.crypto.vncipher
334 }
335
336 // CHECK-LABEL: @test_vec_ncipherlast_be
test_vec_ncipherlast_be(void)337 vector unsigned char test_vec_ncipherlast_be(void)
338 {
339 vector unsigned char a = B_INIT1
340 vector unsigned char b = B_INIT2
341 return vec_ncipherlast_be(a, b);
342 // CHECK: @llvm.ppc.altivec.crypto.vncipherlast
343 }
344
345 // CHECK-LABEL: @test_vec_shasigma_bew
test_vec_shasigma_bew(void)346 vector unsigned int test_vec_shasigma_bew(void)
347 {
348 vector unsigned int a = W_INIT1
349 return vec_shasigma_be(a, 1, 15);
350 // CHECK: @llvm.ppc.altivec.crypto.vshasigmaw
351 }
352
353 // CHECK-LABEL: @test_vec_shasigma_bed
test_vec_shasigma_bed(void)354 vector unsigned long long test_vec_shasigma_bed(void)
355 {
356 vector unsigned long long a = D_INIT2
357 return vec_shasigma_be(a, 1, 15);
358 // CHECK: @llvm.ppc.altivec.crypto.vshasigmad
359 }
360
361 // CHECK-LABEL: @test_vec_pmsum_beb
test_vec_pmsum_beb(void)362 vector unsigned short test_vec_pmsum_beb(void)
363 {
364 vector unsigned char a = B_INIT1
365 vector unsigned char b = B_INIT2
366 return vec_pmsum_be(a, b);
367 // CHECK: @llvm.ppc.altivec.crypto.vpmsumb
368 }
369
370 // CHECK-LABEL: @test_vec_pmsum_beh
test_vec_pmsum_beh(void)371 vector unsigned int test_vec_pmsum_beh(void)
372 {
373 vector unsigned short a = H_INIT1
374 vector unsigned short b = H_INIT2
375 return vec_pmsum_be(a, b);
376 // CHECK: @llvm.ppc.altivec.crypto.vpmsumh
377 }
378
379 // CHECK-LABEL: @test_vec_pmsum_bew
test_vec_pmsum_bew(void)380 vector unsigned long long test_vec_pmsum_bew(void)
381 {
382 vector unsigned int a = W_INIT1
383 vector unsigned int b = W_INIT2
384 return vec_pmsum_be(a, b);
385 // CHECK: @llvm.ppc.altivec.crypto.vpmsumw
386 }
387
388 // CHECK-LABEL: @test_vec_pmsum_bed
test_vec_pmsum_bed(void)389 vector unsigned __int128 test_vec_pmsum_bed(void)
390 {
391 vector unsigned long long a = D_INIT1
392 vector unsigned long long b = D_INIT2
393 return vec_pmsum_be(a, b);
394 // CHECK: @llvm.ppc.altivec.crypto.vpmsumd
395 }
396
397