Daniel Dunbar | 2d6ca8d | 2008-08-21 02:51:29 +0000 | [diff] [blame] | 1 | // RUN: clang -emit-llvm %s -o %t |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 2 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 3 | typedef __attribute__(( ext_vector_type(4) )) float float4; |
| 4 | typedef __attribute__(( ext_vector_type(2) )) float float2; |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 5 | typedef __attribute__(( ext_vector_type(4) )) int int4; |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 6 | |
Nate Begeman | d47d4f5 | 2008-01-25 05:34:48 +0000 | [diff] [blame] | 7 | float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 }; |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 8 | |
Nate Begeman | 59b5da6 | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 9 | const float4 bar = (float4){ 1.0, 2.0, 3.0, __builtin_inff() }; |
| 10 | |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 11 | float4 test1(float4 V) { |
| 12 | return V.wzyx+V; |
| 13 | } |
| 14 | |
| 15 | float2 vec2, vec2_2; |
| 16 | float4 vec4, vec4_2; |
| 17 | float f; |
| 18 | |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 19 | void test2() { |
Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 20 | vec2 = vec4.xy; // shorten |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 21 | 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 Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 28 | void test3(float4 *out) { |
Devang Patel | a83cc33 | 2007-10-24 18:05:48 +0000 | [diff] [blame] | 29 | *out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f }); |
| 30 | } |
| 31 | |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 32 | void test4(float4 *out) { |
Devang Patel | a83cc33 | 2007-10-24 18:05:48 +0000 | [diff] [blame] | 33 | 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 Begeman | 4119d1a | 2007-12-30 02:59:45 +0000 | [diff] [blame] | 39 | |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 40 | void test5(float4 *out) { |
Nate Begeman | 4119d1a | 2007-12-30 02:59:45 +0000 | [diff] [blame] | 41 | 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 Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 52 | |
| 53 | void 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 | |
| 87 | void 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 | } |