xref: /llvm-project/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-cipher.c (revision f563bd74cb9a4f0d2d3eb49d35536b648361ec53)
1 // REQUIRES: powerpc-registered-target
2 // RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu \
3 // RUN:    -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
4 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu \
5 // RUN:   -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
6 // RUN: %clang_cc1 -triple powerpc64-unknown-aix \
7 // RUN:    -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
8 // RUN: %clang_cc1 -triple powerpc-unknown-linux-gnu \
9 // RUN:    -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
10 // RUN: %clang_cc1 -triple powerpcle-unknown-linux-gnu \
11 // RUN:   -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
12 // RUN: %clang_cc1 -triple powerpc-unknown-aix \
13 // RUN:    -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
14 
15 // All of these cipher builtins are only for Power 8 and up.
16 
17 // CHECK-LABEL: @testvcipher(
18 // CHECK:         [[TMP4:%.*]] = call <2 x i64> @llvm.ppc.altivec.crypto.vcipher
19 // CHECK-NEXT:    [[TMP5:%.*]] = bitcast <2 x i64> [[TMP4]] to <16 x i8>
20 // CHECK-NEXT:    ret <16 x i8> [[TMP5]]
21 //
testvcipher(vector unsigned char state_array,vector unsigned char round_key)22 vector unsigned char testvcipher(vector unsigned char state_array, vector unsigned char round_key) {
23   return __vcipher(state_array, round_key);
24 }
25 
26 // CHECK-LABEL: @testvcipherlast(
27 // CHECK:         [[TMP4:%.*]] = call <2 x i64> @llvm.ppc.altivec.crypto.vcipherlast
28 // CHECK-NEXT:    [[TMP5:%.*]] = bitcast <2 x i64> [[TMP4]] to <16 x i8>
29 // CHECK-NEXT:    ret <16 x i8> [[TMP5]]
30 //
testvcipherlast(vector unsigned char state_array,vector unsigned char round_key)31 vector unsigned char testvcipherlast(vector unsigned char state_array, vector unsigned char round_key) {
32   return __vcipherlast(state_array, round_key);
33 }
34 
35 // CHECK-LABEL: @testvncipher(
36 // CHECK:         [[TMP4:%.*]] = call <2 x i64> @llvm.ppc.altivec.crypto.vncipher
37 // CHECK-NEXT:    [[TMP5:%.*]] = bitcast <2 x i64> [[TMP4]] to <16 x i8>
38 // CHECK-NEXT:    ret <16 x i8> [[TMP5]]
39 //
testvncipher(vector unsigned char state_array,vector unsigned char round_key)40 vector unsigned char testvncipher(vector unsigned char state_array, vector unsigned char round_key) {
41   return __vncipher(state_array, round_key);
42 }
43 
44 // CHECK-LABEL: @testvncipherlast(
45 // CHECK:         [[TMP4:%.*]] = call <2 x i64> @llvm.ppc.altivec.crypto.vncipherlast
46 // CHECK-NEXT:    [[TMP5:%.*]] = bitcast <2 x i64> [[TMP4]] to <16 x i8>
47 // CHECK-NEXT:    ret <16 x i8> [[TMP5]]
48 //
testvncipherlast(vector unsigned char state_array,vector unsigned char round_key)49 vector unsigned char testvncipherlast(vector unsigned char state_array, vector unsigned char round_key) {
50   return __vncipherlast(state_array, round_key);
51 }
52 
53 // CHECK-LABEL: @testvpermxor(
54 // CHECK:         [[TMP3:%.*]] = call <16 x i8> @llvm.ppc.altivec.crypto.vpermxor
55 // CHECK-NEXT:    ret <16 x i8> [[TMP3]]
56 //
testvpermxor(vector unsigned char a,vector unsigned char b,vector unsigned char mask)57 vector unsigned char testvpermxor(vector unsigned char a, vector unsigned char b, vector unsigned char mask) {
58   return __vpermxor(a, b, mask);
59 }
60 
61 // CHECK-LABEL: @testvpmsumb(
62 // CHECK:         [[TMP2:%.*]] = call <16 x i8> @llvm.ppc.altivec.crypto.vpmsumb
63 // CHECK-NEXT:    ret <16 x i8> [[TMP2]]
64 //
testvpmsumb(vector unsigned char a,vector unsigned char b)65 vector unsigned char testvpmsumb(vector unsigned char a, vector unsigned char b) {
66   return __vpmsumb(a, b);
67 }
68 
69 // CHECK-LABEL: @testvpmsumd(
70 // CHECK:         [[TMP2:%.*]] = call <2 x i64> @llvm.ppc.altivec.crypto.vpmsumd
71 // CHECK-NEXT:    ret <2 x i64> [[TMP2]]
72 //
testvpmsumd(vector unsigned long long a,vector unsigned long long b)73 vector unsigned long long testvpmsumd(vector unsigned long long a, vector unsigned long long b) {
74   return __vpmsumd(a, b);
75 }
76 
77 // CHECK-LABEL: @testvpmsumh(
78 // CHECK:         [[TMP2:%.*]] = call <8 x i16> @llvm.ppc.altivec.crypto.vpmsumh
79 // CHECK-NEXT:    ret <8 x i16> [[TMP2]]
80 //
testvpmsumh(vector unsigned short a,vector unsigned short b)81 vector unsigned short testvpmsumh(vector unsigned short a, vector unsigned short b) {
82   return __vpmsumh(a, b);
83 }
84 
85 // CHECK-LABEL: @testvpmsumw(
86 // CHECK:         [[TMP2:%.*]] = call <4 x i32> @llvm.ppc.altivec.crypto.vpmsumw
87 // CHECK-NEXT:    ret <4 x i32> [[TMP2]]
88 //
testvpmsumw(vector unsigned int a,vector unsigned int b)89 vector unsigned int testvpmsumw(vector unsigned int a, vector unsigned int b) {
90   return __vpmsumw(a, b);
91 }
92