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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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’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 typedef int v4si __attribute__((vector_size(16))); | 206 typedef int v4s __attribute__((vector_size(16))); |
207 v4si a = {1,2,3,4}; | 207 v4s a = {1,2,3,4}; |
208 v4si b = {5,6,7,8}; | 208 v4s b = {5,6,7,8}; |
209 v4si c, d, e; | 209 v4s c, d, e; |
210 c = b + 1; /* c = b + {1,1,1,1}; */ | 210 c = b + 1; /* c = b + {1,1,1,1}; */ |
211 d = 2 * b; /* d = {2,2,2,2} * b; */ | 211 d = 2 * b; /* d = {2,2,2,2} * b; */ |
212 e = c + d; | 212 e = c + d; |
213 </pre> | 213 </pre> |
214 <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 |
215 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> |
216 <pre class="prettyprint"> | 216 <pre class="prettyprint"> |
217 typedef int v4si __attribute__((vector_size(16))); | 217 typedef int v4s __attribute__((vector_size(16))); |
218 v4si snip(v2si in) { | 218 v4s snip(v4s in) { |
219 v4si limit = {32,64,128,256}; | 219 v4s limit = {32,64,128,256}; |
220 vs4i mask = in > limit; | 220 v4s mask = in > limit; |
221 vs4i ret = in & mask; | 221 v4s ret = in & mask; |
222 return ret; | 222 return ret; |
223 } | 223 } |
224 </pre> | 224 </pre> |
225 <p>Vector datatypes are currently expected to be 128-bit wide with one of | 225 <p>Vector datatypes are currently expected to be 128-bit wide with one of |
226 the following element types:</p> | 226 the following element types:</p> |
227 <table border="1" class="docutils"> | 227 <table border="1" class="docutils"> |
228 <colgroup> | 228 <colgroup> |
229 </colgroup> | 229 </colgroup> |
230 <thead valign="bottom"> | 230 <thead valign="bottom"> |
231 <tr class="row-odd"><th class="head">Type</th> | 231 <tr class="row-odd"><th class="head">Type</th> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 <tr class="row-odd"><td><code>>></code>, <code><<</code></td> | 282 <tr class="row-odd"><td><code>>></code>, <code><<</code></td> |
283 </tr> | 283 </tr> |
284 <tr class="row-even"><td><code>!</code>, <code>&&</code>, <code>||</code ></td> | 284 <tr class="row-even"><td><code>!</code>, <code>&&</code>, <code>||</code ></td> |
285 </tr> | 285 </tr> |
286 <tr class="row-odd"><td><code>==</code>, <code>!=</code>, <code>></code>, <co de><</code>, <code>>=</code>, <code><=</code></td> | 286 <tr class="row-odd"><td><code>==</code>, <code>!=</code>, <code>></code>, <co de><</code>, <code>>=</code>, <code><=</code></td> |
287 </tr> | 287 </tr> |
288 <tr class="row-even"><td><code>=</code></td> | 288 <tr class="row-even"><td><code>=</code></td> |
289 </tr> | 289 </tr> |
290 </tbody> | 290 </tbody> |
291 </table> | 291 </table> |
292 <p>Furthermore, C-style casts can be used for:</p> | 292 <p>C-style casts can be used to convert one vector type to another without |
293 <ul class="small-gap"> | 293 modifying the underlying bits. <code>__builtin_convertvector</code> can be used |
294 <li>Truncation.</li> | 294 to convert from one type to another.</p> |
295 <li>Zero- and sign-extension.</li> | 295 <pre class="prettyprint"> |
296 <li>Conversion to/from floating-point and signed/unsigned integer.</li> | 296 typedef unsigned v4u __attribute__((vector_size(16))); |
297 </ul> | 297 typedef float v4f __attribute__((vector_size(16))); |
298 v4u a = {0,0x40000000,0x40490fdb,0x66ff0c30}; | |
299 v4f b = (v4f) a; /* b = {0,2,3.14159,6.02214e+23} */ | |
300 v4u c = __builtin_convertvector(b, v4u); /* c = {0,2,3,0} */ | |
nfullagar1
2014/04/28 17:35:23
It would be useful if both the example and comment
JF
2014/04/28 17:42:54
Done.
| |
301 </pre> | |
298 <p>It is also possible to use array-style indexing into vectors to extract | 302 <p>It is also possible to use array-style indexing into vectors to extract |
299 individual elements using <code>[]</code>.</p> | 303 individual elements using <code>[]</code>.</p> |
304 <pre class="prettyprint"> | |
305 typedef unsigned v4u __attribute__((vector_size(16))); | |
306 template<typename T> | |
307 void print(const T v) { | |
308 for (size_t i = 0; i != sizeof(v) / sizeof(v[0]); ++i) | |
309 std::cout << v[i] << ' '; | |
310 std::cout << std::endl; | |
311 } | |
312 </pre> | |
300 <p>Vector shuffles are currently unsupported but will be added soon.</p> | 313 <p>Vector shuffles are currently unsupported but will be added soon.</p> |
301 </section><section id="auto-vectorization"> | 314 </section><section id="auto-vectorization"> |
302 <h3 id="auto-vectorization">Auto-Vectorization</h3> | 315 <h3 id="auto-vectorization">Auto-Vectorization</h3> |
303 <p>Auto-vectorization is currently not enabled for Portable Native Client, | 316 <p>Auto-vectorization is currently not enabled for Portable Native Client, |
304 but will be in a future release.</p> | 317 but will be in a future release.</p> |
305 </section></section><section id="undefined-behavior"> | 318 </section></section><section id="undefined-behavior"> |
306 <h2 id="undefined-behavior">Undefined Behavior</h2> | 319 <h2 id="undefined-behavior">Undefined Behavior</h2> |
307 <p>The C and C++ languages expose some undefined behavior which is | 320 <p>The C and C++ languages expose some undefined behavior which is |
308 discussed in <a class="reference internal" href="/native-client/reference/pnacl- undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a >.</p> | 321 discussed in <a class="reference internal" href="/native-client/reference/pnacl- undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a >.</p> |
309 </section><section id="floating-point"> | 322 </section><section id="floating-point"> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 <p>Neither PNaCl nor NaCl currently support asynchronous interruption | 388 <p>Neither PNaCl nor NaCl currently support asynchronous interruption |
376 or suspension of threads.</p> | 389 or suspension of threads.</p> |
377 </li> | 390 </li> |
378 </ul> | 391 </ul> |
379 <p>If PNaCl were to support either of these, the interaction of | 392 <p>If PNaCl were to support either of these, the interaction of |
380 <code>volatile</code> and atomics with same-thread signal handling would need | 393 <code>volatile</code> and atomics with same-thread signal handling would need |
381 to be carefully detailed.</p> | 394 to be carefully detailed.</p> |
382 </section></section></section> | 395 </section></section></section> |
383 | 396 |
384 {{/partials.standard_nacl_article}} | 397 {{/partials.standard_nacl_article}} |
OLD | NEW |