xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/ext-vector.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc typedef __attribute__(( ext_vector_type(4) )) float float4;
4*f4a2713aSLionel Sambuc typedef __attribute__(( ext_vector_type(2) )) float float2;
5*f4a2713aSLionel Sambuc typedef __attribute__(( ext_vector_type(4) )) int int4;
6*f4a2713aSLionel Sambuc typedef __attribute__(( ext_vector_type(4) )) unsigned int uint4;
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc // CHECK: @foo = global <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>
9*f4a2713aSLionel Sambuc float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc // CHECK: @bar = constant <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 0x7FF0000000000000>
12*f4a2713aSLionel Sambuc const float4 bar = (float4){ 1.0, 2.0, 3.0, __builtin_inff() };
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc // CHECK: @test1
15*f4a2713aSLionel Sambuc // CHECK: fadd <4 x float>
test1(float4 V)16*f4a2713aSLionel Sambuc float4 test1(float4 V) {
17*f4a2713aSLionel Sambuc   return V.wzyx+V;
18*f4a2713aSLionel Sambuc }
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc float2 vec2, vec2_2;
21*f4a2713aSLionel Sambuc float4 vec4, vec4_2;
22*f4a2713aSLionel Sambuc float f;
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc // CHECK: @test2
25*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <i32 0, i32 1>
26*f4a2713aSLionel Sambuc // CHECK: extractelement
27*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <i32 1, i32 1, i32 1, i32 1>
28*f4a2713aSLionel Sambuc // CHECK: insertelement
29*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <i32 1, i32 0>
test2()30*f4a2713aSLionel Sambuc void test2() {
31*f4a2713aSLionel Sambuc     vec2 = vec4.xy;  // shorten
32*f4a2713aSLionel Sambuc     f = vec2.x;      // extract elt
33*f4a2713aSLionel Sambuc     vec4 = vec4.yyyy;  // splat
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc     vec2.x = f;      // insert one.
36*f4a2713aSLionel Sambuc     vec2.yx = vec2; // reverse
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc 
39*f4a2713aSLionel Sambuc // CHECK: @test3
40*f4a2713aSLionel Sambuc // CHECK: store <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>
test3(float4 * out)41*f4a2713aSLionel Sambuc void test3(float4 *out) {
42*f4a2713aSLionel Sambuc   *out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f });
43*f4a2713aSLionel Sambuc }
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc // CHECK: @test4
46*f4a2713aSLionel Sambuc // CHECK: store <4 x float>
47*f4a2713aSLionel Sambuc // CHECK: store <4 x float>
test4(float4 * out)48*f4a2713aSLionel Sambuc void test4(float4 *out) {
49*f4a2713aSLionel Sambuc   float a = 1.0f;
50*f4a2713aSLionel Sambuc   float b = 2.0f;
51*f4a2713aSLionel Sambuc   float c = 3.0f;
52*f4a2713aSLionel Sambuc   float d = 4.0f;
53*f4a2713aSLionel Sambuc   *out = ((float4) {a,b,c,d});
54*f4a2713aSLionel Sambuc }
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc // CHECK: @test5
57*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <4 x i32> zeroinitializer
58*f4a2713aSLionel Sambuc // CHECK: fmul <4 x float>
59*f4a2713aSLionel Sambuc // CHECK: fmul <4 x float>
60*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <4 x i32> zeroinitializer
61*f4a2713aSLionel Sambuc // CHECK: fmul <4 x float>
test5(float4 * out)62*f4a2713aSLionel Sambuc void test5(float4 *out) {
63*f4a2713aSLionel Sambuc   float a;
64*f4a2713aSLionel Sambuc   float4 b;
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc   a = 1.0f;
67*f4a2713aSLionel Sambuc   b = a;
68*f4a2713aSLionel Sambuc   b = b * 5.0f;
69*f4a2713aSLionel Sambuc   b = 5.0f * b;
70*f4a2713aSLionel Sambuc   b *= a;
71*f4a2713aSLionel Sambuc 
72*f4a2713aSLionel Sambuc   *out = b;
73*f4a2713aSLionel Sambuc }
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc // CHECK: @test6
test6(float4 * ap,float4 * bp,float c)76*f4a2713aSLionel Sambuc void test6(float4 *ap, float4 *bp, float c) {
77*f4a2713aSLionel Sambuc   float4 a = *ap;
78*f4a2713aSLionel Sambuc   float4 b = *bp;
79*f4a2713aSLionel Sambuc 
80*f4a2713aSLionel Sambuc   // CHECK: fadd <4 x float>
81*f4a2713aSLionel Sambuc   // CHECK: fsub <4 x float>
82*f4a2713aSLionel Sambuc   // CHECK: fmul <4 x float>
83*f4a2713aSLionel Sambuc   // CHECK: fdiv <4 x float>
84*f4a2713aSLionel Sambuc   a = a + b;
85*f4a2713aSLionel Sambuc   a = a - b;
86*f4a2713aSLionel Sambuc   a = a * b;
87*f4a2713aSLionel Sambuc   a = a / b;
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc   // CHECK: fadd <4 x float>
90*f4a2713aSLionel Sambuc   // CHECK: fsub <4 x float>
91*f4a2713aSLionel Sambuc   // CHECK: fmul <4 x float>
92*f4a2713aSLionel Sambuc   // CHECK: fdiv <4 x float>
93*f4a2713aSLionel Sambuc   a = a + c;
94*f4a2713aSLionel Sambuc   a = a - c;
95*f4a2713aSLionel Sambuc   a = a * c;
96*f4a2713aSLionel Sambuc   a = a / c;
97*f4a2713aSLionel Sambuc 
98*f4a2713aSLionel Sambuc   // CHECK: fadd <4 x float>
99*f4a2713aSLionel Sambuc   // CHECK: fsub <4 x float>
100*f4a2713aSLionel Sambuc   // CHECK: fmul <4 x float>
101*f4a2713aSLionel Sambuc   // CHECK: fdiv <4 x float>
102*f4a2713aSLionel Sambuc   a += b;
103*f4a2713aSLionel Sambuc   a -= b;
104*f4a2713aSLionel Sambuc   a *= b;
105*f4a2713aSLionel Sambuc   a /= b;
106*f4a2713aSLionel Sambuc 
107*f4a2713aSLionel Sambuc   // CHECK: fadd <4 x float>
108*f4a2713aSLionel Sambuc   // CHECK: fsub <4 x float>
109*f4a2713aSLionel Sambuc   // CHECK: fmul <4 x float>
110*f4a2713aSLionel Sambuc   // CHECK: fdiv <4 x float>
111*f4a2713aSLionel Sambuc   a += c;
112*f4a2713aSLionel Sambuc   a -= c;
113*f4a2713aSLionel Sambuc   a *= c;
114*f4a2713aSLionel Sambuc   a /= c;
115*f4a2713aSLionel Sambuc 
116*f4a2713aSLionel Sambuc   // Vector comparisons can sometimes crash the x86 backend: rdar://6326239,
117*f4a2713aSLionel Sambuc   // reject them until the implementation is stable.
118*f4a2713aSLionel Sambuc #if 0
119*f4a2713aSLionel Sambuc   int4 cmp;
120*f4a2713aSLionel Sambuc   cmp = a < b;
121*f4a2713aSLionel Sambuc   cmp = a <= b;
122*f4a2713aSLionel Sambuc   cmp = a < b;
123*f4a2713aSLionel Sambuc   cmp = a >= b;
124*f4a2713aSLionel Sambuc   cmp = a == b;
125*f4a2713aSLionel Sambuc   cmp = a != b;
126*f4a2713aSLionel Sambuc #endif
127*f4a2713aSLionel Sambuc }
128*f4a2713aSLionel Sambuc 
129*f4a2713aSLionel Sambuc // CHECK: @test7
test7(int4 * ap,int4 * bp,int c)130*f4a2713aSLionel Sambuc void test7(int4 *ap, int4 *bp, int c) {
131*f4a2713aSLionel Sambuc   int4 a = *ap;
132*f4a2713aSLionel Sambuc   int4 b = *bp;
133*f4a2713aSLionel Sambuc 
134*f4a2713aSLionel Sambuc   // CHECK: add <4 x i32>
135*f4a2713aSLionel Sambuc   // CHECK: sub <4 x i32>
136*f4a2713aSLionel Sambuc   // CHECK: mul <4 x i32>
137*f4a2713aSLionel Sambuc   // CHECK: sdiv <4 x i32>
138*f4a2713aSLionel Sambuc   // CHECK: srem <4 x i32>
139*f4a2713aSLionel Sambuc   a = a + b;
140*f4a2713aSLionel Sambuc   a = a - b;
141*f4a2713aSLionel Sambuc   a = a * b;
142*f4a2713aSLionel Sambuc   a = a / b;
143*f4a2713aSLionel Sambuc   a = a % b;
144*f4a2713aSLionel Sambuc 
145*f4a2713aSLionel Sambuc   // CHECK: add <4 x i32>
146*f4a2713aSLionel Sambuc   // CHECK: sub <4 x i32>
147*f4a2713aSLionel Sambuc   // CHECK: mul <4 x i32>
148*f4a2713aSLionel Sambuc   // CHECK: sdiv <4 x i32>
149*f4a2713aSLionel Sambuc   // CHECK: srem <4 x i32>
150*f4a2713aSLionel Sambuc   a = a + c;
151*f4a2713aSLionel Sambuc   a = a - c;
152*f4a2713aSLionel Sambuc   a = a * c;
153*f4a2713aSLionel Sambuc   a = a / c;
154*f4a2713aSLionel Sambuc   a = a % c;
155*f4a2713aSLionel Sambuc 
156*f4a2713aSLionel Sambuc   // CHECK: add <4 x i32>
157*f4a2713aSLionel Sambuc   // CHECK: sub <4 x i32>
158*f4a2713aSLionel Sambuc   // CHECK: mul <4 x i32>
159*f4a2713aSLionel Sambuc   // CHECK: sdiv <4 x i32>
160*f4a2713aSLionel Sambuc   // CHECK: srem <4 x i32>
161*f4a2713aSLionel Sambuc   a += b;
162*f4a2713aSLionel Sambuc   a -= b;
163*f4a2713aSLionel Sambuc   a *= b;
164*f4a2713aSLionel Sambuc   a /= b;
165*f4a2713aSLionel Sambuc   a %= b;
166*f4a2713aSLionel Sambuc 
167*f4a2713aSLionel Sambuc   // CHECK: add <4 x i32>
168*f4a2713aSLionel Sambuc   // CHECK: sub <4 x i32>
169*f4a2713aSLionel Sambuc   // CHECK: mul <4 x i32>
170*f4a2713aSLionel Sambuc   // CHECK: sdiv <4 x i32>
171*f4a2713aSLionel Sambuc   // CHECK: srem <4 x i32>
172*f4a2713aSLionel Sambuc   a += c;
173*f4a2713aSLionel Sambuc   a -= c;
174*f4a2713aSLionel Sambuc   a *= c;
175*f4a2713aSLionel Sambuc   a /= c;
176*f4a2713aSLionel Sambuc   a %= c;
177*f4a2713aSLionel Sambuc 
178*f4a2713aSLionel Sambuc 
179*f4a2713aSLionel Sambuc   // Vector comparisons.
180*f4a2713aSLionel Sambuc   // CHECK: icmp slt
181*f4a2713aSLionel Sambuc   // CHECK: icmp sle
182*f4a2713aSLionel Sambuc   // CHECK: icmp sgt
183*f4a2713aSLionel Sambuc   // CHECK: icmp sge
184*f4a2713aSLionel Sambuc   // CHECK: icmp eq
185*f4a2713aSLionel Sambuc   // CHECK: icmp ne
186*f4a2713aSLionel Sambuc   int4 cmp;
187*f4a2713aSLionel Sambuc   cmp = a < b;
188*f4a2713aSLionel Sambuc   cmp = a <= b;
189*f4a2713aSLionel Sambuc   cmp = a > b;
190*f4a2713aSLionel Sambuc   cmp = a >= b;
191*f4a2713aSLionel Sambuc   cmp = a == b;
192*f4a2713aSLionel Sambuc   cmp = a != b;
193*f4a2713aSLionel Sambuc }
194*f4a2713aSLionel Sambuc 
195*f4a2713aSLionel Sambuc // CHECK: @test8
test8(float4 * ap,float4 * bp,int c)196*f4a2713aSLionel Sambuc void test8(float4 *ap, float4 *bp, int c) {
197*f4a2713aSLionel Sambuc   float4 a = *ap;
198*f4a2713aSLionel Sambuc   float4 b = *bp;
199*f4a2713aSLionel Sambuc 
200*f4a2713aSLionel Sambuc   // Vector comparisons.
201*f4a2713aSLionel Sambuc   // CHECK: fcmp olt
202*f4a2713aSLionel Sambuc   // CHECK: fcmp ole
203*f4a2713aSLionel Sambuc   // CHECK: fcmp ogt
204*f4a2713aSLionel Sambuc   // CHECK: fcmp oge
205*f4a2713aSLionel Sambuc   // CHECK: fcmp oeq
206*f4a2713aSLionel Sambuc   // CHECK: fcmp une
207*f4a2713aSLionel Sambuc   int4 cmp;
208*f4a2713aSLionel Sambuc   cmp = a < b;
209*f4a2713aSLionel Sambuc   cmp = a <= b;
210*f4a2713aSLionel Sambuc   cmp = a > b;
211*f4a2713aSLionel Sambuc   cmp = a >= b;
212*f4a2713aSLionel Sambuc   cmp = a == b;
213*f4a2713aSLionel Sambuc   cmp = a != b;
214*f4a2713aSLionel Sambuc }
215*f4a2713aSLionel Sambuc 
216*f4a2713aSLionel Sambuc // CHECK: @test9
217*f4a2713aSLionel Sambuc // CHECK: extractelement <4 x i32>
test9(int4 V)218*f4a2713aSLionel Sambuc int test9(int4 V) {
219*f4a2713aSLionel Sambuc   return V.xy.x;
220*f4a2713aSLionel Sambuc }
221*f4a2713aSLionel Sambuc 
222*f4a2713aSLionel Sambuc // CHECK: @test10
223*f4a2713aSLionel Sambuc // CHECK: add <4 x i32>
224*f4a2713aSLionel Sambuc // CHECK: extractelement <4 x i32>
test10(int4 V)225*f4a2713aSLionel Sambuc int test10(int4 V) {
226*f4a2713aSLionel Sambuc   return (V+V).x;
227*f4a2713aSLionel Sambuc }
228*f4a2713aSLionel Sambuc 
229*f4a2713aSLionel Sambuc // CHECK: @test11
230*f4a2713aSLionel Sambuc // CHECK: extractelement <4 x i32>
231*f4a2713aSLionel Sambuc int4 test11a();
test11()232*f4a2713aSLionel Sambuc int test11() {
233*f4a2713aSLionel Sambuc   return test11a().x;
234*f4a2713aSLionel Sambuc }
235*f4a2713aSLionel Sambuc 
236*f4a2713aSLionel Sambuc // CHECK: @test12
237*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0>
238*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <i32 0, i32 1, i32 2, i32 undef>
239*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <i32 4, i32 5, i32 6, i32 3>
test12(int4 V)240*f4a2713aSLionel Sambuc int4 test12(int4 V) {
241*f4a2713aSLionel Sambuc   V.xyz = V.zyx;
242*f4a2713aSLionel Sambuc   return V;
243*f4a2713aSLionel Sambuc }
244*f4a2713aSLionel Sambuc 
245*f4a2713aSLionel Sambuc // CHECK: @test13
246*f4a2713aSLionel Sambuc // CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0, i32 3>
test13(int4 * V)247*f4a2713aSLionel Sambuc int4 test13(int4 *V) {
248*f4a2713aSLionel Sambuc   return V->zyxw;
249*f4a2713aSLionel Sambuc }
250*f4a2713aSLionel Sambuc 
251*f4a2713aSLionel Sambuc // CHECK: @test14
test14(uint4 * ap,uint4 * bp,unsigned c)252*f4a2713aSLionel Sambuc void test14(uint4 *ap, uint4 *bp, unsigned c) {
253*f4a2713aSLionel Sambuc   uint4 a = *ap;
254*f4a2713aSLionel Sambuc   uint4 b = *bp;
255*f4a2713aSLionel Sambuc   int4 d;
256*f4a2713aSLionel Sambuc 
257*f4a2713aSLionel Sambuc   // CHECK: udiv <4 x i32>
258*f4a2713aSLionel Sambuc   // CHECK: urem <4 x i32>
259*f4a2713aSLionel Sambuc   a = a / b;
260*f4a2713aSLionel Sambuc   a = a % b;
261*f4a2713aSLionel Sambuc 
262*f4a2713aSLionel Sambuc   // CHECK: udiv <4 x i32>
263*f4a2713aSLionel Sambuc   // CHECK: urem <4 x i32>
264*f4a2713aSLionel Sambuc   a = a / c;
265*f4a2713aSLionel Sambuc   a = a % c;
266*f4a2713aSLionel Sambuc 
267*f4a2713aSLionel Sambuc   // CHECK: icmp ult
268*f4a2713aSLionel Sambuc   // CHECK: icmp ule
269*f4a2713aSLionel Sambuc   // CHECK: icmp ugt
270*f4a2713aSLionel Sambuc   // CHECK: icmp uge
271*f4a2713aSLionel Sambuc   // CHECK: icmp eq
272*f4a2713aSLionel Sambuc   // CHECK: icmp ne
273*f4a2713aSLionel Sambuc   d = a < b;
274*f4a2713aSLionel Sambuc   d = a <= b;
275*f4a2713aSLionel Sambuc   d = a > b;
276*f4a2713aSLionel Sambuc   d = a >= b;
277*f4a2713aSLionel Sambuc   d = a == b;
278*f4a2713aSLionel Sambuc   d = a != b;
279*f4a2713aSLionel Sambuc }
280*f4a2713aSLionel Sambuc 
281*f4a2713aSLionel Sambuc // CHECK: @test15
test15(uint4 V0)282*f4a2713aSLionel Sambuc int4 test15(uint4 V0) {
283*f4a2713aSLionel Sambuc   // CHECK: icmp eq <4 x i32>
284*f4a2713aSLionel Sambuc   int4 V = !V0;
285*f4a2713aSLionel Sambuc   V = V && V;
286*f4a2713aSLionel Sambuc   V = V || V;
287*f4a2713aSLionel Sambuc   return V;
288*f4a2713aSLionel Sambuc }
289*f4a2713aSLionel Sambuc 
290*f4a2713aSLionel Sambuc // CHECK: @test16
test16(float2 a,float2 b)291*f4a2713aSLionel Sambuc void test16(float2 a, float2 b) {
292*f4a2713aSLionel Sambuc   float2 t0 = (a + b) / 2;
293*f4a2713aSLionel Sambuc }
294*f4a2713aSLionel Sambuc 
295*f4a2713aSLionel Sambuc typedef char char16 __attribute__((ext_vector_type(16)));
296*f4a2713aSLionel Sambuc 
297*f4a2713aSLionel Sambuc // CHECK: @test17
test17(void)298*f4a2713aSLionel Sambuc void test17(void) {
299*f4a2713aSLionel Sambuc   char16 valA;
300*f4a2713aSLionel Sambuc   char valB;
301*f4a2713aSLionel Sambuc   char valC;
302*f4a2713aSLionel Sambuc   char16 destVal = valC ? valA : valB;
303*f4a2713aSLionel Sambuc }
304