ext-vector.c
6.88 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
typedef __attribute__(( ext_vector_type(4) )) float float4;
typedef __attribute__(( ext_vector_type(2) )) float float2;
typedef __attribute__(( ext_vector_type(4) )) int int4;
typedef __attribute__(( ext_vector_type(4) )) unsigned int uint4;
// CHECK: @foo = {{(dso_local )?}}global <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>
float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
// CHECK: @bar = {{(dso_local )?}}constant <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 0x7FF0000000000000>
const float4 bar = (float4){ 1.0, 2.0, 3.0, __builtin_inff() };
// CHECK: @test1
// CHECK: fadd <4 x float>
float4 test1(float4 V) {
return V.wzyx+V;
}
float2 vec2, vec2_2;
float4 vec4, vec4_2;
float f;
// CHECK: @test2
// CHECK: shufflevector {{.*}} <i32 0, i32 1>
// CHECK: extractelement
// CHECK: shufflevector {{.*}} <i32 1, i32 1, i32 1, i32 1>
// CHECK: insertelement
// CHECK: shufflevector {{.*}} <i32 1, i32 0>
void test2() {
vec2 = vec4.xy; // shorten
f = vec2.x; // extract elt
vec4 = vec4.yyyy; // splat
vec2.x = f; // insert one.
vec2.yx = vec2; // reverse
}
// CHECK: @test3
// CHECK: store <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>
void test3(float4 *out) {
*out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f });
}
// CHECK: @test4
// CHECK: store <4 x float>
// CHECK: store <4 x float>
void test4(float4 *out) {
float a = 1.0f;
float b = 2.0f;
float c = 3.0f;
float d = 4.0f;
*out = ((float4) {a,b,c,d});
}
// CHECK: @test5
// CHECK: shufflevector {{.*}} <4 x i32> zeroinitializer
// CHECK: fmul <4 x float>
// CHECK: fmul <4 x float>
// CHECK: shufflevector {{.*}} <4 x i32> zeroinitializer
// CHECK: fmul <4 x float>
void test5(float4 *out) {
float a;
float4 b;
a = 1.0f;
b = a;
b = b * 5.0f;
b = 5.0f * b;
b *= a;
*out = b;
}
// CHECK: @test6
void test6(float4 *ap, float4 *bp, float c) {
float4 a = *ap;
float4 b = *bp;
// CHECK: fadd <4 x float>
// CHECK: fsub <4 x float>
// CHECK: fmul <4 x float>
// CHECK: fdiv <4 x float>
a = a + b;
a = a - b;
a = a * b;
a = a / b;
// CHECK: fadd <4 x float>
// CHECK: fsub <4 x float>
// CHECK: fmul <4 x float>
// CHECK: fdiv <4 x float>
a = a + c;
a = a - c;
a = a * c;
a = a / c;
// CHECK: fadd <4 x float>
// CHECK: fsub <4 x float>
// CHECK: fmul <4 x float>
// CHECK: fdiv <4 x float>
a += b;
a -= b;
a *= b;
a /= b;
// CHECK: fadd <4 x float>
// CHECK: fsub <4 x float>
// CHECK: fmul <4 x float>
// CHECK: fdiv <4 x float>
a += c;
a -= c;
a *= c;
a /= c;
// Vector comparisons can sometimes crash the x86 backend: rdar://6326239,
// reject them until the implementation is stable.
#if 0
int4 cmp;
cmp = a < b;
cmp = a <= b;
cmp = a < b;
cmp = a >= b;
cmp = a == b;
cmp = a != b;
#endif
}
// CHECK: @test7
void test7(int4 *ap, int4 *bp, int c) {
int4 a = *ap;
int4 b = *bp;
// CHECK: add <4 x i32>
// CHECK: sub <4 x i32>
// CHECK: mul <4 x i32>
// CHECK: sdiv <4 x i32>
// CHECK: srem <4 x i32>
a = a + b;
a = a - b;
a = a * b;
a = a / b;
a = a % b;
// CHECK: add <4 x i32>
// CHECK: sub <4 x i32>
// CHECK: mul <4 x i32>
// CHECK: sdiv <4 x i32>
// CHECK: srem <4 x i32>
a = a + c;
a = a - c;
a = a * c;
a = a / c;
a = a % c;
// CHECK: add <4 x i32>
// CHECK: sub <4 x i32>
// CHECK: mul <4 x i32>
// CHECK: sdiv <4 x i32>
// CHECK: srem <4 x i32>
a += b;
a -= b;
a *= b;
a /= b;
a %= b;
// CHECK: add <4 x i32>
// CHECK: sub <4 x i32>
// CHECK: mul <4 x i32>
// CHECK: sdiv <4 x i32>
// CHECK: srem <4 x i32>
a += c;
a -= c;
a *= c;
a /= c;
a %= c;
// Vector comparisons.
// CHECK: icmp slt
// CHECK: icmp sle
// CHECK: icmp sgt
// CHECK: icmp sge
// CHECK: icmp eq
// CHECK: icmp ne
int4 cmp;
cmp = a < b;
cmp = a <= b;
cmp = a > b;
cmp = a >= b;
cmp = a == b;
cmp = a != b;
}
// CHECK: @test8
void test8(float4 *ap, float4 *bp, int c) {
float4 a = *ap;
float4 b = *bp;
// Vector comparisons.
// CHECK: fcmp olt
// CHECK: fcmp ole
// CHECK: fcmp ogt
// CHECK: fcmp oge
// CHECK: fcmp oeq
// CHECK: fcmp une
int4 cmp;
cmp = a < b;
cmp = a <= b;
cmp = a > b;
cmp = a >= b;
cmp = a == b;
cmp = a != b;
}
// CHECK: @test9
// CHECK: extractelement <4 x i32>
int test9(int4 V) {
return V.xy.x;
}
// CHECK: @test10
// CHECK: add <4 x i32>
// CHECK: extractelement <4 x i32>
int test10(int4 V) {
return (V+V).x;
}
// CHECK: @test11
// CHECK: extractelement <4 x i32>
int4 test11a();
int test11() {
return test11a().x;
}
// CHECK: @test12
// CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0>
// CHECK: shufflevector {{.*}} <i32 0, i32 1, i32 2, i32 undef>
// CHECK: shufflevector {{.*}} <i32 4, i32 5, i32 6, i32 3>
int4 test12(int4 V) {
V.xyz = V.zyx;
return V;
}
// CHECK: @test13
// CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0, i32 3>
int4 test13(int4 *V) {
return V->zyxw;
}
// CHECK: @test14
void test14(uint4 *ap, uint4 *bp, unsigned c) {
uint4 a = *ap;
uint4 b = *bp;
int4 d;
// CHECK: udiv <4 x i32>
// CHECK: urem <4 x i32>
a = a / b;
a = a % b;
// CHECK: udiv <4 x i32>
// CHECK: urem <4 x i32>
a = a / c;
a = a % c;
// CHECK: icmp ult
// CHECK: icmp ule
// CHECK: icmp ugt
// CHECK: icmp uge
// CHECK: icmp eq
// CHECK: icmp ne
d = a < b;
d = a <= b;
d = a > b;
d = a >= b;
d = a == b;
d = a != b;
}
// CHECK: @test15
int4 test15(uint4 V0) {
// CHECK: icmp eq <4 x i32>
int4 V = !V0;
V = V && V;
V = V || V;
return V;
}
// CHECK: @test16
void test16(float2 a, float2 b) {
float2 t0 = (a + b) / 2;
}
typedef char char16 __attribute__((ext_vector_type(16)));
// CHECK: @test17
void test17(void) {
char16 valA;
char valB;
char valC;
char16 destVal = valC ? valA : valB;
}
typedef __attribute__(( ext_vector_type(16) )) float float16;
float16 vec16, vec16_2;
// CHECK: @test_rgba
void test_rgba() {
// CHECK: fadd <4 x float>
vec4_2 = vec4.abgr + vec4;
// CHECK: shufflevector {{.*}} <i32 0, i32 1>
vec2 = vec4.rg;
// CHECK: shufflevector {{.*}} <i32 2, i32 3>
vec2_2 = vec4.ba;
// CHECK: extractelement {{.*}} 2
f = vec4.b;
// CHECK: shufflevector {{.*}} <i32 2, i32 2, i32 2, i32 2>
vec4_2 = vec4_2.bbbb;
// CHECK: insertelement {{.*}} 0
vec2.r = f;
// CHECK: shufflevector {{.*}} <i32 1, i32 0>
vec2.gr = vec2;
// CHECK: extractelement {{.*}} 0
f = vec4_2.rg.r;
// CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0>
// CHECK: shufflevector {{.*}} <i32 0, i32 1, i32 2, i32 undef>
// CHECK: shufflevector {{.*}} <i32 4, i32 5, i32 6, i32 3>
vec4.rgb = vec4.bgr;
// CHECK: extractelement {{.*}} 11
// CHECK: insertelement {{.*}} 2
vec4.b = vec16.sb;
// CHECK: shufflevector {{.*}} <i32 10, i32 11, i32 12, i32 13>
vec4_2 = vec16.sabcd;
}