blob: 6a246db63515ddc20e811a4bb756d23ad58131aa [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -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
Chris Lattnerd013aa12009-03-31 07:46:52 +000077 // Vector comparisons can sometimes crash the x86 backend: rdar://6326239,
78 // reject them until the implementation is stable.
79#if 0
Daniel Dunbar523aa602009-01-05 22:55:36 +000080 int4 cmp;
Daniel Dunbar523aa602009-01-05 22:55:36 +000081 cmp = a < b;
82 cmp = a <= b;
83 cmp = a < b;
84 cmp = a >= b;
85 cmp = a == b;
86 cmp = a != b;
Chris Lattnerd013aa12009-03-31 07:46:52 +000087#endif
Daniel Dunbar523aa602009-01-05 22:55:36 +000088}
89
90void test7(int4 *ap, int4 *bp, int c) {
91 int4 a = *ap;
92 int4 b = *bp;
93
94 a = a + b;
95 a = a - b;
96 a = a * b;
97 a = a / b;
98 a = a % b;
99
100 a = a + c;
101 a = a - c;
102 a = a * c;
103 a = a / c;
104 a = a % c;
105
106 a += b;
107 a -= b;
108 a *= b;
109 a /= b;
110 a %= b;
111
112 a += c;
113 a -= c;
114 a *= c;
115 a /= c;
116 a %= c;
117
Chris Lattner9c10fcf2009-07-08 01:08:03 +0000118 // Vector comparisons.
Daniel Dunbar523aa602009-01-05 22:55:36 +0000119 int4 cmp;
Daniel Dunbar523aa602009-01-05 22:55:36 +0000120 cmp = a < b;
121 cmp = a <= b;
122 cmp = a < b;
123 cmp = a >= b;
124 cmp = a == b;
125 cmp = a != b;
126}
Eli Friedman1360d4a2009-07-22 06:07:16 +0000127
128void test8(float4 *ap, float4 *bp, int c) {
129 float4 a = *ap;
130 float4 b = *bp;
131
132 // Vector comparisons.
133 int4 cmp;
134 cmp = a < b;
135 cmp = a <= b;
136 cmp = a < b;
137 cmp = a >= b;
138 cmp = a == b;
139 cmp = a != b;
140}