From: Anton Yartsev Date: Sun, 15 Jan 2012 16:22:24 +0000 (+0000) Subject: added descriptions of vector extensions, info about vector literals and vector operat... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da90c77753f154014daca79e24e1bbabb4612dcf;p=clang added descriptions of vector extensions, info about vector literals and vector operations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148220 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LanguageExtensions.html b/docs/LanguageExtensions.html index 1eeea604f6..5ba2c9711d 100644 --- a/docs/LanguageExtensions.html +++ b/docs/LanguageExtensions.html @@ -384,10 +384,11 @@ is used in the file argument.

Vectors and Extended Vectors

-

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.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OperatorOpenCLAltiVecGCCNEON
[]yesyesyes-
unary operators +, -yesyesyes-
++, --yesyes--
+, -, *, /, %yesyesyes-
bitwise operators &, |, ^, ~yesyesyes-
>>, <<yesyesyes-
!, &&,||no---
==,!=, >, <, >=, <=yesyes--
=yesyesyesyes
:?yes---
sizeofyesyesyesyes
+

See also __builtin_shufflevector.