|
| 1 | +// RUN: %clang_cc1 %s -triple x86_64-linux-gnu -std=c++14 -fsyntax-only -verify |
| 2 | +// RUN: %clang_cc1 %s -triple x86_64-linux-gnu -fexperimental-new-constant-interpreter -std=c++14 -fsyntax-only -verify |
| 3 | + |
| 4 | +using FourCharsVecSize __attribute__((vector_size(4))) = char; |
| 5 | +using FourIntsVecSize __attribute__((vector_size(16))) = int; |
| 6 | +using FourLongLongsVecSize __attribute__((vector_size(32))) = long long; |
| 7 | +using FourFloatsVecSize __attribute__((vector_size(16))) = float; |
| 8 | +using FourDoublesVecSize __attribute__((vector_size(32))) = double; |
| 9 | +using FourI128VecSize __attribute__((vector_size(64))) = __int128; |
| 10 | + |
| 11 | +using FourCharsExtVec __attribute__((ext_vector_type(4))) = char; |
| 12 | +using FourIntsExtVec __attribute__((ext_vector_type(4))) = int; |
| 13 | +using FourI128ExtVec __attribute__((ext_vector_type(4))) = __int128; |
| 14 | + |
| 15 | +// Only int vs float makes a difference here, so we only need to test 1 of each. |
| 16 | +// Test Char to make sure the mixed-nature of shifts around char is evident. |
| 17 | +void CharUsage() { |
| 18 | + constexpr auto H = FourCharsVecSize{-1, -1, 0, -1}; |
| 19 | + constexpr auto InvH = -H; |
| 20 | + static_assert(InvH[0] == 1 && InvH[1] == 1 && InvH[2] == 0 && InvH[3] == 1, ""); |
| 21 | + |
| 22 | + constexpr auto ae = ~FourCharsVecSize{1, 2, 10, 20}; |
| 23 | + static_assert(ae[0] == -2 && ae[1] == -3 && ae[2] == -11 && ae[3] == -21, ""); |
| 24 | + |
| 25 | + constexpr auto af = !FourCharsVecSize{0, 1, 8, -1}; |
| 26 | + static_assert(af[0] == -1 && af[1] == 0 && af[2] == 0 && af[3] == 0, ""); |
| 27 | +} |
| 28 | + |
| 29 | +void CharExtVecUsage() { |
| 30 | + constexpr auto H = FourCharsExtVec{-1, -1, 0, -1}; |
| 31 | + constexpr auto InvH = -H; |
| 32 | + static_assert(InvH[0] == 1 && InvH[1] == 1 && InvH[2] == 0 && InvH[3] == 1, ""); |
| 33 | + |
| 34 | + constexpr auto ae = ~FourCharsExtVec{1, 2, 10, 20}; |
| 35 | + static_assert(ae[0] == -2 && ae[1] == -3 && ae[2] == -11 && ae[3] == -21, ""); |
| 36 | + |
| 37 | + constexpr auto af = !FourCharsExtVec{0, 1, 8, -1}; |
| 38 | + static_assert(af[0] == -1 && af[1] == 0 && af[2] == 0 && af[3] == 0, ""); |
| 39 | +} |
| 40 | + |
| 41 | +void FloatUsage() { |
| 42 | + constexpr auto Y = FourFloatsVecSize{1.200000e+01, 1.700000e+01, -1.000000e+00, -1.000000e+00}; |
| 43 | + constexpr auto Z = -Y; |
| 44 | + static_assert(Z[0] == -1.200000e+01 && Z[1] == -1.700000e+01 && Z[2] == 1.000000e+00 && Z[3] == 1.000000e+00, ""); |
| 45 | + |
| 46 | + // Operator ~ is illegal on floats. |
| 47 | + constexpr auto ae = ~FourFloatsVecSize{0, 1, 8, -1}; // expected-error {{invalid argument type}} |
| 48 | + |
| 49 | + constexpr auto af = !FourFloatsVecSize{0, 1, 8, -1}; |
| 50 | + static_assert(af[0] == -1 && af[1] == 0 && af[2] == 0 && af[3] == 0, ""); |
| 51 | +} |
| 52 | + |
| 53 | +void FloatVecUsage() { |
| 54 | + constexpr auto Y = FourFloatsVecSize{1.200000e+01, 1.700000e+01, -1.000000e+00, -1.000000e+00}; |
| 55 | + constexpr auto Z = -Y; |
| 56 | + static_assert(Z[0] == -1.200000e+01 && Z[1] == -1.700000e+01 && Z[2] == 1.000000e+00 && Z[3] == 1.000000e+00, ""); |
| 57 | + |
| 58 | + // Operator ~ is illegal on floats. |
| 59 | + constexpr auto ae = ~FourFloatsVecSize{0, 1, 8, -1}; // expected-error {{invalid argument type}} |
| 60 | + |
| 61 | + constexpr auto af = !FourFloatsVecSize{0, 1, 8, -1}; |
| 62 | + static_assert(af[0] == -1 && af[1] == 0 && af[2] == 0 && af[3] == 0, ""); |
| 63 | +} |
| 64 | + |
| 65 | +void I128Usage() { |
| 66 | + // Operator ~ is illegal on floats, so no test for that. |
| 67 | + constexpr auto c = ~FourI128VecSize{1, 2, 10, 20}; |
| 68 | + static_assert(c[0] == -2 && c[1] == -3 && c[2] == -11 && c[3] == -21, ""); |
| 69 | + |
| 70 | + constexpr auto d = !FourI128VecSize{0, 1, 8, -1}; |
| 71 | + static_assert(d[0] == -1 && d[1] == 0 && d[2] == 0 && d[3] == 0, ""); |
| 72 | +} |
| 73 | + |
| 74 | +void I128VecUsage() { |
| 75 | + // Operator ~ is illegal on floats, so no test for that. |
| 76 | + constexpr auto c = ~FourI128ExtVec{1, 2, 10, 20}; |
| 77 | + static_assert(c[0] == -2 && c[1] == -3 && c[2] == -11 && c[3] == -21, ""); |
| 78 | + |
| 79 | + constexpr auto d = !FourI128ExtVec{0, 1, 8, -1}; |
| 80 | + static_assert(d[0] == -1 && d[1] == 0 && d[2] == 0 && d[3] == 0, ""); |
| 81 | +} |
| 82 | + |
| 83 | +using FourBoolsExtVec __attribute__((ext_vector_type(4))) = bool; |
| 84 | +void BoolVecUsage() { |
| 85 | + constexpr auto j = !FourBoolsExtVec{true, false, true, false}; |
| 86 | + static_assert(j[0] == false && j[1] == true && j[2] == false && j[3] == true, ""); |
| 87 | + |
| 88 | + constexpr auto k = ~FourBoolsExtVec{true, false, true, false}; |
| 89 | + static_assert(k[0] == false && k[1] == true && k[2] == false && k[3] == true, ""); |
| 90 | +} |
0 commit comments