altivec.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify %s
  2. // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify %s
  3. // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -fsyntax-only -verify %s
  4. __vector char vv_c;
  5. __vector signed char vv_sc;
  6. __vector unsigned char vv_uc;
  7. __vector short vv_s;
  8. __vector signed short vv_ss;
  9. __vector unsigned short vv_us;
  10. __vector short int vv_si;
  11. __vector signed short int vv_ssi;
  12. __vector unsigned short int vv_usi;
  13. __vector int vv_i;
  14. __vector signed int vv_sint;
  15. __vector unsigned int vv_ui;
  16. __vector float vv_f;
  17. __vector bool char vv_bc;
  18. __vector bool short vv_bs;
  19. __vector bool int vv_bi;
  20. __vector __bool char vv___bc;
  21. __vector __bool short vv___bs;
  22. __vector __bool int vv___bi;
  23. __vector __pixel vv_p;
  24. __vector pixel vv__p;
  25. __vector int vf__r();
  26. void vf__a(__vector int a);
  27. void vf__a2(int b, __vector int a);
  28. vector char v_c;
  29. vector signed char v_sc;
  30. vector unsigned char v_uc;
  31. vector short v_s;
  32. vector signed short v_ss;
  33. vector unsigned short v_us;
  34. vector short int v_si;
  35. vector signed short int v_ssi;
  36. vector unsigned short int v_usi;
  37. vector int v_i;
  38. vector signed int v_sint;
  39. vector unsigned int v_ui;
  40. vector float v_f;
  41. vector bool char v_bc;
  42. vector bool short v_bs;
  43. vector bool int v_bi;
  44. vector __bool char v___bc;
  45. vector __bool short v___bs;
  46. vector __bool int v___bi;
  47. vector __pixel v_p;
  48. vector pixel v__p;
  49. vector int f__r();
  50. void f_a(vector int a);
  51. void f_a2(int b, vector int a);
  52. vector int v = (vector int)(-1);
  53. // These should have warnings.
  54. __vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  55. __vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  56. __vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  57. __vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  58. __vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  59. __vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  60. vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  61. vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  62. vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  63. vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  64. vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  65. vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  66. __vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}}
  67. vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}}
  68. vector bool v_b; // expected-warning {{type specifier missing, defaults to 'int'}}
  69. vector __bool v___b; // expected-warning {{type specifier missing, defaults to 'int'}}
  70. // These should have errors.
  71. __vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
  72. vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
  73. __vector bool long long v_bll1; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
  74. __vector __bool long long v_bll2; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
  75. vector bool long long v_bll3; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
  76. vector __bool long long v_bll4; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
  77. __vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
  78. vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
  79. vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}}
  80. vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}}
  81. vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
  82. vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
  83. vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
  84. vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
  85. vector __bool float v___bf; // expected-error {{cannot use 'float' with '__vector bool'}}
  86. vector __bool double v___bd; // expected-error {{cannot use 'double' with '__vector bool'}}
  87. vector __bool pixel v___bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
  88. vector __bool signed char v___bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
  89. vector __bool unsigned int v___bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
  90. vector __bool long v___bl; // expected-error {{cannot use 'long' with '__vector bool'}}
  91. // vector long is deprecated, but vector long long is not.
  92. vector long long v_ll;
  93. vector signed long long v_sll;
  94. vector unsigned long long v_ull;
  95. typedef char i8;
  96. typedef short i16;
  97. typedef int i32;
  98. struct S {
  99. // i8, i16, i32 here are field names, not type names.
  100. vector bool i8; // expected-error {{requires a specifier or qualifier}}
  101. vector pixel i16;
  102. vector long i32; // expected-warning {{deprecated}}
  103. };
  104. void f() {
  105. __vector unsigned int v = {0,0,0,0};
  106. __vector int v__cast = (__vector int)v;
  107. __vector int v_cast = (vector int)v;
  108. __vector char vb_cast = (vector char)v;
  109. // Check some casting between gcc and altivec vectors.
  110. #define gccvector __attribute__((vector_size(16)))
  111. gccvector unsigned int gccv = {0,0,0,0};
  112. gccvector unsigned int gccv1 = gccv;
  113. gccvector int gccv2 = (gccvector int)gccv;
  114. gccvector unsigned int gccv3 = v;
  115. __vector unsigned int av = gccv;
  116. __vector int avi = (__vector int)gccv;
  117. gccvector unsigned int gv = v;
  118. gccvector int gvi = (gccvector int)v;
  119. __attribute__((vector_size(8))) unsigned int gv8;
  120. gv8 = gccv; // expected-error {{assigning to '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int' (vector of 4 'unsigned int' values)}}
  121. av = gv8; // expected-error {{assigning to '__vector unsigned int' (vector of 4 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values)}}
  122. v = gccv;
  123. __vector unsigned int tv = gccv;
  124. gccv = v;
  125. gccvector unsigned int tgv = v;
  126. int res_i;
  127. // bug 7553 - Problem with '==' and vectors
  128. res_i = (vv_sc == vv_sc);
  129. res_i = (vv_uc != vv_uc);
  130. res_i = (vv_s > vv_s);
  131. res_i = (vv_us >= vv_us);
  132. res_i = (vv_i < vv_i);
  133. res_i = (vv_ui <= vv_ui);
  134. res_i = (vv_f <= vv_f);
  135. }
  136. // bug 6895 - Vectorl literal casting confusion.
  137. vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
  138. vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
  139. vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
  140. vector int v4 = (vector int)(1, 2, 3, 4);
  141. vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
  142. vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));