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

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

Issue 250433002: PNaCl documentation: add SIMD vectors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address dschuff's comments. 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 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="id2">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="id3">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="id4">Prep rocessor definitions</a></li> 10 <li><a class="reference internal" href="#preprocessor-definitions" id="id5">Prep rocessor definitions</a></li>
11 </ul> 11 </ul>
12 </li> 12 </li>
13 <li><p class="first"><a class="reference internal" href="#memory-model-and-atomi cs" id="id5">Memory Model and Atomics</a></p> 13 <li><p class="first"><a class="reference internal" href="#memory-model-and-atomi cs" id="id6">Memory Model and Atomics</a></p>
14 <ul class="small-gap"> 14 <ul class="small-gap">
15 <li><a class="reference internal" href="#memory-model-for-concurrent-operations" id="id6">Memory Model for Concurrent Operations</a></li> 15 <li><a class="reference internal" href="#memory-model-for-concurrent-operations" id="id7">Memory Model for Concurrent Operations</a></li>
16 <li><a class="reference internal" href="#atomic-memory-ordering-constraints" id= "id7">Atomic Memory Ordering Constraints</a></li> 16 <li><a class="reference internal" href="#atomic-memory-ordering-constraints" id= "id8">Atomic Memory Ordering Constraints</a></li>
17 <li><a class="reference internal" href="#volatile-memory-accesses" id="id8">Vola tile Memory Accesses</a></li> 17 <li><a class="reference internal" href="#volatile-memory-accesses" id="id9">Vola tile Memory Accesses</a></li>
18 </ul> 18 </ul>
19 </li> 19 </li>
20 <li><a class="reference internal" href="#threading" id="id9">Threading</a></li> 20 <li><a class="reference internal" href="#threading" id="id10">Threading</a></li>
21 <li><a class="reference internal" href="#setjmp-and-longjmp" id="id10"><code>set jmp</code> and <code>longjmp</code></a></li> 21 <li><a class="reference internal" href="#setjmp-and-longjmp" id="id11"><code>set jmp</code> and <code>longjmp</code></a></li>
22 <li><a class="reference internal" href="#c-exception-handling" id="id11">C++ Exc eption Handling</a></li> 22 <li><a class="reference internal" href="#c-exception-handling" id="id12">C++ Exc eption Handling</a></li>
23 <li><a class="reference internal" href="#inline-assembly" id="id12">Inline Assem bly</a></li> 23 <li><a class="reference internal" href="#inline-assembly" id="id13">Inline Assem bly</a></li>
24 <li><a class="reference internal" href="#undefined-behavior" id="id13">Undefined Behavior</a></li> 24 <li><p class="first"><a class="reference internal" href="#portable-simd-vectors" id="id14">Portable SIMD Vectors</a></p>
25 <li><a class="reference internal" href="#floating-point" id="id14">Floating-Poin t</a></li>
26 <li><a class="reference internal" href="#computed-goto" id="id15">Computed <code >goto</code></a></li>
27 <li><p class="first"><a class="reference internal" href="#future-directions" id= "id16">Future Directions</a></p>
28 <ul class="small-gap"> 25 <ul class="small-gap">
29 <li><a class="reference internal" href="#simd" id="id17">SIMD</a></li> 26 <li><a class="reference internal" href="#hand-coding-vector-extensions" id="id15 ">Hand-Coding Vector Extensions</a></li>
30 <li><a class="reference internal" href="#inter-process-communication" id="id18"> Inter-Process Communication</a></li> 27 <li><a class="reference internal" href="#auto-vectorization" id="id16">Auto-Vect orization</a></li>
31 <li><a class="reference internal" href="#posix-style-signal-handling" id="id19"> POSIX-style Signal Handling</a></li> 28 </ul>
29 </li>
30 <li><a class="reference internal" href="#undefined-behavior" id="id17">Undefined Behavior</a></li>
31 <li><a class="reference internal" href="#floating-point" id="id18">Floating-Poin t</a></li>
32 <li><a class="reference internal" href="#computed-goto" id="id19">Computed <code >goto</code></a></li>
33 <li><p class="first"><a class="reference internal" href="#future-directions" id= "id20">Future Directions</a></p>
34 <ul class="small-gap">
35 <li><a class="reference internal" href="#inter-process-communication" id="id21"> Inter-Process Communication</a></li>
36 <li><a class="reference internal" href="#posix-style-signal-handling" id="id22"> POSIX-style Signal Handling</a></li>
32 </ul> 37 </ul>
33 </li> 38 </li>
34 </ul> 39 </ul>
35 40
36 </div><section id="source-language-support"> 41 </div><section id="source-language-support">
37 <h2 id="source-language-support">Source language support</h2> 42 <h2 id="source-language-support">Source language support</h2>
38 <p>The currently supported languages are C and C++. The PNaCl toolchain is 43 <p>The currently supported languages are C and C++. The PNaCl toolchain is
39 based on recent Clang, which fully supports C++11 and most of C11. A 44 based on recent Clang, which fully supports C++11 and most of C11. A
40 detailed status of the language support is available <a class="reference externa l" href="http://clang.llvm.org/cxx_status.html">here</a>.</p> 45 detailed status of the language support is available <a class="reference externa l" href="http://clang.llvm.org/cxx_status.html">here</a>.</p>
41 <p>For information on using languages other than C/C++, see the <a class="refere nce internal" href="/native-client/faq.html#other-languages"><em>FAQ 46 <p>For information on using languages other than C/C++, see the <a class="refere nce internal" href="/native-client/faq.html#other-languages"><em>FAQ
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 <p>Inline assembly isn&#8217;t supported by PNaCl because it isn&#8217;t portabl e. The 178 <p>Inline assembly isn&#8217;t supported by PNaCl because it isn&#8217;t portabl e. The
174 one current exception is the common compiler barrier idiom 179 one current exception is the common compiler barrier idiom
175 <code>asm(&quot;&quot;:::&quot;memory&quot;)</code>, which gets transformed to a sequentially 180 <code>asm(&quot;&quot;:::&quot;memory&quot;)</code>, which gets transformed to a sequentially
176 consistent memory barrier (equivalent to <code>__sync_synchronize()</code>). In 181 consistent memory barrier (equivalent to <code>__sync_synchronize()</code>). In
177 PNaCl this barrier is only guaranteed to order <code>volatile</code> and atomic 182 PNaCl this barrier is only guaranteed to order <code>volatile</code> and atomic
178 memory accesses, though in practice the implementation attempts to also 183 memory accesses, though in practice the implementation attempts to also
179 prevent reordering of memory accesses to objects which may escape.</p> 184 prevent reordering of memory accesses to objects which may escape.</p>
180 <p>NaCl supports a fairly wide subset of inline assembly through GCC&#8217;s 185 <p>NaCl supports a fairly wide subset of inline assembly through GCC&#8217;s
181 inline assembly syntax, with the restriction that the sandboxing model 186 inline assembly syntax, with the restriction that the sandboxing model
182 for the target architecture has to be respected.</p> 187 for the target architecture has to be respected.</p>
183 </section><section id="undefined-behavior"> 188 </section><section id="portable-simd-vectors">
189 <span id="id2"></span><h2 id="portable-simd-vectors"><span id="id2"></span>Porta ble SIMD Vectors</h2>
190 <p>SIMD vectors aren&#8217;t part of the C/C++ standards and are traditionally
191 very hardware-specific. Portable Native Client offers a portable version
192 of SIMD vector datatypes and operations which map well to modern
193 architectures and offer performance which matches or approaches
194 hardware-specific uses.</p>
195 <p>SIMD vector support was added to Portable Native Client for version 36
196 of Chrome, and more features are expected to be added in subsequent
197 releases.</p>
198 <section id="hand-coding-vector-extensions">
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>
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
203 new compiler intrinsics.</p>
204 <p>Vector types can be used through the <code>vector_size</code> attribute:</p>
205 <pre class="prettyprint">
206 typedef int v4si __attribute__((vector_size(16)));
207 v4si a = {1,2,3,4};
208 v4si b = {5,6,7,8};
209 v4si c, d, e;
210 c = b + 1; /* c = b + {1,1,1,1}; */
211 d = 2 * b; /* d = {2,2,2,2} * b; */
212 e = c + d;
213 </pre>
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>
216 <pre class="prettyprint">
217 typedef int v4si __attribute__((vector_size(16)));
218 v4si snip(v2si in) {
219 v4si limit = {32,64,128,256};
220 vs4i mask = in &gt; limit;
221 vs4i ret = in &amp; mask;
222 return ret;
223 }
224 </pre>
225 <p>Vector datatypes are currently expected to be 128-bit wide with one of
226 the following element types:</p>
227 <table border="1" class="docutils">
228 <colgroup>
229 </colgroup>
230 <thead valign="bottom">
231 <tr class="row-odd"><th class="head">Type</th>
232 <th class="head">Num Elements</th>
233 <th class="head">Vector Bit Width</th>
234 </tr>
235 </thead>
236 <tbody valign="top">
237 <tr class="row-even"><td><code>uint8_t</code></td>
238 <td>16</td>
239 <td>128</td>
240 </tr>
241 <tr class="row-odd"><td><code>int8_t</code></td>
242 <td>16</td>
243 <td>128</td>
244 </tr>
245 <tr class="row-even"><td><code>uint16_t</code></td>
246 <td>8</td>
247 <td>128</td>
248 </tr>
249 <tr class="row-odd"><td><code>int16_t</code></td>
250 <td>8</td>
251 <td>128</td>
252 </tr>
253 <tr class="row-even"><td><code>uint32_t</code></td>
254 <td>4</td>
255 <td>128</td>
256 </tr>
257 <tr class="row-odd"><td><code>int32_t</code></td>
258 <td>4</td>
259 <td>128</td>
260 </tr>
261 <tr class="row-even"><td><code>float</code></td>
262 <td>4</td>
263 <td>128</td>
264 </tr>
265 </tbody>
266 </table>
267 <p>64-bit integers and double-precision floating point will be supported in
268 a future release, as will 256-bit and 512-bit vectors.</p>
269 <p>The following operators are supported on vectors:</p>
270 <table border="1" class="docutils">
271 <colgroup>
272 </colgroup>
273 <tbody valign="top">
274 <tr class="row-odd"><td>unary <code>+</code>, <code>-</code></td>
275 </tr>
276 <tr class="row-even"><td><code>++</code>, <code>--</code></td>
277 </tr>
278 <tr class="row-odd"><td><code>+</code>, <code>-</code>, <code>*</code>, <code>/< /code>, <code>%</code></td>
279 </tr>
280 <tr class="row-even"><td><code>&amp;</code>, <code>|</code>, <code>^</code>, <co de>~</code></td>
281 </tr>
282 <tr class="row-odd"><td><code>&gt;&gt;</code>, <code>&lt;&lt;</code></td>
283 </tr>
284 <tr class="row-even"><td><code>!</code>, <code>&amp;&amp;</code>, <code>||</code ></td>
285 </tr>
286 <tr class="row-odd"><td><code>==</code>, <code>!=</code>, <code>&gt;</code>, <co de>&lt;</code>, <code>&gt;=</code>, <code>&lt;=</code></td>
287 </tr>
288 <tr class="row-even"><td><code>=</code></td>
289 </tr>
290 </tbody>
291 </table>
292 <p>Furthermore, C-style casts can be used for:</p>
293 <ul class="small-gap">
294 <li>Truncation.</li>
295 <li>Zero- and sign-extension.</li>
296 <li>Conversion to/from floating-point and signed/unsigned integer.</li>
nfullagar1 2014/04/24 23:25:33 A few comments that should be addressed in a follo
297 </ul>
298 <p>It is also possible to use array-style indexing into vectors to extract
299 individual elements using <code>[]</code>.</p>
300 <p>Vector shuffles are currently unsupported but will be added soon.</p>
301 </section><section id="auto-vectorization">
302 <h3 id="auto-vectorization">Auto-Vectorization</h3>
303 <p>Auto-vectorization is currently not enabled for Portable Native Client,
304 but will be in a future release.</p>
305 </section></section><section id="undefined-behavior">
184 <h2 id="undefined-behavior">Undefined Behavior</h2> 306 <h2 id="undefined-behavior">Undefined Behavior</h2>
185 <p>The C and C++ languages expose some undefined behavior which is 307 <p>The C and C++ languages expose some undefined behavior which is
186 discussed in <a class="reference internal" href="/native-client/reference/pnacl- undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a >.</p> 308 discussed in <a class="reference internal" href="/native-client/reference/pnacl- undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a >.</p>
187 </section><section id="floating-point"> 309 </section><section id="floating-point">
188 <h2 id="floating-point">Floating-Point</h2> 310 <h2 id="floating-point">Floating-Point</h2>
189 <p>PNaCl exposes 32-bit and 64-bit floating point operations which are 311 <p>PNaCl exposes 32-bit and 64-bit floating point operations which are
190 mostly IEEE-754 compliant. There are a few caveats:</p> 312 mostly IEEE-754 compliant. There are a few caveats:</p>
191 <ul class="small-gap"> 313 <ul class="small-gap">
192 <li>Some <a class="reference internal" href="/native-client/reference/pnacl-unde fined-behavior.html#undefined-behavior-fp"><em>floating-point behavior is curren tly left as undefined</em></a>.</li> 314 <li>Some <a class="reference internal" href="/native-client/reference/pnacl-unde fined-behavior.html#undefined-behavior-fp"><em>floating-point behavior is curren tly left as undefined</em></a>.</li>
193 <li>The default rounding mode is round-to-nearest and other rounding modes 315 <li>The default rounding mode is round-to-nearest and other rounding modes
(...skipping 25 matching lines...) Expand all
219 <p>PNaCl supports computed <code>goto</code>, a non-standard GCC extension to C used 341 <p>PNaCl supports computed <code>goto</code>, a non-standard GCC extension to C used
220 by some interpreters, by lowering them to <code>switch</code> statements. The 342 by some interpreters, by lowering them to <code>switch</code> statements. The
221 resulting use of <code>switch</code> might not be as fast as the original 343 resulting use of <code>switch</code> might not be as fast as the original
222 indirect branches. If you are compiling a program that has a 344 indirect branches. If you are compiling a program that has a
223 compile-time option for using computed <code>goto</code>, it&#8217;s possible th at the 345 compile-time option for using computed <code>goto</code>, it&#8217;s possible th at the
224 program will run faster with the option turned off (e.g., if the program 346 program will run faster with the option turned off (e.g., if the program
225 does extra work to take advantage of computed <code>goto</code>).</p> 347 does extra work to take advantage of computed <code>goto</code>).</p>
226 <p>NaCl supports computed <code>goto</code> without any transformation.</p> 348 <p>NaCl supports computed <code>goto</code> without any transformation.</p>
227 </section><section id="future-directions"> 349 </section><section id="future-directions">
228 <h2 id="future-directions">Future Directions</h2> 350 <h2 id="future-directions">Future Directions</h2>
229 <section id="simd"> 351 <section id="inter-process-communication">
230 <h3 id="simd">SIMD</h3>
231 <p>PNaCl currently doesn&#8217;t support SIMD. We plan to add SIMD support in th e
232 very near future.</p>
233 <p>NaCl supports SIMD.</p>
234 </section><section id="inter-process-communication">
235 <h3 id="inter-process-communication">Inter-Process Communication</h3> 352 <h3 id="inter-process-communication">Inter-Process Communication</h3>
236 <p>Inter-process communication through shared memory is currently not 353 <p>Inter-process communication through shared memory is currently not
237 supported by PNaCl/NaCl. When implemented, it may be limited to 354 supported by PNaCl/NaCl. When implemented, it may be limited to
238 operations which are lock-free on the current platform (<code>is_lock_free</code > 355 operations which are lock-free on the current platform (<code>is_lock_free</code >
239 methods). It will rely on the address-free properly discussed in <a class="refer ence internal" href="#memory-model-for-concurrent-operations">Memory 356 methods). It will rely on the address-free properly discussed in <a class="refer ence internal" href="#memory-model-for-concurrent-operations">Memory
240 Model for Concurrent Operations</a>.</p> 357 Model for Concurrent Operations</a>.</p>
241 </section><section id="posix-style-signal-handling"> 358 </section><section id="posix-style-signal-handling">
242 <h3 id="posix-style-signal-handling">POSIX-style Signal Handling</h3> 359 <h3 id="posix-style-signal-handling">POSIX-style Signal Handling</h3>
243 <p>POSIX-style signal handling really consists of two different features:</p> 360 <p>POSIX-style signal handling really consists of two different features:</p>
244 <ul class="small-gap"> 361 <ul class="small-gap">
(...skipping 13 matching lines...) Expand all
258 <p>Neither PNaCl nor NaCl currently support asynchronous interruption 375 <p>Neither PNaCl nor NaCl currently support asynchronous interruption
259 or suspension of threads.</p> 376 or suspension of threads.</p>
260 </li> 377 </li>
261 </ul> 378 </ul>
262 <p>If PNaCl were to support either of these, the interaction of 379 <p>If PNaCl were to support either of these, the interaction of
263 <code>volatile</code> and atomics with same-thread signal handling would need 380 <code>volatile</code> and atomics with same-thread signal handling would need
264 to be carefully detailed.</p> 381 to be carefully detailed.</p>
265 </section></section></section> 382 </section></section></section>
266 383
267 {{/partials.standard_nacl_article}} 384 {{/partials.standard_nacl_article}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698