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

Side by Side 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: Clarify vector width. Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 {{+bindTo:partials.standard_nacl_article}} 1 {{+bindTo:partials.standard_nacl_article}}
2 2
3 <section id="pnacl-c-c-language-support"> 3 <section id="pnacl-c-c-language-support">
4 <h1 id="pnacl-c-c-language-support">PNaCl C/C++ Language Support</h1> 4 <h1 id="pnacl-c-c-language-support">PNaCl C/C++ Language Support</h1>
5 <div class="contents local" id="contents" style="display: none"> 5 <div class="contents local" id="contents" style="display: none">
6 <ul class="small-gap"> 6 <ul class="small-gap">
7 <li><p class="first"><a class="reference internal" href="#source-language-suppor t" id="id3">Source language support</a></p> 7 <li><p class="first"><a class="reference internal" href="#source-language-suppor t" id="id3">Source language support</a></p>
8 <ul class="small-gap"> 8 <ul class="small-gap">
9 <li><a class="reference internal" href="#versions" id="id4">Versions</a></li> 9 <li><a class="reference internal" href="#versions" id="id4">Versions</a></li>
10 <li><a class="reference internal" href="#preprocessor-definitions" id="id5">Prep rocessor definitions</a></li> 10 <li><a class="reference internal" href="#preprocessor-definitions" id="id5">Prep rocessor definitions</a></li>
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 of Chrome, and more features are expected to be added in subsequent 196 of Chrome, and more features are expected to be added in subsequent
197 releases.</p> 197 releases.</p>
198 <section id="hand-coding-vector-extensions"> 198 <section id="hand-coding-vector-extensions">
199 <h3 id="hand-coding-vector-extensions">Hand-Coding Vector Extensions</h3> 199 <h3 id="hand-coding-vector-extensions">Hand-Coding Vector Extensions</h3>
200 <p>The initial vector support in Portable Native Client adds <a class="reference external" href="http://clang.llvm.org/docs/LanguageExtensions.html#vectors-and- extended-vectors">LLVM vectors</a> 200 <p>The initial vector support in Portable Native Client adds <a class="reference external" href="http://clang.llvm.org/docs/LanguageExtensions.html#vectors-and- extended-vectors">LLVM vectors</a>
201 and <a class="reference external" href="http://gcc.gnu.org/onlinedocs/gcc/Vector -Extensions.html">GCC vectors</a> since these 201 and <a class="reference external" href="http://gcc.gnu.org/onlinedocs/gcc/Vector -Extensions.html">GCC vectors</a> since these
202 are well supported by different hardware platforms and don&#8217;t require any 202 are well supported by different hardware platforms and don&#8217;t require any
203 new compiler intrinsics.</p> 203 new compiler intrinsics.</p>
204 <p>Vector types can be used through the <code>vector_size</code> attribute:</p> 204 <p>Vector types can be used through the <code>vector_size</code> attribute:</p>
205 <pre class="prettyprint"> 205 <pre class="prettyprint">
206 typedef int v4s __attribute__((vector_size(16))); 206 #define VECTOR_BYTES 16
207 typedef int v4s __attribute__((vector_size(VECTOR_BYTES)));
207 v4s a = {1,2,3,4}; 208 v4s a = {1,2,3,4};
208 v4s b = {5,6,7,8}; 209 v4s b = {5,6,7,8};
209 v4s c, d, e; 210 v4s c, d, e;
210 c = b + 1; /* c = b + {1,1,1,1}; */ 211 c = b + 1; /* c = b + {1,1,1,1}; */
211 d = 2 * b; /* d = {2,2,2,2} * b; */ 212 d = 2 * b; /* d = {2,2,2,2} * b; */
212 e = c + d; 213 e = c + d;
213 </pre> 214 </pre>
214 <p>Vector comparisons are represented as a bitmask as wide as the compared 215 <p>Vector comparisons are represented as a bitmask as wide as the compared
215 elements of all <code>0</code> or all <code>1</code>:</p> 216 elements of all <code>0</code> or all <code>1</code>:</p>
216 <pre class="prettyprint"> 217 <pre class="prettyprint">
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 individual elements using <code>[]</code>.</p> 306 individual elements using <code>[]</code>.</p>
306 <pre class="prettyprint"> 307 <pre class="prettyprint">
307 typedef unsigned v4u __attribute__((vector_size(16))); 308 typedef unsigned v4u __attribute__((vector_size(16)));
308 template&lt;typename T&gt; 309 template&lt;typename T&gt;
309 void print(const T v) { 310 void print(const T v) {
310 for (size_t i = 0; i != sizeof(v) / sizeof(v[0]); ++i) 311 for (size_t i = 0; i != sizeof(v) / sizeof(v[0]); ++i)
311 std::cout &lt;&lt; v[i] &lt;&lt; ' '; 312 std::cout &lt;&lt; v[i] &lt;&lt; ' ';
312 std::cout &lt;&lt; std::endl; 313 std::cout &lt;&lt; std::endl;
313 } 314 }
314 </pre> 315 </pre>
315 <p>Vector shuffles are currently unsupported but will be added soon.</p> 316 <p>Vector shuffles (often called permutation or swizzle) operations are
317 supported through <code>__builtin_shufflevector</code>. The builtin has two
318 vector arguments of the same element type, followed by a list of
319 constant integers that specify the elements indices of the first two
320 vectors that should be extracted and returned in a new vector. These
321 element indices are numbered sequentially starting with the first
322 vector, continuing into the second vector. Thus, if <code>vec1</code> is a
323 4-element vector, index <code>5</code> would refer to the second element of
324 <code>vec2</code>. An index of <code>-1</code> can be used to indicate that the
325 corresponding element in the returned vector is a don’t care and can be
326 optimized by the backend.</p>
327 <p>The result of <code>__builtin_shufflevector</code> is a vector with the same
328 element type as <code>vec1</code> / <code>vec2</code> but that has an element co unt equal
329 to the number of indices specified.</p>
330 <pre class="prettyprint">
331 // identity operation - return 4-element vector v1.
332 __builtin_shufflevector(v1, v1, 0, 1, 2, 3)
333
334 // &quot;Splat&quot; element 0 of V1 into a 4-element result.
335 __builtin_shufflevector(V1, V1, 0, 0, 0, 0)
336
337 // Reverse 4-element vector V1.
338 __builtin_shufflevector(V1, V1, 3, 2, 1, 0)
339
340 // Concatenate every other element of 4-element vectors V1 and V2.
341 __builtin_shufflevector(V1, V2, 0, 2, 4, 6)
342
343 // Concatenate every other element of 8-element vectors V1 and V2.
344 __builtin_shufflevector(V1, V2, 0, 2, 4, 6, 8, 10, 12, 14)
345
346 // Shuffle v1 with some elements being undefined
347 __builtin_shufflevector(v1, v1, 3, -1, 1, -1)
348 </pre>
316 </section><section id="auto-vectorization"> 349 </section><section id="auto-vectorization">
317 <h3 id="auto-vectorization">Auto-Vectorization</h3> 350 <h3 id="auto-vectorization">Auto-Vectorization</h3>
318 <p>Auto-vectorization is currently not enabled for Portable Native Client, 351 <p>Auto-vectorization is currently not enabled for Portable Native Client,
319 but will be in a future release.</p> 352 but will be in a future release.</p>
320 </section></section><section id="undefined-behavior"> 353 </section></section><section id="undefined-behavior">
321 <h2 id="undefined-behavior">Undefined Behavior</h2> 354 <h2 id="undefined-behavior">Undefined Behavior</h2>
322 <p>The C and C++ languages expose some undefined behavior which is 355 <p>The C and C++ languages expose some undefined behavior which is
323 discussed in <a class="reference internal" href="/native-client/reference/pnacl- undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a >.</p> 356 discussed in <a class="reference internal" href="/native-client/reference/pnacl- undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a >.</p>
324 </section><section id="floating-point"> 357 </section><section id="floating-point">
325 <h2 id="floating-point">Floating-Point</h2> 358 <h2 id="floating-point">Floating-Point</h2>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 <p>Neither PNaCl nor NaCl currently support asynchronous interruption 423 <p>Neither PNaCl nor NaCl currently support asynchronous interruption
391 or suspension of threads.</p> 424 or suspension of threads.</p>
392 </li> 425 </li>
393 </ul> 426 </ul>
394 <p>If PNaCl were to support either of these, the interaction of 427 <p>If PNaCl were to support either of these, the interaction of
395 <code>volatile</code> and atomics with same-thread signal handling would need 428 <code>volatile</code> and atomics with same-thread signal handling would need
396 to be carefully detailed.</p> 429 to be carefully detailed.</p>
397 </section></section></section> 430 </section></section></section>
398 431
399 {{/partials.standard_nacl_article}} 432 {{/partials.standard_nacl_article}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698