blob: 0a57397d7cdd8f42e6f16ce5b9f1b405351bad80 [file] [log] [blame]
Daniel Dunbar2d6ca8d2008-08-21 02:51:29 +00001// RUN: clang -emit-llvm %s -o %t
Chris Lattner90997ac2007-08-03 16:42:43 +00002
Nate Begeman213541a2008-04-18 23:10:10 +00003typedef __attribute__(( ext_vector_type(4) )) float float4;
4typedef __attribute__(( ext_vector_type(2) )) float float2;
Daniel Dunbar523aa602009-01-05 22:55:36 +00005typedef __attribute__(( ext_vector_type(4) )) int int4;
Chris Lattner90997ac2007-08-03 16:42:43 +00006
Nate Begemand47d4f52008-01-25 05:34:48 +00007float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
Chris Lattner90997ac2007-08-03 16:42:43 +00008
Nate Begeman59b5da62009-01-18 03:20:47 +00009const float4 bar = (float4){ 1.0, 2.0, 3.0, __builtin_inff() };
10
Chris Lattner90997ac2007-08-03 16:42:43 +000011float4 test1(float4 V) {
12 return V.wzyx+V;
13}
14
15float2 vec2, vec2_2;
16float4 vec4, vec4_2;
17float f;
18
Daniel Dunbar523aa602009-01-05 22:55:36 +000019void test2() {
Nate Begeman190d6a22009-01-18 02:01:21 +000020 vec2 = vec4.xy; // shorten
Chris Lattner90997ac2007-08-03 16:42:43 +000021 f = vec2.x; // extract elt
22 vec4 = vec4.yyyy; // splat
23
24 vec2.x = f; // insert one.
25 vec2.yx = vec2; // reverse
26}
27
Daniel Dunbar523aa602009-01-05 22:55:36 +000028void test3(float4 *out) {
Devang Patela83cc332007-10-24 18:05:48 +000029 *out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f });
30}
31
Daniel Dunbar523aa602009-01-05 22:55:36 +000032void test4(float4 *out) {
Devang Patela83cc332007-10-24 18:05:48 +000033 float a = 1.0f;
34 float b = 2.0f;
35 float c = 3.0f;
36 float d = 4.0f;
37 *out = ((float4) {a,b,c,d});
38}
Nate Begeman4119d1a2007-12-30 02:59:45 +000039
Daniel Dunbar523aa602009-01-05 22:55:36 +000040void test5(float4 *out) {
Nate Begeman4119d1a2007-12-30 02:59:45 +000041 float a;
42 float4 b;
43
44 a = 1.0f;
45 b = a;
46 b = b * 5.0f;
47 b = 5.0f * b;
48 b *= a;
49
50 *out = b;
51}
Daniel Dunbar523aa602009-01-05 22:55:36 +000052
53void test6(float4 *ap, float4 *bp, float c) {
54 float4 a = *ap;
55 float4 b = *bp;
56
57 a = a + b;
58 a = a - b;
59 a = a * b;
60 a = a / b;
61
62 a = a + c;
63 a = a - c;
64 a = a * c;
65 a = a / c;
66
67 a += b;
68 a -= b;
69 a *= b;
70 a /= b;
71
72 a += c;
73 a -= c;
74 a *= c;
75 a /= c;
76
77 int4 cmp;
78
79 cmp = a < b;
80 cmp = a <= b;
81 cmp = a < b;
82 cmp = a >= b;
83 cmp = a == b;
84 cmp = a != b;
85}
86
87void test7(int4 *ap, int4 *bp, int c) {
88 int4 a = *ap;
89 int4 b = *bp;
90
91 a = a + b;
92 a = a - b;
93 a = a * b;
94 a = a / b;
95 a = a % b;
96
97 a = a + c;
98 a = a - c;
99 a = a * c;
100 a = a / c;
101 a = a % c;
102
103 a += b;
104 a -= b;
105 a *= b;
106 a /= b;
107 a %= b;
108
109 a += c;
110 a -= c;
111 a *= c;
112 a /= c;
113 a %= c;
114
115 int4 cmp;
116
117 cmp = a < b;
118 cmp = a <= b;
119 cmp = a < b;
120 cmp = a >= b;
121 cmp = a == b;
122 cmp = a != b;
123}