Commit 55444b73 authored by jfb@chromium.org's avatar jfb@chromium.org

PNaCl SIMD documentation: fix vector-scalar examples, currently unsupported by LLVM

R= dschuff@chromium.org
TEST= none
BUG= https://code.google.com/p/nativeclient/issues/detail?id=2205
NOTRY=true
(documentation only change)

Review URL: https://codereview.chromium.org/293093004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272339 0039d316-1c4b-4281-b951-d872f2087c98
parent c07c5633
...@@ -211,9 +211,8 @@ typedef int v4s __attribute__((vector_size(VECTOR_BYTES))); ...@@ -211,9 +211,8 @@ typedef int v4s __attribute__((vector_size(VECTOR_BYTES)));
v4s a = {1,2,3,4}; v4s a = {1,2,3,4};
v4s b = {5,6,7,8}; v4s b = {5,6,7,8};
v4s c, d, e; v4s c, d, e;
c = b + 1; /* c = b + {1,1,1,1}; */ c = a + b; /* c = {6,8,10,12} */
d = 2 * b; /* d = {2,2,2,2} * b; */ d = b >> a; /* d = {2,1,0,0} */
e = c + d;
</pre> </pre>
<p>Vector comparisons are represented as a bitmask as wide as the compared <p>Vector comparisons are represented as a bitmask as wide as the compared
elements of all <code>0</code> or all <code>1</code>:</p> elements of all <code>0</code> or all <code>1</code>:</p>
...@@ -334,21 +333,30 @@ to the number of indices specified.</p> ...@@ -334,21 +333,30 @@ to the number of indices specified.</p>
// identity operation - return 4-element vector v1. // identity operation - return 4-element vector v1.
__builtin_shufflevector(v1, v1, 0, 1, 2, 3) __builtin_shufflevector(v1, v1, 0, 1, 2, 3)
// &quot;Splat&quot; element 0 of V1 into a 4-element result. // &quot;Splat&quot; element 0 of v1 into a 4-element result.
__builtin_shufflevector(V1, V1, 0, 0, 0, 0) __builtin_shufflevector(v1, v1, 0, 0, 0, 0)
// Reverse 4-element vector V1. // Reverse 4-element vector v1.
__builtin_shufflevector(V1, V1, 3, 2, 1, 0) __builtin_shufflevector(v1, v1, 3, 2, 1, 0)
// Concatenate every other element of 4-element vectors V1 and V2. // Concatenate every other element of 4-element vectors v1 and v2.
__builtin_shufflevector(V1, V2, 0, 2, 4, 6) __builtin_shufflevector(v1, v2, 0, 2, 4, 6)
// Concatenate every other element of 8-element vectors V1 and V2. // Concatenate every other element of 8-element vectors v1 and v2.
__builtin_shufflevector(V1, V2, 0, 2, 4, 6, 8, 10, 12, 14) __builtin_shufflevector(v1, v2, 0, 2, 4, 6, 8, 10, 12, 14)
// Shuffle v1 with some elements being undefined // Shuffle v1 with some elements being undefined
__builtin_shufflevector(v1, v1, 3, -1, 1, -1) __builtin_shufflevector(v1, v1, 3, -1, 1, -1)
</pre> </pre>
<p>One common use of <code>__builtin_shufflevector</code> is to perform
vector-scalar operations:</p>
<pre class="prettyprint">
typedef int v4s __attribute__((vector_size(16)));
v4s shift_right_by(v4s shift_me, int shift_amount) {
v4s tmp = {shift_amount};
return shift_me &gt;&gt; __builtin_shuffle_vector(tmp, tmp, 0, 0, 0, 0);
}
</pre>
</section><section id="auto-vectorization"> </section><section id="auto-vectorization">
<h3 id="auto-vectorization">Auto-Vectorization</h3> <h3 id="auto-vectorization">Auto-Vectorization</h3>
<p>Auto-vectorization is currently not enabled for Portable Native Client, <p>Auto-vectorization is currently not enabled for Portable Native Client,
......
...@@ -236,9 +236,8 @@ Vector types can be used through the ``vector_size`` attribute: ...@@ -236,9 +236,8 @@ Vector types can be used through the ``vector_size`` attribute:
v4s a = {1,2,3,4}; v4s a = {1,2,3,4};
v4s b = {5,6,7,8}; v4s b = {5,6,7,8};
v4s c, d, e; v4s c, d, e;
c = b + 1; /* c = b + {1,1,1,1}; */ c = a + b; /* c = {6,8,10,12} */
d = 2 * b; /* d = {2,2,2,2} * b; */ d = b >> a; /* d = {2,1,0,0} */
e = c + d;
Vector comparisons are represented as a bitmask as wide as the compared Vector comparisons are represented as a bitmask as wide as the compared
elements of all ``0`` or all ``1``: elements of all ``0`` or all ``1``:
...@@ -339,21 +338,32 @@ to the number of indices specified. ...@@ -339,21 +338,32 @@ to the number of indices specified.
// identity operation - return 4-element vector v1. // identity operation - return 4-element vector v1.
__builtin_shufflevector(v1, v1, 0, 1, 2, 3) __builtin_shufflevector(v1, v1, 0, 1, 2, 3)
// "Splat" element 0 of V1 into a 4-element result. // "Splat" element 0 of v1 into a 4-element result.
__builtin_shufflevector(V1, V1, 0, 0, 0, 0) __builtin_shufflevector(v1, v1, 0, 0, 0, 0)
// Reverse 4-element vector V1. // Reverse 4-element vector v1.
__builtin_shufflevector(V1, V1, 3, 2, 1, 0) __builtin_shufflevector(v1, v1, 3, 2, 1, 0)
// Concatenate every other element of 4-element vectors V1 and V2. // Concatenate every other element of 4-element vectors v1 and v2.
__builtin_shufflevector(V1, V2, 0, 2, 4, 6) __builtin_shufflevector(v1, v2, 0, 2, 4, 6)
// Concatenate every other element of 8-element vectors V1 and V2. // Concatenate every other element of 8-element vectors v1 and v2.
__builtin_shufflevector(V1, V2, 0, 2, 4, 6, 8, 10, 12, 14) __builtin_shufflevector(v1, v2, 0, 2, 4, 6, 8, 10, 12, 14)
// Shuffle v1 with some elements being undefined // Shuffle v1 with some elements being undefined
__builtin_shufflevector(v1, v1, 3, -1, 1, -1) __builtin_shufflevector(v1, v1, 3, -1, 1, -1)
One common use of ``__builtin_shufflevector`` is to perform
vector-scalar operations:
.. naclcode::
typedef int v4s __attribute__((vector_size(16)));
v4s shift_right_by(v4s shift_me, int shift_amount) {
v4s tmp = {shift_amount};
return shift_me >> __builtin_shuffle_vector(tmp, tmp, 0, 0, 0, 0);
}
Auto-Vectorization Auto-Vectorization
------------------ ------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment