Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1308)

Unified Diff: native_client_sdk/doc_generated/reference/pnacl-c-cpp-language-support.html

Issue 265163004: NaCl documentation: update vector documentation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/doc_generated/reference/pnacl-c-cpp-language-support.html
diff --git a/native_client_sdk/doc_generated/reference/pnacl-c-cpp-language-support.html b/native_client_sdk/doc_generated/reference/pnacl-c-cpp-language-support.html
index 5fc75ec1b9a35bba72c2d63527055f7ed9ea61f0..e1914784cd096104aebcb198944367daaca34a1a 100644
--- a/native_client_sdk/doc_generated/reference/pnacl-c-cpp-language-support.html
+++ b/native_client_sdk/doc_generated/reference/pnacl-c-cpp-language-support.html
@@ -203,7 +203,8 @@ are well supported by different hardware platforms and don’t require any
new compiler intrinsics.</p>
<p>Vector types can be used through the <code>vector_size</code> attribute:</p>
<pre class="prettyprint">
-typedef int v4s __attribute__((vector_size(16)));
+#define VECTOR_BYTES 16
+typedef int v4s __attribute__((vector_size(VECTOR_BYTES)));
v4s a = {1,2,3,4};
v4s b = {5,6,7,8};
v4s c, d, e;
@@ -312,7 +313,39 @@ void print(const T v) {
std::cout &lt;&lt; std::endl;
}
</pre>
-<p>Vector shuffles are currently unsupported but will be added soon.</p>
+<p>Vector shuffles (often called permutation or swizzle) operations are
+supported through <code>__builtin_shufflevector</code>. The builtin has two
+vector arguments of the same element type, followed by a list of
+constant integers that specify the elements indices of the first two
+vectors that should be extracted and returned in a new vector. These
+element indices are numbered sequentially starting with the first
+vector, continuing into the second vector. Thus, if <code>vec1</code> is a
+4-element vector, index <code>5</code> would refer to the second element of
+<code>vec2</code>. An index of <code>-1</code> can be used to indicate that the
+corresponding element in the returned vector is a don’t care and can be
+optimized by the backend.</p>
+<p>The result of <code>__builtin_shufflevector</code> is a vector with the same
+element type as <code>vec1</code> / <code>vec2</code> but that has an element count equal
+to the number of indices specified.</p>
+<pre class="prettyprint">
+// identity operation - return 4-element vector v1.
+__builtin_shufflevector(v1, v1, 0, 1, 2, 3)
+
+// &quot;Splat&quot; element 0 of V1 into a 4-element result.
+__builtin_shufflevector(V1, V1, 0, 0, 0, 0)
+
+// Reverse 4-element vector V1.
+__builtin_shufflevector(V1, V1, 3, 2, 1, 0)
+
+// Concatenate every other element of 4-element vectors V1 and V2.
+__builtin_shufflevector(V1, V2, 0, 2, 4, 6)
+
+// Concatenate every other element of 8-element vectors V1 and V2.
+__builtin_shufflevector(V1, V2, 0, 2, 4, 6, 8, 10, 12, 14)
+
+// Shuffle v1 with some elements being undefined
+__builtin_shufflevector(v1, v1, 3, -1, 1, -1)
+</pre>
</section><section id="auto-vectorization">
<h3 id="auto-vectorization">Auto-Vectorization</h3>
<p>Auto-vectorization is currently not enabled for Portable Native Client,

Powered by Google App Engine
This is Rietveld 408576698