From: Anton Yartsev
Supports the GCC vector extensions, plus some stuff like V[1].
+Supports the GCC, OpenCL, AltiVec and NEON vector extensions.
-Also supports ext_vector, which additionally support for V.xyzw -syntax and other tidbits as seen in OpenCL. An example is:
+OpenCL vector types are created using ext_vector_type attribute. It +support for V.xyzw syntax and other tidbits as seen in OpenCL. An example +is:@@ -405,6 +406,159 @@ float4 foo(float2 a, float2 b) {Query for this feature with __has_extension(attribute_ext_vector_type).
+Giving -faltivec option to clang enables support for AltiVec vector syntax +and functions. For example:
+ +++ ++vector float foo(vector int a) { + vector int b; + b = vec_add(a, a) + a; + return (vector float)b; +} ++NEON vector types are created using neon_vector_type and +neon_polyvector_type attributes. For example:
+ +++ + ++typedef __attribute__((neon_vector_type(8))) int8_t int8x8_t; +typedef __attribute__((neon_polyvector_type(16))) poly8_t poly8x16_t; + +int8x8_t foo(int8x8_t a) { + int8x8_t v; + v = a; + return v; +} ++Vector Literals
+ + +Vector literals can be used to create vectors from a set of scalars, or +vectors. Either parentheses or braces form can be used. In the parentheses form +the number of literal values specified must be one, i.e. referring to a scalar +value, or must match the size of the vector type being created. If a single +scalar literal value is specified, the scalar literal value will be replicated +to all the components of the vector type. In the brackets form any number of +literals can be specified. For example:
+ +++ + ++typedef int v4si __attribute__((__vector_size__(16))); +typedef float float4 __attribute__((ext_vector_type(4))); +typedef float float2 __attribute__((ext_vector_type(2))); + +v4si vsi = (v4si){1, 2, 3, 4}; +float4 vf = (float4)(1.0f, 2.0f, 3.0f, 4.0f); +vector int vi1 = (vector int)(1); // vi1 will be (1, 1, 1, 1). +vector int vi2 = (vector int){1}; // vi2 will be (1, 0, 0, 0). +vector int vi3 = (vector int)(1, 2); // error +vector int vi4 = (vector int){1, 2}; // vi4 will be (1, 2, 0, 0). +vector int vi5 = (vector int)(1, 2, 3, 4); +float4 vf = (float4)((float2)(1.0f, 2.0f), (float2)(3.0f, 4.0f)); ++Vector Operations
+ + +The table below shows the support for each operation by vector extension. +A dash indicates that an operation is not accepted according to a corresponding +specification.
+ ++
++ +Operator +OpenCL +AltiVec +GCC +NEON ++ +[] +yes +yes +yes +- ++ +unary operators +, - +yes +yes +yes +- ++ +++, -- +yes +yes +- +- ++ ++, -, *, /, % +yes +yes +yes +- ++ +bitwise operators &, |, ^, ~ +yes +yes +yes +- ++ +>>, << +yes +yes +yes +- ++ +!, &&,|| +no +- +- +- ++ +==,!=, >, <, >=, <= +yes +yes +- +- ++ += +yes +yes +yes +yes ++ +:? +yes +- +- +- ++ +sizeof +yes +yes +yes +yes +See also __builtin_shufflevector.