| OLD | NEW |
| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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’t require any | 202 are well supported by different hardware platforms and don’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 #define VECTOR_BYTES 16 | 206 #define VECTOR_BYTES 16 |
| 207 typedef int v4s __attribute__((vector_size(VECTOR_BYTES))); | 207 typedef int v4s __attribute__((vector_size(VECTOR_BYTES))); |
| 208 v4s a = {1,2,3,4}; | 208 v4s a = {1,2,3,4}; |
| 209 v4s b = {5,6,7,8}; | 209 v4s b = {5,6,7,8}; |
| 210 v4s c, d, e; | 210 v4s c, d, e; |
| 211 c = b + 1; /* c = b + {1,1,1,1}; */ | 211 c = a + b; /* c = {6,8,10,12} */ |
| 212 d = 2 * b; /* d = {2,2,2,2} * b; */ | 212 d = b >> a; /* d = {2,1,0,0} */ |
| 213 e = c + d; | |
| 214 </pre> | 213 </pre> |
| 215 <p>Vector comparisons are represented as a bitmask as wide as the compared | 214 <p>Vector comparisons are represented as a bitmask as wide as the compared |
| 216 elements of all <code>0</code> or all <code>1</code>:</p> | 215 elements of all <code>0</code> or all <code>1</code>:</p> |
| 217 <pre class="prettyprint"> | 216 <pre class="prettyprint"> |
| 218 typedef int v4s __attribute__((vector_size(16))); | 217 typedef int v4s __attribute__((vector_size(16))); |
| 219 v4s snip(v4s in) { | 218 v4s snip(v4s in) { |
| 220 v4s limit = {32,64,128,256}; | 219 v4s limit = {32,64,128,256}; |
| 221 v4s mask = in > limit; | 220 v4s mask = in > limit; |
| 222 v4s ret = in & mask; | 221 v4s ret = in & mask; |
| 223 return ret; | 222 return ret; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 <code>vec2</code>. An index of <code>-1</code> can be used to indicate that the | 323 <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 | 324 corresponding element in the returned vector is a don’t care and can be |
| 326 optimized by the backend.</p> | 325 optimized by the backend.</p> |
| 327 <p>The result of <code>__builtin_shufflevector</code> is a vector with the same | 326 <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 | 327 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> | 328 to the number of indices specified.</p> |
| 330 <pre class="prettyprint"> | 329 <pre class="prettyprint"> |
| 331 // identity operation - return 4-element vector v1. | 330 // identity operation - return 4-element vector v1. |
| 332 __builtin_shufflevector(v1, v1, 0, 1, 2, 3) | 331 __builtin_shufflevector(v1, v1, 0, 1, 2, 3) |
| 333 | 332 |
| 334 // "Splat" element 0 of V1 into a 4-element result. | 333 // "Splat" element 0 of v1 into a 4-element result. |
| 335 __builtin_shufflevector(V1, V1, 0, 0, 0, 0) | 334 __builtin_shufflevector(v1, v1, 0, 0, 0, 0) |
| 336 | 335 |
| 337 // Reverse 4-element vector V1. | 336 // Reverse 4-element vector v1. |
| 338 __builtin_shufflevector(V1, V1, 3, 2, 1, 0) | 337 __builtin_shufflevector(v1, v1, 3, 2, 1, 0) |
| 339 | 338 |
| 340 // Concatenate every other element of 4-element vectors V1 and V2. | 339 // Concatenate every other element of 4-element vectors v1 and v2. |
| 341 __builtin_shufflevector(V1, V2, 0, 2, 4, 6) | 340 __builtin_shufflevector(v1, v2, 0, 2, 4, 6) |
| 342 | 341 |
| 343 // Concatenate every other element of 8-element vectors V1 and V2. | 342 // Concatenate every other element of 8-element vectors v1 and v2. |
| 344 __builtin_shufflevector(V1, V2, 0, 2, 4, 6, 8, 10, 12, 14) | 343 __builtin_shufflevector(v1, v2, 0, 2, 4, 6, 8, 10, 12, 14) |
| 345 | 344 |
| 346 // Shuffle v1 with some elements being undefined | 345 // Shuffle v1 with some elements being undefined |
| 347 __builtin_shufflevector(v1, v1, 3, -1, 1, -1) | 346 __builtin_shufflevector(v1, v1, 3, -1, 1, -1) |
| 348 </pre> | 347 </pre> |
| 348 <p>One common use of <code>__builtin_shufflevector</code> is to perform |
| 349 vector-scalar operations:</p> |
| 350 <pre class="prettyprint"> |
| 351 typedef int v4s __attribute__((vector_size(16))); |
| 352 v4s shift_right_by(v4s shift_me, int shift_amount) { |
| 353 v4s tmp = {shift_amount}; |
| 354 return shift_me >> __builtin_shuffle_vector(tmp, tmp, 0, 0, 0, 0); |
| 355 } |
| 356 </pre> |
| 349 </section><section id="auto-vectorization"> | 357 </section><section id="auto-vectorization"> |
| 350 <h3 id="auto-vectorization">Auto-Vectorization</h3> | 358 <h3 id="auto-vectorization">Auto-Vectorization</h3> |
| 351 <p>Auto-vectorization is currently not enabled for Portable Native Client, | 359 <p>Auto-vectorization is currently not enabled for Portable Native Client, |
| 352 but will be in a future release.</p> | 360 but will be in a future release.</p> |
| 353 </section></section><section id="undefined-behavior"> | 361 </section></section><section id="undefined-behavior"> |
| 354 <h2 id="undefined-behavior">Undefined Behavior</h2> | 362 <h2 id="undefined-behavior">Undefined Behavior</h2> |
| 355 <p>The C and C++ languages expose some undefined behavior which is | 363 <p>The C and C++ languages expose some undefined behavior which is |
| 356 discussed in <a class="reference internal" href="/native-client/reference/pnacl-
undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a
>.</p> | 364 discussed in <a class="reference internal" href="/native-client/reference/pnacl-
undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a
>.</p> |
| 357 </section><section id="floating-point"> | 365 </section><section id="floating-point"> |
| 358 <h2 id="floating-point">Floating-Point</h2> | 366 <h2 id="floating-point">Floating-Point</h2> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 <p>Neither PNaCl nor NaCl currently support asynchronous interruption | 431 <p>Neither PNaCl nor NaCl currently support asynchronous interruption |
| 424 or suspension of threads.</p> | 432 or suspension of threads.</p> |
| 425 </li> | 433 </li> |
| 426 </ul> | 434 </ul> |
| 427 <p>If PNaCl were to support either of these, the interaction of | 435 <p>If PNaCl were to support either of these, the interaction of |
| 428 <code>volatile</code> and atomics with same-thread signal handling would need | 436 <code>volatile</code> and atomics with same-thread signal handling would need |
| 429 to be carefully detailed.</p> | 437 to be carefully detailed.</p> |
| 430 </section></section></section> | 438 </section></section></section> |
| 431 | 439 |
| 432 {{/partials.standard_nacl_article}} | 440 {{/partials.standard_nacl_article}} |
| OLD | NEW |