brintos

brintos / llvm-project-archived public Read only

0
0
Text · 19.4 KiB · 447addb Raw
406 lines · c
1// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected,streamingdifferent -mvscale-min=1 -mvscale-max=1 %s2// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected,streamingdifferent -mvscale-min=2 -mvscale-max=2 -mvscale-streaming-min=2 %s3// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected -mvscale-min=4 -mvscale-max=4 -mvscale-streaming-min=4 -mvscale-streaming-max=4 %s4// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected,streamingdifferent -mvscale-min=8 -mvscale-max=8 -mvscale-streaming-min=4 -mvscale-streaming-max=8 %s5// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -target-feature +sme -ffreestanding -fsyntax-only -verify=expected,streamingdifferent -mvscale-min=16 -mvscale-max=16 %s6 7#include <stdint.h>8 9#define N __ARM_FEATURE_SVE_BITS10 11typedef __fp16 float16_t;12typedef float float32_t;13typedef double float64_t;14typedef __SVInt8_t svint8_t;15typedef __SVInt16_t svint16_t;16typedef __SVInt32_t svint32_t;17typedef __SVInt64_t svint64_t;18typedef __SVUint8_t svuint8_t;19typedef __SVUint16_t svuint16_t;20typedef __SVUint32_t svuint32_t;21typedef __SVUint64_t svuint64_t;22typedef __SVFloat16_t svfloat16_t;23typedef __SVFloat32_t svfloat32_t;24typedef __SVFloat64_t svfloat64_t;25 26#if defined(__ARM_FEATURE_SVE_BF16)27typedef __bf16 bfloat16_t;28typedef __SVBfloat16_t svbfloat16_t;29#endif30 31typedef __SVBool_t svbool_t;32 33// Define valid fixed-width SVE types34typedef svint8_t fixed_int8_t __attribute__((arm_sve_vector_bits(N)));35typedef svint16_t fixed_int16_t __attribute__((arm_sve_vector_bits(N)));36typedef svint32_t fixed_int32_t __attribute__((arm_sve_vector_bits(N)));37typedef svint64_t fixed_int64_t __attribute__((arm_sve_vector_bits(N)));38 39typedef svuint8_t fixed_uint8_t __attribute__((arm_sve_vector_bits(N)));40typedef svuint16_t fixed_uint16_t __attribute__((arm_sve_vector_bits(N)));41typedef svuint32_t fixed_uint32_t __attribute__((arm_sve_vector_bits(N)));42typedef svuint64_t fixed_uint64_t __attribute__((arm_sve_vector_bits(N)));43 44typedef svfloat16_t fixed_float16_t __attribute__((arm_sve_vector_bits(N)));45typedef svfloat32_t fixed_float32_t __attribute__((arm_sve_vector_bits(N)));46typedef svfloat64_t fixed_float64_t __attribute__((arm_sve_vector_bits(N)));47 48typedef svbfloat16_t fixed_bfloat16_t __attribute__((arm_sve_vector_bits(N)));49 50typedef svbool_t fixed_bool_t __attribute__((arm_sve_vector_bits(N)));51 52// GNU vector types53typedef int8_t gnu_int8_t __attribute__((vector_size(N / 8)));54typedef int16_t gnu_int16_t __attribute__((vector_size(N / 8)));55typedef int32_t gnu_int32_t __attribute__((vector_size(N / 8)));56typedef int64_t gnu_int64_t __attribute__((vector_size(N / 8)));57 58typedef uint8_t gnu_uint8_t __attribute__((vector_size(N / 8)));59typedef uint16_t gnu_uint16_t __attribute__((vector_size(N / 8)));60typedef uint32_t gnu_uint32_t __attribute__((vector_size(N / 8)));61typedef uint64_t gnu_uint64_t __attribute__((vector_size(N / 8)));62 63typedef float16_t gnu_float16_t __attribute__((vector_size(N / 8)));64typedef float32_t gnu_float32_t __attribute__((vector_size(N / 8)));65typedef float64_t gnu_float64_t __attribute__((vector_size(N / 8)));66 67typedef bfloat16_t gnu_bfloat16_t __attribute__((vector_size(N / 8)));68 69// Attribute must have a single argument70typedef svint8_t no_argument __attribute__((arm_sve_vector_bits));         // expected-error {{'arm_sve_vector_bits' attribute takes one argument}}71typedef svint8_t two_arguments __attribute__((arm_sve_vector_bits(2, 4))); // expected-error {{'arm_sve_vector_bits' attribute takes one argument}}72 73// The number of SVE vector bits must be an integer constant expression74typedef svint8_t non_int_size1 __attribute__((arm_sve_vector_bits(2.0)));   // expected-error {{'arm_sve_vector_bits' attribute requires an integer constant}}75typedef svint8_t non_int_size2 __attribute__((arm_sve_vector_bits("256"))); // expected-error {{'arm_sve_vector_bits' attribute requires an integer constant}}76 77typedef __clang_svint8x2_t svint8x2_t;78typedef __clang_svfloat32x3_t svfloat32x3_t;79 80// Attribute must be attached to a single SVE vector or predicate type.81typedef void *badtype1 __attribute__((arm_sve_vector_bits(N)));         // expected-error {{'arm_sve_vector_bits' attribute applied to non-SVE type 'void *'}}82typedef int badtype2 __attribute__((arm_sve_vector_bits(N)));           // expected-error {{'arm_sve_vector_bits' attribute applied to non-SVE type 'int'}}83typedef float badtype3 __attribute__((arm_sve_vector_bits(N)));         // expected-error {{'arm_sve_vector_bits' attribute applied to non-SVE type 'float'}}84typedef svint8x2_t badtype4 __attribute__((arm_sve_vector_bits(N)));    // expected-error {{'arm_sve_vector_bits' attribute applied to non-SVE type 'svint8x2_t' (aka '__clang_svint8x2_t')}}85typedef svfloat32x3_t badtype5 __attribute__((arm_sve_vector_bits(N))); // expected-error {{'arm_sve_vector_bits' attribute applied to non-SVE type 'svfloat32x3_t' (aka '__clang_svfloat32x3_t')}}86 87// Attribute only applies to typedefs.88svint8_t non_typedef_type __attribute__((arm_sve_vector_bits(N)));  // expected-error {{'arm_sve_vector_bits' attribute only applies to typedefs}}89 90// Test that we can define non-local fixed-length SVE types (unsupported for91// sizeless types).92fixed_int8_t global_int8;93fixed_bfloat16_t global_bfloat16;94fixed_bool_t global_bool;95 96extern fixed_int8_t extern_int8;97extern fixed_bfloat16_t extern_bfloat16;98extern fixed_bool_t extern_bool;99 100static fixed_int8_t static_int8;101static fixed_bfloat16_t static_bfloat16;102static fixed_bool_t static_bool;103 104fixed_int8_t *global_int8_ptr;105extern fixed_int8_t *extern_int8_ptr;106static fixed_int8_t *static_int8_ptr;107__thread fixed_int8_t thread_int8;108 109typedef fixed_int8_t int8_typedef;110typedef fixed_int8_t *int8_ptr_typedef;111 112// Test sized expressions113int sizeof_int8 = sizeof(global_int8);114int sizeof_int8_var = sizeof(*global_int8_ptr);115int sizeof_int8_var_ptr = sizeof(global_int8_ptr);116 117extern fixed_int8_t *extern_int8_ptr;118 119int alignof_int8 = __alignof__(extern_int8);120int alignof_int8_var = __alignof__(*extern_int8_ptr);121int alignof_int8_var_ptr = __alignof__(extern_int8_ptr);122 123void f(int c) {124  fixed_int8_t fs8;125  svint8_t ss8;126  gnu_int8_t gs8;127 128  // Check conditional expressions where the result is ambiguous are129  // ill-formed.130  void *sel __attribute__((unused));131  sel = c ? ss8 : fs8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}132  sel = c ? fs8 : ss8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}133 134  sel = c ? gs8 : ss8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}135  sel = c ? ss8 : gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}136 137  sel = c ? gs8 : fs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}138  sel = c ? fs8 : gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}139 140  // Check binary expressions where the result is ambiguous are ill-formed.141  ss8 = ss8 + fs8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}142  ss8 = ss8 + gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}143 144  fs8 = fs8 + ss8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}145  fs8 = fs8 + gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}146 147  gs8 = gs8 + ss8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}148  gs8 = gs8 + fs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}149 150  ss8 += fs8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}151  ss8 += gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}152 153  fs8 += ss8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}154  fs8 += gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}155 156  gs8 += ss8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}157  gs8 += fs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}158 159  ss8 = ss8 == fs8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}160  ss8 = ss8 == gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}161 162  fs8 = fs8 == ss8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}163  fs8 = fs8 == gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}164 165  gs8 = gs8 == ss8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}166  gs8 = gs8 == fs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}167 168  ss8 = ss8 & fs8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}169  ss8 = ss8 & gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}170 171  fs8 = fs8 & ss8; // expected-error {{cannot combine fixed-length and sizeless SVE vectors in expression, result is ambiguous}}172  fs8 = fs8 & gs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}173 174  gs8 = gs8 & ss8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}175  gs8 = gs8 & fs8; // expected-error {{cannot combine GNU and SVE vectors in expression, result is ambiguous}}176}177 178// --------------------------------------------------------------------------//179// Sizeof180 181#define VECTOR_SIZE ((N / 8))182#define PRED_SIZE ((N / 64))183 184_Static_assert(sizeof(fixed_int8_t) == VECTOR_SIZE, "");185 186_Static_assert(sizeof(fixed_int16_t) == VECTOR_SIZE, "");187_Static_assert(sizeof(fixed_int32_t) == VECTOR_SIZE, "");188_Static_assert(sizeof(fixed_int64_t) == VECTOR_SIZE, "");189 190_Static_assert(sizeof(fixed_uint8_t) == VECTOR_SIZE, "");191_Static_assert(sizeof(fixed_uint16_t) == VECTOR_SIZE, "");192_Static_assert(sizeof(fixed_uint32_t) == VECTOR_SIZE, "");193_Static_assert(sizeof(fixed_uint64_t) == VECTOR_SIZE, "");194 195_Static_assert(sizeof(fixed_float16_t) == VECTOR_SIZE, "");196_Static_assert(sizeof(fixed_float32_t) == VECTOR_SIZE, "");197_Static_assert(sizeof(fixed_float64_t) == VECTOR_SIZE, "");198 199_Static_assert(sizeof(fixed_bfloat16_t) == VECTOR_SIZE, "");200 201_Static_assert(sizeof(fixed_bool_t) == PRED_SIZE, "");202 203// --------------------------------------------------------------------------//204// Alignof205 206#define VECTOR_ALIGN 16207#define PRED_ALIGN 2208 209_Static_assert(__alignof__(fixed_int8_t) == VECTOR_ALIGN, "");210_Static_assert(__alignof__(fixed_int16_t) == VECTOR_ALIGN, "");211_Static_assert(__alignof__(fixed_int32_t) == VECTOR_ALIGN, "");212_Static_assert(__alignof__(fixed_int64_t) == VECTOR_ALIGN, "");213 214_Static_assert(__alignof__(fixed_uint8_t) == VECTOR_ALIGN, "");215_Static_assert(__alignof__(fixed_uint16_t) == VECTOR_ALIGN, "");216_Static_assert(__alignof__(fixed_uint32_t) == VECTOR_ALIGN, "");217_Static_assert(__alignof__(fixed_uint64_t) == VECTOR_ALIGN, "");218 219_Static_assert(__alignof__(fixed_float16_t) == VECTOR_ALIGN, "");220_Static_assert(__alignof__(fixed_float32_t) == VECTOR_ALIGN, "");221_Static_assert(__alignof__(fixed_float64_t) == VECTOR_ALIGN, "");222 223_Static_assert(__alignof__(fixed_bfloat16_t) == VECTOR_ALIGN, "");224 225_Static_assert(__alignof__(fixed_bool_t) == PRED_ALIGN, "");226 227// --------------------------------------------------------------------------//228// Structs229 230struct struct_int64 { fixed_int64_t x, y[5]; };231struct struct_float64 { fixed_float64_t x, y[5]; };232struct struct_bfloat16 { fixed_bfloat16_t x, y[5]; };233struct struct_bool { fixed_bool_t x, y[5]; };234 235// --------------------------------------------------------------------------//236// Unions237union union_int64 { fixed_int64_t x, y[5]; };238union union_float64 { fixed_float64_t x, y[5]; };239union union_bfloat16 { fixed_bfloat16_t x, y[5]; };240union union_bool { fixed_bool_t x, y[5]; };241 242// --------------------------------------------------------------------------//243// Implicit casts244 245#define TEST_CAST_COMMON(TYPE)                                              \246  sv##TYPE##_t to_sv##TYPE##_t_from_fixed(fixed_##TYPE##_t x) { return x; } \247  fixed_##TYPE##_t from_sv##TYPE##_t_to_fixed(sv##TYPE##_t x) { return x; }248 249#define TEST_CAST_GNU(PREFIX, TYPE)                                                          \250  gnu_##TYPE##_t to_gnu_##TYPE##_t_from_##PREFIX##TYPE##_t(PREFIX##TYPE##_t x) { return x; } \251  PREFIX##TYPE##_t from_gnu_##TYPE##_t_to_##PREFIX##TYPE##_t(gnu_##TYPE##_t x) { return x; }252 253#define TEST_CAST_VECTOR(TYPE) \254  TEST_CAST_COMMON(TYPE)       \255  TEST_CAST_GNU(sv, TYPE)      \256  TEST_CAST_GNU(fixed_, TYPE)257 258TEST_CAST_VECTOR(int8)259TEST_CAST_VECTOR(int16)260TEST_CAST_VECTOR(int32)261TEST_CAST_VECTOR(int64)262TEST_CAST_VECTOR(uint8)263TEST_CAST_VECTOR(uint16)264TEST_CAST_VECTOR(uint32)265TEST_CAST_VECTOR(uint64)266TEST_CAST_VECTOR(float16)267TEST_CAST_VECTOR(float32)268TEST_CAST_VECTOR(float64)269TEST_CAST_VECTOR(bfloat16)270TEST_CAST_COMMON(bool)271 272// Test the implicit conversion only applies to valid types273fixed_bool_t to_fixed_bool_t__from_svint32_t(svint32_t x) { return x; } // expected-error-re {{returning 'svint32_t' (aka '__SVInt32_t') from a function with incompatible result type 'fixed_bool_t' (vector of {{[0-9]+}} 'unsigned char' values)}}274 275// Test implicit conversion between SVE and GNU vector is invalid when276// __ARM_FEATURE_SVE_BITS != N277#if defined(__ARM_FEATURE_SVE_BITS) && __ARM_FEATURE_SVE_BITS == 512278typedef int32_t int4 __attribute__((vector_size(16)));279svint32_t badcast(int4 x) { return x; } // expected-error {{returning 'int4' (vector of 4 'int32_t' values) from a function with incompatible result type 'svint32_t' (aka '__SVInt32_t')}}280#endif281 282// Test conversion between predicate and uint8 is invalid, both have the same283// memory representation.284fixed_bool_t to_fixed_bool_t__from_svuint8_t(svuint8_t x) { return x; } // expected-error-re {{returning 'svuint8_t' (aka '__SVUint8_t') from a function with incompatible result type 'fixed_bool_t' (vector of {{[0-9]+}} 'unsigned char' values)}}285 286// --------------------------------------------------------------------------//287// Test the scalable and fixed-length types can be used interchangeably288 289svint32_t __attribute__((overloadable)) svfunc(svint32_t op1, svint32_t op2);290svfloat64_t __attribute__((overloadable)) svfunc(svfloat64_t op1, svfloat64_t op2);291svbool_t __attribute__((overloadable)) svfunc(svbool_t op1, svbool_t op2);292 293#define TEST_CALL(TYPE)                                              \294  fixed_##TYPE##_t                                                   \295      call_##TYPE##_ff(fixed_##TYPE##_t op1, fixed_##TYPE##_t op2) { \296    return svfunc(op1, op2);                                         \297  }                                                                  \298  fixed_##TYPE##_t                                                   \299      call_##TYPE##_fs(fixed_##TYPE##_t op1, sv##TYPE##_t op2) {     \300    return svfunc(op1, op2);                                         \301  }                                                                  \302  fixed_##TYPE##_t                                                   \303      call_##TYPE##_sf(sv##TYPE##_t op1, fixed_##TYPE##_t op2) {     \304    return svfunc(op1, op2);                                         \305  }306 307TEST_CALL(int32)308TEST_CALL(float64)309TEST_CALL(bool)310 311// --------------------------------------------------------------------------//312// Vector initialization313 314#if __ARM_FEATURE_SVE_BITS == 256315 316typedef svint32_t int32x8 __attribute__((arm_sve_vector_bits(N)));317typedef svfloat64_t float64x4 __attribute__((arm_sve_vector_bits(N)));318 319int32x8 foo = {1, 2, 3, 4, 5, 6, 7, 8};320int32x8 foo2 = {1, 2, 3, 4, 5, 6, 7, 8, 9}; // expected-warning{{excess elements in vector initializer}}321 322float64x4 bar = {1.0, 2.0, 3.0, 4.0};323float64x4 bar2 = {1.0, 2.0, 3.0, 4.0, 5.0}; // expected-warning{{excess elements in vector initializer}}324 325#endif326 327// --------------------------------------------------------------------------//328// Vector ops329 330#define TEST_BINARY(TYPE, NAME, OP)                  \331  TYPE NAME##_##TYPE(TYPE op1, TYPE op2) {           \332    return op1 OP op2;                               \333  }                                                  \334  TYPE compound##NAME##_##TYPE(TYPE op1, TYPE op2) { \335    op1 OP##= op2;                                   \336    return op1;                                      \337  }338 339#define TEST_COMPARISON(TYPE, NAME, OP)    \340  TYPE NAME##_##TYPE(TYPE op1, TYPE op2) { \341    return op1 OP op2;                     \342  }343 344#define TEST_UNARY(TYPE, NAME, OP) \345  TYPE NAME##_##TYPE(TYPE op1) {   \346    return OP op1;                 \347  }348 349#define TEST_OPS(TYPE)           \350  TEST_BINARY(TYPE, add, +)      \351  TEST_BINARY(TYPE, sub, -)      \352  TEST_BINARY(TYPE, mul, *)      \353  TEST_BINARY(TYPE, div, /)      \354  TEST_COMPARISON(TYPE, eq, ==)  \355  TEST_COMPARISON(TYPE, ne, !=)  \356  TEST_COMPARISON(TYPE, lt, <)   \357  TEST_COMPARISON(TYPE, gt, >)   \358  TEST_COMPARISON(TYPE, lte, <=) \359  TEST_COMPARISON(TYPE, gte, >=) \360  TEST_UNARY(TYPE, nop, +)       \361  TEST_UNARY(TYPE, neg, -)362 363#define TEST_INT_OPS(TYPE)   \364  TEST_OPS(TYPE)             \365  TEST_BINARY(TYPE, mod, %)  \366  TEST_BINARY(TYPE, and, &)  \367  TEST_BINARY(TYPE, or, |)   \368  TEST_BINARY(TYPE, xor, ^)  \369  TEST_BINARY(TYPE, shl, <<) \370  TEST_BINARY(TYPE, shr, <<) \371  TEST_UNARY(TYPE, not, ~)372 373TEST_INT_OPS(fixed_int8_t)374TEST_INT_OPS(fixed_int16_t)375TEST_INT_OPS(fixed_int32_t)376TEST_INT_OPS(fixed_int64_t)377TEST_INT_OPS(fixed_uint8_t)378TEST_INT_OPS(fixed_uint16_t)379TEST_INT_OPS(fixed_uint32_t)380TEST_INT_OPS(fixed_uint64_t)381 382TEST_OPS(fixed_float16_t)383TEST_OPS(fixed_float32_t)384TEST_OPS(fixed_float64_t)385 386// --------------------------------------------------------------------------//387// Streaming388__arm_locally_streaming void locally_streaming() {389  svint8_t t1 = extern_int8; // streamingdifferent-error {{cannot be used in a streaming function}}390  svbool_t t2 = extern_bool; // streamingdifferent-error {{cannot be used in a streaming function}}391  void* t3 = extern_int8_ptr;392}393void streaming(void) __arm_streaming {394  svint8_t t1 = extern_int8; // streamingdifferent-error {{cannot be used in a streaming function}}395  svbool_t t2 = extern_bool; // streamingdifferent-error {{cannot be used in a streaming function}}396  void* t3 = extern_int8_ptr;397}398void streaming_compatible(void) __arm_streaming_compatible {399  svint8_t t1 = extern_int8; // streamingdifferent-error {{cannot be used in a streaming-compatible function}} \400                             // streamingdifferent-error {{initializing}}401  svbool_t t2 = extern_bool; // streamingdifferent-error {{cannot be used in a streaming-compatible function}} \402                             // streamingdifferent-error {{initializing}}403  void* t3 = extern_int8_ptr;404}405__arm_locally_streaming void locally_streaming_arg(fixed_int8_t x) {} // streamingdifferent-error {{cannot be used in a streaming function}}406