Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify %s |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2 | |
| 3 | __vector char vv_c; |
| 4 | __vector signed char vv_sc; |
| 5 | __vector unsigned char vv_uc; |
| 6 | __vector short vv_s; |
| 7 | __vector signed short vv_ss; |
| 8 | __vector unsigned short vv_us; |
| 9 | __vector short int vv_si; |
| 10 | __vector signed short int vv_ssi; |
| 11 | __vector unsigned short int vv_usi; |
| 12 | __vector int vv_i; |
| 13 | __vector signed int vv_sint; |
| 14 | __vector unsigned int vv_ui; |
| 15 | __vector float vv_f; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 16 | __vector bool char vv_bc; |
| 17 | __vector bool short vv_bs; |
| 18 | __vector bool int vv_bi; |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 19 | __vector __pixel vv_p; |
| 20 | __vector pixel vv__p; |
| 21 | __vector int vf__r(); |
| 22 | void vf__a(__vector int a); |
| 23 | void vf__a2(int b, __vector int a); |
| 24 | |
| 25 | vector char v_c; |
| 26 | vector signed char v_sc; |
| 27 | vector unsigned char v_uc; |
| 28 | vector short v_s; |
| 29 | vector signed short v_ss; |
| 30 | vector unsigned short v_us; |
| 31 | vector short int v_si; |
| 32 | vector signed short int v_ssi; |
| 33 | vector unsigned short int v_usi; |
| 34 | vector int v_i; |
| 35 | vector signed int v_sint; |
| 36 | vector unsigned int v_ui; |
| 37 | vector float v_f; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 38 | vector bool char v_bc; |
| 39 | vector bool short v_bs; |
| 40 | vector bool int v_bi; |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 41 | vector __pixel v_p; |
| 42 | vector pixel v__p; |
| 43 | vector int f__r(); |
| 44 | void f_a(vector int a); |
| 45 | void f_a2(int b, vector int a); |
| 46 | |
Chris Lattner | e12a779 | 2010-04-20 05:19:10 +0000 | [diff] [blame] | 47 | vector int v = (vector int)(-1); |
| 48 | |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 49 | // These should have warnings. |
Chris Lattner | ffaf4c5 | 2010-03-07 18:50:21 +0000 | [diff] [blame] | 50 | __vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 51 | __vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 52 | __vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 53 | __vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 54 | __vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 55 | __vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 56 | vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 57 | vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 58 | vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 59 | vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 60 | vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 61 | vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} |
| 62 | __vector long double vv_ld; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} |
| 63 | vector long double v_ld; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 64 | |
| 65 | // These should have errors. |
Chris Lattner | ffaf4c5 | 2010-03-07 18:50:21 +0000 | [diff] [blame] | 66 | __vector double vv_d1; // expected-error {{cannot use 'double' with '__vector'}} |
| 67 | vector double v_d2; // expected-error {{cannot use 'double' with '__vector'}} |
| 68 | __vector long double vv_ld3; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} |
| 69 | vector long double v_ld4; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 70 | vector bool v_b; // expected-error {{error: C++ requires a type specifier for all declarations}} |
| 71 | vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}} |
| 72 | vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}} |
| 73 | vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}} |
| 74 | vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}} |
| 75 | vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}} |
| 76 | vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}} |
| 77 | vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}} |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 78 | |
| 79 | void f() { |
| 80 | __vector unsigned int v = {0,0,0,0}; |
| 81 | __vector int v__cast = (__vector int)v; |
| 82 | __vector int v_cast = (vector int)v; |
| 83 | __vector char vb_cast = (vector char)v; |
| 84 | |
| 85 | // Check some casting between gcc and altivec vectors. |
| 86 | #define gccvector __attribute__((vector_size(16))) |
| 87 | gccvector unsigned int gccv = {0,0,0,0}; |
| 88 | gccvector unsigned int gccv1 = gccv; |
| 89 | gccvector int gccv2 = (gccvector int)gccv; |
| 90 | gccvector unsigned int gccv3 = v; |
| 91 | __vector unsigned int av = gccv; |
| 92 | __vector int avi = (__vector int)gccv; |
| 93 | gccvector unsigned int gv = v; |
| 94 | gccvector int gvi = (gccvector int)v; |
| 95 | __attribute__((vector_size(8))) unsigned int gv8; |
Douglas Gregor | d4eea83 | 2010-04-09 00:35:39 +0000 | [diff] [blame] | 96 | gv8 = gccv; // expected-error {{assigning to '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' from incompatible type '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int'}} |
| 97 | av = gv8; // expected-error {{assigning to '__vector unsigned int' from incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int'}} |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 98 | |
| 99 | v = gccv; |
| 100 | __vector unsigned int tv = gccv; |
| 101 | gccv = v; |
| 102 | gccvector unsigned int tgv = v; |
| 103 | } |
| 104 | |
| 105 | // Now for the C++ version: |
| 106 | |
| 107 | class vc__v { |
| 108 | __vector int v; |
| 109 | __vector int f__r(); |
| 110 | void f__a(__vector int a); |
| 111 | void f__a2(int b, __vector int a); |
| 112 | }; |
| 113 | |
| 114 | class c_v { |
| 115 | vector int v; |
| 116 | vector int f__r(); |
| 117 | void f__a(vector int a); |
| 118 | void f__a2(int b, vector int a); |
| 119 | }; |
| 120 | |
John Thompson | 8bb59a8 | 2010-06-30 22:55:51 +0000 | [diff] [blame] | 121 | |
| 122 | // bug 6895 - Vectorl literal casting confusion. |
| 123 | vector char v1 = (vector char)((vector int)(1, 2, 3, 4)); |
| 124 | vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f)); |
| 125 | vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd')); |
| 126 | vector int v4 = (vector int)(1, 2, 3, 4); |
| 127 | vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); |
| 128 | vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); |
John Thompson | 35cc962 | 2010-08-09 21:53:52 +0000 | [diff] [blame^] | 129 | |
| 130 | #if 0 // Not ready yet. |
| 131 | // bug 7553 - Problem with '==' and vectors |
| 132 | void func() { |
| 133 | vector int v10i = (vector int)(1, 2, 3, 4); |
| 134 | vector int v11i = (vector int)(1, 2, 3, 4); |
| 135 | bool r10ieq = (v10i == v11i); |
| 136 | bool r10ine = (v10i != v11i); |
| 137 | bool r10igt = (v10i > v11i); |
| 138 | bool r10ige = (v10i >= v11i); |
| 139 | bool r10ilt = (v10i < v11i); |
| 140 | bool r10ile = (v10i <= v11i); |
| 141 | vector float v10f = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); |
| 142 | vector float v11f = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); |
| 143 | bool r10feq = (v10f == v11f); |
| 144 | bool r10fne = (v10f != v11f); |
| 145 | bool r10fgt = (v10f > v11f); |
| 146 | bool r10fge = (v10f >= v11f); |
| 147 | bool r10flt = (v10f < v11f); |
| 148 | bool r10fle = (v10f <= v11f); |
| 149 | } |
| 150 | #endif |
| 151 | |
| 152 | // vecreturn attribute test |
| 153 | struct Vector |
| 154 | { |
| 155 | __vector float xyzw; |
| 156 | } __attribute__((vecreturn)); |
| 157 | |
| 158 | Vector Add(Vector lhs, Vector rhs) |
| 159 | { |
| 160 | Vector result; |
| 161 | result.xyzw = vec_add(lhs.xyzw, rhs.xyzw); |
| 162 | return result; // This will (eventually) be returned in a register |
| 163 | } |