|
| 1 | +// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only %s |
| 2 | +// expected-no-diagnostics |
| 3 | + |
| 4 | +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 5 | +#define LITTLE_END 1 |
| 6 | +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 7 | +#define LITTLE_END 0 |
| 8 | +#else |
| 9 | +#error "huh?" |
| 10 | +#endif |
| 11 | + |
| 12 | +typedef double vector4double __attribute__((__vector_size__(32))); |
| 13 | +typedef float vector4float __attribute__((__vector_size__(16))); |
| 14 | +typedef long long vector4long __attribute__((__vector_size__(32))); |
| 15 | +typedef int vector4int __attribute__((__vector_size__(16))); |
| 16 | +typedef short vector4short __attribute__((__vector_size__(8))); |
| 17 | +typedef char vector4char __attribute__((__vector_size__(4))); |
| 18 | +typedef double vector8double __attribute__((__vector_size__(64))); |
| 19 | +typedef float vector8float __attribute__((__vector_size__(32))); |
| 20 | +typedef long long vector8long __attribute__((__vector_size__(64))); |
| 21 | +typedef int vector8int __attribute__((__vector_size__(32))); |
| 22 | +typedef short vector8short __attribute__((__vector_size__(16))); |
| 23 | +typedef char vector8char __attribute__((__vector_size__(8))); |
| 24 | + |
| 25 | +#define CHECK_NUM(__size, __typeFrom, __typeTo, ...) \ |
| 26 | + constexpr vector##__size##__typeTo \ |
| 27 | + from_##vector##__size##__typeFrom##_to_##vector##__size##__typeTo##_var = \ |
| 28 | + __builtin_convertvector((vector##__size##__typeFrom){__VA_ARGS__}, \ |
| 29 | + vector##__size##__typeTo); |
| 30 | +#define CHECK_TO_ALL_TYPES(__size, __typeFrom, ...) \ |
| 31 | + CHECK_NUM(__size, __typeFrom, double, __VA_ARGS__) \ |
| 32 | + CHECK_NUM(__size, __typeFrom, float, __VA_ARGS__) \ |
| 33 | + CHECK_NUM(__size, __typeFrom, long, __VA_ARGS__) \ |
| 34 | + CHECK_NUM(__size, __typeFrom, int, __VA_ARGS__) \ |
| 35 | + CHECK_NUM(__size, __typeFrom, short, __VA_ARGS__) \ |
| 36 | + CHECK_NUM(__size, __typeFrom, char, __VA_ARGS__) \ |
| 37 | + static_assert( \ |
| 38 | + __builtin_bit_cast( \ |
| 39 | + unsigned, \ |
| 40 | + __builtin_shufflevector( \ |
| 41 | + from_vector##__size##__typeFrom##_to_vector##__size##char_var, \ |
| 42 | + from_vector##__size##__typeFrom##_to_vector##__size##char_var, \ |
| 43 | + 0, 1, 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203)); \ |
| 44 | + static_assert( \ |
| 45 | + __builtin_bit_cast( \ |
| 46 | + unsigned long long, \ |
| 47 | + __builtin_shufflevector( \ |
| 48 | + from_vector##__size##__typeFrom##_to_vector##__size##short_var, \ |
| 49 | + from_vector##__size##__typeFrom##_to_vector##__size##short_var, \ |
| 50 | + 0, 1, 2, 3)) == \ |
| 51 | + (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003)); |
| 52 | + |
| 53 | +#define CHECK_ALL_COMBINATIONS(__size, ...) \ |
| 54 | + CHECK_TO_ALL_TYPES(__size, double, __VA_ARGS__) \ |
| 55 | + CHECK_TO_ALL_TYPES(__size, float, __VA_ARGS__) \ |
| 56 | + CHECK_TO_ALL_TYPES(__size, long, __VA_ARGS__) \ |
| 57 | + CHECK_TO_ALL_TYPES(__size, int, __VA_ARGS__) \ |
| 58 | + CHECK_TO_ALL_TYPES(__size, short, __VA_ARGS__) \ |
| 59 | + CHECK_TO_ALL_TYPES(__size, char, __VA_ARGS__) |
| 60 | + |
| 61 | +CHECK_ALL_COMBINATIONS(4, 0, 1, 2, 3); |
| 62 | +CHECK_ALL_COMBINATIONS(8, 0, 1, 2, 3, 4, 5, 6, 7); |
| 63 | +#undef CHECK_ALL_COMBINATIONS |
| 64 | +#undef CHECK_TO_ALL_TYPES |
| 65 | +#undef CHECK_NUM |
| 66 | + |
| 67 | +// Shuffle vector |
| 68 | +constexpr vector4char vector4charConst1 = {0, 1, 2, 3}; |
| 69 | +constexpr vector4char vector4charConst2 = {4, 5, 6, 7}; |
| 70 | +constexpr vector8char vector8intConst = {8, 9, 10, 11, 12, 13, 14, 15}; |
| 71 | + |
| 72 | +constexpr vector4char vectorShuffle1 = |
| 73 | + __builtin_shufflevector(vector4charConst1, vector4charConst2, 0, 1, 2, 3); |
| 74 | +static_assert(__builtin_bit_cast(unsigned, vectorShuffle1) == |
| 75 | + (LITTLE_END ? 0x03020100 : 0x00010203)); |
| 76 | +constexpr vector4char vectorShuffle2 = |
| 77 | + __builtin_shufflevector(vector4charConst1, vector4charConst2, 4, 5, 6, 7); |
| 78 | +static_assert(__builtin_bit_cast(unsigned, vectorShuffle2) == |
| 79 | + (LITTLE_END ? 0x07060504 : 0x04050607)); |
| 80 | +constexpr vector4char vectorShuffle3 = __builtin_shufflevector( |
| 81 | + vector4charConst1, vector4charConst2, -1, -1, -1, -1); |
| 82 | +static_assert(__builtin_bit_cast(unsigned, vectorShuffle3) == |
| 83 | + (LITTLE_END ? 0x00000000 : 0x00000000)); |
| 84 | +constexpr vector4char vectorShuffle4 = |
| 85 | + __builtin_shufflevector(vector4charConst1, vector4charConst2, 0, 2, 4, 6); |
| 86 | +static_assert(__builtin_bit_cast(unsigned, vectorShuffle4) == |
| 87 | + (LITTLE_END ? 0x06040200 : 0x00020406)); |
| 88 | +constexpr vector8char vectorShuffle5 = __builtin_shufflevector( |
| 89 | + vector8intConst, vector8intConst, 0, 2, 4, 6, 8, 10, 12, 14); |
| 90 | +static_assert(__builtin_bit_cast(unsigned long long, vectorShuffle5) == |
| 91 | + (LITTLE_END ? 0x0E0C0A080E0C0A08 : 0x080A0C0E080A0C0E)); |
| 92 | +constexpr vector4char vectorShuffle6 = |
| 93 | + __builtin_shufflevector(vector8intConst, vector8intConst, 0, 2, 4, 6); |
| 94 | +static_assert(__builtin_bit_cast(unsigned, vectorShuffle6) == |
| 95 | + (LITTLE_END ? 0x0E0C0A08 : 0x080A0C0E)); |
| 96 | +constexpr vector8char vectorShuffle7 = __builtin_shufflevector( |
| 97 | + vector4charConst1, vector4charConst2, 0, 2, 4, 6, 1, 3, 5, 7); |
| 98 | +static_assert(__builtin_bit_cast(unsigned long long, vectorShuffle7) == |
| 99 | + (LITTLE_END ? 0x0705030106040200 : 0x0002040601030507)); |
0 commit comments